10#include <QApplication>
19#include <kconfiggroup.h>
20#include <ksharedconfig.h>
41 setWindowFlags(Qt::ToolTip | Qt::NoDropShadowWindowHint);
56 QPoint parentPos =
m_parent->mapToGlobal(QPoint(0,0));
57 const QRect availRect = this->screen()->availableGeometry();
59 if ( parentPos.x() - 100 > availRect.x() ) {
60 targetPos = QPoint(parentPos.x() - 100, parentPos.y());
61 }
else if ( parentPos.x() +
m_parent->width() + 100 < availRect.right()) {
63 }
else if ( parentPos.y() - 100 > availRect.y() ) {
64 targetPos = QPoint(parentPos.x(), parentPos.y() - 100);
66 targetPos = QPoint(parentPos.x(), parentPos.y() +
m_parent->height());
68 setGeometry(targetPos.x(), targetPos.y(), 100, 150);
69 setAttribute(Qt::WA_TranslucentBackground);
99 p.fillRect(0, 0, width(), width(),
m_color);
104#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
110 QWidget::enterEvent(e);
115 QWidget::leaveEvent(e);
132 m_colorUpdateAllowed(true),
133 m_colorUpdateSelf(false),
134 m_hideTimer(new QTimer(this)),
135 m_popupOnMouseOver(false),
136 m_popupOnMouseClick(true),
139 m_hideOnMouseClick(false),
146 using namespace std::placeholders;
166 setMouseTracking(
true);
178 m_canvas->disconnectCanvasObserver(
this);
185 connect(
m_canvas->displayColorConverter(), SIGNAL(displayConfigurationChanged()),
186 SLOT(
reset()), Qt::UniqueConnection);
191 if (
m_canvas->viewManager() &&
m_canvas->viewManager()->canvasResourceProvider()) {
217 event->button() == Qt::MiddleButton) {
221 int x =
event->globalX();
222 int y =
event->globalY();
223 int popupsize =
m_popup->width();
227 const QRect availRect = this->screen()->availableGeometry();
233 if(x+
m_popup->width()>availRect.x()+availRect.width())
234 x = availRect.x()+availRect.width()-
m_popup->width();
235 if(y+
m_popup->height()>availRect.y()+availRect.height())
236 y = availRect.y()+availRect.height()-
m_popup->height();
243 }
else if (
m_isPopup && event->button() == Qt::MiddleButton) {
259 if (e->button() == Qt::MiddleButton) {
270#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
276 if (m_popup && m_popup->isVisible()) {
277 m_popup->m_hideTimer->stop();
280 if (m_isPopup && m_hideTimer->isActive()) {
288 !m_isPopup && m_popupOnMouseOver &&
289 (!m_popup || m_popup->isHidden())) {
293 const QRect availRect = this->screen()->availableGeometry();
295 QPoint proposedTopLeft =
rect().center() - m_popup->rect().center();
296 proposedTopLeft = mapToGlobal(proposedTopLeft);
298 QRect popupRect = QRect(proposedTopLeft, m_popup->size());
301 m_popup->setGeometry(popupRect);
302 m_popup->setHidingTime(200);
306#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
307 QWidget::enterEvent(e);
309 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent*
>(e);
310 QWidget::enterEvent(enterEvent);
318 QWidget::leaveEvent(e);
330 if(e->mimeData()->hasColor())
331 e->acceptProposedAction();
332 if(e->mimeData()->hasText() && QColor(e->mimeData()->text()).isValid())
333 e->acceptProposedAction();
339 if(e->mimeData()->hasColor()) {
340 color = qvariant_cast<QColor>(e->mimeData()->colorData());
342 else if(e->mimeData()->hasText()) {
343 color.setNamedColor(e->mimeData()->text());
356 if (needsExplicitColorReset) {
394 m_popup->setWindowFlags(Qt::FramelessWindowHint |
395#
if defined(Q_OS_MACOS) || defined(Q_OS_ANDROID)
400 Qt::NoDropShadowWindowHint |
401 Qt::BypassWindowManagerHint);
415 QPoint cursorPos = QCursor::pos();
416 const QRect availRect = this->screen()->availableGeometry();
420 QRect rc =
m_popup->geometry();
421 if (rc.x() < availRect.x()) rc.setX(availRect.x());
422 if (rc.y() < availRect.y()) rc.setY(availRect.y());
450 m_canvas->resourceManager()->setForegroundColor(color);
452 m_canvas->resourceManager()->setBackgroundColor(color);
491 KConfigGroup cfg = KSharedConfig::openConfig()->group(
"advancedColorSelector");
494 int zoomSelectorOptions = (int) cfg.readEntry(
"zoomSelectorOptions", 0) ;
495 if (zoomSelectorOptions == 0) {
497 }
else if (zoomSelectorOptions == 1) {
508 const int zoomSize = cfg.readEntry(
"zoomSize", 280);
509 resize(zoomSize, zoomSize);
568 if(
m_isPopup && event->type() == QEvent::ActivationChange && !isActiveWindow()) {
572 QWidget::changeEvent(event);
577 QWidget::showEvent(event);
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QPointer< KisView > imageView() const
Base class for all color selectors, that should support color management and zooming.
KisColorSelectorBase * m_popup
void requestUpdateColorAndPreview(const KoColor &color, Acs::ColorRole role)
~KisColorSelectorBase() override
const KoColorSpace * m_colorSpace
void dropEvent(QDropEvent *) override
void updatePreviousColorPreview()
void updateColorPreview(const KoColor &color)
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 t...
void dragEnterEvent(QDragEnterEvent *) override
void updateLastUsedColorPreview(const KoColor &color)
void slotUpdateColorAndPreview(QPair< KoColor, Acs::ColorRole > color)
void changeEvent(QEvent *event) override
virtual void updateSettings()
virtual void setCanvas(KisCanvas2 *canvas)
KisDisplayColorConverter * converter() const
const KoColorSpace * colorSpace() const
virtual void setColor(const KoColor &color)
void mouseReleaseEvent(QMouseEvent *) override
KisColorSelectorBase(QWidget *parent=0)
void mousePressEvent(QMouseEvent *) override
void enterEvent(QEnterEvent *e) override
KisColorPreviewPopup * m_colorPreviewPopup
virtual void unsetCanvas()
bool m_colorUpdateAllowed
void showEvent(QShowEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void commitColor(const KoColor &koColor, Acs::ColorRole role)
QScopedPointer< ColorCompressorType > m_updateColorCompressor
QPointer< KisCanvas2 > m_canvas
void setHidingTime(int time)
KisSignalCompressorWithParam< QPair< KoColor, Acs::ColorRole > > ColorCompressorType
void updateBaseColorPreview(const KoColor &color)
void setPopupBehaviour(bool onMouseOver, bool onMouseClick)
void setColorSpace(const KoColorSpace *colorSpace)
virtual void showPopup(Move move=MoveToMousePosition)
void leaveEvent(QEvent *e) override
virtual KisColorSelectorBase * createPopup() const =0
void updateColor(const KoColor &color, Acs::ColorRole role, bool needsExplicitColorReset)
void keyPressEvent(QKeyEvent *) override
const KoColorSpace * paintingColorSpace() const
static KisDisplayColorConverter * dumbConverterInstance()
#define KIS_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_NOOP(cond)
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
KoColor currentColor(ResourceProvider *provider, ColorRole role)
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.
static KoColorSpaceRegistry * instance()