Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/appletinterface.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "appletinterface.h" | 21 | #include "appletinterface.h" | ||
22 | 22 | | |||
23 | #include <QAction> | 23 | #include <QAction> | ||
24 | #include <QDir> | 24 | #include <QDir> | ||
25 | #include <QFile> | 25 | #include <QFile> | ||
26 | #include <QIcon> | 26 | #include <QIcon> | ||
27 | #include <QTimer> | 27 | #include <QTimer> | ||
28 | #include <QStyleHints> | ||||
28 | 29 | | |||
29 | #include <kactioncollection.h> | 30 | #include <kactioncollection.h> | ||
30 | #include <QDebug> | 31 | #include <QDebug> | ||
31 | #include <kservice.h> | 32 | #include <kservice.h> | ||
32 | #include <klocalizedstring.h> | 33 | #include <klocalizedstring.h> | ||
33 | #include <KConfigLoader> | 34 | #include <KConfigLoader> | ||
34 | 35 | | |||
35 | #include <Plasma/Plasma> | 36 | #include <Plasma/Plasma> | ||
Show All 16 Lines | 51 | : AppletQuickItem(script->applet(), parent), | |||
52 | m_appletScriptEngine(script), | 53 | m_appletScriptEngine(script), | ||
53 | m_toolTipTextFormat(0), | 54 | m_toolTipTextFormat(0), | ||
54 | m_toolTipItem(nullptr), | 55 | m_toolTipItem(nullptr), | ||
55 | m_args(args), | 56 | m_args(args), | ||
56 | m_backgroundHints(Plasma::Types::StandardBackground), | 57 | m_backgroundHints(Plasma::Types::StandardBackground), | ||
57 | m_hideOnDeactivate(true), | 58 | m_hideOnDeactivate(true), | ||
58 | m_oldKeyboardShortcut(0), | 59 | m_oldKeyboardShortcut(0), | ||
59 | m_dummyNativeInterface(nullptr), | 60 | m_dummyNativeInterface(nullptr), | ||
60 | m_positionBeforeRemoval(QPointF(-1, -1)) | 61 | m_positionBeforeRemoval(QPointF(-1, -1)), | ||
62 | m_longTap(new QTimer(this)) | ||||
61 | { | 63 | { | ||
62 | qmlRegisterType<QAction>(); | 64 | qmlRegisterType<QAction>(); | ||
63 | 65 | | |||
64 | connect(this, &AppletInterface::configNeedsSaving, | 66 | connect(this, &AppletInterface::configNeedsSaving, | ||
65 | applet(), &Plasma::Applet::configNeedsSaving); | 67 | applet(), &Plasma::Applet::configNeedsSaving); | ||
66 | connect(applet(), &Plasma::Applet::immutabilityChanged, | 68 | connect(applet(), &Plasma::Applet::immutabilityChanged, | ||
67 | this, &AppletInterface::immutabilityChanged); | 69 | this, &AppletInterface::immutabilityChanged); | ||
68 | connect(applet(), &Plasma::Applet::userConfiguringChanged, | 70 | connect(applet(), &Plasma::Applet::userConfiguringChanged, | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 136 | if (compactRepresentationItem() && fullRepresentationItem() && | |||
136 | fullRepresentationItem()->window() != compactRepresentationItem()->window() && | 138 | fullRepresentationItem()->window() != compactRepresentationItem()->window() && | ||
137 | fullRepresentationItem()->parentItem()) { | 139 | fullRepresentationItem()->parentItem()) { | ||
138 | fullRepresentationItem()->parentItem()->installEventFilter(this); | 140 | fullRepresentationItem()->parentItem()->installEventFilter(this); | ||
139 | } else if (fullRepresentationItem() && fullRepresentationItem()->parentItem()) { | 141 | } else if (fullRepresentationItem() && fullRepresentationItem()->parentItem()) { | ||
140 | fullRepresentationItem()->parentItem()->removeEventFilter(this); | 142 | fullRepresentationItem()->parentItem()->removeEventFilter(this); | ||
141 | } | 143 | } | ||
142 | } | 144 | } | ||
143 | }); | 145 | }); | ||
146 | | ||||
147 | m_longTap->setSingleShot(true); | ||||
148 | m_longTap->setInterval(QGuiApplication::styleHints()->mousePressAndHoldInterval()); | ||||
149 | connect(m_longTap, &QTimer::timeout, this, &AppletInterface::showContextMenuTap); | ||||
144 | } | 150 | } | ||
145 | 151 | | |||
146 | AppletInterface::~AppletInterface() | 152 | AppletInterface::~AppletInterface() | ||
147 | { | 153 | { | ||
148 | } | 154 | } | ||
149 | 155 | | |||
150 | DeclarativeAppletScript *AppletInterface::appletScript() const | 156 | DeclarativeAppletScript *AppletInterface::appletScript() const | ||
151 | { | 157 | { | ||
▲ Show 20 Lines • Show All 563 Lines • ▼ Show 20 Line(s) | 719 | if (screenId > -1) { | |||
715 | //make it relative | 721 | //make it relative | ||
716 | QRect geometry = applet()->containment()->corona()->screenGeometry(screenId); | 722 | QRect geometry = applet()->containment()->corona()->screenGeometry(screenId); | ||
717 | rect.moveTo(rect.topLeft() - geometry.topLeft()); | 723 | rect.moveTo(rect.topLeft() - geometry.topLeft()); | ||
718 | } | 724 | } | ||
719 | 725 | | |||
720 | return rect; | 726 | return rect; | ||
721 | } | 727 | } | ||
722 | 728 | | |||
729 | void AppletInterface::touchEvent(QTouchEvent* event) | ||||
730 | { | ||||
731 | if (event->touchPoints().count() != 1) | ||||
732 | return; | ||||
733 | | ||||
734 | if (event->touchPointStates() & Qt::TouchPointPressed) { | ||||
735 | m_longTap->start(); | ||||
736 | m_longTapPos = event->touchPoints().constFirst(); | ||||
737 | } | ||||
738 | if (event->touchPointStates() & Qt::TouchPointReleased) { | ||||
739 | m_longTap->stop(); | ||||
740 | } | ||||
741 | AppletQuickItem::touchEvent(event); | ||||
742 | } | ||||
743 | | ||||
723 | bool AppletInterface::event(QEvent *event) | 744 | bool AppletInterface::event(QEvent *event) | ||
724 | { | 745 | { | ||
725 | // QAction keyboard shortcuts cannot work with QML2 (and probably newver will | 746 | // QAction keyboard shortcuts cannot work with QML2 (and probably newver will | ||
726 | // since in Qt qtquick and qwidgets cannot depend from each other in any way) | 747 | // since in Qt qtquick and qwidgets cannot depend from each other in any way) | ||
727 | // so do a simple keyboard shortcut matching here | 748 | // so do a simple keyboard shortcut matching here | ||
728 | if (event->type() == QEvent::KeyPress) { | 749 | if (event->type() == QEvent::KeyPress) { | ||
729 | QKeyEvent *ke = static_cast<QKeyEvent *>(event); | 750 | QKeyEvent *ke = static_cast<QKeyEvent *>(event); | ||
730 | QKeySequence seq(ke->key()|ke->modifiers()); | 751 | QKeySequence seq(ke->key()|ke->modifiers()); | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 817 | if (c) { | |||
837 | delete desktopMenu; | 858 | delete desktopMenu; | ||
838 | return false; | 859 | return false; | ||
839 | } | 860 | } | ||
840 | } | 861 | } | ||
841 | 862 | | |||
842 | return AppletQuickItem::eventFilter(watched, event); | 863 | return AppletQuickItem::eventFilter(watched, event); | ||
843 | } | 864 | } | ||
844 | 865 | | |||
866 | void AppletInterface::showContextMenuTap() | ||||
867 | { | ||||
868 | QMouseEvent ev(QEvent::MouseButtonPress, m_longTapPos.pos(), m_longTapPos.scenePos(), m_longTapPos.screenPos(), Qt::RightButton, Qt::RightButton, nullptr); | ||||
869 | mousePressEvent(&ev); | ||||
870 | } | ||||
871 | | ||||
872 | void AppletInterface::showContextMenu() | ||||
873 | { | ||||
874 | ContainmentInterface *ci = applet()->containment()->property("_plasma_graphicObject").value<ContainmentInterface *>(); | ||||
875 | const auto pos = mapToItem(ci, boundingRect().center()); | ||||
876 | QMouseEvent ev(QEvent::MouseButtonPress, pos, mapToScene(pos), mapToGlobal(pos), Qt::RightButton, nullptr, nullptr); | ||||
877 | if (!ci) { | ||||
878 | return; | ||||
879 | } | ||||
880 | ci->mousePressEvent(&ev); | ||||
881 | } | ||||
845 | 882 | | |||
846 | #include "moc_appletinterface.cpp" | 883 | #include "moc_appletinterface.cpp" |