diff --git a/plasma-windowed/CMakeLists.txt b/plasma-windowed/CMakeLists.txt --- a/plasma-windowed/CMakeLists.txt +++ b/plasma-windowed/CMakeLists.txt @@ -12,6 +12,7 @@ Qt5::Quick Qt5::Qml KF5::I18n + KF5::IconThemes KF5::XmlGui KF5::PlasmaQuick KF5::Plasma diff --git a/plasma-windowed/plasmawindowedview.h b/plasma-windowed/plasmawindowedview.h --- a/plasma-windowed/plasmawindowedview.h +++ b/plasma-windowed/plasmawindowedview.h @@ -58,6 +58,7 @@ Plasma::Applet *m_applet; QPointer m_layout; QPointer m_configView; + QPointer m_rootObject; KStatusNotifierItem* m_statusNotifier; bool m_withStatusNotifier; }; diff --git a/plasma-windowed/plasmawindowedview.cpp b/plasma-windowed/plasmawindowedview.cpp --- a/plasma-windowed/plasmawindowedview.cpp +++ b/plasma-windowed/plasmawindowedview.cpp @@ -27,9 +27,11 @@ #include #include #include +#include #include #include +#include #include @@ -41,8 +43,9 @@ m_withStatusNotifier(false) { engine()->rootContext()->setContextProperty(QStringLiteral("root"), contentItem()); - 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, \"\");")); - expr->evaluate(); + //access appletInterface.Layout.minimumWidth, to create the Layout attached object for appletInterface as a sideeffect + 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, \"\");")); + m_rootObject = expr->evaluate().value(); } PlasmaWindowedView::~PlasmaWindowedView() @@ -67,16 +70,24 @@ return; } - const QRect geom = m_applet->config().readEntry("geometry", QRect()); - if (geom.isValid()) { - setGeometry(geom); - } - - i->setParentItem(contentItem()); + i->setParentItem(m_rootObject); + m_rootObject->setProperty("appletInterface", QVariant::fromValue(i)); i->setVisible(true); setTitle(applet->title()); setIcon(QIcon::fromTheme(applet->icon())); + const QSize switchSize(i->property("switchWidth").toInt(), i->property("switchHeight").toInt()); + QRect geom = m_applet->config().readEntry("geometry", QRect()); + + if (geom.isValid()) { + geom.setWidth(qMax(geom.width(), switchSize.width() + 1)); + geom.setHeight(qMax(geom.height(), switchSize.height() + 1)); + setGeometry(geom); + } else { + setMinimumSize(QSize(qMax((int)KIconLoader::SizeEnormous, switchSize.width() + 1), + qMax((int)KIconLoader::SizeEnormous, switchSize.height() + 1))); + } + foreach (QObject *child, i->children()) { //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && @@ -92,6 +103,8 @@ connect(m_layout, SIGNAL(minimumWidthChanged()), this, SLOT(minimumWidthChanged())); connect(m_layout, SIGNAL(minimumHeightChanged()), this, SLOT(minimumHeightChanged())); } + minimumWidthChanged(); + minimumHeightChanged(); QObject::connect(applet->containment(), &Plasma::Containment::configureRequested, this, &PlasmaWindowedView::showConfigurationInterface); @@ -122,6 +135,8 @@ return; } + minimumWidthChanged(); + minimumHeightChanged(); i->setWidth(ev->size().width()); i->setHeight(ev->size().height()); @@ -202,16 +217,16 @@ return; } - setMinimumWidth(m_layout->property("minimumWidth").toInt()); + setMinimumWidth(qMax((int)KIconLoader::SizeEnormous, m_layout->property("minimumWidth").toInt())); } void PlasmaWindowedView::minimumHeightChanged() { if (!m_layout) { return; } - setMinimumHeight(m_layout->property("minimumHeight").toInt()); + setMinimumHeight(qMax((int)KIconLoader::SizeEnormous, m_layout->property("minimumHeight").toInt())); } void PlasmaWindowedView::maximumWidthChanged()