Skip to content

Commit

Permalink
qml: refactor CSDButtonSets to use CSDButtonModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jagannatharjun authored and fcartegnie committed Dec 23, 2022
1 parent 99ee50c commit 68a57d6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 61 deletions.
51 changes: 19 additions & 32 deletions modules/gui/qt/widgets/qml/CSDThemeButtonSet.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,34 @@ Rectangle {

spacing: root._interNavButtonSpacing

CSDThemeButton {
id: minimizeButton
Repeater {
model: MainCtx.csdButtonModel.windowCSDButtons

anchors.verticalCenter: parent.verticalCenter
CSDThemeButton {

bannerHeight: root.height
anchors.verticalCenter: parent.verticalCenter

buttonType: CSDThemeImage.MINIMIZE
bannerHeight: root.height

onClicked: MainCtx.requestInterfaceMinimized()
}

CSDThemeButton {
id: maximizeButton

anchors.verticalCenter: parent.verticalCenter
buttonType: {
switch (modelData.type) {
case CSDButton.Minimize:
return CSDThemeImage.MINIMIZE

bannerHeight: root.height
case CSDButton.MaximizeRestore:
return (MainCtx.intfMainWindow.visibility === Window.Maximized)
? CSDThemeImage.RESTORE
: CSDThemeImage.MAXIMIZE

buttonType: (MainCtx.intfMainWindow.visibility === Window.Maximized) ? CSDThemeImage.RESTORE : CSDThemeImage.MAXIMIZE
case CSDButton.Close:
return CSDThemeButton.CLOSE
}

onClicked: {
if (MainCtx.intfMainWindow.visibility === Window.Maximized) {
MainCtx.requestInterfaceNormal()
} else {
MainCtx.requestInterfaceMaximized()
console.assert(false, "unreachable")
}
}
}

CSDThemeButton {
id: closeButton

anchors.verticalCenter: parent.verticalCenter

bannerHeight: root.height

buttonType: CSDThemeImage.CLOSE

onClicked: MainCtx.intfMainWindow.close()
onClicked: modelData.click()
}
}
}

}
66 changes: 37 additions & 29 deletions modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,46 @@ Row {
property color color: VLCStyle.colors.text
property color hoverColor: VLCStyle.colors.windowCSDButtonBg

property bool hovered: minimizeButton.hovered || maximizeButton.hovered || closeButton.hovered

CSDWindowButton {
id: minimizeButton
iconTxt: VLCIcons.window_minimize
onClicked: MainCtx.requestInterfaceMinimized()
height: windowButtonGroup.height
color: windowButtonGroup.color
hoverColor: windowButtonGroup.hoverColor
readonly property bool hovered: {
var h = false
for (var i = 0; i < repeater.count; ++i) {
var button = repeater.itemAt(i)
h = h || button.hovered
}

return h
}

CSDWindowButton {
id: maximizeButton
iconTxt: (MainCtx.intfMainWindow.visibility === Window.Maximized) ? VLCIcons.window_restore :VLCIcons.window_maximize
onClicked: {
if (MainCtx.intfMainWindow.visibility === Window.Maximized) {
MainCtx.requestInterfaceNormal()
} else {
MainCtx.requestInterfaceMaximized()
Repeater {
id: repeater

model: MainCtx.csdButtonModel.windowCSDButtons

CSDWindowButton {
height: windowButtonGroup.height

color: (modelData.type === CSDButton.Close && (hovered)) ? "white" : windowButtonGroup.color

hoverColor: (modelData.type === CSDButton.Close) ? "red" : windowButtonGroup.hoverColor

iconTxt: {
switch (modelData.type) {
case CSDButton.Minimize:
return VLCIcons.window_minimize

case CSDButton.MaximizeRestore:
return (MainCtx.intfMainWindow.visibility === Window.Maximized)
? VLCIcons.window_restore
: VLCIcons.window_maximize

case CSDButton.Close:
return VLCIcons.window_close
}

console.assert(false, "unreachable")
}
}
height: windowButtonGroup.height
color: windowButtonGroup.color
hoverColor: windowButtonGroup.hoverColor
}

CSDWindowButton {
id: closeButton
iconTxt: VLCIcons.window_close
onClicked: MainCtx.intfMainWindow.close()
height: windowButtonGroup.height
color: closeButton.hovered ? "white" : windowButtonGroup.color
hoverColor: "red"
onClicked: modelData.click()
}
}
}

0 comments on commit 68a57d6

Please sign in to comment.