File indexing completed on 2024-05-12 16:02:01

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *  SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #ifndef __KIS_PALETTE_VIEW_H
0009 #define __KIS_PALETTE_VIEW_H
0010 
0011 #include <QScopedPointer>
0012 #include <QTableView>
0013 #include <QPushButton>
0014 #include <QPixmap>
0015 #include <QIcon>
0016 
0017 #include <KoColorSet.h>
0018 #include "kritawidgets_export.h"
0019 
0020 #include <KisKineticScroller.h>
0021 
0022 class KisPaletteModel;
0023 class QWheelEvent;
0024 class KoColorDisplayRendererInterface;
0025 
0026 class KRITAWIDGETS_EXPORT KisPaletteView : public QTableView
0027 {
0028     Q_OBJECT
0029 private:
0030     static int MININUM_ROW_HEIGHT;
0031 public:
0032     explicit KisPaletteView(QWidget *parent = 0);
0033     ~KisPaletteView() override;
0034 
0035     void setPaletteModel(KisPaletteModel *model);
0036     KisPaletteModel *paletteModel() const;
0037 
0038 public:
0039 
0040     /**
0041      * @brief setAllowModification
0042      * Set whether doubleclick calls up a modification window. This is to prevent users from editing
0043      * the palette when the palette is intended to be a list of items.
0044      */
0045     void setAllowModification(bool allow);
0046 
0047     void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
0048 
0049     /**
0050      * @brief setCrossedKeyword
0051      * this apparently allows you to set keywords that can cross out colors.
0052      * This is implemented to mark the lazybrush "transparent" color.
0053      * @param value
0054      */
0055     void setCrossedKeyword(const QString &value);
0056     void removeSelectedEntry();
0057     /**
0058      * @brief selectClosestColor
0059      * select a color that's closest to parameter color
0060      * @param color
0061      */
0062     void selectClosestColor(const KoColor &color);
0063 
0064     /**
0065      * @brief closestColor
0066      * determines closest swatch in the active palette and returns it's color as KoColor
0067      * @param color
0068      * @return KoColor
0069      */
0070     const KoColor closestColor(const KoColor& color) const;
0071 
0072     /**
0073      * add an entry with a dialog window.
0074      * @warning deprecated.
0075      * kept for compatibility with PaletteView in libkis
0076      */
0077     bool addEntryWithDialog(KoColor color);
0078     /**
0079      * remove entry with a dialog window.(Necessary for groups.
0080      * @warning deprecated.
0081      * kept for compatibility with PaletteView in libkis
0082      */
0083     bool removeEntryWithDialog(QModelIndex index);
0084     /**
0085      * add entry with a dialog window.
0086      * @warning deprecated.
0087      * kept for compatibility with PaletteView in libkis
0088      */
0089     bool addGroupWithDialog();
0090 
0091 Q_SIGNALS:
0092     void sigIndexSelected(const QModelIndex &index);
0093     void sigColorSelected(const KoColor &);
0094     void sigPaletteUpdatedFromModel();
0095 
0096 public Q_SLOTS:
0097     /**
0098      *  This tries to select the closest color in the palette.
0099      *  This doesn't update the foreground color, just the visual selection.
0100      */
0101     void slotFGColorChanged(const KoColor &);
0102 
0103     void slotScrollerStateChanged(QScroller::State state){KisKineticScroller::updateCursor(this, state);}
0104 
0105 private Q_SLOTS:
0106     void slotHorizontalHeaderResized(int, int, int newSize);
0107     void slotAdditionalGuiUpdate();
0108     void slotCurrentSelectionChanged(const QModelIndex &newCurrent);
0109 
0110 private:
0111     void resizeRows(int newSize);
0112     void saveModification();
0113 
0114 private:
0115     struct Private;
0116     const QScopedPointer<Private> m_d;
0117 };
0118 
0119 #endif /* __KIS_PALETTE_VIEW_H */