refactor: move loadHidpiIcon from ActionManager to ToolButton.
setting loadHidpiIcon in ToolButton is better than ActionManager. ToolButton has less code and its aim also include loading icon.
This commit is contained in:
+2
-13
@@ -5,22 +5,11 @@
|
|||||||
#include "actionmanager.h"
|
#include "actionmanager.h"
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "toolbutton.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QSvgRenderer>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz)
|
|
||||||
{
|
|
||||||
QSvgRenderer r(resp);
|
|
||||||
QPixmap pm = QPixmap(sz * qApp->devicePixelRatio());
|
|
||||||
pm.fill(Qt::transparent);
|
|
||||||
QPainter p(&pm);
|
|
||||||
r.render(&p);
|
|
||||||
pm.setDevicePixelRatio(qApp->devicePixelRatio());
|
|
||||||
return QIcon(pm);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionManager::setupAction(MainWindow *mainWindow)
|
void ActionManager::setupAction(MainWindow *mainWindow)
|
||||||
{
|
{
|
||||||
// region: Action and Its Icon Creation
|
// region: Action and Its Icon Creation
|
||||||
@@ -34,7 +23,7 @@ void ActionManager::setupAction(MainWindow *mainWindow)
|
|||||||
auto create_action = [] (QWidget *w, QAction **a, QString i, QString an, bool iconFromTheme = false) {
|
auto create_action = [] (QWidget *w, QAction **a, QString i, QString an, bool iconFromTheme = false) {
|
||||||
*a = new QAction(w);
|
*a = new QAction(w);
|
||||||
if (!i.isNull())
|
if (!i.isNull())
|
||||||
(*a)->setIcon(iconFromTheme ? QIcon::fromTheme(i) : ActionManager::loadHidpiIcon(i));
|
(*a)->setIcon(iconFromTheme ? QIcon::fromTheme(i) : ToolButton::loadHidpiIcon(i));
|
||||||
(*a)->setObjectName(an);
|
(*a)->setObjectName(an);
|
||||||
w->addAction(*a);
|
w->addAction(*a);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ public:
|
|||||||
void setupShortcuts();
|
void setupShortcuts();
|
||||||
void enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction);
|
void enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction);
|
||||||
|
|
||||||
static QIcon loadHidpiIcon(const QString &resp, QSize sz = QSize(32, 32));
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QAction *actionOpen;
|
QAction *actionOpen;
|
||||||
|
|
||||||
|
|||||||
+14
-2
@@ -4,9 +4,10 @@
|
|||||||
|
|
||||||
#include "toolbutton.h"
|
#include "toolbutton.h"
|
||||||
|
|
||||||
#include "actionmanager.h"
|
|
||||||
#include "opacityhelper.h"
|
#include "opacityhelper.h"
|
||||||
|
|
||||||
|
#include <QSvgRenderer>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QGraphicsOpacityEffect>
|
#include <QGraphicsOpacityEffect>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
@@ -29,7 +30,18 @@ ToolButton::ToolButton(bool hoverColor, QWidget *parent)
|
|||||||
|
|
||||||
void ToolButton::setIconResourcePath(const QString &iconp)
|
void ToolButton::setIconResourcePath(const QString &iconp)
|
||||||
{
|
{
|
||||||
this->setIcon(ActionManager::loadHidpiIcon(iconp, this->iconSize()));
|
this->setIcon(ToolButton::loadHidpiIcon(iconp, this->iconSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon ToolButton::loadHidpiIcon(const QString &resp, QSize sz)
|
||||||
|
{
|
||||||
|
QSvgRenderer r(resp);
|
||||||
|
QPixmap pm = QPixmap(sz * qApp->devicePixelRatio());
|
||||||
|
pm.fill(Qt::transparent);
|
||||||
|
QPainter p(&pm);
|
||||||
|
r.render(&p);
|
||||||
|
pm.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||||
|
return QIcon(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolButton::setOpacity(qreal opacity, bool animated)
|
void ToolButton::setOpacity(qreal opacity, bool animated)
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public:
|
|||||||
ToolButton(bool hoverColor = false, QWidget * parent = nullptr);
|
ToolButton(bool hoverColor = false, QWidget * parent = nullptr);
|
||||||
void setIconResourcePath(const QString &iconp);
|
void setIconResourcePath(const QString &iconp);
|
||||||
|
|
||||||
|
static QIcon loadHidpiIcon(const QString &resp, QSize sz = QSize(32, 32));
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setOpacity(qreal opacity, bool animated = true);
|
void setOpacity(qreal opacity, bool animated = true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user