Skip to content

Commit

Permalink
Theme: add icon size fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 10, 2024
1 parent a7c3352 commit d90252e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
48 changes: 21 additions & 27 deletions src/app/GUI/BoxesList/boxsinglewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,40 +575,34 @@ void BoxSingleWidget::setTargetAbstraction(SWT_Abstraction *abs) {
void BoxSingleWidget::loadStaticPixmaps(int iconSize)
{
if (sStaticPixmapsLoaded) { return; }
const auto sizes = QIcon::fromTheme("visible").availableSizes();

qWarning() << "Icon theme:" << QIcon::themeName() << iconSize;
qWarning() << "Icon path:" << QIcon::themeSearchPaths();
qWarning() << "Icon sizes:" << sizes;

if (!sizes.contains(QSize(iconSize, iconSize))) {
if (!ThemeSupport::hasIconSize(iconSize)) {
QMessageBox::warning(nullptr,
tr("Icon issues"),
tr("<p>Requested icon size <b>%1</b> is not available,"
" expect blurry and missing icons.</p>"
" expect blurry icons.</p>"
"<p>Note that this may happen if you change the display scaling"
" in Windows without restarting."
" If you still have issues after restarting please report this issue.</p>").arg(iconSize));
}

VISIBLE_ICON = new QPixmap(QIcon::fromTheme("visible").pixmap(iconSize, iconSize));
INVISIBLE_ICON = new QPixmap(QIcon::fromTheme("hidden").pixmap(iconSize, iconSize));
BOX_CHILDREN_VISIBLE_ICON = new QPixmap(QIcon::fromTheme("visible-child").pixmap(iconSize, iconSize));
BOX_CHILDREN_HIDDEN_ICON = new QPixmap(QIcon::fromTheme("hidden-child").pixmap(iconSize, iconSize));
ANIMATOR_CHILDREN_VISIBLE_ICON = new QPixmap(QIcon::fromTheme("visible-child-small").pixmap(iconSize, iconSize));
ANIMATOR_CHILDREN_HIDDEN_ICON = new QPixmap(QIcon::fromTheme("hidden-child-small").pixmap(iconSize, iconSize));
LOCKED_ICON = new QPixmap(QIcon::fromTheme("locked").pixmap(iconSize, iconSize));
UNLOCKED_ICON = new QPixmap(QIcon::fromTheme("unlocked").pixmap(iconSize, iconSize));
MUTED_ICON = new QPixmap(QIcon::fromTheme("muted").pixmap(iconSize, iconSize));
UNMUTED_ICON = new QPixmap(QIcon::fromTheme("unmuted").pixmap(iconSize, iconSize));
ANIMATOR_RECORDING_ICON = new QPixmap(QIcon::fromTheme("record").pixmap(iconSize, iconSize));
ANIMATOR_NOT_RECORDING_ICON = new QPixmap(QIcon::fromTheme("norecord").pixmap(iconSize, iconSize));
ANIMATOR_DESCENDANT_RECORDING_ICON = new QPixmap(QIcon::fromTheme("record-child").pixmap(iconSize, iconSize));
C_ICON = new QPixmap(QIcon::fromTheme("cpu-active").pixmap(iconSize, iconSize));
G_ICON = new QPixmap(QIcon::fromTheme("gpu-active").pixmap(iconSize, iconSize));
CG_ICON = new QPixmap(QIcon::fromTheme("cpu-gpu").pixmap(iconSize, iconSize));
GRAPH_PROPERTY_ICON = new QPixmap(QIcon::fromTheme("graph_property_2").pixmap(iconSize, iconSize));
PROMOTE_TO_LAYER_ICON = new QPixmap(QIcon::fromTheme("layer").pixmap(iconSize, iconSize));
const auto pixmapSize = ThemeSupport::getIconSize(iconSize);
VISIBLE_ICON = new QPixmap(QIcon::fromTheme("visible").pixmap(pixmapSize));
INVISIBLE_ICON = new QPixmap(QIcon::fromTheme("hidden").pixmap(pixmapSize));
BOX_CHILDREN_VISIBLE_ICON = new QPixmap(QIcon::fromTheme("visible-child").pixmap(pixmapSize));
BOX_CHILDREN_HIDDEN_ICON = new QPixmap(QIcon::fromTheme("hidden-child").pixmap(pixmapSize));
ANIMATOR_CHILDREN_VISIBLE_ICON = new QPixmap(QIcon::fromTheme("visible-child-small").pixmap(pixmapSize));
ANIMATOR_CHILDREN_HIDDEN_ICON = new QPixmap(QIcon::fromTheme("hidden-child-small").pixmap(pixmapSize));
LOCKED_ICON = new QPixmap(QIcon::fromTheme("locked").pixmap(pixmapSize));
UNLOCKED_ICON = new QPixmap(QIcon::fromTheme("unlocked").pixmap(pixmapSize));
MUTED_ICON = new QPixmap(QIcon::fromTheme("muted").pixmap(pixmapSize));
UNMUTED_ICON = new QPixmap(QIcon::fromTheme("unmuted").pixmap(pixmapSize));
ANIMATOR_RECORDING_ICON = new QPixmap(QIcon::fromTheme("record").pixmap(pixmapSize));
ANIMATOR_NOT_RECORDING_ICON = new QPixmap(QIcon::fromTheme("norecord").pixmap(pixmapSize));
ANIMATOR_DESCENDANT_RECORDING_ICON = new QPixmap(QIcon::fromTheme("record-child").pixmap(pixmapSize));
C_ICON = new QPixmap(QIcon::fromTheme("cpu-active").pixmap(pixmapSize));
G_ICON = new QPixmap(QIcon::fromTheme("gpu-active").pixmap(pixmapSize));
CG_ICON = new QPixmap(QIcon::fromTheme("cpu-gpu").pixmap(pixmapSize));
GRAPH_PROPERTY_ICON = new QPixmap(QIcon::fromTheme("graph_property_2").pixmap(pixmapSize));
PROMOTE_TO_LAYER_ICON = new QPixmap(QIcon::fromTheme("layer").pixmap(pixmapSize));

sStaticPixmapsLoaded = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/friction.qss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

/*

Colors and icon size from 'src/core/themesupport.cpp'.

%1 = getThemeButtonBaseColor
%2 = getThemeButtonBorderColor
%3 = getThemeBaseDarkerColor
Expand Down Expand Up @@ -312,7 +314,6 @@ QPushButton#FlatButton:hover,
QToolButton#FlatButton:hover {
background-color: rgb(19, 19, 21);
border-color: rgb(104, 144, 206);

}

QTabWidget#ThirdPartyBrowser { border: 0; }
Expand Down
31 changes: 30 additions & 1 deletion src/core/themesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const QString ThemeSupport::getThemeStyle(int iconSize)
getThemeHighlightColor().name(),
getThemeBaseColor().name(),
getThemeAlternateColor().name(),
QString::number(iconSize),
QString::number(getIconSize(iconSize).width()),
getThemeColorOrange().name(),
getThemeRangeSelectedColor().name());
}
Expand Down Expand Up @@ -227,3 +227,32 @@ void ThemeSupport::setupTheme(const int iconSize)
qApp->setPalette(palette);
qApp->setStyleSheet(getThemeStyle(iconSize));
}

const QList<QSize> ThemeSupport::getAvailableIconSizes()
{
return QIcon::fromTheme("visible").availableSizes();
}

const QSize ThemeSupport::getIconSize(const int size)
{
QSize requestedSize(size, size);
const auto iconSizes = getAvailableIconSizes();
if (iconSizes.contains(requestedSize)) { return requestedSize; }
return findClosestIconSize(size);
}

bool ThemeSupport::hasIconSize(const int size)
{
return getAvailableIconSizes().contains(QSize(size, size));
}

const QSize ThemeSupport::findClosestIconSize(int iconSize)
{
const auto iconSizes = getAvailableIconSizes();
return *std::min_element(iconSizes.begin(),
iconSizes.end(),
[iconSize](const QSize& a,
const QSize& b) {
return qAbs(a.width() - iconSize) < qAbs(b.width() - iconSize);
});
}
6 changes: 6 additions & 0 deletions src/core/themesupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "core_global.h"

#include <QPalette>
#include <QList>
#include <QSize>

#include "include/core/SkColor.h"

Expand Down Expand Up @@ -64,6 +66,10 @@ class CORE_EXPORT ThemeSupport
static const QPalette getNotSoDarkPalette(int alpha = 255);
static const QString getThemeStyle(int iconSize = 20);
static void setupTheme(const int iconSize = 20);
static const QList<QSize> getAvailableIconSizes();
static const QSize getIconSize(const int size);
static bool hasIconSize(const int size);
static const QSize findClosestIconSize(int iconSize);
};

#endif // THEMESUPPORT_H

0 comments on commit d90252e

Please sign in to comment.