Make activity action button an actual button, clean up contents
authorClaudio Cambra <claudio.cambra@gmail.com>
Wed, 27 Jul 2022 19:07:53 +0000 (21:07 +0200)
committerClaudio Cambra <claudio.cambra@gmail.com>
Wed, 28 Sep 2022 11:07:08 +0000 (13:07 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
resources.qrc
src/gui/tray/ActivityActionButton.qml
src/gui/tray/ActivityItemActions.qml
src/gui/tray/CustomButton.qml
src/gui/tray/CustomTextButton.qml [deleted file]
src/gui/tray/NCButtonBackground.qml [new file with mode: 0644]
src/gui/tray/NCButtonContents.qml [new file with mode: 0644]
src/gui/tray/TextButtonContents.qml [new file with mode: 0644]

index 6d41588b5a2dc8a70ff6d316c8d47d2de977fada..16864dfa1488eff8634776937d5f0f59682fe700 100644 (file)
@@ -28,7 +28,9 @@
         <file>src/gui/tray/UnifiedSearchResultNothingFound.qml</file>
         <file>src/gui/tray/UnifiedSearchResultSectionItem.qml</file>
         <file>src/gui/tray/CustomButton.qml</file>
-        <file>src/gui/tray/CustomTextButton.qml</file>
+        <file>src/gui/tray/NCButtonContents.qml</file>
+        <file>src/gui/tray/NCButtonBackground.qml</file>
+        <file>src/gui/tray/TextButtonContents.qml</file>
         <file>src/gui/tray/ActivityItemContextMenu.qml</file>
         <file>src/gui/tray/ActivityItemActions.qml</file>
         <file>src/gui/tray/ActivityItemContent.qml</file>
index a6b0d70da297bd891f5eb0855dc2eb45cae72c30..2c5a0e57e134343a68d5b539c41186d87b5d373e 100644 (file)
@@ -1,13 +1,11 @@
 import QtQuick 2.15
 import QtQuick.Controls 2.3
-import QtQuick.Layouts 1.15
 import Style 1.0
 import com.nextcloud.desktopclient 1.0
 
-Item {
+AbstractButton {
     id: root
 
-    property string text: ""
     property string toolTipText: ""
 
     property bool primaryButton: false
@@ -15,52 +13,65 @@ Item {
     property string imageSource: ""
     property string imageSourceHover: ""
 
-    property color textColor: Style.ncTextColor
-    property color textColorHovered: Style.ncSecondaryTextColor
+    property color adjustedHeaderColor: Style.ncBlue
+    property color textColor: primaryButton ? adjustedHeaderColor : Style.ncTextColor
+    property color textColorHovered: primaryButton ? UserModel.currentUser.headerTextColor : Style.ncTextColor
 
-    signal clicked()
+    property string verb: ""
+    property bool isTalkReplyButton: false
 
-    Loader {
-        active: !root.primaryButton
 
-        anchors.fill: parent
-
-        sourceComponent: CustomTextButton {
-             anchors.fill: parent
-             text: root.text
-             toolTipText: root.toolTipText
+    background: NCButtonBackground {
+        color: UserModel.currentUser.headerColor
+        hovered: root.hovered
+        visible: root.primaryButton
+    }
 
-             textColor: root.textColor
-             textColorHovered: root.textColorHovered
+    contentItem: Loader {
+        id: contentItemLoader
+        active: true
+        sourceComponent: root.primaryButton ? primaryButtonContent : textButtonContent
+    }
 
-             onClicked: root.clicked()
+    ToolTip {
+        id: customTextButtonTooltip
+        text: root.toolTipText
+        delay: Qt.styleHints.mousePressAndHoldInterval
+        visible: root.toolTipText !== "" && root.hovered
+        contentItem: Label {
+            text: customTextButtonTooltip.text
+            color: Style.ncTextColor
+        }
+        background: Rectangle {
+            border.color: Style.menuBorder
+            color: Style.backgroundColor
         }
     }
 
-    Loader {
-        active: root.primaryButton
-
-        anchors.fill: parent
-
-        sourceComponent: CustomButton {
+    Component {
+        id: textButtonContent
+        TextButtonContents {
             anchors.fill: parent
-            anchors.topMargin: Style.roundedButtonBackgroundVerticalMargins
-            anchors.bottomMargin: Style.roundedButtonBackgroundVerticalMargins
-
+            hovered: root.hovered
             text: root.text
-            toolTipText: root.toolTipText
-
             textColor: root.textColor
             textColorHovered: root.textColorHovered
 
             bold: root.primaryButton
+        }
+    }
 
-            imageSource: root.imageSource
+    Component {
+        id: primaryButtonContent
+        NCButtonContents {
+            anchors.fill: parent
+            hovered: root.hovered
             imageSourceHover: root.imageSourceHover
-
-            bgColor: UserModel.currentUser.headerColor
-
-            onClicked: root.clicked()
+            imageSource: root.imageSource
+            text: root.text
+            textColor: root.textColor
+            textColorHovered: root.textColorHovered
+            bold: root.primaryButton
         }
     }
 }
index 130a515665eb68ff67137917c10c04a568a50e9a..57230cc56d6211d6ec3b28625543186f6b1fe594 100644 (file)
@@ -33,25 +33,22 @@ RowLayout {
         ActivityActionButton {
             id: activityActionButton
 
-            readonly property string verb: model.modelData.verb
-            readonly property bool primary: (model.index === 0 && verb !== "DELETE") || model.modelData.primary
-            readonly property bool isTalkReplyButton: verb === "REPLY"
+            Layout.minimumWidth: primaryButton ? Style.activityItemActionPrimaryButtonMinWidth : Style.activityItemActionSecondaryButtonMinWidth
+            Layout.preferredHeight: parent.height
+            Layout.preferredWidth: primaryButton ? -1 : parent.height
 
-            Layout.minimumWidth: primary ? Style.activityItemActionPrimaryButtonMinWidth : Style.activityItemActionSecondaryButtonMinWidth
-            Layout.preferredHeight: primary ? parent.height : parent.height * 0.3
-            Layout.preferredWidth: primary ? -1 : parent.height
+            verb: model.modelData.verb
+            primaryButton: (model.index === 0 && verb !== "DELETE") || model.modelData.primary
+            isTalkReplyButton: verb === "REPLY"
 
             text: model.modelData.label
 
+            adjustedHeaderColor: root.adjustedHeaderColor
+
             imageSource: model.modelData.imageSource ? model.modelData.imageSource + root.adjustedHeaderColor : ""
             imageSourceHover: model.modelData.imageSourceHovered ? model.modelData.imageSourceHovered + UserModel.currentUser.headerTextColor : ""
 
-            textColor: primary ? root.adjustedHeaderColor : Style.ncTextColor
-            textColorHovered: primary ? UserModel.currentUser.headerTextColor : Style.ncTextColor
-
-            primaryButton: primary
-
-            onClicked: !isTalkReplyButton ? root.triggerAction(model.index) : root.showReplyField()
+            onClicked: isTalkReplyButton ? root.showReplyField() : root.triggerAction(model.index)
         }
     }
 
index 70693c7df4a3db88d88cd20ebfeac5988d9cd68a..e9a75c6635ccac4b849fcbede63e24f35a3b8069 100644 (file)
@@ -8,7 +8,6 @@ Button {
 
     property string imageSource: ""
     property string imageSourceHover: ""
-    property Image iconItem: icon
 
     property string toolTipText: ""
 
@@ -21,11 +20,9 @@ Button {
 
     property real bgOpacity: 0.3
 
-    background: Rectangle {
+    background: NCButtonBackground {
         id: bgRectangle
-        color: "transparent"
-        opacity: parent.hovered ? 1.0 : bgOpacity
-        radius: width / 2
+        hovered: root.hovered
     }
 
     leftPadding: root.text === "" ? 5 : 10
@@ -36,32 +33,13 @@ Button {
         visible: root.toolTipText !== "" && root.hovered
     }
 
-    contentItem: RowLayout {
-        Image {
-            id: icon
-
-            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
-
-            source: root.hovered ? root.imageSourceHover : root.imageSource
-            fillMode: Image.PreserveAspectFit
-        }
-
-        Label {
-            Layout.maximumWidth: icon.width > 0 ? parent.width - icon.width - parent.spacing : parent.width
-            Layout.fillWidth: icon.status !== Image.Ready
-
-            text: root.text
-            textFormat: Text.PlainText
-            font.bold: root.bold
-
-            visible: root.text !== ""
-
-            color: root.hovered ? root.textColorHovered : root.textColor
-
-            horizontalAlignment: Text.AlignHCenter
-            verticalAlignment: Text.AlignVCenter
-
-            elide: Text.ElideRight
-        }
+    contentItem: NCButtonContents {
+        hovered: root.hovered
+        imageSourceHover: root.imageSourceHover
+        imageSource: root.imageSource
+        text: root.text
+        textColor: root.textColor
+        textColorHovered: root.textColorHovered
+        bold: root.bold
     }
 }
diff --git a/src/gui/tray/CustomTextButton.qml b/src/gui/tray/CustomTextButton.qml
deleted file mode 100644 (file)
index 9268b19..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-import QtQuick 2.15
-import QtQuick.Controls 2.3
-import Style 1.0
-
-Label {
-    id: root
-
-    property string toolTipText: ""
-    property Action action: null
-    property alias acceptedButtons: mouseArea.acceptedButtons
-    property bool hovered: mouseArea.containsMouse
-
-    height: implicitHeight
-
-    property color textColor: Style.ncTextColor
-    property color textColorHovered: Style.ncSecondaryTextColor
-
-    Accessible.role: Accessible.Button
-    Accessible.name: text
-    Accessible.onPressAction: root.clicked(null)
-
-    text: action ? action.text : ""
-    textFormat: Text.PlainText
-    enabled: !action || action.enabled
-    onClicked: if (action) action.trigger()
-
-    font.underline: true
-    color: root.hovered ? root.textColorHovered : root.textColor
-    horizontalAlignment: Text.AlignLeft
-    verticalAlignment: Text.AlignVCenter
-    elide: Text.ElideRight
-
-    signal pressed(QtObject mouse)
-    signal clicked(QtObject mouse)
-
-    NCToolTip {
-        text: root.toolTipText
-        visible: root.toolTipText !== "" && root.hovered
-    }
-
-    MouseArea {
-        id: mouseArea
-        anchors.fill: parent
-        hoverEnabled: true
-
-        onClicked: root.clicked(mouse)
-        onPressed: root.pressed(mouse)
-    }
-}
diff --git a/src/gui/tray/NCButtonBackground.qml b/src/gui/tray/NCButtonBackground.qml
new file mode 100644 (file)
index 0000000..678c590
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+import QtQuick 2.15
+
+Rectangle {
+    property bool hovered: false
+    property real normalOpacity: 0.3
+    property real hoverOpacity: 1.0
+
+    color: "transparent"
+    opacity: hovered ? hoverOpacity : normalOpacity
+    radius: width / 2
+}
diff --git a/src/gui/tray/NCButtonContents.qml b/src/gui/tray/NCButtonContents.qml
new file mode 100644 (file)
index 0000000..806cc08
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+
+import Style 1.0
+
+RowLayout {
+    id: root
+
+    property bool hovered: false
+    property string imageSourceHover: ""
+    property string imageSource: ""
+    property string text: ""
+
+    property color textColor: Style.ncTextColor
+    property color textColorHovered: textColor
+    property bool bold: false
+
+    Image {
+        id: icon
+
+        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
+
+        source: root.hovered ? root.imageSourceHover : root.imageSource
+        fillMode: Image.PreserveAspectFit
+    }
+
+    Label {
+        Layout.maximumWidth: icon.width > 0 ? parent.width - icon.width - parent.spacing : parent.width
+        Layout.fillWidth: icon.status !== Image.Ready
+
+        text: root.text
+        textFormat: Text.PlainText
+        font.bold: root.bold
+
+        visible: root.text !== ""
+
+        color: root.hovered ? root.textColorHovered : root.textColor
+
+        horizontalAlignment: Text.AlignHCenter
+        verticalAlignment: Text.AlignVCenter
+
+        elide: Text.ElideRight
+    }
+}
diff --git a/src/gui/tray/TextButtonContents.qml b/src/gui/tray/TextButtonContents.qml
new file mode 100644 (file)
index 0000000..8699faa
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+
+import Style 1.0
+
+Label {
+    property bool hovered: false
+    property color textColor: Style.ncTextColor
+    property color textColorHovered: Style.ncSecondaryTextColor
+    property bool bold: false
+
+    textFormat: Text.PlainText
+    font.underline: true
+    font.bold: bold
+    color: hovered ? textColorHovered : textColor
+
+    horizontalAlignment: Text.AlignLeft
+    verticalAlignment: Text.AlignVCenter
+
+    elide: Text.ElideRight
+}
+