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

#include <WGColorPatches.h>

+ Inheritance diagram for WGColorPatches:

Public Types

enum  Preset { None , History , CommonColors }
 
- Public Types inherited from WGSelectorWidgetBase
enum  UiMode { DockerMode , PopupMode }
 

Public Slots

void updateIcons ()
 

Signals

void sigColorChanged (const KoColor &color)
 
- Signals inherited from WGSelectorWidgetBase
void sigChannelValuesChanged (const QVector4D &values)
 
void sigColorInteraction (bool active)
 

Public Member Functions

KisUniqueColorSetcolorHistoryModel () const
 
QPoint popupOffset () const override
 The position, relative to the top left corner, where the cursor of the cursor shall be when showing the popup.
 
void setAdditionalButtons (QList< QToolButton * > buttonList)
 
void setColorHistoryModel (KisUniqueColorSet *history)
 
void setPreset (Preset preset)
 
void updateSettings () override
 
 WGColorPatches (WGSelectorDisplayConfigSP displayConfig, KisUniqueColorSet *history, QWidget *parent=nullptr)
 
- Public Member Functions inherited from WGSelectorWidgetBase
WGSelectorDisplayConfigSP displayConfiguration () const
 
const KisDisplayColorConverterdisplayConverter () const
 
virtual void setModel (KisVisualColorModelSP model)
 
void setUiMode (UiMode mode)
 
UiMode uiMode () const
 
 WGSelectorWidgetBase (WGSelectorDisplayConfigSP displayConfig, QWidget *parent=nullptr, UiMode uiMode=UiMode::DockerMode)
 

Protected Member Functions

void contentPaintEvent (QPaintEvent *event)
 
bool event (QEvent *event) override
 
bool eventFilter (QObject *watched, QEvent *e) override
 
QToolButton * fetchButton (QList< QToolButton * > &recycleList)
 
int indexAt (const QPoint &widgetPos) const
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
QRect patchRect (int gridIndex) const
 
void reconnectButtons (KisUniqueColorSet *oldSet, KisUniqueColorSet *newSet)
 
void resizeEvent (QResizeEvent *event) override
 
QPoint scrollOffset () const
 
QSize sizeHint () const override
 
void updateMetrics ()
 
void wheelEvent (QWheelEvent *event) override
 

Private Attributes

bool m_allowScrolling {true}
 
QList< QToolButton * > m_buttonList
 
QPointer< KisUniqueColorSetm_colorHistoryModel
 
const WGConfig::ColorPatchesm_configSource {0}
 
QWidget * m_contentWidget {0}
 
int m_maxScroll {0}
 
int m_mouseIndex {-1}
 
int m_numLines {1}
 
Qt::Orientation m_orientation {Qt::Horizontal}
 
int m_patchCount {30}
 
int m_patchesPerLine {30}
 
int m_patchHeight {16}
 
int m_patchWidth {16}
 
Preset m_preset {None}
 
bool m_scrollInline {true}
 
int m_scrollValue {0}
 
int m_totalLines {1}
 
QWidget * m_viewport {0}
 

Detailed Description

Definition at line 22 of file WGColorPatches.h.

Member Enumeration Documentation

◆ Preset

Enumerator
None 
History 
CommonColors 

Definition at line 26 of file WGColorPatches.h.

Constructor & Destructor Documentation

◆ WGColorPatches()

WGColorPatches::WGColorPatches ( WGSelectorDisplayConfigSP displayConfig,
KisUniqueColorSet * history,
QWidget * parent = nullptr )

Definition at line 26 of file WGColorPatches.cpp.

27 : WGSelectorWidgetBase(displayConfig, parent)
28{
29 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
30 m_viewport = new QWidget(this);
31 m_viewport->installEventFilter(this);
32 m_viewport->setFocusProxy(this);
33 m_contentWidget = new QWidget(m_viewport);
34 m_contentWidget->installEventFilter(this);
35 m_contentWidget->setAttribute(Qt::WA_StaticContents);
36 // this prevents repainting the entire content widget when scrolling:
37 m_contentWidget->setAutoFillBackground(true);
38 setColorHistoryModel(history);
39}
QWidget * m_contentWidget
void setColorHistoryModel(KisUniqueColorSet *history)
QWidget * m_viewport
WGSelectorWidgetBase(WGSelectorDisplayConfigSP displayConfig, QWidget *parent=nullptr, UiMode uiMode=UiMode::DockerMode)

References m_contentWidget, m_viewport, and setColorHistoryModel().

Member Function Documentation

◆ colorHistoryModel()

KisUniqueColorSet * WGColorPatches::colorHistoryModel ( ) const

Definition at line 41 of file WGColorPatches.cpp.

42{
44}
QPointer< KisUniqueColorSet > m_colorHistoryModel

References m_colorHistoryModel.

◆ contentPaintEvent()

void WGColorPatches::contentPaintEvent ( QPaintEvent * event)
protected

Definition at line 343 of file WGColorPatches.cpp.

344{
345 QRect updateRect = event->rect();
346 //qDebug() << "WGColorPatches::conentPaintEvent region:" << event->region();
347 int numColors = m_colorHistoryModel ? m_colorHistoryModel->size() : 0;
348 if (numColors <= 0) {
349 return;
350 }
351
352 QPainter painter(m_contentWidget);
353 const KisDisplayColorConverter *converter = displayConverter();
354
355 // this could be optimized a bit more...
356 for (int i = 0; i < qMin(m_patchCount, m_colorHistoryModel->size()); i++) {
357 QRect patch = patchRect(i);
358 if (patch.intersects(updateRect)) {
359 QColor qcolor = converter->toQColor(m_colorHistoryModel->color(i));
360
361 painter.fillRect(patch, qcolor);
362 }
363 }
364}
QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const
QRect patchRect(int gridIndex) const
const KisDisplayColorConverter * displayConverter() const

References WGSelectorWidgetBase::displayConverter(), m_colorHistoryModel, m_contentWidget, m_patchCount, patchRect(), and KisDisplayColorConverter::toQColor().

◆ event()

bool WGColorPatches::event ( QEvent * event)
overrideprotected

Definition at line 191 of file WGColorPatches.cpp.

192{
193 switch (event->type()) {
194 case QEvent::Paint:
195 // TODO: remove?
196 // this widget doesn't paint anything on itself, instead the viewport's paint event
197 // is redirected to this paintEvent() handler
198 return true;
199 case QEvent::ScrollPrepare:
200 {
201 QScrollPrepareEvent *se = static_cast<QScrollPrepareEvent *>(event);
202 if (m_allowScrolling && m_maxScroll > 0) {
203
204 se->setViewportSize(size());
205 if ((m_orientation == Qt::Horizontal && m_scrollInline) ||
206 (m_orientation == Qt::Vertical && !m_scrollInline)) {
207 se->setContentPosRange(QRectF(0, 0, m_maxScroll, 0));
208 se->setContentPos(QPointF(m_scrollValue, 0));
209 }
210 else {
211 se->setContentPosRange(QRectF(0, 0, 0, m_maxScroll));
212 se->setContentPos(QPointF(0, m_scrollValue));
213 }
214 se->accept();
215 return true;
216 }
217 return false;
218 }
219 case QEvent::Scroll:
220 {
221 QScrollEvent *se = static_cast<QScrollEvent *>(event);
222
223 if ((m_orientation == Qt::Horizontal && m_scrollInline) ||
224 (m_orientation == Qt::Vertical && !m_scrollInline)) {
225 m_scrollValue = qRound(se->contentPos().x() + se->overshootDistance().x());
226 }
227 else {
228 m_scrollValue = qRound(se->contentPos().y() + se->overshootDistance().y());
229 }
230
231 // TODO: keep overshoot seperately
232
234 return true;
235 }
236 default:
237 return WGSelectorWidgetBase::event(event);
238 }
239}
bool event(QEvent *event) override
QPoint scrollOffset() const
Qt::Orientation m_orientation
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References event(), m_allowScrolling, m_contentWidget, m_maxScroll, m_orientation, m_scrollInline, m_scrollValue, and scrollOffset().

◆ eventFilter()

bool WGColorPatches::eventFilter ( QObject * watched,
QEvent * e )
overrideprotected

Definition at line 241 of file WGColorPatches.cpp.

242{
243 if (watched == m_viewport) {
244 // this is basically a stripped down version of QAbstractScrollArea::viewportEvent()
245 switch (e->type()) {
246 // redirect to base class, as this event() implementation does not care
247 case QEvent::ContextMenu:
248 case QEvent::Wheel:
249 case QEvent::Drop:
250 case QEvent::DragEnter:
251 case QEvent::DragMove:
252 case QEvent::DragLeave:
253 return WGSelectorWidgetBase::event(e);
254
255 // these are handled in WGColorPatches::event()
256 case QEvent::ScrollPrepare:
257 case QEvent::Scroll:
258 return event(e);
259
260 default: break;
261 }
262 }
263 else if (watched == m_contentWidget) {
264 switch (e->type()) {
265 // redirect to base class and handle them in the specialized handlers
266 case QEvent::MouseButtonPress:
267 case QEvent::MouseButtonRelease:
268 case QEvent::MouseButtonDblClick:
269 case QEvent::TouchBegin:
270 case QEvent::TouchUpdate:
271 case QEvent::TouchEnd:
272 case QEvent::MouseMove:
273 return WGSelectorWidgetBase::event(e);
274
275 case QEvent::Paint:
276 {
277 QPaintEvent *pe = static_cast<QPaintEvent*>(e);
278 this->contentPaintEvent(pe);
279 return true;
280 }
281 default:
282 break;
283 }
284 }
285 return false;
286}
void contentPaintEvent(QPaintEvent *event)

References contentPaintEvent(), event(), m_contentWidget, and m_viewport.

◆ fetchButton()

QToolButton * WGColorPatches::fetchButton ( QList< QToolButton * > & recycleList)
protected

Definition at line 501 of file WGColorPatches.cpp.

502{
503 if (recycleList.size() > 0) {
504 return recycleList.takeLast();
505 }
506 QToolButton *button = new QToolButton(this);
507 button->setAutoRaise(true);
508 button->show();
509 return button;
510}
QString button(const QWheelEvent &ev)

References button().

◆ indexAt()

int WGColorPatches::indexAt ( const QPoint & widgetPos) const
protected

Definition at line 396 of file WGColorPatches.cpp.

397{
398 if(!m_colorHistoryModel || !m_contentWidget->rect().contains(widgetPos))
399 return -1;
400
401 QPoint pos = (m_orientation == Qt::Horizontal) ? widgetPos : transposed(widgetPos);
402
403 int col = pos.x() / m_patchWidth;
404 int row = pos.y() / m_patchHeight;
405
406 if (col > m_patchesPerLine || row > m_totalLines) {
407 return -1;
408 }
409
410 int patchNr = m_scrollInline ? col * m_numLines + row : row * m_patchesPerLine + col;
411
412 //patchNr -= m_buttonList.size();
413
414 if (patchNr >= 0 && patchNr < qMin(m_patchCount, m_colorHistoryModel->size())) {
415 return patchNr;
416 }
417 return -1;
418}

References m_colorHistoryModel, m_contentWidget, m_numLines, m_orientation, m_patchCount, m_patchesPerLine, m_patchHeight, m_patchWidth, m_scrollInline, and m_totalLines.

◆ mouseMoveEvent()

void WGColorPatches::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Definition at line 288 of file WGColorPatches.cpp.

289{
290 if (event->buttons() & Qt::LeftButton) {
291 int index = indexAt(event->pos());
292 if (index >= 0 && index != m_mouseIndex) {
293 Q_EMIT sigColorChanged(m_colorHistoryModel->color(index));
294 m_mouseIndex = index;
295 }
296 }
297}
int indexAt(const QPoint &widgetPos) const
void sigColorChanged(const KoColor &color)

References event(), indexAt(), m_colorHistoryModel, m_mouseIndex, and sigColorChanged().

◆ mousePressEvent()

void WGColorPatches::mousePressEvent ( QMouseEvent * event)
overrideprotected

Definition at line 299 of file WGColorPatches.cpp.

300{
301 if (event->button() == Qt::LeftButton) {
302 Q_EMIT sigColorInteraction(true);
303 m_mouseIndex = indexAt(event->pos());
304 if (m_mouseIndex >= 0) {
306 }
307 }
308}
void sigColorInteraction(bool active)

References event(), indexAt(), m_colorHistoryModel, m_mouseIndex, sigColorChanged(), and WGSelectorWidgetBase::sigColorInteraction().

◆ mouseReleaseEvent()

void WGColorPatches::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

Definition at line 310 of file WGColorPatches.cpp.

311{
312 if (event->button() == Qt::LeftButton) {
313 Q_EMIT sigColorInteraction(false);
314 }
315}

References event(), and WGSelectorWidgetBase::sigColorInteraction().

◆ patchRect()

QRect WGColorPatches::patchRect ( int gridIndex) const
protected

Definition at line 420 of file WGColorPatches.cpp.

421{
422 int row, col;
423 if (m_scrollInline) {
424 row = gridIndex % m_numLines;
425 col = gridIndex / m_numLines;
426 }
427 else {
428 row = gridIndex / m_patchesPerLine;
429 col = gridIndex % m_patchesPerLine;
430 }
431
432 QSize patchSize(m_patchWidth, m_patchHeight);
433 QPoint pos(col * m_patchWidth, row * m_patchHeight);
434
435 return (m_orientation == Qt::Horizontal) ? QRect(pos, patchSize)
436 : QRect(transposed(pos), patchSize.transposed());
437}

References m_numLines, m_orientation, m_patchesPerLine, m_patchHeight, m_patchWidth, and m_scrollInline.

◆ popupOffset()

QPoint WGColorPatches::popupOffset ( ) const
overridevirtual

The position, relative to the top left corner, where the cursor of the cursor shall be when showing the popup.

The default implementation returns the widget center.

Returns
desired cursor position relative to the top left corner

Reimplemented from WGSelectorWidgetBase.

Definition at line 142 of file WGColorPatches.cpp.

143{
144 return patchRect(m_buttonList.size()).center();
145}
QList< QToolButton * > m_buttonList

References m_buttonList, and patchRect().

◆ reconnectButtons()

void WGColorPatches::reconnectButtons ( KisUniqueColorSet * oldSet,
KisUniqueColorSet * newSet )
protected

Definition at line 512 of file WGColorPatches.cpp.

513{
514 if (m_preset == History && !m_buttonList.isEmpty()) {
515 QToolButton *clearButton = m_buttonList.first();
516 if (oldSet) {
517 clearButton->disconnect(oldSet);
518 }
519 if (newSet) {
520 connect(clearButton, SIGNAL(clicked(bool)), newSet, SLOT(clear()));
521 }
522 }
523 else if (m_preset == CommonColors && !m_buttonList.isEmpty()) {
524 QToolButton *reloadButton = m_buttonList.first();
525 if (oldSet) {
526 reloadButton->disconnect(oldSet);
527 }
528 WGCommonColorSet *ccSet = qobject_cast<WGCommonColorSet *>(newSet);
529 if (ccSet) {
530 connect(reloadButton, SIGNAL(clicked(bool)), ccSet, SLOT(slotUpdateColors()));
531 }
532 }
533}
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)

References CommonColors, History, m_buttonList, and m_preset.

◆ resizeEvent()

void WGColorPatches::resizeEvent ( QResizeEvent * event)
overrideprotected

Definition at line 366 of file WGColorPatches.cpp.

367{
368 Q_UNUSED(event)
369 int oldLineLength = m_patchesPerLine;
371 m_viewport->resize(size());
373 if (oldLineLength != m_patchesPerLine) {
375 m_contentWidget->resize(m_orientation == Qt::Horizontal ? conentSize : conentSize.transposed());
376 // notify the layout system that sizeHint() in the fixed policy dimension changed
377 updateGeometry();
378 }
379 for (int i = 0; i < m_buttonList.size(); i++) {
380 QRect buttonRect = patchRect(i);
381 // mirror the rect around the center
382 buttonRect.moveBottomRight(rect().bottomRight() - buttonRect.topLeft());
383 m_buttonList[i]->setGeometry(buttonRect);
384 }
385}

References event(), m_buttonList, m_contentWidget, m_maxScroll, m_orientation, m_patchesPerLine, m_patchHeight, m_patchWidth, m_scrollValue, m_totalLines, m_viewport, patchRect(), and updateMetrics().

◆ scrollOffset()

QPoint WGColorPatches::scrollOffset ( ) const
protected

Definition at line 439 of file WGColorPatches.cpp.

440{
441 if (!m_allowScrolling) {
442 return QPoint(0, 0);
443 }
444 QPoint offset(0, 0);
445 if (m_orientation == Qt::Horizontal) {
446 if (m_scrollInline) {
447 offset.rx() += m_scrollValue;
448 } else {
449 offset.ry() += m_scrollValue;
450 }
451 } else {
452 if (m_scrollInline) {
453 offset.ry() += m_scrollValue;
454 } else {
455 offset.rx() += m_scrollValue;
456 }
457 }
458 return offset;
459}

References m_allowScrolling, m_orientation, m_scrollInline, and m_scrollValue.

◆ setAdditionalButtons()

void WGColorPatches::setAdditionalButtons ( QList< QToolButton * > 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 147 of file WGColorPatches.cpp.

148{
149 for (int i = 0; i < buttonList.size(); i++) {
150 buttonList[i]->setParent(this);
151 //buttonList[i]->setAutoFillBackground(true);
152 buttonList[i]->raise();
153 }
154 m_buttonList = buttonList;
155 // recalc metrics and resize content widget
156 m_patchesPerLine = -1; // ensure resizeEvent() sets new content dimensions
157 QResizeEvent dummyEvent(size(), size());
158 resizeEvent(&dummyEvent);
159}
void resizeEvent(QResizeEvent *event) override

References m_buttonList, m_patchesPerLine, and resizeEvent().

◆ setColorHistoryModel()

void WGColorPatches::setColorHistoryModel ( KisUniqueColorSet * history)

Definition at line 161 of file WGColorPatches.cpp.

162{
165 }
166 if (colorHistoryModel) {
167 connect(colorHistoryModel, SIGNAL(sigColorAdded(int)), m_contentWidget, SLOT(update()));
168 connect(colorHistoryModel, SIGNAL(sigColorMoved(int,int)), m_contentWidget, SLOT(update()));
169 connect(colorHistoryModel, SIGNAL(sigColorRemoved(int)), m_contentWidget, SLOT(update()));
170 connect(colorHistoryModel, SIGNAL(sigReset()), m_contentWidget, SLOT(update()));
171 m_scrollValue = 0;
172 }
175 m_contentWidget->update();
176}
KisUniqueColorSet * colorHistoryModel() const
void reconnectButtons(KisUniqueColorSet *oldSet, KisUniqueColorSet *newSet)
bool update(QSpinBox *spinBox)

References colorHistoryModel(), m_colorHistoryModel, m_contentWidget, m_scrollValue, and reconnectButtons().

◆ setPreset()

void WGColorPatches::setPreset ( Preset preset)

Definition at line 114 of file WGColorPatches.cpp.

115{
116 if (preset == m_preset) {
117 return;
118 }
119
120 m_preset = preset;
121
122 if (uiMode() == PopupMode) {
124 }
125 else {
126 switch (preset) {
127 case History:
129 break;
130 case CommonColors:
132 break;
133 case None:
134 default:
135 m_configSource = nullptr;
136 }
137 }
138
140}
void updateSettings() override
const WGConfig::ColorPatches * m_configSource
const ColorPatches commonColors
Definition WGConfig.cpp:221
const ColorPatches popupPatches
Definition WGConfig.cpp:229
const ColorPatches colorHistory
Definition WGConfig.cpp:213

References WGConfig::colorHistory, CommonColors, WGConfig::commonColors, History, m_configSource, m_preset, None, WGSelectorWidgetBase::PopupMode, WGConfig::popupPatches, WGSelectorWidgetBase::uiMode(), and updateSettings().

◆ sigColorChanged

void WGColorPatches::sigColorChanged ( const KoColor & color)
signal

◆ sizeHint()

QSize WGColorPatches::sizeHint ( ) const
overrideprotected

Definition at line 387 of file WGColorPatches.cpp.

388{
389 if (m_orientation == Qt::Vertical) {
391 } else {
393 }
394}

References m_numLines, m_orientation, m_patchesPerLine, m_patchHeight, and m_patchWidth.

◆ updateIcons

void WGColorPatches::updateIcons ( )
slot

Definition at line 178 of file WGColorPatches.cpp.

179{
180 if (m_buttonList.isEmpty() || m_preset == None) {
181 return;
182 }
183 if (m_preset == History) {
184 m_buttonList.first()->setIcon(KisIconUtils::loadIcon("edit-clear-16"));
185 }
186 else if (m_preset == CommonColors) {
187 m_buttonList.first()->setIcon(KisIconUtils::loadIcon("reload-preset-16"));
188 }
189}
QIcon loadIcon(const QString &name)

References CommonColors, History, KisIconUtils::loadIcon(), m_buttonList, m_preset, and None.

◆ updateMetrics()

void WGColorPatches::updateMetrics ( )
protected

Definition at line 461 of file WGColorPatches.cpp.

462{
463 if (m_scrollInline) {
466 }
467 else {
468 // in this mode, the line length and count depends on widget size
469 int availableLength = (m_orientation == Qt::Horizontal) ? width() : height();
470 m_patchesPerLine = qMax(1, availableLength / m_patchWidth);
471
472 if (m_allowScrolling) {
473 // with only one line, we need to subtract the buttons because we can't scroll past them
474 if (m_numLines == 1) {
477 } else {
479 }
480 } else {
483 m_maxScroll = 0;
484 }
485 }
486 // scroll limit
487 if (m_allowScrolling) {
488 if (m_scrollInline) {
489 int available = (m_orientation == Qt::Horizontal) ? width() : height();
490 int required = m_patchesPerLine * m_patchWidth;
491 m_maxScroll = qMax(0, required - available);
492 }
493 else {
494 int available = (m_orientation == Qt::Horizontal) ? height() : width();
495 int required = m_totalLines * m_patchHeight;
496 m_maxScroll = qMax(0, required - available);
497 }
498 }
499}

References m_allowScrolling, m_buttonList, m_maxScroll, m_numLines, m_orientation, m_patchCount, m_patchesPerLine, m_patchHeight, m_patchWidth, m_scrollInline, and m_totalLines.

◆ updateSettings()

void WGColorPatches::updateSettings ( )
overridevirtual

Reimplemented from WGSelectorWidgetBase.

Definition at line 46 of file WGColorPatches.cpp.

47{
48 if (!m_configSource) {
49 return;
50 }
51
53
54 QSize patchSize = cfg.get(m_configSource->patchSize);
55 m_patchWidth = patchSize.width();
56 m_patchHeight = patchSize.height();
58 m_numLines = cfg.get(m_configSource->rows);
60
61 WGConfig::Scrolling scrolling = cfg.get(m_configSource->scrolling);
64
65 if (m_orientation == Qt::Vertical) {
66 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
67 } else {
68 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
69 }
70
71 // redo buttons
73 if (m_preset == History) {
74 bool showClearButton = cfg.get(WGConfig::colorHistoryShowClearButton);
75 if (showClearButton) {
77 }
78 }
79 else if (m_preset == CommonColors) {
80 if (uiMode() == PopupMode) {
81 // Small workaround: override patch limit because it's basically a
82 // property of WGCommonColorSet.
83 m_patchCount = cfg.get(WGConfig::commonColors.maxCount);
84 }
86 }
87 // clear leftover buttons (if any) and set new list
88 while (m_buttonList.size() > 0) {
89 delete m_buttonList.takeLast();
90 }
94
95 // recalc metrics and resize content widget
96 m_patchesPerLine = -1; // ensure resizeEvent() sets new content dimensions
97 QResizeEvent dummyEvent(size(), size());
98 resizeEvent(&dummyEvent);
99
100 if (QScroller::hasScroller(m_viewport)) {
101 QScroller *scroller = QScroller::scroller(m_viewport);
102 if (m_orientation == Qt::Horizontal) {
103 scroller->setSnapPositionsX(0.0, m_patchWidth);
104 scroller->setSnapPositionsY(0.0, m_patchHeight);
105 } else {
106 scroller->setSnapPositionsX(0.0, m_patchHeight);
107 scroller->setSnapPositionsY(0.0, m_patchWidth);
108 }
109 }
110
111 m_contentWidget->update();
112}
QToolButton * fetchButton(QList< QToolButton * > &recycleList)
QString buttons(const T &ev)
const GenericSetting< bool > colorHistoryShowClearButton
Definition WGConfig.cpp:241
class WGConfig Accessor
@ ScrollLongitudinal
Definition WGConfig.h:190
@ ScrollNone
Definition WGConfig.h:189
NumericSetting< Scrolling > scrolling
Definition WGConfig.h:200
NumericSetting< Qt::Orientation > orientation
Definition WGConfig.h:196
NumericSetting< int > rows
Definition WGConfig.h:199
NumericSetting< int > maxCount
Definition WGConfig.h:198
NumericSetting< QSize > patchSize
Definition WGConfig.h:197

References buttons(), WGConfig::colorHistoryShowClearButton, CommonColors, WGConfig::commonColors, fetchButton(), History, m_allowScrolling, m_buttonList, m_colorHistoryModel, m_configSource, m_contentWidget, m_numLines, m_orientation, m_patchCount, m_patchesPerLine, m_patchHeight, m_patchWidth, m_preset, m_scrollInline, m_viewport, WGConfig::ColorPatches::maxCount, WGConfig::ColorPatches::orientation, WGConfig::ColorPatches::patchSize, WGSelectorWidgetBase::PopupMode, reconnectButtons(), resizeEvent(), WGConfig::ColorPatches::rows, WGConfig::ColorPatches::scrolling, WGConfig::ScrollLongitudinal, WGConfig::ScrollNone, WGSelectorWidgetBase::uiMode(), and updateIcons().

◆ wheelEvent()

void WGColorPatches::wheelEvent ( QWheelEvent * event)
overrideprotected

Definition at line 317 of file WGColorPatches.cpp.

318{
319 if (!m_allowScrolling) {
320 return;
321 }
322
323 int oldScroll = m_scrollValue;
324
325 if (m_scrollInline) {
326 // scroll two patches per "tick"
327 int scrollAmount = 2 * m_patchWidth;
328 scrollAmount = (event->angleDelta().y() * scrollAmount) / QWheelEvent::DefaultDeltasPerStep;
329 m_scrollValue = qBound(0, m_scrollValue - scrollAmount, m_maxScroll);
330 }
331 else {
332 // scroll one row per "tick"
333 int scrollAmount = (event->angleDelta().y() * m_patchHeight) / QWheelEvent::DefaultDeltasPerStep;
334 m_scrollValue = qBound(0, m_scrollValue - scrollAmount, m_maxScroll);
335 }
336
337 if (oldScroll != m_scrollValue) {
339 }
340 event->accept();
341}

References m_allowScrolling, m_contentWidget, m_maxScroll, m_patchHeight, m_patchWidth, m_scrollInline, m_scrollValue, and scrollOffset().

Member Data Documentation

◆ m_allowScrolling

bool WGColorPatches::m_allowScrolling {true}
private

Definition at line 79 of file WGColorPatches.h.

79{true};

◆ m_buttonList

QList<QToolButton*> WGColorPatches::m_buttonList
private

Definition at line 65 of file WGColorPatches.h.

◆ m_colorHistoryModel

QPointer<KisUniqueColorSet> WGColorPatches::m_colorHistoryModel
private

Definition at line 64 of file WGColorPatches.h.

◆ m_configSource

const WGConfig::ColorPatches* WGColorPatches::m_configSource {0}
private

Definition at line 67 of file WGColorPatches.h.

67{0};

◆ m_contentWidget

QWidget* WGColorPatches::m_contentWidget {0}
private

Definition at line 69 of file WGColorPatches.h.

69{0};

◆ m_maxScroll

int WGColorPatches::m_maxScroll {0}
private

Definition at line 77 of file WGColorPatches.h.

77{0};

◆ m_mouseIndex

int WGColorPatches::m_mouseIndex {-1}
private

Definition at line 78 of file WGColorPatches.h.

78{-1};

◆ m_numLines

int WGColorPatches::m_numLines {1}
private

Definition at line 70 of file WGColorPatches.h.

70{1};

◆ m_orientation

Qt::Orientation WGColorPatches::m_orientation {Qt::Horizontal}
private

Definition at line 66 of file WGColorPatches.h.

66{Qt::Horizontal};

◆ m_patchCount

int WGColorPatches::m_patchCount {30}
private

Definition at line 75 of file WGColorPatches.h.

75{30};

◆ m_patchesPerLine

int WGColorPatches::m_patchesPerLine {30}
private

Definition at line 71 of file WGColorPatches.h.

71{30};

◆ m_patchHeight

int WGColorPatches::m_patchHeight {16}
private

Definition at line 74 of file WGColorPatches.h.

74{16};

◆ m_patchWidth

int WGColorPatches::m_patchWidth {16}
private

Definition at line 73 of file WGColorPatches.h.

73{16};

◆ m_preset

Preset WGColorPatches::m_preset {None}
private

Definition at line 81 of file WGColorPatches.h.

81{None};

◆ m_scrollInline

bool WGColorPatches::m_scrollInline {true}
private

Definition at line 80 of file WGColorPatches.h.

80{true};

◆ m_scrollValue

int WGColorPatches::m_scrollValue {0}
private

Definition at line 76 of file WGColorPatches.h.

76{0};

◆ m_totalLines

int WGColorPatches::m_totalLines {1}
private

Definition at line 72 of file WGColorPatches.h.

72{1};

◆ m_viewport

QWidget* WGColorPatches::m_viewport {0}
private

Definition at line 68 of file WGColorPatches.h.

68{0};

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