Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSPenSettings Class Reference

#include <KisSPenSettings.h>

+ Inheritance diagram for KisSPenSettings:

Public Slots

void loadDefaultPreferences () override
 
void loadPreferences () override
 
void savePreferences () const override
 
- Public Slots inherited from KisPreferenceSet
virtual void loadDefaultPreferences ()=0
 
virtual void loadPreferences ()=0
 
virtual void savePreferences () const =0
 

Signals

void settingsChanged () const
 

Public Member Functions

QString header () override
 
QIcon icon () override
 
QString id () override
 
 KisSPenSettings (QWidget *parent=0)
 
QString name () override
 
 ~KisSPenSettings () override
 
- Public Member Functions inherited from KisPreferenceSet
 KisPreferenceSet (QWidget *parent=0)
 

Private Member Functions

QString actionNameForIndex (int index) const
 
int indexFromActionName (QString actionName) const
 

Private Attributes

QStandardItemModel * m_model
 
WdgSPenSettingsmUi
 

Static Private Attributes

static const int m_ACTION_NAME_COLUMN = 1
 
static const int m_ACTION_TEXT_COLUMN = 0
 

Detailed Description

Definition at line 29 of file KisSPenSettings.h.

Constructor & Destructor Documentation

◆ KisSPenSettings()

KisSPenSettings::KisSPenSettings ( QWidget * parent = 0)

Definition at line 26 of file KisSPenSettings.cpp.

27 : KisPreferenceSet(parent)
28 , m_model(new QStandardItemModel())
29{
30 mUi = new WdgSPenSettings(this);
31 mUi->setupUi(this);
32
33 m_model->setColumnCount(2);
34
35 // TODO - popup palette is different action mechanism, thus is missing in this list; maybe we could create a fake KisAction for it
36 // Thanks to the KisActionSnapshot, we can list all actions even when no document is open
37 QScopedPointer<KisActionsSnapshot> actionsSnapshot(new KisActionsSnapshot());
38
40 for (QAction *action: actionCollection->actions()) {
41 actionsSnapshot->addAction(action->objectName(), action);
42 }
43
44 QMap<QString, KisKActionCollection*> sortedCollections = actionsSnapshot->actionCollections();
45 for (KisKActionCollection* collection: sortedCollections) {
46 for (QAction* action: collection->actions()) {
47 QString actionName = KLocalizedString::removeAcceleratorMarker(action->text());
48 QStandardItem* item = new QStandardItem(action->icon(), actionName);
49 QStandardItem* actionNameItem = new QStandardItem(action->objectName());
50 m_model->appendRow(QList<QStandardItem*>() << item << actionNameItem);
51 }
52 }
53
55 m_model->insertRow(0, new QStandardItem(i18n("Do nothing")));
56
57 mUi->cmbClickAction->setModel(m_model);
58 mUi->cmbDoubleClickAction->setModel(m_model);
59 mUi->cmbGestureSwipeUp->setModel(m_model);
60 mUi->cmbGestureSwipeDown->setModel(m_model);
61 mUi->cmbGestureSwipeLeft->setModel(m_model);
62 mUi->cmbGestureSwipeRight->setModel(m_model);
63 mUi->cmbGestureCircleCW->setModel(m_model);
64 mUi->cmbGestureCircleCCW->setModel(m_model);
65
67}
The KisActionsSnapshot class.
A container for a set of QAction objects.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
virtual KisKActionCollection * actionCollection() const
static KisPart * instance()
Definition KisPart.cpp:131
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483
KisPreferenceSet(QWidget *parent=0)
WdgSPenSettings * mUi
void loadPreferences() override
static const int m_ACTION_TEXT_COLUMN
QStandardItemModel * m_model

References KisKXMLGUIClient::actionCollection(), KisKActionCollection::actions(), KisKActionCollection::addAction(), KisPart::currentMainwindow(), KisPart::instance(), loadPreferences(), m_ACTION_TEXT_COLUMN, m_model, and mUi.

◆ ~KisSPenSettings()

KisSPenSettings::~KisSPenSettings ( )
override

Definition at line 69 of file KisSPenSettings.cpp.

70{
71 delete mUi;
72 delete m_model;
73}

References m_model, and mUi.

Member Function Documentation

◆ actionNameForIndex()

QString KisSPenSettings::actionNameForIndex ( int index) const
private

Definition at line 138 of file KisSPenSettings.cpp.

139{
140 QModelIndex modelIndex = m_model->index(index, m_ACTION_NAME_COLUMN);
141 QString actionName = m_model->itemFromIndex(modelIndex)->data(Qt::DisplayRole).toString();
142 return actionName;
143}
static const int m_ACTION_NAME_COLUMN

References m_ACTION_NAME_COLUMN, and m_model.

◆ header()

QString KisSPenSettings::header ( )
overridevirtual

Implements KisPreferenceSet.

Definition at line 85 of file KisSPenSettings.cpp.

86{
87 return QString(i18n("S-Pen Actions"));
88}

◆ icon()

QIcon KisSPenSettings::icon ( )
overridevirtual

Implements KisPreferenceSet.

Definition at line 90 of file KisSPenSettings.cpp.

91{
92 return KisIconUtils::loadIcon("spen-remote");
93}
QIcon loadIcon(const QString &name)

References KisIconUtils::loadIcon().

◆ id()

QString KisSPenSettings::id ( )
overridevirtual

Implements KisPreferenceSet.

Definition at line 75 of file KisSPenSettings.cpp.

76{
77 return QString("SPenSettings");
78}

◆ indexFromActionName()

int KisSPenSettings::indexFromActionName ( QString actionName) const
private

Definition at line 145 of file KisSPenSettings.cpp.

146{
147 if (actionName.isEmpty()) {
148 return 0;
149 } else {
150 QList<QStandardItem*> itemsFound = m_model->findItems(actionName, Qt::MatchExactly, m_ACTION_NAME_COLUMN);
151 if (itemsFound.size() == 0) {
152 return 1;
153 } else {
154 return itemsFound[0]->index().row();
155 }
156 }
157}

References m_ACTION_NAME_COLUMN, and m_model.

◆ loadDefaultPreferences

void KisSPenSettings::loadDefaultPreferences ( )
overrideslot

Definition at line 126 of file KisSPenSettings.cpp.

127{
128 mUi->cmbClickAction->setCurrentIndex(indexFromActionName(QString("fake_show_popup_palette")));
129 mUi->cmbDoubleClickAction->setCurrentIndex(indexFromActionName(QString("erase_action")));
130 mUi->cmbGestureSwipeUp->setCurrentIndex(indexFromActionName(QString("make_brush_color_lighter")));
131 mUi->cmbGestureSwipeDown->setCurrentIndex(indexFromActionName(QString("make_brush_color_darker")));
132 mUi->cmbGestureSwipeLeft->setCurrentIndex(indexFromActionName(QString("KritaShape/KisToolBrush")));
133 mUi->cmbGestureSwipeRight->setCurrentIndex(indexFromActionName(QString("KritaSelected/KisToolColorSampler")));
134 mUi->cmbGestureCircleCW->setCurrentIndex(indexFromActionName(QString("shift_brush_color_clockwise")));
135 mUi->cmbGestureCircleCCW->setCurrentIndex(indexFromActionName(QString("shift_brush_color_counter_clockwise")));
136}
int indexFromActionName(QString actionName) const

References indexFromActionName(), and mUi.

◆ loadPreferences

void KisSPenSettings::loadPreferences ( )
overrideslot

Definition at line 111 of file KisSPenSettings.cpp.

112{
113 KConfigGroup cfg = KSharedConfig::openConfig()->group("SPenSettings");
114
115 mUi->cmbClickAction->setCurrentIndex(indexFromActionName(cfg.readEntry("actionButtonClick", QString())));
116 mUi->cmbDoubleClickAction->setCurrentIndex(indexFromActionName(cfg.readEntry("actionButtonDoubleClick", QString())));
117 mUi->cmbGestureSwipeUp->setCurrentIndex(indexFromActionName(cfg.readEntry("actionGestureSwipeUp", QString())));
118 mUi->cmbGestureSwipeDown->setCurrentIndex(indexFromActionName(cfg.readEntry("actionGestureSwipeDown", QString())));
119 mUi->cmbGestureSwipeLeft->setCurrentIndex(indexFromActionName(cfg.readEntry("actionGestureSwipeLeft", QString())));
120 mUi->cmbGestureSwipeRight->setCurrentIndex(indexFromActionName(cfg.readEntry("actionGestureSwipeRight", QString())));
121 mUi->cmbGestureCircleCW->setCurrentIndex(indexFromActionName(cfg.readEntry("actionGestureCircleCW", QString())));
122 mUi->cmbGestureCircleCCW->setCurrentIndex(indexFromActionName(cfg.readEntry("actionGestureCircleCCW", QString())));
123
124}

References indexFromActionName(), and mUi.

◆ name()

QString KisSPenSettings::name ( )
overridevirtual

Implements KisPreferenceSet.

Definition at line 80 of file KisSPenSettings.cpp.

81{
82 return header();
83}
QString header() override

References header().

◆ savePreferences

void KisSPenSettings::savePreferences ( ) const
overrideslot

Definition at line 95 of file KisSPenSettings.cpp.

96{
97 KConfigGroup cfg = KSharedConfig::openConfig()->group("SPenSettings");
98
99 cfg.writeEntry("actionButtonClick", actionNameForIndex(mUi->cmbClickAction->currentIndex()));
100 cfg.writeEntry("actionButtonDoubleClick", actionNameForIndex(mUi->cmbDoubleClickAction->currentIndex()));
101 cfg.writeEntry("actionGestureSwipeUp", actionNameForIndex(mUi->cmbGestureSwipeUp->currentIndex()));
102 cfg.writeEntry("actionGestureSwipeDown", actionNameForIndex(mUi->cmbGestureSwipeDown->currentIndex()));
103 cfg.writeEntry("actionGestureSwipeLeft", actionNameForIndex(mUi->cmbGestureSwipeLeft->currentIndex()));
104 cfg.writeEntry("actionGestureSwipeRight", actionNameForIndex(mUi->cmbGestureSwipeRight->currentIndex()));
105 cfg.writeEntry("actionGestureCircleCW", actionNameForIndex(mUi->cmbGestureCircleCW->currentIndex()));
106 cfg.writeEntry("actionGestureCircleCCW", actionNameForIndex(mUi->cmbGestureCircleCCW->currentIndex()));
107
108 Q_EMIT settingsChanged();
109}
void settingsChanged() const
QString actionNameForIndex(int index) const

References actionNameForIndex(), mUi, and settingsChanged().

◆ settingsChanged

void KisSPenSettings::settingsChanged ( ) const
signal

Member Data Documentation

◆ m_ACTION_NAME_COLUMN

const int KisSPenSettings::m_ACTION_NAME_COLUMN = 1
staticprivate

Definition at line 51 of file KisSPenSettings.h.

◆ m_ACTION_TEXT_COLUMN

const int KisSPenSettings::m_ACTION_TEXT_COLUMN = 0
staticprivate

Definition at line 50 of file KisSPenSettings.h.

◆ m_model

QStandardItemModel* KisSPenSettings::m_model
private

Definition at line 57 of file KisSPenSettings.h.

◆ mUi

WdgSPenSettings* KisSPenSettings::mUi
private

Definition at line 56 of file KisSPenSettings.h.


The documentation for this class was generated from the following files: