Commit 5238ae3a authored by Frederik Gladhorn's avatar Frederik Gladhorn

Make the action selector OSD independent of the other OSDs

Summary:
This OSD should handle keyboard input and behave different, so make it work on its own.
In follow up changes, the keyboard handling will be added.

CCBUG: 395804

Reviewers: #plasma, davidedmundson

Subscribers: broulik, davidedmundson, zzag, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14143
parent ea63b2ce
......@@ -26,7 +26,7 @@
#include <QLoggingCategory>
#include <QTimer>
#include <QStandardPaths>
#include <KDeclarative/QmlObject>
#include <KDeclarative/QmlObjectSharedEngine>
using namespace KScreen;
......@@ -61,7 +61,7 @@ bool Osd::initOsd()
return false;
}
m_osdObject = new KDeclarative::QmlObject(this);
m_osdObject = new KDeclarative::QmlObjectSharedEngine(this);
m_osdObject->setSource(QUrl::fromLocalFile(osdPath));
if (m_osdObject->status() != QQmlComponent::Ready) {
......@@ -116,21 +116,31 @@ void Osd::showOutputIdentifier(const KScreen::OutputPtr &output)
void Osd::showActionSelector()
{
if (!initOsd()) {
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<QObject*>();
connect(osdItem, SIGNAL(clicked(int)),
this, SLOT(onOsdActionSelected(int)));
m_timeout = 0; // no timeout for this one
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::QmlObjectSharedEngine(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;
}
showOsd();
auto *rootObject = m_osdActionSelector->rootObject();
connect(rootObject, SIGNAL(clicked(int)),
this, SLOT(onOsdActionSelected(int)));
}
if (auto *rootObject = m_osdActionSelector->rootObject()) {
rootObject->setProperty("visible", true);
} else {
qCWarning(KSCREEN_KDED) << "Could not get root object for action selector.";
}
}
void Osd::onOsdActionSelected(int action)
......@@ -195,14 +205,14 @@ void Osd::showOsd()
void Osd::hideOsd()
{
if (!initOsd()) {
return;
if (m_osdActionSelector) {
if (auto *rootObject = m_osdActionSelector->rootObject()) {
rootObject->setProperty("visible", false);
}
}
auto *rootObject = m_osdObject->rootObject();
if (!rootObject) {
return;
if (m_osdObject) {
if (auto *rootObject = m_osdObject->rootObject()) {
rootObject->setProperty("visible", false);
}
}
rootObject->setProperty("visible", false);
}
......@@ -64,9 +64,9 @@ private:
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
......
......@@ -24,94 +24,96 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.KScreen 1.0
Item {
PlasmaCore.Dialog {
id: root
property QtObject rootItem
location: PlasmaCore.Types.Floating
type: PlasmaCore.Dialog.Normal
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 {
Accessible.name: modelData.label
PlasmaCore.IconItem {
source: modelData.iconSource
height: buttonRow.height - ((units.smallSpacing / 2) * 3)
width: height
anchors.centerIn: parent
}
]
delegate: PlasmaComponents.Button {
Accessible.name: modelData.label
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...");
}
Component.onCompleted: print("OsdSelector loaded...");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment