16#include <KConfigGroup>
17#include <KSharedConfig>
18#include <KLocalizedString>
49 setDropIndicatorShown(
true);
50 setDragDropMode(QAbstractItemView::DragDrop);
51 setSelectionMode(QAbstractItemView::SingleSelection);
53 setAcceptDrops(
false);
61 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
64 horizontalHeader()->setVisible(
false);
65 verticalHeader()->setVisible(
false);
66 horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
68 verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
71 connect(horizontalHeader(), SIGNAL(sectionResized(
int,
int,
int)),
73 setAutoFillBackground(
true);
77 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
100 dialog.setWindowTitle(i18nc(
"@title:dialog",
"Add a new Color Swatch"));
101 QFormLayout *editableItems =
new QFormLayout(dialog.mainWidget());
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;
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));
121 chkSpot->setChecked(
false);
123 if (dialog.exec() == KoDialog::Accepted) {
124 QString groupName = cmbGroups->currentText();
125 if (groupName == defaultGroupName) {
126 groupName = QString();
130 newEntry.
setName(lnName->text());
131 newEntry.
setId(lnIDName->text());
133 d->model->addSwatch(newEntry, groupName);
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);
150 if (dialog.exec() == KoDialog::Accepted) {
151 d->model->addGroup(lnName->text());
160 bool keepColors =
false;
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);
168 if (dialog.exec() != KoDialog::Accepted) {
return false; }
169 keepColors = chkKeep->isChecked();
171 d->model->removeSwatch(index, keepColors);
181 if (!colorSet || !colorSet->valid() || currentIndex().row() < 0) {
186 if (
d->model->getSwatch(currentIndex()).color() == color) {
190 selectionModel()->clearSelection();
191 QModelIndex index =
d->model->indexForClosest(color);
193 selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
198 QModelIndex index =
d->model->indexForClosest(color);
199 KisSwatch swatch =
d->model->getSwatch(index);
200 return swatch.
color();
211 disconnect(
d->model, 0,
this, 0);
229 setAcceptDrops(allow);
240 verticalHeader()->setDefaultSectionSize(newSize);
241 verticalHeader()->resizeSections(QHeaderView::Fixed);
251 if (selectedIndexes().size() <= 0) {
254 d->model->removeSwatch(currentIndex());
265 if (!
d->model->colorSet())
return;
268 resizeRows(verticalHeader()->defaultSectionSize());
272 for (
const QString &groupName :
d->model->colorSet()->swatchGroupNames()) {
273 if (groupName.isEmpty())
continue;
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);
291 if (!newCurrent.isValid()) {
return; }
296 const KisSwatch newEntry =
d->model->getSwatch(newCurrent);
311 d->model->setDisplayRenderer(displayRenderer);
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setCrossedKeyword(const QString &value)
The KisPaletteModel class This, together with KisPaletteView and KisPaletteDelegate forms a mvc way t...
void setCrossedKeyword(const QString &value)
setCrossedKeyword This allows you to set keywords that can cross out colors. This is implemented to m...
void setAllowModification(bool allow)
setAllowModification Set whether doubleclick calls up a modification window. This is to prevent users...
void slotAdditionalGuiUpdate()
bool removeEntryWithDialog(QModelIndex index)
void sigColorSelected(const KoColor &)
const KoColor closestColor(const KoColor &color) const
closestColor determines closest swatch in the active palette and returns it's color as KoColor
void slotFGColorChanged(const KoColor &)
const QScopedPointer< Private > d
void removeSelectedEntry()
void slotHorizontalHeaderResized(int, int, int newSize)
void slotCurrentSelectionChanged(const QModelIndex &newCurrent)
void sigIndexSelected(const QModelIndex &index)
KisPaletteModel * paletteModel() const
void setPaletteModel(KisPaletteModel *model)
~KisPaletteView() override
void slotScrollerStateChanged(QScroller::State state)
bool addGroupWithDialog()
bool addEntryWithDialog(KoColor color)
KisPaletteView(QWidget *parent=0)
void resizeRows(int newSize)
static int MINIMUM_ROW_HEIGHT
void selectClosestColor(const KoColor &color)
selectClosestColor select a color that's closest to parameter color
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
void setSpotColor(bool spotColor)
void setColor(const KoColor &color)
void setId(const QString &id)
void setName(const QString &name)
A dialog base class with standard buttons and predefined layouts.
#define KIS_ASSERT_RECOVER_RETURN(cond)
QPointer< KisPaletteModel > model