summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorronso0 <ronso0@mixxx.org>2020-12-14 14:28:19 +0100
committerronso0 <ronso0@mixxx.org>2020-12-17 02:00:38 +0100
commitfb9db14be6afc23a3b40ec63683a4db5cb16711a (patch)
treeb03712efc270304a8ae0064a2c016478af02d3f2
parente80ce44df0f440e108ca1f0cecb1e16b26517c3e (diff)
Library: overhaul setting font and row height
Previously, there was an artificial lower limit for the row height (31px for me) that would ignore lower values of the row height spinbox. Now, the new font height is used as lower limit for the row height. When changing the font (size) the row height is automatically adjusted by using the previous font height/row height ratio.
-rw-r--r--src/library/library.cpp9
-rw-r--r--src/preferences/dialog/dlgpreflibrary.cpp8
-rw-r--r--src/widget/wlibrarytableview.cpp7
3 files changed, 16 insertions, 8 deletions
diff --git a/src/library/library.cpp b/src/library/library.cpp
index dec5cc5b3a..59c528c37c 100644
--- a/src/library/library.cpp
+++ b/src/library/library.cpp
@@ -522,8 +522,17 @@ QStringList Library::getDirs() {
}
void Library::setFont(const QFont& font) {
+ QFontMetrics currMetrics(m_trackTableFont);
+ QFontMetrics newMetrics(font);
+ double currFontHeight = currMetrics.height();
+ double newFontHeight = newMetrics.height();
+
m_trackTableFont = font;
emit setTrackTableFont(font);
+ // adapt the previous font heigh/row height ratio
+ int scaledRowHeight = static_cast<int>(std::round(
+ (newFontHeight / currFontHeight) * m_iTrackTableRowHeight));
+ setRowHeight(scaledRowHeight);
}
void Library::setRowHeight(int rowHeight) {
diff --git a/src/preferences/dialog/dlgpreflibrary.cpp b/src/preferences/dialog/dlgpreflibrary.cpp
index 861b2eec08..8c9bebdc9a 100644
--- a/src/preferences/dialog/dlgpreflibrary.cpp
+++ b/src/preferences/dialog/dlgpreflibrary.cpp
@@ -383,13 +383,13 @@ void DlgPrefLibrary::setLibraryFont(const QFont& font) {
font.family(), font.styleName(), QString::number(font.pointSizeF())));
m_pLibrary->setFont(font);
- // Don't let the row height exceed the library height.
+ // Don't let the font height exceed the row height.
QFontMetrics metrics(font);
int fontHeight = metrics.height();
- if (fontHeight > spinBoxRowHeight->value()) {
- spinBoxRowHeight->setValue(fontHeight);
- }
spinBoxRowHeight->setMinimum(fontHeight);
+ // library.cpp takes care of setting the new row height according to the
+ // previous font height/ row height ratio
+ spinBoxRowHeight->setValue(m_pLibrary->getTrackTableRowHeight());
}
void DlgPrefLibrary::slotSelectFont() {
diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp
index 6c63faf993..8ed732a69f 100644
--- a/src/widget/wlibrarytableview.cpp
+++ b/src/widget/wlibrarytableview.cpp
@@ -132,14 +132,13 @@ void WLibraryTableView::restoreVScrollBarPos(TrackModel* key){
void WLibraryTableView::setTrackTableFont(const QFont& font) {
setFont(font);
- setTrackTableRowHeight(verticalHeader()->defaultSectionSize());
+ QFontMetrics metrics(font);
+ verticalHeader()->setMinimumSectionSize(metrics.height());
}
void WLibraryTableView::setTrackTableRowHeight(int rowHeight) {
- QFontMetrics metrics(font());
- int fontHeightPx = metrics.height();
verticalHeader()->setDefaultSectionSize(math_max(
- rowHeight, fontHeightPx));
+ rowHeight, verticalHeader()->minimumSectionSize()));
}
void WLibraryTableView::setSelectedClick(bool enable) {