Krita

PaletteView.cpp
1/*
2 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include <PaletteView.h>
8#include <QVBoxLayout>
9
10struct PaletteView::Private
11{
12 KisPaletteModel *model = 0;
13 KisPaletteView *widget = 0;
14 bool allowPaletteModification = true;
15};
16
17PaletteView::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(sigIndexSelected(QModelIndex)),
29 this, SLOT(fgSelected(QModelIndex)));
30}
31
32PaletteView::~PaletteView()
33{
34 delete d->widget;
35 delete d->model;
36}
37
39{
40 d->model->setColorSet(palette->colorSet());
41 d->widget->setPaletteModel(d->model);
42}
43
45{
46 if (d->model->colorSet()) {
47 return d->widget->addEntryWithDialog(color->color());
48 }
49 return false;
50}
51
53{
54 if (d->model->colorSet()) {
55 return d->widget->addGroupWithDialog();
56 }
57 return false;
58}
59
61{
62 if (d->model->colorSet()) {
63 return d->widget->removeEntryWithDialog(d->widget->currentIndex());
64 }
65 return false;
66}
67
69{
70 d->widget->selectClosestColor(color->color());
71}
72
73void PaletteView::fgSelected(QModelIndex index)
74{
75 KisSwatch swatch = d->model->getSwatch(index);
77}
The ManagedColor class is a class to handle colors that are color managed.
void entrySelectedForeGround(Swatch entry)
entrySelectedForeGround fires when a swatch is selected with leftclick.
bool addEntryWithDialog(ManagedColor *color)
addEntryWithDialog This gives a simple dialog for adding colors, with options like adding name,...
bool removeSelectedEntryWithDialog()
removeSelectedEntryWithDialog removes the selected entry.
void setPalette(Palette *palette)
setPalette Set a new palette.
void trySelectClosestColor(ManagedColor *color)
trySelectClosestColor tries to select the closest color to the one given.
bool addGroupWithDialog()
addGroupWithDialog gives a little dialog to ask for the desired groupname.
The Palette class Palette is a resource object that stores organised color data.
Definition Palette.h:45
The Swatch class is a thin wrapper around the KisSwatch class.
Definition Swatch.h:22
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:12:36 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.