Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorPatches Class Reference

#include <kis_color_patches.h>

+ Inheritance diagram for KisColorPatches:

Public Types

enum  Direction { Horizontal , Vertical }
 
- Public Types inherited from KisColorSelectorBase
enum  Move { MoveToMousePosition , DontMove }
 

Public Slots

void updateSettings () override
 
- Public Slots inherited from KisColorSelectorBase
virtual void reset ()
 
virtual void showPopup (Move move=MoveToMousePosition)
 
virtual void updateSettings ()
 

Public Member Functions

void addColorPatch (const KoColor &color)
 
QList< KoColorcolors () const
 
 KisColorPatches (QString configPrefix, QWidget *parent=0)
 
void mousePressEvent (QMouseEvent *) override
 
void mouseReleaseEvent (QMouseEvent *) override
 
int patchCount () const
 
void setAdditionalButtons (QList< QWidget * > buttonList)
 
void setCanvas (KisCanvas2 *canvas) override
 
void setColors (const QList< KoColor > &colors)
 
void unsetCanvas () override
 
- Public Member Functions inherited from KisColorSelectorBase
const KoColorSpacecolorSpace () const
 
KisDisplayColorConverterconverter () const
 
void enterEvent (QEnterEvent *e) override
 
 KisColorSelectorBase (QWidget *parent=0)
 
void leaveEvent (QEvent *e) override
 
void mousePressEvent (QMouseEvent *) override
 
void mouseReleaseEvent (QMouseEvent *) override
 
virtual void setColor (const KoColor &color)
 
void setColorSpace (const KoColorSpace *colorSpace)
 
void setPopupBehaviour (bool onMouseOver, bool onMouseClick)
 
void showColorPreview ()
 
void slotUpdateColorAndPreview (QPair< KoColor, Acs::ColorRole > color)
 
void tryHideAllPopups ()
 
void updateBaseColorPreview (const KoColor &color)
 
void updateColor (const KoColor &color, Acs::ColorRole role, bool needsExplicitColorReset)
 
void updateColorPreview (const KoColor &color)
 
void updatePreviousColorPreview ()
 
 ~KisColorSelectorBase () override
 

Private Attributes

QList< QWidget * > m_buttonList
 
KisColorPatchesTableViewm_colorPatchesView
 
QString m_configPrefix
 
Direction m_direction
 

Additional Inherited Members

- Protected Slots inherited from KisColorSelectorBase
virtual void canvasResourceChanged (int key, const QVariant &v)
 if you overwrite this, keep in mind, that you should set the color only, if m_colorUpdateAllowed is true
 
void hidePopup ()
 
void updateLastUsedColorPreview (const KoColor &color)
 
- Protected Member Functions inherited from KisColorSelectorBase
void changeEvent (QEvent *event) override
 
virtual KisColorSelectorBasecreatePopup () const =0
 
void dragEnterEvent (QDragEnterEvent *) override
 
void dropEvent (QDropEvent *) override
 
bool isPopup () const
 
void keyPressEvent (QKeyEvent *) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void requestUpdateColorAndPreview (const KoColor &color, Acs::ColorRole role)
 
void setHidingTime (int time)
 
void showEvent (QShowEvent *event) override
 
- Protected Attributes inherited from KisColorSelectorBase
QPointer< KisCanvas2m_canvas
 
bool m_colorUpdateAllowed
 
bool m_colorUpdateSelf
 
QWidget * m_parent
 
KisColorSelectorBasem_popup
 

Detailed Description

Definition at line 18 of file kis_color_patches.h.

Member Enumeration Documentation

◆ Direction

Enumerator
Horizontal 
Vertical 

Definition at line 23 of file kis_color_patches.h.

Constructor & Destructor Documentation

◆ KisColorPatches()

KisColorPatches::KisColorPatches ( QString configPrefix,
QWidget * parent = 0 )
explicit

Definition at line 27 of file kis_color_patches.cpp.

28 : KisColorSelectorBase(parent)
29 , m_configPrefix(configPrefix)
30 , m_colorPatchesView(new KisColorPatchesTableView(configPrefix, parent))
31{
33}
void updateSettings() override
KisColorPatchesTableView * m_colorPatchesView
KisColorSelectorBase(QWidget *parent=0)

References updateSettings().

Member Function Documentation

◆ addColorPatch()

void KisColorPatches::addColorPatch ( const KoColor & color)

Definition at line 90 of file kis_color_patches.cpp.

91{
93}
void addColorPatch(const KoColor &color)

References KisColorPatchesTableView::addColorPatch(), and m_colorPatchesView.

◆ colors()

QList< KoColor > KisColorPatches::colors ( ) const

Definition at line 154 of file kis_color_patches.cpp.

155{
156 return m_colorPatchesView->colors();
157}

References KisColorPatchesTableView::colors(), and m_colorPatchesView.

◆ mousePressEvent()

void KisColorPatches::mousePressEvent ( QMouseEvent * event)
override

Definition at line 58 of file kis_color_patches.cpp.

59{
60 boost::optional<KoColor> isColor = m_colorPatchesView->colorPatchAt(event->globalPos());
61 if (!isColor) {
62 return;
63 }
64
65 KoColor color = *isColor;
66
68 if (event->isAccepted())
69 return;
70
71 updateColorPreview(color);
72 event->accept();
73}
boost::optional< KoColor > colorPatchAt(const QPoint &pos) const
void updateColorPreview(const KoColor &color)
void mousePressEvent(QMouseEvent *) override

References KisColorPatchesTableView::colorPatchAt(), m_colorPatchesView, KisColorSelectorBase::mousePressEvent(), and KisColorSelectorBase::updateColorPreview().

◆ mouseReleaseEvent()

void KisColorPatches::mouseReleaseEvent ( QMouseEvent * event)
override

Definition at line 35 of file kis_color_patches.cpp.

36{
37 event->ignore();
39 if (event->isAccepted() || !rect().contains(event->pos()))
40 return;
41
42 if (!m_canvas) return;
43
44 boost::optional<KoColor> isColor = m_colorPatchesView->colorPatchAt(event->globalPos());
45 if (!isColor) {
46 return;
47 }
48
49 KoColor color = *isColor;
50 if (event->button() == Qt::LeftButton) {
51 m_canvas->resourceManager()->setForegroundColor(color);
52 } else if (event->button() == Qt::RightButton) {
53 m_canvas->resourceManager()->setBackgroundColor(color);
54 }
55 event->accept();
56}
void mouseReleaseEvent(QMouseEvent *) override
QPointer< KisCanvas2 > m_canvas

References KisColorPatchesTableView::colorPatchAt(), KisColorSelectorBase::m_canvas, m_colorPatchesView, and KisColorSelectorBase::mouseReleaseEvent().

◆ patchCount()

int KisColorPatches::patchCount ( ) const

◆ setAdditionalButtons()

void KisColorPatches::setAdditionalButtons ( QList< QWidget * > buttonList)

set buttons, that should be drawn additionally to the patches this class takes ownership of them and will delete them they will be resized to the patchsize

Definition at line 95 of file kis_color_patches.cpp.

96{
97 for (int i = 0; i < buttonList.size(); i++) {
98 buttonList.at(i)->setParent(this);
99 }
100 m_buttonList = buttonList;
101}
QList< QWidget * > m_buttonList

References m_buttonList.

◆ setCanvas()

void KisColorPatches::setCanvas ( KisCanvas2 * canvas)
overridevirtual

Reimplemented from KisColorSelectorBase.

Reimplemented in KisCommonColors.

Definition at line 80 of file kis_color_patches.cpp.

81{
83}
virtual void setCanvas(KisCanvas2 *canvas)

References KisColorSelectorBase::setCanvas().

◆ setColors()

void KisColorPatches::setColors ( const QList< KoColor > & colors)

Definition at line 149 of file kis_color_patches.cpp.

150{
152}
void setColors(const QList< KoColor > &colors)
QList< KoColor > colors() const

References colors(), m_colorPatchesView, and KisColorPatchesTableView::setColors().

◆ unsetCanvas()

void KisColorPatches::unsetCanvas ( )
overridevirtual

Reimplemented from KisColorSelectorBase.

Reimplemented in KisCommonColors.

Definition at line 85 of file kis_color_patches.cpp.

References KisColorSelectorBase::unsetCanvas().

◆ updateSettings

void KisColorPatches::updateSettings ( )
overrideslot

Definition at line 103 of file kis_color_patches.cpp.

104{
106
107 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
109
110 QBoxLayout::Direction layoutDirection;
111 if (cfg.readEntry(m_configPrefix + "Alignment", false)) {
113 layoutDirection = QBoxLayout::TopToBottom;
114 } else {
116 layoutDirection = QBoxLayout::LeftToRight;
117 }
118
119 QBoxLayout *boxLayout = dynamic_cast<QBoxLayout*>(layout());
120 if (!boxLayout) {
121 boxLayout = new QBoxLayout(layoutDirection, this);
122 boxLayout->setContentsMargins(0, 0, 0, 0);
123 setLayout(boxLayout);
124 layout()->addWidget(m_colorPatchesView);
125 } else if (boxLayout->direction() != layoutDirection) {
126 boxLayout->setDirection(layoutDirection);
127 }
128
129
130 if (isPopup()) {
131 if (m_direction == Vertical) {
132 setMinimumWidth(m_colorPatchesView->width());
133 setMaximumWidth(m_colorPatchesView->width());
134 } else {
135 setMinimumHeight(m_colorPatchesView->height());
136 setMaximumHeight(m_colorPatchesView->height());
137 }
138 }
139
140 for (int i = 0; i < m_buttonList.size(); i++) {
141 m_buttonList.at(i)->setGeometry(QRect(QPoint(0, 0), m_colorPatchesView->cellSize()));
142 }
143
144 setPopupBehaviour(false, false);
145 update();
146}
void setPopupBehaviour(bool onMouseOver, bool onMouseClick)
bool update(QSpinBox *spinBox)

References KisColorPatchesTableView::cellSize(), Horizontal, KisColorSelectorBase::isPopup(), m_buttonList, m_colorPatchesView, m_configPrefix, m_direction, KisColorPatchesTableView::reloadWidgetConfig(), KisColorSelectorBase::setPopupBehaviour(), KisColorSelectorBase::updateSettings(), and Vertical.

Member Data Documentation

◆ m_buttonList

QList<QWidget*> KisColorPatches::m_buttonList
private

Definition at line 50 of file kis_color_patches.h.

◆ m_colorPatchesView

KisColorPatchesTableView* KisColorPatches::m_colorPatchesView
private

Definition at line 52 of file kis_color_patches.h.

◆ m_configPrefix

QString KisColorPatches::m_configPrefix
private

Definition at line 51 of file kis_color_patches.h.

◆ m_direction

Direction KisColorPatches::m_direction
private

Definition at line 49 of file kis_color_patches.h.


The documentation for this class was generated from the following files: