diff --git a/kded/osd.h b/kded/osd.h --- a/kded/osd.h +++ b/kded/osd.h @@ -64,9 +64,9 @@ KScreen::OutputPtr m_output; QRect m_outputGeometry; KDeclarative::QmlObject *m_osdObject = nullptr; + KDeclarative::QmlObject *m_osdActionSelector = nullptr; QTimer *m_osdTimer = nullptr; int m_timeout = 0; - }; } // ns diff --git a/kded/osd.cpp b/kded/osd.cpp --- a/kded/osd.cpp +++ b/kded/osd.cpp @@ -55,7 +55,7 @@ return true; } - const QString &osdPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml")); + QString osdPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml")); if (osdPath.isEmpty()) { qCWarning(KSCREEN_KDED) << "Failed to find OSD QML file" << osdPath; return false; @@ -116,21 +116,26 @@ void Osd::showActionSelector() { - if (!initOsd()) { - return; + if (!m_osdActionSelector) { + const QString &osdPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/OsdSelector.qml")); + if (osdPath.isEmpty()) { + qCWarning(KSCREEN_KDED) << "Failed to find action selector OSD QML file" << osdPath; + return; + } + m_osdActionSelector = new KDeclarative::QmlObject(this); + m_osdActionSelector->setSource(QUrl::fromLocalFile(osdPath)); + + if (m_osdActionSelector->status() != QQmlComponent::Ready) { + qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << osdPath; + delete m_osdActionSelector; + m_osdActionSelector = nullptr; + return; + } } - m_outputGeometry = m_output->geometry(); - auto *rootObject = m_osdObject->rootObject(); - rootObject->setProperty("itemSource", QStringLiteral("OsdSelector.qml")); - rootObject->setProperty("timeout", 0); - rootObject->setProperty("outputOnly", false); - auto osdItem = rootObject->property("osdItem").value(); - connect(osdItem, SIGNAL(clicked(int)), + auto *rootObject = m_osdActionSelector->rootObject(); + connect(rootObject, SIGNAL(clicked(int)), this, SLOT(onOsdActionSelected(int))); - m_timeout = 0; // no timeout for this one - - showOsd(); } void Osd::onOsdActionSelected(int action) diff --git a/kded/qml/OsdSelector.qml b/kded/qml/OsdSelector.qml --- a/kded/qml/OsdSelector.qml +++ b/kded/qml/OsdSelector.qml @@ -24,93 +24,97 @@ import org.kde.KScreen 1.0 -Item { +PlasmaCore.Dialog { id: root - property QtObject rootItem + location: PlasmaCore.Types.Floating + type: PlasmaCore.Dialog.Normal + visible: true + property string infoText signal clicked(int actionId) - height: Math.min(units.gridUnit * 15, Screen.desktopAvailableHeight / 5) - width: buttonRow.width - - PlasmaComponents.ButtonRow { - id: buttonRow - - exclusive: false - - height: parent.height - label.height - ((units.smallSpacing/2) * 3) - width: (actionRepeater.count * height) + ((actionRepeater.count - 1) * buttonRow.spacing); - - Repeater { - id: actionRepeater - model: [ - { - iconSource: "osd-shutd-laptop", - label: i18n("Switch to external screen"), - action: OsdAction.SwitchToExternal - }, - { - iconSource: "osd-shutd-screen", - label: i18n("Switch to laptop screen"), - action: OsdAction.SwitchToInternal - }, - { - iconSource: "osd-duplicate", - label: i18n("Unify outputs"), - action: OsdAction.Clone - }, - { - iconSource: "osd-sbs-left", - label: i18n("Extend to left"), - action: OsdAction.ExtendLeft - }, - { - iconSource: "osd-sbs-sright", - label: i18n("Extend to right"), - action: OsdAction.ExtendRight - }, - { - iconSource: "dialog-cancel", - label: i18n("Leave unchanged"), - action: OsdAction.NoAction + mainItem: Item { + height: Math.min(units.gridUnit * 15, Screen.desktopAvailableHeight / 5) + width: buttonRow.width + + PlasmaComponents.ButtonRow { + id: buttonRow + exclusive: false + + height: parent.height - label.height - ((units.smallSpacing/2) * 3) + width: (actionRepeater.count * height) + ((actionRepeater.count - 1) * buttonRow.spacing); + + Repeater { + id: actionRepeater + model: [ + { + iconSource: "osd-shutd-laptop", + label: i18n("Switch to external screen"), + action: OsdAction.SwitchToExternal + }, + { + iconSource: "osd-shutd-screen", + label: i18n("Switch to laptop screen"), + action: OsdAction.SwitchToInternal + }, + { + iconSource: "osd-duplicate", + label: i18n("Unify outputs"), + action: OsdAction.Clone + }, + { + iconSource: "osd-sbs-left", + label: i18n("Extend to left"), + action: OsdAction.ExtendLeft + }, + { + iconSource: "osd-sbs-sright", + label: i18n("Extend to right"), + action: OsdAction.ExtendRight + }, + { + iconSource: "dialog-cancel", + label: i18n("Leave unchanged"), + action: OsdAction.NoAction + } + ] + delegate: PlasmaComponents.Button { + PlasmaCore.IconItem { + source: modelData.iconSource + height: buttonRow.height - ((units.smallSpacing / 2) * 3) + width: height + anchors.centerIn: parent } - ] - delegate: PlasmaComponents.Button { - PlasmaCore.IconItem { - source: modelData.iconSource - height: buttonRow.height - ((units.smallSpacing / 2) * 3) + height: parent.height width: height - anchors.centerIn: parent - } - height: parent.height - width: height - onHoveredChanged: rootItem.infoText = (hovered ? modelData.label : "") + onHoveredChanged: root.infoText = (hovered ? modelData.label : "") - onClicked: root.clicked(modelData.action) + onClicked: root.clicked(modelData.action) + } } } - } - // TODO: keep? remove? - PlasmaExtras.Heading { - id: label - anchors { - bottom: parent.bottom - left: parent.left - right: parent.right - margins: Math.floor(units.smallSpacing / 2) + PlasmaExtras.Heading { + id: label + anchors { + bottom: parent.bottom + left: parent.left + right: parent.right + margins: Math.floor(units.smallSpacing / 2) + } + + text: root.infoText + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + maximumLineCount: 2 + elide: Text.ElideLeft + minimumPointSize: theme.defaultFont.pointSize + fontSizeMode: Text.HorizontalFit } - text: rootItem.infoText - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.WordWrap - maximumLineCount: 2 - elide: Text.ElideLeft - minimumPointSize: theme.defaultFont.pointSize - fontSizeMode: Text.HorizontalFit + Component.onCompleted: print("OsdSelector loaded..."); + Keys.onEscapePressed: clicked("dialog-cancel") } - - Component.onCompleted: print("OsdSelector loaded..."); }