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

#include <KisView_p.h>

+ Inheritance diagram for UnitActionGroup:

Public Member Functions

 UnitActionGroup (KisDocument *document, bool addPixelUnit, QObject *parent=0)
 

Private Slots

void onTriggered (QAction *action)
 
void onUnitChanged (const KoUnit &unit)
 

Private Attributes

KisDocumentm_document
 
KoUnit::ListOptions m_listOptions
 

Detailed Description

Definition at line 17 of file KisView_p.h.

Constructor & Destructor Documentation

◆ UnitActionGroup()

UnitActionGroup::UnitActionGroup ( KisDocument * document,
bool addPixelUnit,
QObject * parent = 0 )
inlineexplicit

Definition at line 21 of file KisView_p.h.

22 : QActionGroup(parent)
23 , m_document(document)
24 , m_listOptions(addPixelUnit ? KoUnit::ListAll : KoUnit::HidePixel)
25 {
26 setExclusive(true);
27 connect(this, SIGNAL(triggered(QAction*)), SLOT(onTriggered(QAction*)));
28 connect(document, SIGNAL(unitChanged(KoUnit)), SLOT(onUnitChanged(KoUnit)));
29
31 const int currentUnitIndex = m_document->unit().indexInListForUi(m_listOptions);
32
33 for (int i = 0; i < unitNames.count(); ++i) {
34 QAction* action = new QAction(unitNames.at(i), this);
35 action->setData(i);
36 action->setCheckable(true);
37
38 if (currentUnitIndex == i) {
39 action->setChecked(true);
40 }
41 }
42 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
@ ListAll
Definition KoUnit.h:88
static QStringList listOfUnitNameForUi(ListOptions listOptions=ListAll)
Returns the list of unit types for the UI, controlled with the given listOptions.
Definition KoUnit.cpp:69
int indexInListForUi(ListOptions listOptions=ListAll) const
Definition KoUnit.cpp:101
KisDocument * m_document
Definition KisView_p.h:69
KoUnit::ListOptions m_listOptions
Definition KisView_p.h:70
void onTriggered(QAction *action)
Definition KisView_p.h:45
void onUnitChanged(const KoUnit &unit)
Definition KisView_p.h:50

References connect(), KoUnit::indexInListForUi(), KoUnit::listOfUnitNameForUi(), m_document, m_listOptions, onTriggered(), onUnitChanged(), and KisDocument::unit.

Member Function Documentation

◆ onTriggered

void UnitActionGroup::onTriggered ( QAction * action)
inlineprivateslot

Definition at line 45 of file KisView_p.h.

46 {
47 m_document->setUnit(KoUnit::fromListForUi(action->data().toInt(), m_listOptions));
48 }
void setUnit(const KoUnit &unit)
static KoUnit fromListForUi(int index, ListOptions listOptions=ListAll, qreal factor=1.0)
Definition KoUnit.cpp:80

References KoUnit::fromListForUi(), m_document, m_listOptions, and KisDocument::setUnit().

◆ onUnitChanged

void UnitActionGroup::onUnitChanged ( const KoUnit & unit)
inlineprivateslot

Definition at line 50 of file KisView_p.h.

51 {
52 const int indexInList = unit.indexInListForUi(m_listOptions);
53
54 Q_FOREACH (QAction *action, actions()) {
55 if (action->data().toInt() == indexInList) {
56 action->setChecked(true);
57 break;
58 }
59 // in case the new unit is not in the list of actions
60 // this ensures that the action currently checked is unchecked
61 // once the end of actions has been reached
62 if (action->isChecked()) {
63 action->setChecked(false);
64 }
65 }
66 }

References KoUnit::indexInListForUi(), and m_listOptions.

Member Data Documentation

◆ m_document

KisDocument* UnitActionGroup::m_document
private

Definition at line 69 of file KisView_p.h.

◆ m_listOptions

KoUnit::ListOptions UnitActionGroup::m_listOptions
private

Definition at line 70 of file KisView_p.h.


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