Make activity action button an actual button, clean up contents

Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
This commit is contained in:
Claudio Cambra 2022-07-27 21:07:53 +02:00
parent 5dfd605049
commit db861e1ade
8 changed files with 187 additions and 127 deletions

View 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>

View 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
background: NCButtonBackground {
color: UserModel.currentUser.headerColor
hovered: root.hovered
visible: root.primaryButton
}
sourceComponent: CustomTextButton {
anchors.fill: parent
text: root.text
toolTipText: root.toolTipText
contentItem: Loader {
id: contentItemLoader
active: true
sourceComponent: root.primaryButton ? primaryButtonContent : textButtonContent
}
textColor: root.textColor
textColorHovered: root.textColorHovered
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
Component {
id: textButtonContent
TextButtonContents {
anchors.fill: parent
sourceComponent: CustomButton {
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
}
}
}

View 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)
}
}

View 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
contentItem: NCButtonContents {
hovered: root.hovered
imageSourceHover: root.imageSourceHover
imageSource: root.imageSource
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
}
textColor: root.textColor
textColorHovered: root.textColorHovered
bold: root.bold
}
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}