18#include <QScrollEvent>
22 inline QPoint transposed(QPoint point) {
23 return point.transposed();
29 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
66 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
68 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
75 if (showClearButton) {
97 QResizeEvent dummyEvent(size(), size());
101 QScroller *scroller = QScroller::scroller(
m_viewport);
149 for (
int i = 0; i < buttonList.size(); i++) {
150 buttonList[i]->setParent(
this);
152 buttonList[i]->raise();
157 QResizeEvent dummyEvent(size(), size());
192 switch (
event->type()) {
198 case QEvent::ScrollPrepare:
200 QScrollPrepareEvent *se =
static_cast<QScrollPrepareEvent *
>(
event);
203 se->setViewportSize(size());
206 se->setContentPosRange(QRectF(0, 0,
m_maxScroll, 0));
210 se->setContentPosRange(QRectF(0, 0, 0,
m_maxScroll));
220 QScrollEvent *se =
static_cast<QScrollEvent *
>(
event);
224 m_scrollValue = qRound(se->contentPos().x() + se->overshootDistance().x());
227 m_scrollValue = qRound(se->contentPos().y() + se->overshootDistance().y());
236 return WGSelectorWidgetBase::event(
event);
246 case QEvent::ContextMenu:
249 case QEvent::DragEnter:
250 case QEvent::DragMove:
251 case QEvent::DragLeave:
252 return WGSelectorWidgetBase::event(e);
255 case QEvent::ScrollPrepare:
265 case QEvent::MouseButtonPress:
266 case QEvent::MouseButtonRelease:
267 case QEvent::MouseButtonDblClick:
268 case QEvent::TouchBegin:
269 case QEvent::TouchUpdate:
270 case QEvent::TouchEnd:
271 case QEvent::MouseMove:
272 return WGSelectorWidgetBase::event(e);
276 QPaintEvent *pe =
static_cast<QPaintEvent*
>(e);
289 if (
event->buttons() & Qt::LeftButton) {
300 if (
event->button() == Qt::LeftButton) {
311 if (
event->button() == Qt::LeftButton) {
327 scrollAmount = (
event->angleDelta().y() * scrollAmount) / QWheelEvent::DefaultDeltasPerStep;
332 int scrollAmount = (
event->angleDelta().y() *
m_patchHeight) / QWheelEvent::DefaultDeltasPerStep;
344 QRect updateRect =
event->rect();
347 if (numColors <= 0) {
357 if (patch.intersects(updateRect)) {
360 painter.fillRect(patch, qcolor);
381 buttonRect.moveBottomRight(
rect().bottomRight() - buttonRect.topLeft());
400 QPoint pos = (
m_orientation == Qt::Horizontal) ? widgetPos : transposed(widgetPos);
434 return (
m_orientation == Qt::Horizontal) ? QRect(pos, patchSize)
435 : QRect(transposed(pos), patchSize.transposed());
468 int availableLength = (
m_orientation == Qt::Horizontal) ? width() : height();
488 int available = (
m_orientation == Qt::Horizontal) ? width() : height();
493 int available = (
m_orientation == Qt::Horizontal) ? height() : width();
502 if (recycleList.size() > 0) {
503 return recycleList.takeLast();
505 QToolButton *
button =
new QToolButton(
this);
506 button->setAutoRaise(
true);
516 clearButton->disconnect(oldSet);
518 connect(clearButton, SIGNAL(clicked(
bool)), newSet, SLOT(clear()));
523 reloadButton->disconnect(oldSet);
527 connect(reloadButton, SIGNAL(clicked(
bool)), ccSet, SLOT(slotUpdateColors()));
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const
QPoint popupOffset() const override
The position, relative to the top left corner, where the cursor of the cursor shall be when showing t...
QSize sizeHint() const override
void mousePressEvent(QMouseEvent *event) override
void setAdditionalButtons(QList< QToolButton * > buttonList)
QRect patchRect(int gridIndex) const
int indexAt(const QPoint &widgetPos) const
void resizeEvent(QResizeEvent *event) override
QWidget * m_contentWidget
QToolButton * fetchButton(QList< QToolButton * > &recycleList)
void sigColorChanged(const KoColor &color)
void setPreset(Preset preset)
bool eventFilter(QObject *watched, QEvent *e) override
bool event(QEvent *event) override
QPointer< KisUniqueColorSet > m_colors
QPoint scrollOffset() const
QList< QToolButton * > m_buttonList
void mouseMoveEvent(QMouseEvent *event) override
void contentPaintEvent(QPaintEvent *event)
void updateSettings() override
void mouseReleaseEvent(QMouseEvent *event) override
void setColorHistory(KisUniqueColorSet *history)
WGColorPatches(WGSelectorDisplayConfigSP displayConfig, KisUniqueColorSet *history, QWidget *parent=nullptr)
Qt::Orientation m_orientation
const WGConfig::ColorPatches * m_configSource
void wheelEvent(QWheelEvent *event) override
void reconnectButtons(KisUniqueColorSet *oldSet, KisUniqueColorSet *newSet)
KisUniqueColorSet * colorHistory() const
QString button(const QWheelEvent &ev)
QString buttons(const T &ev)
QIcon loadIcon(const QString &name)
const ColorPatches commonColors
const ColorPatches popupPatches
const GenericSetting< bool > colorHistoryShowClearButton
const ColorPatches colorHistory
NumericSetting< Scrolling > scrolling
NumericSetting< Qt::Orientation > orientation
NumericSetting< int > rows
NumericSetting< int > maxCount
NumericSetting< QSize > patchSize