Krita

PaletteView.cpp
1 /*
2  * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #include <PaletteView.h>
8 #include <QVBoxLayout>
9 
10 struct PaletteView::Private
11 {
12  KisPaletteModel *model = 0;
13  KisPaletteView *widget = 0;
14  bool allowPaletteModification = true;
15 };
16 
17 PaletteView::PaletteView(QWidget *parent)
18  : QWidget(parent), d(new Private)
19 {
20  d->widget = new KisPaletteView();
21  d->model = new KisPaletteModel();
22  d->widget->setPaletteModel(d->model);
23 
24  QVBoxLayout *layout = new QVBoxLayout(this);
25  layout->addWidget(d->widget);
26 
27  //forward signals.
28  connect(d->widget, SIGNAL(entrySelected(KisSwatch)),
29  this, SLOT(fgSelected(KisSwatch)));
30  connect(d->widget, SIGNAL(entrySelectedBackGround(KisSwatch)),
31  this, SLOT(bgSelected(KisSwatch)));
32 }
33 
34 PaletteView::~PaletteView()
35 {
36  delete d->model;
37 }
38 
40 {
41  d->model->setColorSet(palette->colorSet());
42  d->widget->setPaletteModel(d->model);
43 }
44 
46 {
47  if (d->model->colorSet()) {
48  return d->widget->addEntryWithDialog(color->color());
49  }
50  return false;
51 }
52 
54 {
55  if (d->model->colorSet()) {
56  return d->widget->addGroupWithDialog();
57  }
58  return false;
59 }
60 
62 {
63  if (d->model->colorSet()) {
64  return d->widget->removeEntryWithDialog(d->widget->currentIndex());
65  }
66  return false;
67 }
68 
70 {
71  d->widget->selectClosestColor(color->color());
72 }
73 
74 void PaletteView::fgSelected(KisSwatch swatch)
75 {
76  emit entrySelectedForeGround(Swatch(swatch));
77 }
78 
79 void PaletteView::bgSelected(KisSwatch swatch)
80 {
81  emit entrySelectedBackGround(Swatch(swatch));
82 }
bool removeSelectedEntryWithDialog()
removeSelectedEntryWithDialog removes the selected entry.
Definition: PaletteView.cpp:61
The Palette class Palette is a resource object that stores organised color data.
Definition: Palette.h:45
bool addEntryWithDialog(ManagedColor *color)
addEntryWithDialog This gives a simple dialog for adding colors, with options like adding name,...
Definition: PaletteView.cpp:45
void entrySelectedBackGround(Swatch entry)
entrySelectedBackGround fires when a swatch is selected with rightclick.
void setPalette(Palette *palette)
setPalette Set a new palette.
Definition: PaletteView.cpp:39
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void entrySelectedForeGround(Swatch entry)
entrySelectedForeGround fires when a swatch is selected with leftclick.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
bool addGroupWithDialog()
addGroupWithDialog gives a little dialog to ask for the desired groupname.
Definition: PaletteView.cpp:53
void trySelectClosestColor(ManagedColor *color)
trySelectClosestColor tries to select the closest color to the one given.
Definition: PaletteView.cpp:69
The Swatch class is a thin wrapper around the KisSwatch class.
Definition: Swatch.h:21
The ManagedColor class is a class to handle colors that are color managed.
Definition: ManagedColor.h:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 03:58:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.