mirror of
https://github.com/YACReader/yacreader
synced 2026-03-01 10:22:58 -05:00
Initial implementation of theming
This commit is contained in:
@ -62,6 +62,15 @@ QList<QAction *> ActionsGroupsModel::getActions(const QModelIndex &mi)
|
||||
return QList<QAction *>();
|
||||
}
|
||||
|
||||
void ActionsGroupsModel::updateGroupIcon(int row, const QIcon &icon)
|
||||
{
|
||||
if (row >= 0 && row < groups.size()) {
|
||||
groups[row].setIcon(icon);
|
||||
QModelIndex idx = index(row, 0);
|
||||
emit dataChanged(idx, idx, { Qt::DecorationRole });
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList<QAction *> &actions)
|
||||
@ -74,6 +83,11 @@ QString ActionsGroup::getName() const
|
||||
return name;
|
||||
}
|
||||
|
||||
void ActionsGroup::setIcon(const QIcon &newIcon)
|
||||
{
|
||||
icon = newIcon;
|
||||
}
|
||||
|
||||
QIcon ActionsGroup::getIcon() const
|
||||
{
|
||||
return icon;
|
||||
|
||||
@ -13,6 +13,7 @@ public:
|
||||
QString getName() const;
|
||||
QIcon getIcon() const;
|
||||
QList<QAction *> getActions() const;
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
protected:
|
||||
QString name;
|
||||
@ -34,6 +35,7 @@ public:
|
||||
|
||||
void addActionsGroup(const ActionsGroup &group);
|
||||
QList<QAction *> getActions(const QModelIndex &mi);
|
||||
void updateGroupIcon(int row, const QIcon &icon);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@ -63,12 +63,12 @@ KeySequenceLineEdit::KeySequenceLineEdit(QWidget *parent)
|
||||
acceptButton = new QToolButton(this);
|
||||
QString buttonsStyle = "QToolButton { border: none; padding: 0px; }";
|
||||
|
||||
clearButton->setIcon(QIcon(":/images/clear_shortcut.svg"));
|
||||
clearButton->setIcon(QIcon(":/images/shortcuts/clear_shortcut.svg"));
|
||||
clearButton->setIconSize(QSize(15, 15));
|
||||
clearButton->setCursor(Qt::ArrowCursor);
|
||||
clearButton->setStyleSheet(buttonsStyle);
|
||||
|
||||
acceptButton->setIcon(QIcon(":/images/accept_shortcut.svg"));
|
||||
acceptButton->setIcon(QIcon(":/images/shortcuts/accept_shortcut.svg"));
|
||||
acceptButton->setIconSize(QSize(15, 15));
|
||||
acceptButton->setCursor(Qt::ArrowCursor);
|
||||
acceptButton->setStyleSheet(buttonsStyle);
|
||||
|
||||
@ -71,6 +71,32 @@ EditShortcutsDialog::EditShortcutsDialog(QWidget *parent)
|
||||
setWindowTitle(tr("Shortcuts settings"));
|
||||
|
||||
setModal(true);
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void EditShortcutsDialog::applyTheme(const Theme &theme)
|
||||
{
|
||||
updateGroupIcons(theme);
|
||||
}
|
||||
|
||||
void EditShortcutsDialog::updateGroupIcons(const Theme &theme)
|
||||
{
|
||||
// Update icons for all groups based on the mapping
|
||||
for (int i = 0; i < groupsModel->rowCount(); ++i) {
|
||||
QModelIndex idx = groupsModel->index(i, 0);
|
||||
QString groupName = groupsModel->data(idx, Qt::DisplayRole).toString();
|
||||
|
||||
if (groupIconMapping.contains(groupName)) {
|
||||
QIcon newIcon = groupIconMapping[groupName](theme);
|
||||
groupsModel->updateGroupIcon(i, newIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditShortcutsDialog::setGroupIconMapping(const QMap<QString, std::function<QIcon(const Theme &)>> &mapping)
|
||||
{
|
||||
groupIconMapping = mapping;
|
||||
}
|
||||
|
||||
void EditShortcutsDialog::addActionsGroup(const QString &name, const QIcon &ico, QList<QAction *> &group)
|
||||
|
||||
@ -4,18 +4,21 @@
|
||||
#include <QDialog>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "themable.h"
|
||||
|
||||
class QListView;
|
||||
class QTableView;
|
||||
|
||||
class ActionsGroupsModel;
|
||||
class ActionsShortcutsModel;
|
||||
|
||||
class EditShortcutsDialog : public QDialog
|
||||
class EditShortcutsDialog : public QDialog, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EditShortcutsDialog(QWidget *parent = 0);
|
||||
void addActionsGroup(const QString &name, const QIcon &ico, QList<QAction *> &group);
|
||||
void setGroupIconMapping(const QMap<QString, std::function<QIcon(const Theme&)>> &mapping);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
@ -24,9 +27,14 @@ public slots:
|
||||
void processConflict(const QString &shortcutInConflict);
|
||||
|
||||
protected:
|
||||
void applyTheme(const Theme &theme) override;
|
||||
void updateGroupIcons(const Theme &theme);
|
||||
|
||||
QListView *actionsGroupsListView;
|
||||
QTableView *actionsTableView;
|
||||
ActionsGroupsModel *groupsModel;
|
||||
|
||||
QMap<QString, std::function<QIcon(const Theme&)>> groupIconMapping;
|
||||
ActionsShortcutsModel *actionsModel;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user