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

#include <kis_cmb_idlist.h>

+ Inheritance diagram for KisCmbIDList:

Signals

void activated (const KoID &)
 
void highlighted (const KoID &)
 

Public Member Functions

void allowAuto (bool setAuto=true)
 allowAuto sets whether the combobox should keep an extra "AUTO" option, where the use allows the program to decide an appropriate option based on context.
 
KoID currentItem () const
 
 KisCmbIDList (QWidget *parent=0, const char *name=0)
 
void setAutoHint (const QString &hint)
 
void setCurrent (const KoID id)
 
void setCurrent (const QString &id)
 
void setIDList (const QList< KoID > &list, bool sorted=true)
 setIDList clears the combobox and sorts the given list by user-visible name and then adds the items to the combobox
 
 ~KisCmbIDList () override
 

Static Public Attributes

static const KoID AutoOptionID = KoID("AUTO", ki18nc("Automatic", "Auto"))
 

Private Slots

void slotIDActivated (int index)
 
void slotIDHighlighted (int index)
 

Private Member Functions

void buildItems ()
 

Private Attributes

QString m_autoHint
 
bool m_autoOption = false
 
QList< KoIDm_idList
 
bool m_sorted = true
 

Detailed Description

A combobox that is associated with a list of KoID's. The descriptive (i18n'ed) text is displayed, but the various signals return a KoID.

Definition at line 23 of file kis_cmb_idlist.h.

Constructor & Destructor Documentation

◆ KisCmbIDList()

KisCmbIDList::KisCmbIDList ( QWidget * parent = 0,
const char * name = 0 )

Definition at line 15 of file kis_cmb_idlist.cc.

16 : QComboBox(parent)
17{
18 setObjectName(name);
19 setEditable(false);
20 connect(this, SIGNAL(activated(int)), this, SLOT(slotIDActivated(int)));
21 connect(this, SIGNAL(highlighted(int)), this, SLOT(slotIDHighlighted(int)));
22}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotIDActivated(int index)
void slotIDHighlighted(int index)
void activated(const KoID &)
void highlighted(const KoID &)

References activated(), connect(), highlighted(), slotIDActivated(), and slotIDHighlighted().

◆ ~KisCmbIDList()

KisCmbIDList::~KisCmbIDList ( )
override

Definition at line 24 of file kis_cmb_idlist.cc.

25{
26}

Member Function Documentation

◆ activated

void KisCmbIDList::activated ( const KoID & )
signal

◆ allowAuto()

void KisCmbIDList::allowAuto ( bool setAuto = true)

allowAuto sets whether the combobox should keep an extra "AUTO" option, where the use allows the program to decide an appropriate option based on context.

Definition at line 38 of file kis_cmb_idlist.cc.

39{
40 m_autoOption = setAuto;
41
42 buildItems();
43}

References buildItems(), and m_autoOption.

◆ buildItems()

void KisCmbIDList::buildItems ( )
private

Definition at line 98 of file kis_cmb_idlist.cc.

99{
100 const KoID selectedID = currentItem();
101
102 clear();
103
104 // m_idList has auto, remove it temporarily.
105 if (m_idList.contains(AutoOptionID)) {
106 m_idList.removeAll(AutoOptionID);
107 }
108
109 // Sort id list..
110 if (m_sorted) {
111 std::sort(m_idList.begin(), m_idList.end(), KoID::compareNames);
112 }
113
114 // Re-add "Auto" option to front of list if auto enabled..
115 if (m_autoOption) {
116 m_idList.insert(0, AutoOptionID);
117 }
118
119 // Populate GUI item list..
120 for (qint32 i = 0; i < m_idList.count(); ++i) {
121 const KoID &id = m_idList.at(i);
122 if (id == AutoOptionID && !m_autoHint.isEmpty()) {
123 addItem(QString("%1 (%2)").arg(id.name(), m_autoHint));
124 } else {
125 addItem(m_idList.at(i).name());
126 }
127 }
128
129 setCurrent(selectedID);
130}
KoID currentItem() const
QString m_autoHint
static const KoID AutoOptionID
QList< KoID > m_idList
void setCurrent(const KoID id)
Definition KoID.h:30
static bool compareNames(const KoID &id1, const KoID &id2)
Definition KoID.h:87
const char * name(StandardAction id)
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)

References AutoOptionID, KoID::compareNames(), currentItem(), m_autoHint, m_autoOption, m_idList, m_sorted, and setCurrent().

◆ currentItem()

KoID KisCmbIDList::currentItem ( ) const

Definition at line 52 of file kis_cmb_idlist.cc.

53{
54 qint32 index = QComboBox::currentIndex();
55
56 if (index > m_idList.count() - 1 || index < 0) return KoID();
57
58 return m_idList[index];
59}

References m_idList.

◆ highlighted

void KisCmbIDList::highlighted ( const KoID & )
signal

◆ setAutoHint()

void KisCmbIDList::setAutoHint ( const QString & hint)

Definition at line 45 of file kis_cmb_idlist.cc.

46{
47 m_autoHint = hint;
48
49 buildItems();
50}

References buildItems(), and m_autoHint.

◆ setCurrent() [1/2]

void KisCmbIDList::setCurrent ( const KoID id)

Definition at line 61 of file kis_cmb_idlist.cc.

62{
63 qint32 index = m_idList.indexOf(id);
64
65 if (index >= 0) {
66 QComboBox::setCurrentIndex(index);
67 } else if (id != KoID()) {
68 m_idList.push_back(id);
69 buildItems();
70 QComboBox::setCurrentIndex(m_idList.indexOf(id));
71 }
72}

References buildItems(), and m_idList.

◆ setCurrent() [2/2]

void KisCmbIDList::setCurrent ( const QString & id)

Definition at line 74 of file kis_cmb_idlist.cc.

75{
76 for (qint32 index = 0; index < m_idList.count(); ++index) {
77 if (m_idList.at(index).id() == id) {
78 QComboBox::setCurrentIndex(index);
79 break;
80 }
81 }
82}

References m_idList.

◆ setIDList()

void KisCmbIDList::setIDList ( const QList< KoID > & list,
bool sorted = true )

setIDList clears the combobox and sorts the given list by user-visible name and then adds the items to the combobox

Parameters
listthe (unsorted) list of KoID's
sortedif true, the id's will be sorted by name

Definition at line 30 of file kis_cmb_idlist.cc.

31{
32 m_idList = list;
33 m_sorted = sorted;
34
35 buildItems();
36}

References buildItems(), m_idList, and m_sorted.

◆ slotIDActivated

void KisCmbIDList::slotIDActivated ( int index)
privateslot

Definition at line 84 of file kis_cmb_idlist.cc.

85{
86 if (index > m_idList.count() - 1 || index < 0) return;
87
88 Q_EMIT activated(m_idList[index]);
89}

References activated(), and m_idList.

◆ slotIDHighlighted

void KisCmbIDList::slotIDHighlighted ( int index)
privateslot

Definition at line 91 of file kis_cmb_idlist.cc.

92{
93 if (index > m_idList.count() - 1 || index < 0) return;
94
95 Q_EMIT highlighted(m_idList[index]);
96}

References highlighted(), and m_idList.

Member Data Documentation

◆ AutoOptionID

const KoID KisCmbIDList::AutoOptionID = KoID("AUTO", ki18nc("Automatic", "Auto"))
static

Definition at line 31 of file kis_cmb_idlist.h.

◆ m_autoHint

QString KisCmbIDList::m_autoHint
private

Definition at line 70 of file kis_cmb_idlist.h.

◆ m_autoOption

bool KisCmbIDList::m_autoOption = false
private

Definition at line 69 of file kis_cmb_idlist.h.

◆ m_idList

QList<KoID> KisCmbIDList::m_idList
private

Definition at line 67 of file kis_cmb_idlist.h.

◆ m_sorted

bool KisCmbIDList::m_sorted = true
private

Definition at line 68 of file kis_cmb_idlist.h.


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