diff --git a/ui/drivers/qt/playlist.cpp b/ui/drivers/qt/playlist.cpp index a3c81c3502..fbb6989da1 100644 --- a/ui/drivers/qt/playlist.cpp +++ b/ui/drivers/qt/playlist.cpp @@ -37,6 +37,20 @@ inline static bool comp_hash_label_key_lower(const QHash &lhs, return lhs.value("label").toLower() < rhs.value("label").toLower(); } +/* https://stackoverflow.com/questions/7246622/how-to-create-a-slider-with-a-non-linear-scale */ +static double expScale(double inputValue, double midValue, double maxValue) +{ + double returnValue = 0; + double M = maxValue / midValue; + double C = log(pow(M - 1, 2)); + double B = maxValue / (exp(C) - 1); + double A = -1 * B; + + returnValue = A + B * exp(C * inputValue); + + return returnValue; +} + static void addDirectoryFilesToList(QStringList &list, QDir &dir) { QStringList dirList = dir.entryList(QStringList(), QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, QDir::Name); @@ -908,6 +922,33 @@ finish: addPlaylistHashToGrid(items); } +/* https://gist.github.com/andrey-str/0f9c7709cbf0c9c49ef9 */ +static void setElidedText(QLabel *label, QWidget *clipWidget, int padding, const QString &text) +{ + QFontMetrics metrix(label->font()); + int width = clipWidget->width() - padding; + QString clippedText = metrix.elidedText(text, Qt::ElideRight, width); + label->setText(clippedText); +} + +inline void MainWindow::calcGridItemSize(GridItem *item, int zoomValue) +{ + int newSize = 0; + QLabel *label = NULL; + + if (zoomValue < 50) + newSize = expScale(lerp(0, 49, 25, 49, zoomValue) / 50.0, 102, 256); + else + newSize = expScale(zoomValue / 100.0, 256, 1024); + + item->widget->setFixedSize(QSize(newSize, newSize)); + + label = item->widget->findChild("thumbnailQLabel"); + + if (label) + setElidedText(label, item->widget, item->widget->layout()->contentsMargins().left() + item->widget->layout()->spacing() + 2, item->labelText); +} + void MainWindow::addPlaylistHashToGrid(const QVector > &items) { QScreen *screen = qApp->primaryScreen(); diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index 44583f313a..460e7542ad 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -113,24 +113,6 @@ static const QPixmap getInvader() return pix; } -static double lerp(double x, double y, double a, double b, double d) { - return a + (b - a) * ((double)(d - x) / (double)(y - x)); -} - -/* https://stackoverflow.com/questions/7246622/how-to-create-a-slider-with-a-non-linear-scale */ -static double expScale(double inputValue, double midValue, double maxValue) -{ - double returnValue = 0; - double M = maxValue / midValue; - double C = log(pow(M - 1, 2)); - double B = maxValue / (exp(C) - 1); - double A = -1 * B; - - returnValue = A + B * exp(C * inputValue); - - return returnValue; -} - #ifdef HAVE_LIBRETRODB static void scan_finished_handler(void *task_data, void *user_data, const char *err) { @@ -156,15 +138,6 @@ static void scan_finished_handler(void *task_data, void *user_data, const char * } #endif -/* https://gist.github.com/andrey-str/0f9c7709cbf0c9c49ef9 */ -static void setElidedText(QLabel *label, QWidget *clipWidget, int padding, const QString &text) -{ - QFontMetrics metrix(label->font()); - int width = clipWidget->width() - padding; - QString clippedText = metrix.elidedText(text, Qt::ElideRight, width); - label->setText(clippedText); -} - GridItem::GridItem() : QObject() ,widget(NULL) @@ -586,6 +559,10 @@ MainWindow::~MainWindow() removeGridItems(); } +double MainWindow::lerp(double x, double y, double a, double b, double d) { + return a + (b - a) * ((double)(d - x) / (double)(y - x)); +} + void MainWindow::onShaderParamsDialogResized(QSize size) { QVariant scrollAreaVariant = m_shaderParamsDialog->property("scrollArea"); @@ -949,24 +926,6 @@ void MainWindow::onListViewClicked() onCurrentListItemChanged(m_listWidget->currentItem(), NULL); } -inline void MainWindow::calcGridItemSize(GridItem *item, int zoomValue) -{ - int newSize = 0; - QLabel *label = NULL; - - if (zoomValue < 50) - newSize = expScale(lerp(0, 49, 25, 49, zoomValue) / 50.0, 102, 256); - else - newSize = expScale(zoomValue / 100.0, 256, 1024); - - item->widget->setFixedSize(QSize(newSize, newSize)); - - label = item->widget->findChild("thumbnailQLabel"); - - if (label) - setElidedText(label, item->widget, item->widget->layout()->contentsMargins().left() + item->widget->layout()->spacing() + 2, item->labelText); -} - void MainWindow::onZoomValueChanged(int value) { int i; diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 05972d13e2..418e1fb441 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -276,6 +276,7 @@ public: void addFilesToPlaylist(QStringList files); QString getCurrentPlaylistPath(); QHash getCurrentContentHash(); + static double lerp(double x, double y, double a, double b, double d); signals: void thumbnailChanged(const QPixmap &pixmap);