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

The KisPaletteComboBox class A combobox used with KisPaletteView. More...

#include <KisPaletteComboBox.h>

+ Inheritance diagram for KisPaletteComboBox:

Signals

void sigColorSelected (const KoColor &)
 

Public Member Functions

 KisPaletteComboBox (QWidget *parent=0)
 
void setCompanionView (KisPaletteView *)
 
 ~KisPaletteComboBox ()
 
- Public Member Functions inherited from KisSqueezedComboBox
void addSqueezedItem (const QIcon &icon, const QString &newItem, QVariant userData=QVariant())
 
void addSqueezedItem (const QString &newItem, QVariant userData=QVariant())
 
bool contains (const QString &text) const
 
QString currentUnsqueezedText ()
 
qint32 findOriginalText (const QString &text) const
 
void insertSqueezedItem (const QIcon &icon, const QString &newItem, int index, QVariant userData=QVariant())
 
void insertSqueezedItem (const QString &newItem, int index, QVariant userData=QVariant())
 
 KisSqueezedComboBox (QWidget *parent=0, const char *name=0)
 
QStringList originalTexts () const
 
void removeSqueezedItem (int index)
 
void resetOriginalTexts (const QStringList &texts)
 
void setCurrent (const QString &itemText)
 
QSize sizeHint () const override
 
 ~KisSqueezedComboBox () override
 

Private Types

typedef QHash< SwatchPosType, int > PosIdxMapType
 
typedef QPair< int, int > SwatchPosType
 

Private Slots

void setPaletteModel (const KisPaletteModel *)
 
void slotIndexUpdated (int)
 
void slotPaletteChanged ()
 
void slotSwatchSelected (const QModelIndex &index)
 

Private Member Functions

QPixmap createColorSquare (const KisSwatch &swatch) const
 

Static Private Member Functions

static bool swatchInfoLess (const KisSwatchGroup::SwatchInfo &, const KisSwatchGroup::SwatchInfo &)
 

Private Attributes

QHash< QString, PosIdxMapTypem_groupMapMap
 
QVector< KisSwatchm_idxSwatchMap
 
QPointer< const KisPaletteModelm_model
 
QPointer< KisPaletteViewm_view
 

Additional Inherited Members

- Static Public Member Functions inherited from KisSqueezedComboBox
static QString squeezeText (const QString &original, const QWidget *widget)
 

Detailed Description

The KisPaletteComboBox class A combobox used with KisPaletteView.

Definition at line 27 of file KisPaletteComboBox.h.

Member Typedef Documentation

◆ PosIdxMapType

typedef QHash<SwatchPosType, int> KisPaletteComboBox::PosIdxMapType
private

Definition at line 33 of file KisPaletteComboBox.h.

◆ SwatchPosType

typedef QPair<int, int> KisPaletteComboBox::SwatchPosType
private

Definition at line 32 of file KisPaletteComboBox.h.

Constructor & Destructor Documentation

◆ KisPaletteComboBox()

KisPaletteComboBox::KisPaletteComboBox ( QWidget * parent = 0)
explicit

Definition at line 19 of file KisPaletteComboBox.cpp.

20 : KisSqueezedComboBox(parent)
21 , m_model(0)
22{
23 setEditable(true);
24 setInsertPolicy(NoInsert);
25 completer()->setCompletionMode(QCompleter::PopupCompletion);
26 completer()->setCaseSensitivity(Qt::CaseInsensitive);
27 completer()->setFilterMode(Qt::MatchContains);
28 connect(this, SIGNAL(currentIndexChanged(int)), SLOT(slotIndexUpdated(int)));
29}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QPointer< const KisPaletteModel > m_model
KisSqueezedComboBox(QWidget *parent=0, const char *name=0)

References connect(), and slotIndexUpdated().

◆ ~KisPaletteComboBox()

KisPaletteComboBox::~KisPaletteComboBox ( )

Definition at line 31 of file KisPaletteComboBox.cpp.

32{ }

Member Function Documentation

◆ createColorSquare()

QPixmap KisPaletteComboBox::createColorSquare ( const KisSwatch & swatch) const
private

Definition at line 106 of file KisPaletteComboBox.cpp.

107{
108 QPixmap colorSquare(32, 32);
109 if (swatch.spotColor()) {
110 QImage img = QImage(32, 32, QImage::Format_ARGB32);
111 QPainter circlePainter;
112 img.fill(Qt::transparent);
113 circlePainter.begin(&img);
114 QBrush brush = QBrush(Qt::SolidPattern);
115 brush.setColor(swatch.color().toQColor());
116 circlePainter.setBrush(brush);
117 QPen pen = circlePainter.pen();
118 pen.setColor(Qt::transparent);
119 pen.setWidth(0);
120 circlePainter.setPen(pen);
121 circlePainter.drawEllipse(0, 0, 32, 32);
122 circlePainter.end();
123 colorSquare = QPixmap::fromImage(img);
124 } else {
125 colorSquare.fill(swatch.color().toQColor());
126 }
127 return colorSquare;
128}
KoColor color() const
Definition KisSwatch.h:30
bool spotColor() const
Definition KisSwatch.h:33
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198

References KisSwatch::color(), KisSwatch::spotColor(), and KoColor::toQColor().

◆ setCompanionView()

void KisPaletteComboBox::setCompanionView ( KisPaletteView * view)

Definition at line 46 of file KisPaletteComboBox.cpp.

47{
48 if (!m_view.isNull()) {
49 m_view->disconnect(this);
50 disconnect(m_view.data());
51 }
52 m_view = view;
54 connect(view, SIGNAL(sigIndexSelected(QModelIndex)), SLOT(slotSwatchSelected(QModelIndex)));
55}
void slotSwatchSelected(const QModelIndex &index)
QPointer< KisPaletteView > m_view
void setPaletteModel(const KisPaletteModel *)
KisPaletteModel * paletteModel() const

References connect(), m_view, KisPaletteView::paletteModel(), setPaletteModel(), and slotSwatchSelected().

◆ setPaletteModel

void KisPaletteComboBox::setPaletteModel ( const KisPaletteModel * paletteModel)
privateslot

Definition at line 34 of file KisPaletteComboBox.cpp.

35{
36 if (!m_model.isNull()) {
37 m_model->disconnect(this);
38 }
39 m_model = paletteModel;
40 if (m_model.isNull()) { return; }
42 connect(m_model, SIGNAL(sigPaletteChanged()), SLOT(slotPaletteChanged()));
43 connect(m_model, SIGNAL(sigPaletteModified()), SLOT(slotPaletteChanged()));
44}

References connect(), m_model, and slotPaletteChanged().

◆ sigColorSelected

void KisPaletteComboBox::sigColorSelected ( const KoColor & )
signal

◆ slotIndexUpdated

void KisPaletteComboBox::slotIndexUpdated ( int idx)
privateslot

Definition at line 143 of file KisPaletteComboBox.cpp.

144{
145 if (idx >= 0 && idx < m_idxSwatchMap.size()) {
146 Q_EMIT sigColorSelected(m_idxSwatchMap[idx].color());
147 }
148}
void sigColorSelected(const KoColor &)
QVector< KisSwatch > m_idxSwatchMap

References m_idxSwatchMap, and sigColorSelected().

◆ slotPaletteChanged

void KisPaletteComboBox::slotPaletteChanged ( )
privateslot

Definition at line 57 of file KisPaletteComboBox.cpp.

58{
59 clear();
60 m_groupMapMap.clear();
61 m_idxSwatchMap.clear();
62
63 if (QSharedPointer<KoColorSet>(m_model->colorSet()).isNull()) { return; }
64
65 for (const QString &groupName : m_model->colorSet()->swatchGroupNames()) {
67 PosIdxMapType posIdxMap;
68 const KisSwatchGroupSP group = m_model->colorSet()->getGroup(groupName);
69 for (const KisSwatchGroup::SwatchInfo &info : group->infoList()) {
70 infoList.append(info);
71 }
72 std::sort(infoList.begin(), infoList.end(), swatchInfoLess);
73 for (const KisSwatchGroup::SwatchInfo &info : infoList) {
74 const KisSwatch &swatch = info.swatch;
75 QString name = swatch.name();
76 if (!swatch.id().isEmpty()){
77 name = swatch.id() + " - " + swatch.name();
78 }
79 addSqueezedItem(QIcon(createColorSquare(swatch)), name);
80 posIdxMap[SwatchPosType(info.column, info.row)] = count() - 1;
81 m_idxSwatchMap.push_back(swatch);
82 }
83 m_groupMapMap[group->name()] = posIdxMap;
84 }
85 if (m_view.isNull()) {
86 setCurrentIndex(0);
87 }
88 QModelIndex idx = m_view->currentIndex();
89 if (!idx.isValid()) { return; }
90 // FIXME! checkIndex() is just a workaround to not trigger ASSERT failures amidst model resets/row changes.
91 // This class really needs a rewrite to conform with Qt's MVC patterns...
92 if (!m_model->checkIndex(idx, QAbstractItemModel::CheckIndexOption::IndexIsValid)) { return; }
93 if (qvariant_cast<bool>(idx.data(KisPaletteModel::IsGroupNameRole))) { return; }
94 if (!qvariant_cast<bool>(idx.data(KisPaletteModel::CheckSlotRole))) { return; }
95
96 blockSignals(true); // this is a passive selection; this shouldn't make others change
98 blockSignals(false);
99}
QPair< int, int > SwatchPosType
QHash< QString, PosIdxMapType > m_groupMapMap
static bool swatchInfoLess(const KisSwatchGroup::SwatchInfo &, const KisSwatchGroup::SwatchInfo &)
QHash< SwatchPosType, int > PosIdxMapType
QPixmap createColorSquare(const KisSwatch &swatch) const
void addSqueezedItem(const QString &newItem, QVariant userData=QVariant())
QString name() const
Definition KisSwatch.h:24
QString id() const
Definition KisSwatch.h:27
const char * name(StandardAction id)
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)

References KisSqueezedComboBox::addSqueezedItem(), KisPaletteModel::CheckSlotRole, createColorSquare(), KisSwatch::id(), KisPaletteModel::IsGroupNameRole, m_groupMapMap, m_idxSwatchMap, m_model, m_view, KisSwatch::name(), slotSwatchSelected(), and swatchInfoLess().

◆ slotSwatchSelected

void KisPaletteComboBox::slotSwatchSelected ( const QModelIndex & index)
privateslot

Definition at line 130 of file KisPaletteComboBox.cpp.

131{
132 if (!qvariant_cast<bool>(index.data(KisPaletteModel::CheckSlotRole))) {
133 return;
134 }
135 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
136 return;
137 }
138 QString gName = qvariant_cast<QString>(index.data(KisPaletteModel::GroupNameRole));
139 int rowInGroup = qvariant_cast<int>(index.data(KisPaletteModel::RowInGroupRole));
140 setCurrentIndex(m_groupMapMap[gName][SwatchPosType(index.column(), rowInGroup)]);
141}

References KisPaletteModel::CheckSlotRole, KisPaletteModel::GroupNameRole, KisPaletteModel::IsGroupNameRole, m_groupMapMap, and KisPaletteModel::RowInGroupRole.

◆ swatchInfoLess()

bool KisPaletteComboBox::swatchInfoLess ( const KisSwatchGroup::SwatchInfo & first,
const KisSwatchGroup::SwatchInfo & second )
staticprivate

Definition at line 101 of file KisPaletteComboBox.cpp.

102{
103 return first.swatch.name() < second.swatch.name();
104}

Member Data Documentation

◆ m_groupMapMap

QHash<QString, PosIdxMapType> KisPaletteComboBox::m_groupMapMap
private

Definition at line 60 of file KisPaletteComboBox.h.

◆ m_idxSwatchMap

QVector<KisSwatch> KisPaletteComboBox::m_idxSwatchMap
private

Definition at line 61 of file KisPaletteComboBox.h.

◆ m_model

QPointer<const KisPaletteModel> KisPaletteComboBox::m_model
private

Definition at line 58 of file KisPaletteComboBox.h.

◆ m_view

QPointer<KisPaletteView> KisPaletteComboBox::m_view
private

Definition at line 59 of file KisPaletteComboBox.h.


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