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());
193 switch (
event->type()) {
199 case QEvent::ScrollPrepare:
201 QScrollPrepareEvent *se =
static_cast<QScrollPrepareEvent *
>(
event);
204 se->setViewportSize(size());
207 se->setContentPosRange(QRectF(0, 0,
m_maxScroll, 0));
211 se->setContentPosRange(QRectF(0, 0, 0,
m_maxScroll));
221 QScrollEvent *se =
static_cast<QScrollEvent *
>(
event);
225 m_scrollValue = qRound(se->contentPos().x() + se->overshootDistance().x());
228 m_scrollValue = qRound(se->contentPos().y() + se->overshootDistance().y());
237 return WGSelectorWidgetBase::event(
event);
247 case QEvent::ContextMenu:
250 case QEvent::DragEnter:
251 case QEvent::DragMove:
252 case QEvent::DragLeave:
253 return WGSelectorWidgetBase::event(e);
256 case QEvent::ScrollPrepare:
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);
277 QPaintEvent *pe =
static_cast<QPaintEvent*
>(e);
290 if (
event->buttons() & Qt::LeftButton) {
301 if (
event->button() == Qt::LeftButton) {
312 if (
event->button() == Qt::LeftButton) {
328 scrollAmount = (
event->angleDelta().y() * scrollAmount) / QWheelEvent::DefaultDeltasPerStep;
333 int scrollAmount = (
event->angleDelta().y() *
m_patchHeight) / QWheelEvent::DefaultDeltasPerStep;
345 QRect updateRect =
event->rect();
348 if (numColors <= 0) {
358 if (patch.intersects(updateRect)) {
361 painter.fillRect(patch, qcolor);
382 buttonRect.moveBottomRight(
rect().bottomRight() - buttonRect.topLeft());
401 QPoint pos = (
m_orientation == Qt::Horizontal) ? widgetPos : transposed(widgetPos);
435 return (
m_orientation == Qt::Horizontal) ? QRect(pos, patchSize)
436 : QRect(transposed(pos), patchSize.transposed());
469 int availableLength = (
m_orientation == Qt::Horizontal) ? width() : height();
489 int available = (
m_orientation == Qt::Horizontal) ? width() : height();
494 int available = (
m_orientation == Qt::Horizontal) ? height() : width();
503 if (recycleList.size() > 0) {
504 return recycleList.takeLast();
506 QToolButton *
button =
new QToolButton(
this);
507 button->setAutoRaise(
true);
517 clearButton->disconnect(oldSet);
520 connect(clearButton, SIGNAL(clicked(
bool)), newSet, SLOT(clear()));
526 reloadButton->disconnect(oldSet);
530 connect(reloadButton, SIGNAL(clicked(
bool)), ccSet, SLOT(slotUpdateColors()));
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
QPointer< KisUniqueColorSet > m_colorHistoryModel
int indexAt(const QPoint &widgetPos) const
void resizeEvent(QResizeEvent *event) override
QWidget * m_contentWidget
KisUniqueColorSet * colorHistoryModel() const
void setColorHistoryModel(KisUniqueColorSet *history)
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
QPoint scrollOffset() const
QList< QToolButton * > m_buttonList
void mouseMoveEvent(QMouseEvent *event) override
void contentPaintEvent(QPaintEvent *event)
void updateSettings() override
void mouseReleaseEvent(QMouseEvent *event) override
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)
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