From 8b2cd81dbb1da7711284320155a1c8dbb487e68f Mon Sep 17 00:00:00 2001 From: APTX Date: Sun, 26 Nov 2017 21:25:10 +0900 Subject: [PATCH] Use custom controls instead of QtQuick.Controls --- core/trackmodel.cpp | 5 ++ core/trackmodel.h | 7 ++ uiplugins/ui_desktop_qml_default/qml.qrc | 2 + .../qml/BasicButton.qml | 66 +++++++++++++++++++ .../ui_desktop_qml_default/qml/Button.qml | 23 ------- .../qml/ComboButton.qml | 38 +++++++++++ .../ui_desktop_qml_default/qml/OpenButton.qml | 3 +- .../qml/PlayerControls.qml | 36 +++++----- 8 files changed, 134 insertions(+), 46 deletions(-) create mode 100644 uiplugins/ui_desktop_qml_default/qml/BasicButton.qml delete mode 100644 uiplugins/ui_desktop_qml_default/qml/Button.qml create mode 100644 uiplugins/ui_desktop_qml_default/qml/ComboButton.qml diff --git a/core/trackmodel.cpp b/core/trackmodel.cpp index 76a82fe..0f33d4e 100644 --- a/core/trackmodel.cpp +++ b/core/trackmodel.cpp @@ -50,6 +50,11 @@ QVariant TrackModel::data(const QModelIndex &index, int role) const { return {}; } +int TrackModel::count() const +{ + return rowCount(); +} + void TrackModel::requestTrackChangeForRow(int row) { if (row < 0 || row >= rowCount()) diff --git a/core/trackmodel.h b/core/trackmodel.h index 03b7a83..0025905 100644 --- a/core/trackmodel.h +++ b/core/trackmodel.h @@ -7,6 +7,8 @@ class TrackModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged STORED false) + public: enum TrackRoles { TitleRole = Qt::UserRole + 1, LanguageRole, IdRole }; @@ -18,8 +20,11 @@ public: int rowCount(const QModelIndex &parent = QModelIndex{}) const override; QVariant data(const QModelIndex &index, int role) const override; + // TODO make const or private QString type; + int count() const; + public slots: void requestTrackChangeForRow(int row); int rowForTrackIndex(int trackIndex); @@ -27,6 +32,8 @@ public slots: signals: void trackChangeRequested(int track); + void countChanged(int count); + private: PlayerPluginInterface::TrackList m_data; }; diff --git a/uiplugins/ui_desktop_qml_default/qml.qrc b/uiplugins/ui_desktop_qml_default/qml.qrc index eaf22ec..43c51d0 100644 --- a/uiplugins/ui_desktop_qml_default/qml.qrc +++ b/uiplugins/ui_desktop_qml_default/qml.qrc @@ -7,5 +7,7 @@ qml/PlaybackPosition.qml qml/VolumeSlider.qml qml/TextWithBackground.qml + qml/BasicButton.qml + qml/ComboButton.qml diff --git a/uiplugins/ui_desktop_qml_default/qml/BasicButton.qml b/uiplugins/ui_desktop_qml_default/qml/BasicButton.qml new file mode 100644 index 0000000..b5eefb1 --- /dev/null +++ b/uiplugins/ui_desktop_qml_default/qml/BasicButton.qml @@ -0,0 +1,66 @@ +import QtQuick 2.0 + +Rectangle { + id: buttonRoot + property string text: "" + property bool checkable: false + property bool checked: false + + signal clicked + signal checkedChangedByUser(bool checked) + + width: label.width + 6 + height: label.height + 6 + color: "#0000ff" + + Text { + id: label + text: { + if(checkable) { + return (checked ? "+ " : "- ") + buttonRoot.text + } + return buttonRoot.text + } + + color: "red" + font.pointSize: 14 + anchors.centerIn: parent + } + + MouseArea { + id: ma + anchors.fill: parent + hoverEnabled: true + onEntered: buttonRoot.state = "hover" + onExited: buttonRoot.state = "" + onPressed: buttonRoot.state = "pressed" + onReleased: { + if (buttonRoot.state === "pressed") { + buttonRoot.clicked(); + if (checkable) { + checked = !checked + buttonRoot.checkedChangedByUser(checked) + } + buttonRoot.state = "hover" + } + } + } + + + states: [ + State { + name: "hover" + PropertyChanges { + target: buttonRoot + color: "yellow" + } + }, + State { + name: "pressed" + PropertyChanges { + target: buttonRoot + color: "green" + } + } + ] +} diff --git a/uiplugins/ui_desktop_qml_default/qml/Button.qml b/uiplugins/ui_desktop_qml_default/qml/Button.qml deleted file mode 100644 index 1cb984d..0000000 --- a/uiplugins/ui_desktop_qml_default/qml/Button.qml +++ /dev/null @@ -1,23 +0,0 @@ -import QtQuick 2.0 - -Item { - id: buttonRoot - property alias text: label.text - - signal clicked - - width: 80 - height: label.lineHeight - - Text { - id: label - color: "red" - font.pointSize: 24 - anchors.fill: parent - } - MouseArea { - id: ma - anchors.fill: parent - onClicked: buttonRoot.clicked() - } -} diff --git a/uiplugins/ui_desktop_qml_default/qml/ComboButton.qml b/uiplugins/ui_desktop_qml_default/qml/ComboButton.qml new file mode 100644 index 0000000..b0a858b --- /dev/null +++ b/uiplugins/ui_desktop_qml_default/qml/ComboButton.qml @@ -0,0 +1,38 @@ +import QtQuick 2.0 + +BasicButton { + property var model: null + property int currentIndex: 0 + property string textRole: null + + signal activated(int index) + + ListModel { + id: ph + } + + text: { + if (!model) return "-"; + if (textRole) return model.data(model.index(currentIndex, 0), textRole); + if (currentIndex) return "-"; + return (currentIndex - 1); + } + + onCurrentIndexChanged: { + console.log("idx change detected " + currentIndex); + } + + onClicked: { + if (!model) return; + var nextIndex = currentIndex; + ++nextIndex; + if (nextIndex >= model.count) + nextIndex = 0; + + if (nextIndex === currentIndex) + return; + + currentIndex = nextIndex; + activated(currentIndex); + } +} diff --git a/uiplugins/ui_desktop_qml_default/qml/OpenButton.qml b/uiplugins/ui_desktop_qml_default/qml/OpenButton.qml index 4e2f967..0cd78c3 100644 --- a/uiplugins/ui_desktop_qml_default/qml/OpenButton.qml +++ b/uiplugins/ui_desktop_qml_default/qml/OpenButton.qml @@ -1,8 +1,7 @@ import QtQuick 2.0 import QtQuick.Dialogs 1.2 -import QtQuick.Controls 1.4 -Button { +BasicButton { signal openFileRequested(string file) text: "Open" diff --git a/uiplugins/ui_desktop_qml_default/qml/PlayerControls.qml b/uiplugins/ui_desktop_qml_default/qml/PlayerControls.qml index 600e852..566a5c5 100644 --- a/uiplugins/ui_desktop_qml_default/qml/PlayerControls.qml +++ b/uiplugins/ui_desktop_qml_default/qml/PlayerControls.qml @@ -70,31 +70,25 @@ Row { controlledPlayer.loadAndPlay(file) } } - Button { + BasicButton { id: togglePlayButton - text: "Play" + text: { + if (controlledPlayer) { + return controlledPlayer.state === Player.Playing ? "Pause" + : "Play" + } + return "Play" + } onClicked: { + console.log("I got clicked " + controlledPlayer.state) if (controlledPlayer.state === Player.Stopped) { openButton.open() } else { controlledPlayer.togglePlay() } } - state: { - if (!controlledPlayer) return ""; - return controlledPlayer.state === Player.Playing ? "pause" : "" - } - states: [ - State { - name: "pause" - PropertyChanges { - target: togglePlayButton - text: "Pause" - } - } - ] } - Button { + BasicButton { id: fullscreenButton text: "FS" checkable: true @@ -106,7 +100,7 @@ Row { } } } - Button { + BasicButton { id: stayOnTopButton text: "OnTop" enabled: !controlledWindow.isFullScreen() @@ -119,7 +113,7 @@ Row { } } } - Button { + BasicButton { id: framelessButton text: "Frameless" enabled: !controlledWindow.isFullScreen() @@ -153,21 +147,21 @@ Row { volume: controlledPlayer ? controlledPlayer.volume : 1 onVolumeChangeRequested: controlledPlayer.setVolume(volume) } - ComboBox { + ComboButton { id: videoTracks model: player.videoTrackModel textRole: "text" currentIndex: player.videoTrackModel.rowForTrackIndex(player.currentVideoTrack) onActivated: player.videoTrackModel.requestTrackChangeForRow(index) } - ComboBox { + ComboButton { id: audioTracks model: player.audioTrackModel textRole: "text" currentIndex: player.audioTrackModel.rowForTrackIndex(player.currentAudioTrack) onActivated: player.audioTrackModel.requestTrackChangeForRow(index) } - ComboBox { + ComboButton { id: subtitleTracks model: player.subtitleTrackModel textRole: "text" -- 2.52.0