Krita Source Code Documentation
Loading...
Searching...
No Matches
WGSelectorPopup.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Mathias Wein <lynx.mw+kde@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6#include "WGSelectorPopup.h"
7
8#include <QApplication>
9#include <QBoxLayout>
10#include <QCursor>
11#include <QScreen>
12#include <QPainter>
13#include <QScreen>
14
15#include <kis_global.h>
18#include <WGShadeSelector.h>
19
21 : QWidget(parent, Qt::Popup | Qt::FramelessWindowHint), m_hideTimer(new QTimer(this))
22{
23 setAttribute(Qt::WA_TranslucentBackground);
24 QBoxLayout *lo = new QBoxLayout(QBoxLayout::LeftToRight, this);
25 lo->setObjectName("WGSelectorPopupLayout");
26 lo->setSizeConstraint(QLayout::SetFixedSize);
27 lo->setContentsMargins(m_margin, m_margin, m_margin, m_margin);
28 m_hideTimer->setSingleShot(true);
29 m_hideTimer->setInterval(50);
30 connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hide()));
31
32}
33
35{
36 replaceCentranWidget(selector);
37 connect(selector, SIGNAL(sigInteraction(bool)), SLOT(slotInteraction(bool)));
39}
40
42{
43 replaceCentranWidget(selector);
44 connect(selector, SIGNAL(sigColorInteraction(bool)), SLOT(slotInteraction(bool)));
45 m_selectorWidget = selector;
46}
47
52
54{
55 QPoint cursorPos = QCursor::pos();
56 const QRect availRect = this->screen()->availableGeometry();
57
58 QRect popupRect(geometry());
60 : popupRect.center() - popupRect.topLeft();
61
62 popupRect.moveTopLeft(cursorPos - offset);
63 popupRect = kisEnsureInRect(popupRect, availRect);
64
65
66 move(popupRect.topLeft());
67
68 show();
69 //m_colorPreviewPopup->show();
70}
71
72void WGSelectorPopup::paintEvent(QPaintEvent *event)
73{
74 Q_UNUSED(event);
75 QPainter painter(this);
76 painter.setRenderHint(QPainter::Antialiasing);
77 painter.setPen(Qt::NoPen);
78 painter.setBrush(palette().window());
79 painter.drawRoundedRect(QRect(0, 0, width(), height()), m_margin, m_margin);
80}
81
82#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
83void WGSelectorPopup::enterEvent(QEvent *event)
84#else
85void WGSelectorPopup::enterEvent(QEnterEvent *event)
86#endif
87{
88 Q_UNUSED(event);
89 if (m_hideTimer->isActive()) {
90 m_hideTimer->stop();
91 }
92}
93
94void WGSelectorPopup::leaveEvent(QEvent *event)
95{
96 Q_UNUSED(event);
97
98 if (!m_isInteracting) {
99 m_hideTimer->start();
100 }
101}
102
103void WGSelectorPopup::keyPressEvent(QKeyEvent *event)
104{
105 Q_UNUSED(event);
106 hide();
107}
108
109void WGSelectorPopup::hideEvent(QHideEvent *event)
110{
111 QWidget::hideEvent(event);
112 Q_EMIT sigPopupClosed(this);
113}
114
116{
117 m_isInteracting = active;
118 if (!active && !underMouse()) {
119 hide();
120 }
121}
122
124{
125 widget->setParent(this);
126 while (QLayoutItem *child = layout()->takeAt(0)) {
127 delete child->widget();
128 delete child;
129 }
130 layout()->addWidget(widget);
131 widget->show();
132 layout()->update();
133 adjustSize();
134}
135
136
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisVisualColorSelector class.
void replaceCentranWidget(QWidget *widget)
void sigPopupClosed(WGSelectorPopup *popup)
void enterEvent(QEnterEvent *event) override
WGSelectorPopup(QWidget *parent=nullptr)
void keyPressEvent(QKeyEvent *event) override
void hideEvent(QHideEvent *event) override
void paintEvent(QPaintEvent *event) override
void slotInteraction(bool active)
void setSelectorWidget(KisVisualColorSelector *selector)
void leaveEvent(QEvent *event) override
WGSelectorWidgetBase * selectorWidget() const
WGSelectorWidgetBase * m_selectorWidget
virtual QPoint popupOffset() const
The position, relative to the top left corner, where the cursor of the cursor shall be when showing t...
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
Definition kis_global.h:267
rgba palette[MAX_PALETTE]
Definition palette.c:35