Changeset View
Changeset View
Standalone View
Standalone View
plasma-windowed/plasmawindowedview.cpp
Show All 26 Lines | |||||
27 | #include <QMenu> | 27 | #include <QMenu> | ||
28 | #include <QQmlEngine> | 28 | #include <QQmlEngine> | ||
29 | #include <QQmlContext> | 29 | #include <QQmlContext> | ||
30 | #include <QQmlProperty> | 30 | #include <QQmlProperty> | ||
31 | 31 | | |||
32 | #include <KActionCollection> | 32 | #include <KActionCollection> | ||
33 | #include <KStatusNotifierItem> | 33 | #include <KStatusNotifierItem> | ||
34 | #include <KIconLoader> | 34 | #include <KIconLoader> | ||
35 | #include <KLocalizedString> | ||||
35 | 36 | | |||
36 | #include <Plasma/Package> | 37 | #include <Plasma/Package> | ||
37 | 38 | | |||
38 | 39 | | |||
39 | PlasmaWindowedView::PlasmaWindowedView(QWindow *parent) | 40 | PlasmaWindowedView::PlasmaWindowedView(QWindow *parent) | ||
40 | : QQuickView(parent), | 41 | : QQuickView(parent), | ||
41 | m_applet(0), | 42 | m_applet(0), | ||
42 | m_statusNotifier(0), | 43 | m_statusNotifier(0), | ||
Show All 18 Lines | |||||
61 | void PlasmaWindowedView::setApplet(Plasma::Applet *applet) | 62 | void PlasmaWindowedView::setApplet(Plasma::Applet *applet) | ||
62 | { | 63 | { | ||
63 | m_applet = applet; | 64 | m_applet = applet; | ||
64 | if (!applet) { | 65 | if (!applet) { | ||
65 | return; | 66 | return; | ||
66 | } | 67 | } | ||
67 | 68 | | |||
68 | m_appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>(); | 69 | m_appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>(); | ||
70 | | ||||
69 | if (!m_appletInterface) { | 71 | if (!m_appletInterface) { | ||
70 | return; | 72 | return; | ||
71 | } | 73 | } | ||
72 | 74 | | |||
73 | m_appletInterface->setParentItem(m_rootObject); | 75 | m_appletInterface->setParentItem(m_rootObject); | ||
74 | m_rootObject->setProperty("appletInterface", QVariant::fromValue(m_appletInterface.data())); | 76 | m_rootObject->setProperty("appletInterface", QVariant::fromValue(m_appletInterface.data())); | ||
75 | m_appletInterface->setVisible(true); | 77 | m_appletInterface->setVisible(true); | ||
76 | setTitle(applet->title()); | 78 | setTitle(applet->title()); | ||
Show All 27 Lines | |||||
104 | } | 106 | } | ||
105 | minimumWidthChanged(); | 107 | minimumWidthChanged(); | ||
106 | minimumHeightChanged(); | 108 | minimumHeightChanged(); | ||
107 | QObject::connect(applet->containment(), &Plasma::Containment::configureRequested, | 109 | QObject::connect(applet->containment(), &Plasma::Containment::configureRequested, | ||
108 | this, &PlasmaWindowedView::showConfigurationInterface); | 110 | this, &PlasmaWindowedView::showConfigurationInterface); | ||
109 | 111 | | |||
110 | Q_ASSERT(!m_statusNotifier); | 112 | Q_ASSERT(!m_statusNotifier); | ||
111 | if (m_withStatusNotifier) { | 113 | if (m_withStatusNotifier) { | ||
112 | m_statusNotifier = new KStatusNotifierItem(this); | 114 | m_statusNotifier = new KStatusNotifierItem(applet->pluginMetaData().pluginId(), this); | ||
113 | m_statusNotifier->setIconByName(applet->icon()); | 115 | m_statusNotifier->setIconByName(applet->icon()); | ||
114 | m_statusNotifier->setTitle(applet->title()); | 116 | m_statusNotifier->setTitle(applet->title()); | ||
115 | m_statusNotifier->setToolTipTitle(applet->title()); | 117 | m_statusNotifier->setToolTipTitle(applet->title()); | ||
118 | m_statusNotifier->setStandardActionsEnabled(false); | ||||
119 | | ||||
120 | //set up actions | ||||
121 | for (auto a : applet->contextualActions()) { | ||||
122 | m_statusNotifier->contextMenu()->addAction(a); | ||||
123 | } | ||||
124 | QAction *closeAction = new QAction(QIcon::fromTheme(QStringLiteral("window-close")), i18n("Close %1", applet->title()), this); | ||||
125 | connect(closeAction, &QAction::triggered, this, [this]() { | ||||
126 | m_statusNotifier->deleteLater(); | ||||
127 | close(); | ||||
128 | }); | ||||
129 | m_statusNotifier->contextMenu()->addAction(closeAction); | ||||
116 | 130 | | |||
117 | connect(m_statusNotifier, &KStatusNotifierItem::activateRequested, this, [this](bool active, const QPoint& /*pos*/){ | 131 | connect(m_statusNotifier, &KStatusNotifierItem::activateRequested, this, [this](bool active, const QPoint& /*pos*/){ | ||
118 | setVisible(active); | 132 | if (isVisible() && isActive()) { | ||
119 | if (active) { | 133 | hide(); | ||
134 | } else { | ||||
135 | show(); | ||||
120 | raise(); | 136 | raise(); | ||
121 | } | 137 | } | ||
122 | }); | 138 | }); | ||
139 | auto syncStatus = [this]() { | ||||
140 | switch(m_applet->status()) { | ||||
141 | case Plasma::Types::AcceptingInputStatus: | ||||
142 | case Plasma::Types::RequiresAttentionStatus: | ||||
143 | case Plasma::Types::NeedsAttentionStatus: | ||||
144 | m_statusNotifier->setStatus(KStatusNotifierItem::NeedsAttention); | ||||
145 | break; | ||||
146 | case Plasma::Types::ActiveStatus: | ||||
147 | m_statusNotifier->setStatus(KStatusNotifierItem::Active); | ||||
148 | break; | ||||
149 | default: | ||||
150 | m_statusNotifier->setStatus(KStatusNotifierItem::Passive); | ||||
151 | } | ||||
152 | }; | ||||
153 | connect(applet, &Plasma::Applet::statusChanged, this, syncStatus); | ||||
154 | syncStatus(); | ||||
123 | } | 155 | } | ||
124 | } | 156 | } | ||
125 | 157 | | |||
126 | void PlasmaWindowedView::resizeEvent(QResizeEvent *ev) | 158 | void PlasmaWindowedView::resizeEvent(QResizeEvent *ev) | ||
127 | { | 159 | { | ||
128 | if (!m_applet) { | 160 | if (!m_applet) { | ||
129 | return; | 161 | return; | ||
130 | } | 162 | } | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 181 | { | |||
175 | 207 | | |||
176 | menu.exec(ev->globalPos()); | 208 | menu.exec(ev->globalPos()); | ||
177 | ev->setAccepted(true); | 209 | ev->setAccepted(true); | ||
178 | } | 210 | } | ||
179 | 211 | | |||
180 | void PlasmaWindowedView::keyPressEvent(QKeyEvent *ev) | 212 | void PlasmaWindowedView::keyPressEvent(QKeyEvent *ev) | ||
181 | { | 213 | { | ||
182 | if (ev->matches(QKeySequence::Quit)) { | 214 | if (ev->matches(QKeySequence::Quit)) { | ||
215 | m_statusNotifier->deleteLater(); | ||||
apol: `m_statusNotifier` should be a `QPointer`? | |||||
183 | close(); | 216 | close(); | ||
184 | } | 217 | } | ||
185 | QQuickView::keyReleaseEvent(ev); | 218 | QQuickView::keyReleaseEvent(ev); | ||
186 | } | 219 | } | ||
187 | 220 | | |||
188 | void PlasmaWindowedView::moveEvent(QMoveEvent *ev) | 221 | void PlasmaWindowedView::moveEvent(QMoveEvent *ev) | ||
189 | { | 222 | { | ||
190 | Q_UNUSED(ev) | 223 | Q_UNUSED(ev) | ||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |
m_statusNotifier should be a QPointer?