File indexing completed on 2024-05-12 15:59:07

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include <PaletteView.h>
0008 #include <QVBoxLayout>
0009 
0010 struct PaletteView::Private
0011 {
0012     KisPaletteModel *model = 0;
0013     KisPaletteView *widget = 0;
0014     bool allowPaletteModification = true;
0015 };
0016 
0017 PaletteView::PaletteView(QWidget *parent)
0018     : QWidget(parent), d(new Private)
0019 {
0020     d->widget = new KisPaletteView();
0021     d->model = new KisPaletteModel();
0022     d->widget->setPaletteModel(d->model);
0023 
0024     QVBoxLayout *layout = new QVBoxLayout(this);
0025     layout->addWidget(d->widget);
0026 
0027     //forward signals.
0028     connect(d->widget, SIGNAL(entrySelected(KisSwatch)),
0029                  this, SLOT(fgSelected(KisSwatch)));
0030     connect(d->widget, SIGNAL(entrySelectedBackGround(KisSwatch)),
0031             this, SLOT(bgSelected(KisSwatch)));
0032 }
0033 
0034 PaletteView::~PaletteView()
0035 {
0036     delete d->model;
0037 }
0038 
0039 void PaletteView::setPalette(Palette *palette)
0040 {
0041     d->model->setPalette(palette->colorSet());
0042     d->widget->setPaletteModel(d->model);
0043 }
0044 
0045 bool PaletteView::addEntryWithDialog(ManagedColor *color)
0046 {
0047     if (d->model->colorSet()) {
0048         return d->widget->addEntryWithDialog(color->color());
0049     }
0050     return false;
0051 }
0052 
0053 bool PaletteView::addGroupWithDialog()
0054 {
0055     if (d->model->colorSet()) {
0056         return d->widget->addGroupWithDialog();
0057     }
0058     return false;
0059 }
0060 
0061 bool PaletteView::removeSelectedEntryWithDialog()
0062 {
0063     if (d->model->colorSet()) {
0064         return d->widget->removeEntryWithDialog(d->widget->currentIndex());
0065     }
0066     return false;
0067 }
0068 
0069 void PaletteView::trySelectClosestColor(ManagedColor *color)
0070 {
0071     d->widget->selectClosestColor(color->color());
0072 }
0073 
0074 void PaletteView::fgSelected(KisSwatch swatch)
0075 {
0076     emit entrySelectedForeGround(Swatch(swatch));
0077 }
0078 
0079 void PaletteView::bgSelected(KisSwatch swatch)
0080 {
0081     emit entrySelectedBackGround(Swatch(swatch));
0082 }