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 scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible) override
 
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 44 of file kis_palette_view.cpp.

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

◆ ~KisPaletteView()

KisPaletteView::~KisPaletteView ( )
override

Definition at line 86 of file kis_palette_view.cpp.

87{
88}

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 99 of file kis_palette_view.cpp.

100{
102 dialog.setWindowTitle(i18nc("@title:dialog", "Add a new Color Swatch"));
103 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
104
105 QComboBox *cmbGroups = new QComboBox;
106 QString defaultGroupName = i18nc("Name for default swatch group", "Default");
107 cmbGroups->addItem(defaultGroupName);
108 cmbGroups->addItems(d->model->colorSet()->swatchGroupNames());
109 QLineEdit *lnIDName = new QLineEdit;
110 QLineEdit *lnName = new QLineEdit;
111 KisColorButton *bnColor = new KisColorButton;
112 QCheckBox *chkSpot = new QCheckBox;
113 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."));
114 editableItems->addRow(i18n("Swatch Group:"), cmbGroups);
115 editableItems->addRow(i18n("Swatch ID:"), lnIDName);
116 editableItems->addRow(i18n("Color swatch name:"), lnName);
117 editableItems->addRow(i18nc("Color as the Color of a Swatch in a Palette", "Color:"), bnColor);
118 editableItems->addRow(i18n("Spot color:"), chkSpot);
119 cmbGroups->setCurrentIndex(0);
120 lnName->setText(i18nc("Prefix of a color swatch default name, as in Color 1","Color")+" " + QString::number(d->model->colorSet()->colorCount()+1));
121 lnIDName->setText(QString::number(d->model->colorSet()->colorCount() + 1));
122 bnColor->setColor(color);
123 chkSpot->setChecked(false);
124
125 if (dialog.exec() == KoDialog::Accepted) {
126 QString groupName = cmbGroups->currentText();
127 if (groupName == defaultGroupName) {
128 groupName = QString();
129 }
130 KisSwatch newEntry;
131 newEntry.setColor(bnColor->color());
132 newEntry.setName(lnName->text());
133 newEntry.setId(lnIDName->text());
134 newEntry.setSpotColor(chkSpot->isChecked());
135 d->model->addSwatch(newEntry, groupName);
137 return true;
138 }
139
140 return false;
141}
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 143 of file kis_palette_view.cpp.

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

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 205 of file kis_palette_view.cpp.

206{
207 QModelIndex index = d->model->indexForClosest(color);
208 KisSwatch swatch = d->model->getSwatch(index);
209 return swatch.color();
210}
KoColor color() const
Definition KisSwatch.h:30

References KisSwatch::color(), and d.

◆ paletteModel()

KisPaletteModel * KisPaletteView::paletteModel ( ) const

Definition at line 232 of file kis_palette_view.cpp.

233{
234 return d->model;
235}

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 167 of file kis_palette_view.cpp.

168{
169 bool keepColors = false;
170 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
172 dialog.setWindowTitle(i18nc("@title:dialog","Removing Group"));
173 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
174 QCheckBox *chkKeep = new QCheckBox();
175 editableItems->addRow(i18nc("Shows up when deleting a swatch group", "Keep the Colors"), chkKeep);
176
177 if (dialog.exec() != KoDialog::Accepted) { return false; }
178 keepColors = chkKeep->isChecked();
179 }
180 d->model->removeSwatch(index, keepColors);
181
183
184 return true;
185}

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

◆ removeSelectedEntry()

void KisPaletteView::removeSelectedEntry ( )

Definition at line 259 of file kis_palette_view.cpp.

260{
261 if (selectedIndexes().size() <= 0) {
262 return;
263 }
264 d->model->removeSwatch(currentIndex());
265}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d.

◆ resizeRows()

void KisPaletteView::resizeRows ( int newSize)
private

Definition at line 248 of file kis_palette_view.cpp.

249{
250 verticalHeader()->setDefaultSectionSize(newSize);
251 verticalHeader()->resizeSections(QHeaderView::Fixed);
252}

◆ saveModification()

void KisPaletteView::saveModification ( )
private

Definition at line 254 of file kis_palette_view.cpp.

255{
257}
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)

References d, and KisResourceUserOperations::updateResourceWithUserInput().

◆ scrollTo()

void KisPaletteView::scrollTo ( const QModelIndex & index,
ScrollHint hint = EnsureVisible )
override

Definition at line 160 of file kis_palette_view.cpp.

161{
162 if(!d->foregroundColorChangeInProgress) {
163 QTableView::scrollTo(index, hint);
164 }
165}

References d.

◆ selectClosestColor()

void KisPaletteView::selectClosestColor ( const KoColor & color)

selectClosestColor select a color that's closest to parameter color

Parameters
color

Definition at line 187 of file kis_palette_view.cpp.

188{
189 KoColorSetSP colorSet = d->model->colorSet();
190 if (!colorSet || !colorSet->valid() || currentIndex().row() < 0) {
191 return;
192 }
193
194 //also don't select if the color is the same as the current selection
195 if (d->model->getSwatch(currentIndex()).color() == color) {
196 return;
197 }
198
199 selectionModel()->clearSelection();
200 QModelIndex index = d->model->indexForClosest(color);
201
202 selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
203}

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 237 of file kis_palette_view.cpp.

238{
239 setAcceptDrops(allow);
240}

◆ 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 90 of file kis_palette_view.cpp.

91{
92 KisPaletteDelegate *delegate =
93 dynamic_cast<KisPaletteDelegate*>(itemDelegate());
95
96 delegate->setCrossedKeyword(value);
97}
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 318 of file kis_palette_view.cpp.

319{
320 Q_ASSERT(d->model);
321 d->model->setDisplayRenderer(displayRenderer);
322}

References d.

◆ setPaletteModel()

void KisPaletteView::setPaletteModel ( KisPaletteModel * model)

Definition at line 218 of file kis_palette_view.cpp.

219{
220 if (d->model) {
221 disconnect(d->model, 0, this, 0);
222 }
223 d->model = model;
224 setModel(model);
226
227 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotAdditionalGuiUpdate()));
228 connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(slotAdditionalGuiUpdate()));
229 connect(model, SIGNAL(modelReset()), SLOT(slotAdditionalGuiUpdate()));
230}

References 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 267 of file kis_palette_view.cpp.

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

References d, and resizeRows().

◆ slotCurrentSelectionChanged

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

Definition at line 299 of file kis_palette_view.cpp.

300{
301 if (!newCurrent.isValid()) { return; }
302
303 const bool isGroupName = newCurrent.data(KisPaletteModel::IsGroupNameRole).toBool();
304 const bool isCheckSlot = newCurrent.data(KisPaletteModel::CheckSlotRole).toBool();
305
306 const KisSwatch newEntry = d->model->getSwatch(newCurrent);
307
308 Q_EMIT sigIndexSelected(newCurrent);
309 if (isGroupName) {
310 return;
311 }
312
313 if (isCheckSlot) {
314 Q_EMIT sigColorSelected(newEntry.color());
315 }
316}
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 212 of file kis_palette_view.cpp.

213{
214 QScopedValueRollback<bool> rollback(d->foregroundColorChangeInProgress, true);
215 selectClosestColor(color);
216}
void selectClosestColor(const KoColor &color)
selectClosestColor select a color that's closest to parameter color

References d, and selectClosestColor().

◆ slotHorizontalHeaderResized

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

Definition at line 242 of file kis_palette_view.cpp.

243{
244 resizeRows(newSize);
246}

References resizeRows(), and slotAdditionalGuiUpdate().

◆ slotScrollerStateChanged

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

Definition at line 106 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 119 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: