添加跟随主题的背景和文字,收藏区域组件

This commit is contained in:
qiqi 2022-12-21 10:22:48 +08:00 committed by hewenfei
parent add50cca1a
commit b8a4a009b1
6 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import org.ukui.menu.core 1.0
RoundButton {
id: control
property string appName: ""
property string appIcon: ""
height: 104
width: height
radius: 10
scale: control.pressed ? 1.1 : 1.0
hoverEnabled: true
contentItem: IconLabel {
anchors.fill: parent
appName: control.appName
appIcon: control.appIcon
display: Display.TextUnderIcon
}
background: StyleBackground {
radius: control.radius
useStyleTransparent: false
alpha: control.pressed ? 0.75 : control.hovered ? 0.6 : 0.40
}
}

View File

@ -0,0 +1,70 @@
import QtQuick 2.0
import org.ukui.menu.core 1.0
Item {
id: root
property int display: Display.TextUnderIcon
// icon48*48 icon32*32
property int iconHeight: 48
property int iconWidth: 48
property string appName: ""
property string appIcon: ""
// spacing0 spacing12
property int spacing: 2
state: root.display
states: [
State {
name: Display.TextBesideIcon
AnchorChanges {
target: iconImage
anchors.verticalCenter: root.verticalCenter
}
PropertyChanges {
target: iconText
textMaxWidth: root.width - iconImage.width - root.spacing
anchors.left: iconImage.right
anchors.leftMargin: root.spacing
anchors.verticalCenter: root.verticalCenter
}
},
State {
name: Display.TextUnderIcon
PropertyChanges {
target: iconImage
anchors.top: root.top
anchors.topMargin: (root.height - root.spacing -iconImage.height -iconText.height) / 2
anchors.horizontalCenter: root.horizontalCenter
}
PropertyChanges {
target: iconText
textMaxWidth: root.width
anchors.top: iconImage.bottom
anchors.topMargin: root.spacing
anchors.horizontalCenter: root.horizontalCenter
}
}
]
Image {
id: iconImage
height: root.iconHeight
width: root.iconWidth
source: root.appIcon
}
StyleText {
id: iconText
property int textMaxWidth: root.width
text: root.appName
font.pixelSize: 14
elide: Text.ElideRight
Component.onCompleted: {
var textWidth = contentWidth > textMaxWidth ? textMaxWidth : contentWidth
width = textWidth
}
}
}

View File

@ -0,0 +1,42 @@
import QtQuick 2.0
import QtQuick.Controls 2.5
import org.ukui.menu.core 1.0
Rectangle {
property bool useStyleTransparent: true
property int paletteRole: Palette.Base
property int paletteGroup: Palette.Active
property real alpha: 1.0
clip: true
function updateColor() {
if (useStyleTransparent) {
color = themePalette.paletteColorWithTransparency(paletteRole,paletteGroup)
} else {
color = themePalette.paletteColorWithCustomTransparency(paletteRole,paletteGroup,alpha)
}
}
Component.onCompleted: {
updateColor()
themePalette.styleColorChanged.connect(updateColor)
}
Component.onDestruction: {
themePalette.styleColorChanged.disconnect(updateColor)
}
onUseStyleTransparentChanged: {
updateColor()
}
onPaletteRoleChanged: {
updateColor()
}
onPaletteGroupChanged: {
updateColor()
}
onAlphaChanged: {
updateColor()
}
}

View File

@ -0,0 +1,22 @@
import QtQuick 2.0
import org.ukui.menu.core 1.0
Text {
property int paletteRole: Palette.Text
function updateColor() {
color = themePalette.paletteColor(paletteRole)
}
Component.onCompleted: {
updateColor()
themePalette.styleColorChanged.connect(updateColor)
}
Component.onDestruction: {
themePalette.styleColorChanged.disconnect(updateColor)
}
onPaletteRoleChanged: {
updateColor()
}
}

View File

@ -10,5 +10,9 @@
<file>AppUI/Sidebar.qml</file>
<file>AppControls2/qmldir</file>
<file>AppControls2/App.qml</file>
<file>AppControls2/CollectionItem.qml</file>
<file>AppControls2/StyleBackground.qml</file>
<file>AppControls2/StyleText.qml</file>
<file>AppControls2/IconLabel.qml</file>
</qresource>
</RCC>

View File

@ -24,6 +24,19 @@
namespace UkuiMenu {
class Display {
Q_GADGET
public:
enum Type {
IconOnly,
TextOnly,
TextBesideIcon,
TextUnderIcon
};
Q_ENUM(Type)
};
class SortType
{
Q_GADGET
@ -94,6 +107,7 @@ public:
qRegisterMetaType<UkuiMenu::DataType::Type>("DataType::Type");
qRegisterMetaType<UkuiMenu::DataEntity>("DataEntity");
qmlRegisterUncreatableType<Display>(uri, versionMajor, versionMinor, "Display", "Use enums only.");
qmlRegisterUncreatableType<UkuiMenu::SortType>(uri, versionMajor, versionMinor, "SortType", "Use enums only");
qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only");
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");