Files
asteria-qt/src/qml/components/SideBar.qml
T

183 lines
4.7 KiB
QML

import QtQuick
import QtQuick.Controls
import Asteria
Rectangle {
id: sidebar
width: sidebarOpen ? Theme.sidebarWidth : 0
clip: true
color: Theme.surface
property bool sidebarOpen: false
signal closeDrawer()
signal navigateTo(string page)
signal openFile()
signal closeBook()
Behavior on width {
NumberAnimation {
duration: sidebarOpen ? Theme.animDurationOpen : Theme.animDurationClose
easing.type: Easing.OutQuad
}
}
Text {
anchors.left: parent.left
anchors.leftMargin: 16
y: Theme.headerHeight / 2 - height / 2
text: "Asteria"
font.pixelSize: 18
font.bold: true
color: Theme.uiText
}
// Close button aligned with main header row
Button {
anchors.right: parent.right
anchors.rightMargin: 12
y: Theme.headerHeight / 2 - height / 2
z: 1
flat: true
contentItem: Text {
text: "\ue5cb"
font.family: "Material Icons Outlined"
font.pixelSize: 24
color: Theme.sidebarButtonText
}
background: Item {}
onClicked: sidebar.closeDrawer()
}
Column {
id: navColumn
y: Theme.headerHeight
width: Theme.sidebarWidth
SideBarButton {
iconText: "\ue86d"
title: "Book"
onClicked: sidebar.navigateTo("reader")
}
SideBarButton {
iconText: "\ue02f"
title: "Library"
onClicked: sidebar.navigateTo("library")
}
SideBarButton {
iconText: "\ue30a"
title: "Files"
onClicked: sidebar.openFile()
}
SideBarButton {
visible: bookController.hasBook
iconText: "\ue5cd"
title: "Close Book"
onClicked: sidebar.closeBook()
}
// Divider
Rectangle {
width: parent.width
height: 1
color: Theme.divider
}
SideBarButton {
iconText: "\ue3a9"
title: "Dark Theme"
onClicked: {} // Non-functional
}
SideBarButton {
iconText: "\ue3a6"
title: "Light Theme"
onClicked: {} // Non-functional
}
// Divider
Rectangle {
width: parent.width
height: 1
color: Theme.divider
}
SideBarButton {
iconText: "\ue8b8"
title: "Settings"
onClicked: sidebar.navigateTo("settings")
}
}
// TOC section — shown when the current book has a table of contents
Item {
visible: bookController.hasBook && bookController.toc.length > 0
anchors.top: navColumn.bottom
anchors.bottom: parent.bottom
width: parent.width
Rectangle {
id: tocDivider
width: parent.width
height: 1
color: Theme.divider
}
Text {
id: tocLabel
anchors.top: tocDivider.bottom
anchors.topMargin: 8
anchors.left: parent.left
anchors.leftMargin: 16
text: "Contents"
font.pixelSize: 10
font.bold: true
color: Theme.dimText
font.letterSpacing: 1
}
ListView {
anchors.top: tocLabel.bottom
anchors.topMargin: 4
anchors.bottom: parent.bottom
width: parent.width
clip: true
model: bookController.toc
delegate: Rectangle {
width: ListView.view.width
height: tocEntryText.implicitHeight + 10
color: readingModel.currentChapter === modelData.chapterIndex
? Qt.rgba(1, 1, 1, 0.05)
: "transparent"
Text {
id: tocEntryText
anchors.verticalCenter: parent.verticalCenter
x: 16 + modelData.depth * 12
width: parent.width - x - 8
text: modelData.title
font.pixelSize: 13
color: readingModel.currentChapter === modelData.chapterIndex
? Theme.sidebarButtonText
: Theme.uiText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
MouseArea {
anchors.fill: parent
onClicked: {
readingModel.goToChapter(modelData.chapterIndex)
sidebar.navigateTo("reader")
sidebar.closeDrawer()
}
}
}
}
}
}