mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2025-12-06 06:36:15 +00:00
feat: add NIconTabButton widget for icon-only tabs
This commit is contained in:
64
Widgets/NIconTabButton.qml
Normal file
64
Widgets/NIconTabButton.qml
Normal file
@@ -0,0 +1,64 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import qs.Commons
|
||||
import qs.Widgets
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
// Public properties
|
||||
property string icon: ""
|
||||
property bool checked: false
|
||||
property int tabIndex: 0
|
||||
|
||||
// Internal state
|
||||
property bool isHovered: false
|
||||
|
||||
signal clicked
|
||||
|
||||
// Sizing
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
// Styling
|
||||
radius: Style.radiusXS
|
||||
color: root.checked ? Color.mPrimary : (root.isHovered ? Color.mHover : Color.mSurface)
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Style.animationFast
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
|
||||
NIcon {
|
||||
id: tabIcon
|
||||
anchors.centerIn: parent
|
||||
icon: root.icon
|
||||
pointSize: Style.fontSizeL
|
||||
color: root.checked ? Color.mOnPrimary : root.isHovered ? Color.mOnHover : Color.mOnSurface
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Style.animationFast
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onEntered: root.isHovered = true
|
||||
onExited: root.isHovered = false
|
||||
onClicked: {
|
||||
root.clicked();
|
||||
// Update parent NTabBar's currentIndex
|
||||
if (root.parent && root.parent.parent && root.parent.parent.currentIndex !== undefined) {
|
||||
root.parent.parent.currentIndex = root.tabIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user