Changeset View
Changeset View
Standalone View
Standalone View
plasma-windowed/plasmawindowedview.cpp
Show All 21 Lines | |||||
22 | #include "plasmawindowedview.h" | 22 | #include "plasmawindowedview.h" | ||
23 | 23 | | |||
24 | #include <QQuickItem> | 24 | #include <QQuickItem> | ||
25 | #include <QResizeEvent> | 25 | #include <QResizeEvent> | ||
26 | #include <QQmlExpression> | 26 | #include <QQmlExpression> | ||
27 | #include <QMenu> | 27 | #include <QMenu> | ||
28 | #include <QQmlEngine> | 28 | #include <QQmlEngine> | ||
29 | #include <QQmlContext> | 29 | #include <QQmlContext> | ||
30 | #include <QQmlProperty> | ||||
30 | 31 | | |||
31 | #include <KActionCollection> | 32 | #include <KActionCollection> | ||
32 | #include <KStatusNotifierItem> | 33 | #include <KStatusNotifierItem> | ||
34 | #include <KIconLoader> | ||||
33 | 35 | | |||
34 | #include <Plasma/Package> | 36 | #include <Plasma/Package> | ||
35 | 37 | | |||
36 | 38 | | |||
37 | PlasmaWindowedView::PlasmaWindowedView(QWindow *parent) | 39 | PlasmaWindowedView::PlasmaWindowedView(QWindow *parent) | ||
38 | : QQuickView(parent), | 40 | : QQuickView(parent), | ||
39 | m_applet(0), | 41 | m_applet(0), | ||
40 | m_statusNotifier(0), | 42 | m_statusNotifier(0), | ||
41 | m_withStatusNotifier(false) | 43 | m_withStatusNotifier(false) | ||
42 | { | 44 | { | ||
43 | engine()->rootContext()->setContextProperty(QStringLiteral("root"), contentItem()); | 45 | engine()->rootContext()->setContextProperty(QStringLiteral("root"), contentItem()); | ||
44 | QQmlExpression *expr = new QQmlExpression(engine()->rootContext(), contentItem(), QStringLiteral("Qt.createQmlObject('import QtQuick 2.0; import org.kde.plasma.core 2.0; Rectangle {color: theme.backgroundColor; anchors.fill:parent}', root, \"\");")); | 46 | //access appletInterface.Layout.minimumWidth, to create the Layout attached object for appletInterface as a sideeffect | ||
45 | expr->evaluate(); | 47 | QQmlExpression *expr = new QQmlExpression(engine()->rootContext(), contentItem(), QStringLiteral("Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Layouts 1.1; import org.kde.plasma.core 2.0; Rectangle {color: theme.backgroundColor; anchors.fill:parent; property Item appletInterface; onAppletInterfaceChanged: print(appletInterface.Layout.minimumWidth)}', root, \"\");")); | ||
48 | m_rootObject = expr->evaluate().value<QQuickItem*>(); | ||||
46 | } | 49 | } | ||
47 | 50 | | |||
48 | PlasmaWindowedView::~PlasmaWindowedView() | 51 | PlasmaWindowedView::~PlasmaWindowedView() | ||
49 | { | 52 | { | ||
50 | } | 53 | } | ||
51 | 54 | | |||
52 | void PlasmaWindowedView::setHasStatusNotifier(bool stay) | 55 | void PlasmaWindowedView::setHasStatusNotifier(bool stay) | ||
53 | { | 56 | { | ||
54 | Q_ASSERT(!m_statusNotifier); | 57 | Q_ASSERT(!m_statusNotifier); | ||
55 | m_withStatusNotifier = stay; | 58 | m_withStatusNotifier = stay; | ||
56 | } | 59 | } | ||
57 | 60 | | |||
58 | void PlasmaWindowedView::setApplet(Plasma::Applet *applet) | 61 | void PlasmaWindowedView::setApplet(Plasma::Applet *applet) | ||
59 | { | 62 | { | ||
60 | m_applet = applet; | 63 | m_applet = applet; | ||
61 | if (!applet) { | 64 | if (!applet) { | ||
62 | return; | 65 | return; | ||
63 | } | 66 | } | ||
64 | 67 | | |||
65 | QQuickItem *i = applet->property("_plasma_graphicObject").value<QQuickItem *>(); | 68 | m_appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>(); | ||
66 | if (!i) { | 69 | if (!m_appletInterface) { | ||
67 | return; | 70 | return; | ||
68 | } | 71 | } | ||
69 | 72 | | |||
70 | const QRect geom = m_applet->config().readEntry("geometry", QRect()); | 73 | m_appletInterface->setParentItem(m_rootObject); | ||
74 | m_rootObject->setProperty("appletInterface", QVariant::fromValue(m_appletInterface.data())); | ||||
75 | m_appletInterface->setVisible(true); | ||||
76 | setTitle(applet->title()); | ||||
77 | setIcon(QIcon::fromTheme(applet->icon())); | ||||
78 | | ||||
79 | const QSize switchSize(m_appletInterface->property("switchWidth").toInt(), m_appletInterface->property("switchHeight").toInt()); | ||||
80 | QRect geom = m_applet->config().readEntry("geometry", QRect()); | ||||
81 | | ||||
71 | if (geom.isValid()) { | 82 | if (geom.isValid()) { | ||
83 | geom.setWidth(qMax(geom.width(), switchSize.width() + 1)); | ||||
84 | geom.setHeight(qMax(geom.height(), switchSize.height() + 1)); | ||||
72 | setGeometry(geom); | 85 | setGeometry(geom); | ||
73 | } | 86 | } | ||
87 | setMinimumSize(QSize(qMax((int)KIconLoader::SizeEnormous, switchSize.width() + 1), | ||||
88 | qMax((int)KIconLoader::SizeEnormous, switchSize.height() + 1))); | ||||
74 | 89 | | |||
75 | i->setParentItem(contentItem()); | 90 | foreach (QObject *child, m_appletInterface->children()) { | ||
76 | i->setVisible(true); | | |||
77 | setTitle(applet->title()); | | |||
78 | setIcon(QIcon::fromTheme(applet->icon())); | | |||
79 | | ||||
80 | foreach (QObject *child, i->children()) { | | |||
81 | //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight | 91 | //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight | ||
82 | if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && | 92 | if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && | ||
83 | child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && | 93 | child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && | ||
84 | child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && | 94 | child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() && | ||
85 | child->property("fillWidth").isValid() && child->property("fillHeight").isValid() | 95 | child->property("fillWidth").isValid() && child->property("fillHeight").isValid() | ||
86 | ) { | 96 | ) { | ||
87 | m_layout = child; | 97 | m_layout = child; | ||
88 | } | 98 | } | ||
89 | } | 99 | } | ||
90 | 100 | | |||
91 | if (m_layout) { | 101 | if (m_layout) { | ||
92 | connect(m_layout, SIGNAL(minimumWidthChanged()), this, SLOT(minimumWidthChanged())); | 102 | connect(m_layout, SIGNAL(minimumWidthChanged()), this, SLOT(minimumWidthChanged())); | ||
93 | connect(m_layout, SIGNAL(minimumHeightChanged()), this, SLOT(minimumHeightChanged())); | 103 | connect(m_layout, SIGNAL(minimumHeightChanged()), this, SLOT(minimumHeightChanged())); | ||
94 | } | 104 | } | ||
105 | minimumWidthChanged(); | ||||
106 | minimumHeightChanged(); | ||||
95 | QObject::connect(applet->containment(), &Plasma::Containment::configureRequested, | 107 | QObject::connect(applet->containment(), &Plasma::Containment::configureRequested, | ||
96 | this, &PlasmaWindowedView::showConfigurationInterface); | 108 | this, &PlasmaWindowedView::showConfigurationInterface); | ||
97 | 109 | | |||
98 | Q_ASSERT(!m_statusNotifier); | 110 | Q_ASSERT(!m_statusNotifier); | ||
99 | if (m_withStatusNotifier) { | 111 | if (m_withStatusNotifier) { | ||
100 | m_statusNotifier = new KStatusNotifierItem(this); | 112 | m_statusNotifier = new KStatusNotifierItem(this); | ||
101 | m_statusNotifier->setIconByName(applet->icon()); | 113 | m_statusNotifier->setIconByName(applet->icon()); | ||
102 | m_statusNotifier->setTitle(applet->title()); | 114 | m_statusNotifier->setTitle(applet->title()); | ||
Show All 14 Lines | 128 | if (!m_applet) { | |||
117 | return; | 129 | return; | ||
118 | } | 130 | } | ||
119 | 131 | | |||
120 | QQuickItem *i = m_applet->property("_plasma_graphicObject").value<QQuickItem *>(); | 132 | QQuickItem *i = m_applet->property("_plasma_graphicObject").value<QQuickItem *>(); | ||
121 | if (!i) { | 133 | if (!i) { | ||
122 | return; | 134 | return; | ||
123 | } | 135 | } | ||
124 | 136 | | |||
137 | minimumWidthChanged(); | ||||
138 | minimumHeightChanged(); | ||||
125 | i->setWidth(ev->size().width()); | 139 | i->setWidth(ev->size().width()); | ||
126 | i->setHeight(ev->size().height()); | 140 | i->setHeight(ev->size().height()); | ||
127 | 141 | | |||
128 | contentItem()->setWidth(ev->size().width()); | 142 | contentItem()->setWidth(ev->size().width()); | ||
129 | contentItem()->setHeight(ev->size().height()); | 143 | contentItem()->setHeight(ev->size().height()); | ||
130 | 144 | | |||
131 | m_applet->config().writeEntry("geometry", QRect(position(), ev->size())); | 145 | m_applet->config().writeEntry("geometry", QRect(position(), ev->size())); | ||
132 | } | 146 | } | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 197 | { | |||
193 | m_configView = new PlasmaQuick::ConfigView(applet); | 207 | m_configView = new PlasmaQuick::ConfigView(applet); | ||
194 | 208 | | |||
195 | m_configView->init(); | 209 | m_configView->init(); | ||
196 | m_configView->show(); | 210 | m_configView->show(); | ||
197 | } | 211 | } | ||
198 | 212 | | |||
199 | void PlasmaWindowedView::minimumWidthChanged() | 213 | void PlasmaWindowedView::minimumWidthChanged() | ||
200 | { | 214 | { | ||
201 | if (!m_layout) { | 215 | if (!m_layout || !m_appletInterface) { | ||
202 | return; | 216 | return; | ||
203 | } | 217 | } | ||
204 | 218 | | |||
205 | setMinimumWidth(m_layout->property("minimumWidth").toInt()); | 219 | setMinimumWidth(qMax(m_appletInterface->property("switchWidth").toInt() + 1, qMax((int)KIconLoader::SizeEnormous, m_layout->property("minimumWidth").toInt()))); | ||
206 | } | 220 | } | ||
207 | 221 | | |||
208 | void PlasmaWindowedView::minimumHeightChanged() | 222 | void PlasmaWindowedView::minimumHeightChanged() | ||
209 | { | 223 | { | ||
210 | if (!m_layout) { | 224 | if (!m_layout || !m_appletInterface) { | ||
211 | return; | 225 | return; | ||
212 | } | 226 | } | ||
213 | 227 | | |||
214 | setMinimumHeight(m_layout->property("minimumHeight").toInt()); | 228 | setMinimumHeight(qMax(m_appletInterface->property("switchHeight").toInt() + 1, qMax((int)KIconLoader::SizeEnormous, m_layout->property("minimumHeight").toInt()))); | ||
215 | } | 229 | } | ||
216 | 230 | | |||
217 | void PlasmaWindowedView::maximumWidthChanged() | 231 | void PlasmaWindowedView::maximumWidthChanged() | ||
218 | { | 232 | { | ||
219 | if (!m_layout) { | 233 | if (!m_layout) { | ||
220 | return; | 234 | return; | ||
221 | } | 235 | } | ||
222 | 236 | | |||
Show All 12 Lines |