]> Some of my projects - aniplayer.git/commitdiff
Use custom controls instead of QtQuick.Controls
authorAPTX <marek321@gmail.com>
Sun, 26 Nov 2017 12:25:10 +0000 (21:25 +0900)
committerAPTX <marek321@gmail.com>
Sun, 26 Nov 2017 12:25:10 +0000 (21:25 +0900)
core/trackmodel.cpp
core/trackmodel.h
uiplugins/ui_desktop_qml_default/qml.qrc
uiplugins/ui_desktop_qml_default/qml/BasicButton.qml [new file with mode: 0644]
uiplugins/ui_desktop_qml_default/qml/Button.qml [deleted file]
uiplugins/ui_desktop_qml_default/qml/ComboButton.qml [new file with mode: 0644]
uiplugins/ui_desktop_qml_default/qml/OpenButton.qml
uiplugins/ui_desktop_qml_default/qml/PlayerControls.qml

index 76a82fec03128aa91bc63ce2d0221676c6b2f7eb..0f33d4e9b558ce88193f3320d2dddc4ff45e7ae7 100644 (file)
@@ -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())
index 03b7a837a9059b9a7bcb2bc55e1a5c95691f3fa3..0025905a7f7881077f43a9658a0549cc9824a479 100644 (file)
@@ -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;
 };
index eaf22ec6c65ce18395cdda681b8d25a35da55cf7..43c51d07105a2c9cbb8aa5274dfe9c34339f71c9 100644 (file)
@@ -7,5 +7,7 @@
         <file>qml/PlaybackPosition.qml</file>
         <file>qml/VolumeSlider.qml</file>
         <file>qml/TextWithBackground.qml</file>
+        <file>qml/BasicButton.qml</file>
+        <file>qml/ComboButton.qml</file>
     </qresource>
 </RCC>
diff --git a/uiplugins/ui_desktop_qml_default/qml/BasicButton.qml b/uiplugins/ui_desktop_qml_default/qml/BasicButton.qml
new file mode 100644 (file)
index 0000000..b5eefb1
--- /dev/null
@@ -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 (file)
index 1cb984d..0000000
+++ /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 (file)
index 0000000..b0a858b
--- /dev/null
@@ -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);
+    }
+}
index 4e2f967205d54dfc61d76e7677e36d7e0f902bac..0cd78c3fa89963facfc861040edd2170499ac219 100644 (file)
@@ -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"
index 600e8525182d72066c6478fabe35748838cdf8ba..566a5c555f202f37af2dbb6e14d24f4beed99e64 100644 (file)
@@ -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"