Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPopupWidgetAction.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
3 * SPDX-FileCopyrightText: 2021 Emmet O 'Neill <emmetoneill.pdx@gmail.com>
4 * SPDX-FileCopyrightText: 2021 Eoin O 'Neill <eoinoneill1991@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
10
11#include <QCursor>
12#include <QMenu>
13
14#include <klocalizedstring.h>
15
17#include <kis_canvas2.h>
18#include "kis_tool_proxy.h"
19#include "kis_popup_palette.h"
20#include "kis_input_manager.h"
21
22struct SinglePressEventEater : public QObject
23{
24 bool eventFilter(QObject *, QEvent *event) override {
25 if (hungry && event->type() == QEvent::MouseButtonPress) {
26 hungry = false;
27 return true;
28 }
29
30 return false;
31 }
32
33private:
34 bool hungry = true;
35};
36
37
38//=================================================================
39
41 : KisAbstractInputAction("Show Popup Widget"),
42 m_requestedWithStylus(false)
43{
44 setName(i18n("Show Popup Widget"));
45 setDescription(i18n("Show the current tool's popup widget."));
46}
47
51
52void KisPopupWidgetAction::end(QEvent *event)
53{
54 if (QMenu *popupMenu = inputManager()->toolProxy()->popupActionsMenu()) { // Handle popup menus...
55 m_requestedWithStylus = event && event->type() == QEvent::TabletPress;
56
61 QTimer::singleShot(0, this, [this, popupMenu](){
62 if (popupMenu) {
63 QPoint stylusOffset;
64 QScopedPointer<SinglePressEventEater> eventEater;
65
67 eventEater.reset(new SinglePressEventEater());
68 popupMenu->installEventFilter(eventEater.data());
69 stylusOffset += QPoint(10,10);
70 }
71
72 popupMenu->exec(QCursor::pos() + stylusOffset);
73 popupMenu->clear();
74 }
75 });
76 } else if (KisPopupWidgetInterface *popupWidget = inputManager()->toolProxy()->popupWidget()) { // Handle other popup widgets...
77 if (!popupWidget->onScreen()) {
78 QPoint pos = eventPos(event);
79 if (pos.isNull()) {
80 pos = inputManager()->canvas()->canvasWidget()->mapFromGlobal(QCursor::pos());
81 }
82 inputManager()->registerPopupWidget(popupWidget);
83 popupWidget->popup(pos);
84 } else {
85 popupWidget->dismiss();
86 }
87 }
88}
Abstract base class for input actions.
static KisInputManager * inputManager
QPoint eventPos(const QEvent *event)
void setName(const QString &name)
void setDescription(const QString &description)
KisAbstractCanvasWidget * canvasWidget
KisCanvas2 * canvas() const
QPointer< KisToolProxy > toolProxy() const
void registerPopupWidget(KisPopupWidgetInterface *popupWidget)
void end(QEvent *) override
The PopupWidgetInterface abstract class defines the basic interface that will be used by all popup wi...
bool eventFilter(QObject *, QEvent *event) override