10#include <QApplication>
19#include <kconfiggroup.h>
20#include <ksharedconfig.h>
39#if defined HAVE_WAYLAND && QT_VERSION >= QT_VERSION_CHECK(6, 11, 0)
40#define HAVE_QT_PRIVATE_TOOLTIP_POSITION_API
43#ifdef HAVE_QT_PRIVATE_TOOLTIP_POSITION_API
44#include <QtWaylandClient/private/qwaylandwindow_p.h>
49 QWidget* findNearestDockerOrNativeParent(QWidget *w) {
50 if (!w ||
w->inherits(
"QDockWidget") ||
w->windowHandle()) {
54 return findNearestDockerOrNativeParent(
w->parentWidget());
63 setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::NoDropShadowWindowHint);
64 setAttribute(Qt::WA_TranslucentBackground);
86#ifdef HAVE_QT_PRIVATE_TOOLTIP_POSITION_API
87 if (
auto waylandWindow =
dynamic_cast<QNativeInterface::Private::QWaylandWindow *
>(windowHandle()->handle())) {
88 QWidget *referenceWidget = findNearestDockerOrNativeParent(parentWidget());
89 if (!referenceWidget) {
90 referenceWidget = parentWidget();
93 const QPoint parentPos = parentWidget()->window()->mapFromGlobal(referenceWidget->mapToGlobal(QPoint()));
94 const QRect gravityRect(QRect(parentPos, QSize(referenceWidget->width(), 10)));
96 waylandWindow->setParentControlGeometry(gravityRect);
100 waylandWindow->setExtendedWindowType(QNativeInterface::Private::QWaylandWindow::SubMenu);
104 QPoint parentPos =
m_parent->mapToGlobal(QPoint(0,0));
105 const QRect availRect = this->screen()->availableGeometry();
107 if ( parentPos.x() - 100 > availRect.x() ) {
108 targetPos = QPoint(parentPos.x() - 100, parentPos.y());
109 }
else if ( parentPos.x() +
m_parent->width() + 100 < availRect.right()) {
111 }
else if ( parentPos.y() - 100 > availRect.y() ) {
112 targetPos = QPoint(parentPos.x(), parentPos.y() - 100);
114 targetPos = QPoint(parentPos.x(), parentPos.y() +
m_parent->height());
116 move(targetPos.x(), targetPos.y());
155 p.fillRect(0, 0, width(), width(),
m_color);
160#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
167 QWidget::enterEvent(e);
172 QWidget::leaveEvent(e);
188 m_colorUpdateAllowed(true),
189 m_colorUpdateSelf(false),
190 m_hideTimer(new QTimer(this)),
191 m_popupOnMouseOver(false),
192 m_popupOnMouseClick(true),
195 m_hideOnMouseClick(false),
202 using namespace std::placeholders;
208 setContextMenuPolicy(Qt::PreventContextMenu);
226 setMouseTracking(
true);
238 m_canvas->disconnectCanvasObserver(
this);
245 connect(
m_canvas->displayColorConverter(), SIGNAL(displayConfigurationChanged()),
246 SLOT(
reset()), Qt::UniqueConnection);
248 connect(canvas->
imageView()->resourceProvider(), SIGNAL(sigFGColorUsed(
KoColor)),
251 if (
m_canvas->viewManager() &&
m_canvas->viewManager()->canvasResourceProvider()) {
255 auto colorHistory =
m_canvas->viewManager()->canvasResourceProvider()->colorHistoryColors();
256 const KoColor lastUsedColor = !colorHistory.isEmpty() ? colorHistory.first() : currentColor;
286 event->button() == Qt::MiddleButton) {
293 }
else if (
m_isPopup && event->button() == Qt::MiddleButton) {
309 if (e->button() == Qt::MiddleButton) {
320#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
327 if (m_hideTimer->isActive()) {
335 !m_isPopup && m_popupOnMouseOver &&
336 (!m_popup || m_popup->isHidden())) {
340 const QPoint preferredCenter = mapToGlobal(rect().center());
341 showPopup(preferredCenter);
344#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
345 QWidget::enterEvent(e);
347 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent*
>(e);
348 QWidget::enterEvent(enterEvent);
356 QWidget::leaveEvent(e);
366 if(e->mimeData()->hasColor())
367 e->acceptProposedAction();
368 if(e->mimeData()->hasText() && QColor(e->mimeData()->text()).isValid())
369 e->acceptProposedAction();
375 if(e->mimeData()->hasColor()) {
376 color = qvariant_cast<QColor>(e->mimeData()->colorData());
378 else if(e->mimeData()->hasText()) {
379#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
380 color.setNamedColor(e->mimeData()->text());
382 color.fromString(e->mimeData()->text());
396 if (needsExplicitColorReset) {
427 m_popup->setWindowFlags(Qt::FramelessWindowHint |
429 Qt::NoDropShadowWindowHint |
430 Qt::BypassWindowManagerHint);
444 const QPoint preferredGlobalCenterPos = preferredCenter ? *preferredCenter : QCursor::pos();
448 const QPoint preferredGlobalTopLeft =
449 QPoint(preferredGlobalCenterPos.x() -
m_popup->width() / 2, preferredGlobalCenterPos.y() -
m_popup->height() / 2);
452 if (qApp->platformName() ==
"wayland") {
453 m_popup->move(preferredGlobalTopLeft);
457 const QRect availRect = this->screen()->availableGeometry();
458 QRect rc(preferredGlobalTopLeft,
m_popup->size());
493 m_canvas->resourceManager()->setForegroundColor(color);
495 m_canvas->resourceManager()->setBackgroundColor(color);
534 KConfigGroup cfg = KSharedConfig::openConfig()->group(
"advancedColorSelector");
537 int zoomSelectorOptions = (int) cfg.readEntry(
"zoomSelectorOptions", 0) ;
538 if (zoomSelectorOptions == 0) {
540 }
else if (zoomSelectorOptions == 1) {
550 const int zoomSize = cfg.readEntry(
"zoomSize", 280);
551 resize(zoomSize, zoomSize);
592 if(
m_isPopup && event->type() == QEvent::ActivationChange && !isActiveWindow()) {
596 QWidget::changeEvent(event);
601 QWidget::showEvent(event);
QPointer< KisView > imageView() const
Base class for all color selectors, that should support color management and zooming.
KisColorSelectorBase * m_popup
void showPopup(std::optional< QPoint > preferredCenter=std::nullopt)
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
KisSignalCompressorWithParam< QPair< KoColor, Acs::ColorRole > > ColorCompressorType
void updateBaseColorPreview(const KoColor &color)
void setPopupBehaviour(bool onMouseOver, bool onMouseClick)
void setColorSpace(const KoColorSpace *colorSpace)
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()
QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const
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()