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
>
16
#include <
KisVisualColorSelector.h
>
17
#include <
WGSelectorWidgetBase.h
>
18
#include <
WGShadeSelector.h
>
19
20
WGSelectorPopup::WGSelectorPopup
(QWidget *parent)
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
34
void
WGSelectorPopup::setSelectorWidget
(
KisVisualColorSelector
*selector)
35
{
36
replaceCentranWidget
(selector);
37
connect(selector, SIGNAL(sigInteraction(
bool
)), SLOT(
slotInteraction
(
bool
)));
38
m_selectorWidget
= 0;
39
}
40
41
void
WGSelectorPopup::setSelectorWidget
(
WGSelectorWidgetBase
*selector)
42
{
43
replaceCentranWidget
(selector);
44
connect(selector, SIGNAL(sigColorInteraction(
bool
)), SLOT(
slotInteraction
(
bool
)));
45
m_selectorWidget
= selector;
46
}
47
48
WGSelectorWidgetBase
*
WGSelectorPopup::selectorWidget
()
const
49
{
50
return
m_selectorWidget
;
51
}
52
53
void
WGSelectorPopup::slotShowPopup
()
54
{
55
QPoint cursorPos = QCursor::pos();
56
const
QRect availRect = this->screen()->availableGeometry();
57
58
QRect popupRect(geometry());
59
QPoint offset =
m_selectorWidget
?
m_selectorWidget
->pos() +
m_selectorWidget
->
popupOffset
()
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
72
void
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))
83
void
WGSelectorPopup::enterEvent
(QEvent *event)
84
#else
85
void
WGSelectorPopup::enterEvent
(QEnterEvent *event)
86
#endif
87
{
88
Q_UNUSED(event);
89
if
(m_hideTimer->isActive()) {
90
m_hideTimer->stop();
91
}
92
}
93
94
void
WGSelectorPopup::leaveEvent
(QEvent *event)
95
{
96
Q_UNUSED(event);
97
98
if
(!
m_isInteracting
) {
99
m_hideTimer
->start();
100
}
101
}
102
103
void
WGSelectorPopup::keyPressEvent
(QKeyEvent *event)
104
{
105
Q_UNUSED(event);
106
hide();
107
}
108
109
void
WGSelectorPopup::hideEvent
(QHideEvent *event)
110
{
111
QWidget::hideEvent(event);
112
Q_EMIT
sigPopupClosed
(
this
);
113
}
114
115
void
WGSelectorPopup::slotInteraction
(
bool
active)
116
{
117
m_isInteracting
= active;
118
if
(!active && !underMouse()) {
119
hide();
120
}
121
}
122
123
void
WGSelectorPopup::replaceCentranWidget
(QWidget *widget)
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
KisVisualColorSelector.h
WGSelectorPopup.h
WGSelectorWidgetBase.h
WGShadeSelector.h
KisVisualColorSelector
The KisVisualColorSelector class.
Definition
KisVisualColorSelector.h:31
WGSelectorPopup::replaceCentranWidget
void replaceCentranWidget(QWidget *widget)
Definition
WGSelectorPopup.cpp:123
WGSelectorPopup::sigPopupClosed
void sigPopupClosed(WGSelectorPopup *popup)
WGSelectorPopup::m_hideTimer
QTimer * m_hideTimer
Definition
WGSelectorPopup.h:48
WGSelectorPopup::m_isInteracting
bool m_isInteracting
Definition
WGSelectorPopup.h:46
WGSelectorPopup::enterEvent
void enterEvent(QEnterEvent *event) override
Definition
WGSelectorPopup.cpp:85
WGSelectorPopup::WGSelectorPopup
WGSelectorPopup(QWidget *parent=nullptr)
Definition
WGSelectorPopup.cpp:20
WGSelectorPopup::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Definition
WGSelectorPopup.cpp:103
WGSelectorPopup::hideEvent
void hideEvent(QHideEvent *event) override
Definition
WGSelectorPopup.cpp:109
WGSelectorPopup::paintEvent
void paintEvent(QPaintEvent *event) override
Definition
WGSelectorPopup.cpp:72
WGSelectorPopup::slotInteraction
void slotInteraction(bool active)
Definition
WGSelectorPopup.cpp:115
WGSelectorPopup::m_margin
int m_margin
Definition
WGSelectorPopup.h:45
WGSelectorPopup::setSelectorWidget
void setSelectorWidget(KisVisualColorSelector *selector)
Definition
WGSelectorPopup.cpp:34
WGSelectorPopup::leaveEvent
void leaveEvent(QEvent *event) override
Definition
WGSelectorPopup.cpp:94
WGSelectorPopup::slotShowPopup
void slotShowPopup()
Definition
WGSelectorPopup.cpp:53
WGSelectorPopup::selectorWidget
WGSelectorWidgetBase * selectorWidget() const
Definition
WGSelectorPopup.cpp:48
WGSelectorPopup::m_selectorWidget
WGSelectorWidgetBase * m_selectorWidget
Definition
WGSelectorPopup.h:47
WGSelectorWidgetBase
Definition
WGSelectorWidgetBase.h:37
WGSelectorWidgetBase::popupOffset
virtual QPoint popupOffset() const
The position, relative to the top left corner, where the cursor of the cursor shall be when showing t...
Definition
WGSelectorWidgetBase.cpp:69
kis_global.h
kisEnsureInRect
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
Definition
kis_global.h:291
palette
rgba palette[MAX_PALETTE]
Definition
palette.c:35
plugins
dockers
widegamutcolorselector
WGSelectorPopup.cpp
Generated at
2026-01-15 02:30:07+01:00
from
Krita
branch
master
, commit
38b517ca06286bb65279453cbf9a2b4fbd1153d1