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

#include <kis_palette_view.h>

+ Inheritance diagram for KisPaletteView:

Classes

struct  Private
 

Public Slots

void slotFGColorChanged (const KoColor &)
 
void slotScrollerStateChanged (QScroller::State state)
 

Signals

void sigColorSelected (const KoColor &)
 
void sigIndexSelected (const QModelIndex &index)
 

Public Member Functions

bool addEntryWithDialog (KoColor color)
 
bool addGroupWithDialog ()
 
const KoColor closestColor (const KoColor &color) const
 closestColor determines closest swatch in the active palette and returns it's color as KoColor
 
 KisPaletteView (QWidget *parent=0)
 
KisPaletteModelpaletteModel () const
 
bool removeEntryWithDialog (QModelIndex index)
 
void removeSelectedEntry ()
 
void selectClosestColor (const KoColor &color)
 selectClosestColor select a color that's closest to parameter color
 
void setAllowModification (bool allow)
 setAllowModification Set whether doubleclick calls up a modification window. This is to prevent users from editing the palette when the palette is intended to be a list of items.
 
void setCrossedKeyword (const QString &value)
 setCrossedKeyword This allows you to set keywords that can cross out colors. This is implemented to mark the lazybrush "transparent" color.
 
void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer)
 
void setPaletteModel (KisPaletteModel *model)
 
 ~KisPaletteView () override
 

Private Slots

void slotAdditionalGuiUpdate ()
 
void slotCurrentSelectionChanged (const QModelIndex &newCurrent)
 
void slotHorizontalHeaderResized (int, int, int newSize)
 

Private Member Functions

void resizeRows (int newSize)
 
void saveModification ()
 

Private Attributes

const QScopedPointer< Privated
 

Static Private Attributes

static int MINIMUM_ROW_HEIGHT = 10
 

Detailed Description

Definition at line 24 of file kis_palette_view.h.

Constructor & Destructor Documentation

◆ KisPaletteView()

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

Definition at line 42 of file kis_palette_view.cpp.

43 : QTableView(parent)
44 , d(new Private)
45{
46 setItemDelegate(new KisPaletteDelegate(this));
47
48 setShowGrid(true);
49 setDropIndicatorShown(true);
50 setDragDropMode(QAbstractItemView::DragDrop);
51 setSelectionMode(QAbstractItemView::SingleSelection);
52 setDragEnabled(true);
53 setAcceptDrops(false);
54
55 /*
56 * without this, a cycle might be created:
57 * the view stretches to right border, and this make it need a scroll bar;
58 * after the bar is added, the view shrinks to the bar, and this makes it
59 * no longer need the bar any more, and the bar is removed again
60 */
61 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
62
63 // set the size of swatches
64 horizontalHeader()->setVisible(false);
65 verticalHeader()->setVisible(false);
66 horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
67 horizontalHeader()->setMinimumSectionSize(MINIMUM_ROW_HEIGHT);
68 verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
69 verticalHeader()->setMinimumSectionSize(MINIMUM_ROW_HEIGHT);
70
71 connect(horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
72 SLOT(slotHorizontalHeaderResized(int,int,int)));
73 setAutoFillBackground(true);
74
75 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
76 if (scroller) {
77 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
78 this, SLOT(slotScrollerStateChanged(QScroller::State)));
79 }
80
81 connect(this, SIGNAL(clicked(QModelIndex)), SLOT(slotCurrentSelectionChanged(QModelIndex)));
82}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
const QScopedPointer< Private > d
void slotHorizontalHeaderResized(int, int, int newSize)
void slotCurrentSelectionChanged(const QModelIndex &newCurrent)
void slotScrollerStateChanged(QScroller::State state)
static int MINIMUM_ROW_HEIGHT
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)

References connect(), KisKineticScroller::createPreconfiguredScroller(), MINIMUM_ROW_HEIGHT, slotCurrentSelectionChanged(), slotHorizontalHeaderResized(), and slotScrollerStateChanged().

◆ ~KisPaletteView()

KisPaletteView::~KisPaletteView ( )
override

Definition at line 84 of file kis_palette_view.cpp.

85{
86}

Member Function Documentation

◆ addEntryWithDialog()

bool KisPaletteView::addEntryWithDialog ( KoColor color)

add an entry with a dialog window.

Warning
deprecated. kept for compatibility with PaletteView in libkis

Definition at line 97 of file kis_palette_view.cpp.

98{
100 dialog.setWindowTitle(i18nc("@title:dialog", "Add a new Color Swatch"));
101 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
102
103 QComboBox *cmbGroups = new QComboBox;
104 QString defaultGroupName = i18nc("Name for default swatch group", "Default");
105 cmbGroups->addItem(defaultGroupName);
106 cmbGroups->addItems(d->model->colorSet()->swatchGroupNames());
107 QLineEdit *lnIDName = new QLineEdit;
108 QLineEdit *lnName = new QLineEdit;
109 KisColorButton *bnColor = new KisColorButton;
110 QCheckBox *chkSpot = new QCheckBox;
111 chkSpot->setToolTip(i18nc("@info:tooltip", "A spot color is a color that the printer is able to print without mixing the paints it has available to it. The opposite is called a process color."));
112 editableItems->addRow(i18n("Swatch Group:"), cmbGroups);
113 editableItems->addRow(i18n("Swatch ID:"), lnIDName);
114 editableItems->addRow(i18n("Color swatch name:"), lnName);
115 editableItems->addRow(i18nc("Color as the Color of a Swatch in a Palette", "Color:"), bnColor);
116 editableItems->addRow(i18n("Spot color:"), chkSpot);
117 cmbGroups->setCurrentIndex(0);
118 lnName->setText(i18nc("Prefix of a color swatch default name, as in Color 1","Color")+" " + QString::number(d->model->colorSet()->colorCount()+1));
119 lnIDName->setText(QString::number(d->model->colorSet()->colorCount() + 1));
120 bnColor->setColor(color);
121 chkSpot->setChecked(false);
122
123 if (dialog.exec() == KoDialog::Accepted) {
124 QString groupName = cmbGroups->currentText();
125 if (groupName == defaultGroupName) {
126 groupName = QString();
127 }
128 KisSwatch newEntry;
129 newEntry.setColor(bnColor->color());
130 newEntry.setName(lnName->text());
131 newEntry.setId(lnIDName->text());
132 newEntry.setSpotColor(chkSpot->isChecked());
133 d->model->addSwatch(newEntry, groupName);
135 return true;
136 }
137
138 return false;
139}
A pushbutton to display or allow user selection of a color.
void setColor(const KoColor &c)
void setSpotColor(bool spotColor)
Definition KisSwatch.cpp:38
void setColor(const KoColor &color)
Definition KisSwatch.cpp:32
void setId(const QString &id)
Definition KisSwatch.cpp:26
void setName(const QString &name)
Definition KisSwatch.cpp:20
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116

References KisColorButton::color, d, saveModification(), KisColorButton::setColor(), KisSwatch::setColor(), KisSwatch::setId(), KisSwatch::setName(), and KisSwatch::setSpotColor().

◆ addGroupWithDialog()

bool KisPaletteView::addGroupWithDialog ( )

add entry with a dialog window.

Warning
deprecated. kept for compatibility with PaletteView in libkis

Definition at line 141 of file kis_palette_view.cpp.

142{
144 dialog.setWindowTitle(i18nc("@title:dialog","Add a new group"));
145 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
146 QLineEdit *lnName = new QLineEdit();
147 lnName->setText(i18nc("Part of default name for a new group", "Color Group")+""+QString::number(d->model->colorSet()->swatchGroupNames().size()+1));
148 editableItems->addRow(i18nc("Name for a group", "Name"), lnName);
149
150 if (dialog.exec() == KoDialog::Accepted) {
151 d->model->addGroup(lnName->text());
153 return true;
154 }
155 return false;
156}

References d, and saveModification().

◆ closestColor()

const KoColor KisPaletteView::closestColor ( const KoColor & color) const

closestColor determines closest swatch in the active palette and returns it's color as KoColor

Parameters
color
Returns
KoColor

Definition at line 196 of file kis_palette_view.cpp.

197{
198 QModelIndex index = d->model->indexForClosest(color);
199 KisSwatch swatch = d->model->getSwatch(index);
200 return swatch.color();
201}
KoColor color() const
Definition KisSwatch.h:30

References KisSwatch::color(), and d.

◆ paletteModel()

KisPaletteModel * KisPaletteView::paletteModel ( ) const

Definition at line 222 of file kis_palette_view.cpp.

223{
224 return d->model;
225}

References d.

◆ removeEntryWithDialog()

bool KisPaletteView::removeEntryWithDialog ( QModelIndex index)

remove entry with a dialog window.(Necessary for groups.

Warning
deprecated. kept for compatibility with PaletteView in libkis

Definition at line 158 of file kis_palette_view.cpp.

159{
160 bool keepColors = false;
161 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
163 dialog.setWindowTitle(i18nc("@title:dialog","Removing Group"));
164 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
165 QCheckBox *chkKeep = new QCheckBox();
166 editableItems->addRow(i18nc("Shows up when deleting a swatch group", "Keep the Colors"), chkKeep);
167
168 if (dialog.exec() != KoDialog::Accepted) { return false; }
169 keepColors = chkKeep->isChecked();
170 }
171 d->model->removeSwatch(index, keepColors);
172
174
175 return true;
176}

References d, KisPaletteModel::IsGroupNameRole, and saveModification().

◆ removeSelectedEntry()

void KisPaletteView::removeSelectedEntry ( )

Definition at line 249 of file kis_palette_view.cpp.

250{
251 if (selectedIndexes().size() <= 0) {
252 return;
253 }
254 d->model->removeSwatch(currentIndex());
255}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d.

◆ resizeRows()

void KisPaletteView::resizeRows ( int newSize)
private

Definition at line 238 of file kis_palette_view.cpp.

239{
240 verticalHeader()->setDefaultSectionSize(newSize);
241 verticalHeader()->resizeSections(QHeaderView::Fixed);
242}

◆ saveModification()

void KisPaletteView::saveModification ( )
private

Definition at line 244 of file kis_palette_view.cpp.

245{
247}
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)

References d, and KisResourceUserOperations::updateResourceWithUserInput().

◆ selectClosestColor()

void KisPaletteView::selectClosestColor ( const KoColor & color)

selectClosestColor select a color that's closest to parameter color

Parameters
color

Definition at line 178 of file kis_palette_view.cpp.

179{
180 KoColorSetSP colorSet = d->model->colorSet();
181 if (!colorSet || !colorSet->valid() || currentIndex().row() < 0) {
182 return;
183 }
184
185 //also don't select if the color is the same as the current selection
186 if (d->model->getSwatch(currentIndex()).color() == color) {
187 return;
188 }
189
190 selectionModel()->clearSelection();
191 QModelIndex index = d->model->indexForClosest(color);
192
193 selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
194}

References d.

◆ setAllowModification()

void KisPaletteView::setAllowModification ( bool allow)

setAllowModification Set whether doubleclick calls up a modification window. This is to prevent users from editing the palette when the palette is intended to be a list of items.

Definition at line 227 of file kis_palette_view.cpp.

228{
229 setAcceptDrops(allow);
230}

◆ setCrossedKeyword()

void KisPaletteView::setCrossedKeyword ( const QString & value)

setCrossedKeyword This allows you to set keywords that can cross out colors. This is implemented to mark the lazybrush "transparent" color.

Parameters
value

Definition at line 88 of file kis_palette_view.cpp.

89{
90 KisPaletteDelegate *delegate =
91 dynamic_cast<KisPaletteDelegate*>(itemDelegate());
93
94 delegate->setCrossedKeyword(value);
95}
float value(const T *src, size_t ch)
void setCrossedKeyword(const QString &value)
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KIS_ASSERT_RECOVER_RETURN, KisPaletteDelegate::setCrossedKeyword(), and value().

◆ setDisplayRenderer()

void KisPaletteView::setDisplayRenderer ( const KoColorDisplayRendererInterface * displayRenderer)

Definition at line 308 of file kis_palette_view.cpp.

309{
310 Q_ASSERT(d->model);
311 d->model->setDisplayRenderer(displayRenderer);
312}

References d.

◆ setPaletteModel()

void KisPaletteView::setPaletteModel ( KisPaletteModel * model)

Definition at line 208 of file kis_palette_view.cpp.

209{
210 if (d->model) {
211 disconnect(d->model, 0, this, 0);
212 }
213 d->model = model;
214 setModel(model);
216
217 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotAdditionalGuiUpdate()));
218 connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(slotAdditionalGuiUpdate()));
219 connect(model, SIGNAL(modelReset()), SLOT(slotAdditionalGuiUpdate()));
220}

References connect(), d, and slotAdditionalGuiUpdate().

◆ sigColorSelected

void KisPaletteView::sigColorSelected ( const KoColor & )
signal

◆ sigIndexSelected

void KisPaletteView::sigIndexSelected ( const QModelIndex & index)
signal

◆ slotAdditionalGuiUpdate

void KisPaletteView::slotAdditionalGuiUpdate ( )
privateslot

Definition at line 257 of file kis_palette_view.cpp.

258{
259 /*
260 * Note: QTableView (Qt 5.15) does not clear spans on model resets.
261 * But it does move spans on row inserts/removals, so incremental updates
262 * would be possible.
263 * Moving rows on the other hand does NOT update row spans accordingly...
264 */
265 if (!d->model->colorSet()) return;
266
267 clearSpans();
268 resizeRows(verticalHeader()->defaultSectionSize());
269
270// int row = -1;
271
272 for (const QString &groupName : d->model->colorSet()->swatchGroupNames()) {
273 if (groupName.isEmpty()) continue;
274
275// KisSwatchGroupSP group = d->model->colorSet()->getGroup(groupName);
276// row += group->rowCount() + 1;
277// setSpan(row, 0, 1, d->model->columnCount());
278// setRowHeight(row, fontMetrics().lineSpacing() + 6);
279// verticalHeader()->resizeSection(row, fontMetrics().lineSpacing() + 6);
280
281
282 int rowNumber = d->model->colorSet()->startRowForGroup(groupName);
283 setSpan(rowNumber, 0, 1, d->model->columnCount());
284 setRowHeight(rowNumber, fontMetrics().lineSpacing() + 6);
285 verticalHeader()->resizeSection(rowNumber, fontMetrics().lineSpacing() + 6);
286 }
287}
void resizeRows(int newSize)

References d, and resizeRows().

◆ slotCurrentSelectionChanged

void KisPaletteView::slotCurrentSelectionChanged ( const QModelIndex & newCurrent)
privateslot

Definition at line 289 of file kis_palette_view.cpp.

290{
291 if (!newCurrent.isValid()) { return; }
292
293 const bool isGroupName = newCurrent.data(KisPaletteModel::IsGroupNameRole).toBool();
294 const bool isCheckSlot = newCurrent.data(KisPaletteModel::CheckSlotRole).toBool();
295
296 const KisSwatch newEntry = d->model->getSwatch(newCurrent);
297
298 Q_EMIT sigIndexSelected(newCurrent);
299 if (isGroupName) {
300 return;
301 }
302
303 if (isCheckSlot) {
304 Q_EMIT sigColorSelected(newEntry.color());
305 }
306}
void sigColorSelected(const KoColor &)
void sigIndexSelected(const QModelIndex &index)

References KisPaletteModel::CheckSlotRole, KisSwatch::color(), d, KisPaletteModel::IsGroupNameRole, sigColorSelected(), and sigIndexSelected().

◆ slotFGColorChanged

void KisPaletteView::slotFGColorChanged ( const KoColor & color)
slot

This tries to select the closest color in the palette. This doesn't update the foreground color, just the visual selection.

Definition at line 203 of file kis_palette_view.cpp.

204{
205 selectClosestColor(color);
206}
void selectClosestColor(const KoColor &color)
selectClosestColor select a color that's closest to parameter color

References selectClosestColor().

◆ slotHorizontalHeaderResized

void KisPaletteView::slotHorizontalHeaderResized ( int ,
int ,
int newSize )
privateslot

Definition at line 232 of file kis_palette_view.cpp.

233{
234 resizeRows(newSize);
236}

References resizeRows(), and slotAdditionalGuiUpdate().

◆ slotScrollerStateChanged

void KisPaletteView::slotScrollerStateChanged ( QScroller::State state)
inlineslot

Definition at line 104 of file kis_palette_view.h.

KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)

References KisKineticScroller::updateCursor().

Member Data Documentation

◆ d

const QScopedPointer<Private> KisPaletteView::d
private

Definition at line 117 of file kis_palette_view.h.

◆ MINIMUM_ROW_HEIGHT

int KisPaletteView::MINIMUM_ROW_HEIGHT = 10
staticprivate

Definition at line 28 of file kis_palette_view.h.


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