Skip to content

Commit

Permalink
#24: override elements set for maximized windows
Browse files Browse the repository at this point in the history
  • Loading branch information
antroids committed Mar 28, 2024
1 parent 29876b3 commit f9a5373
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 98 deletions.
6 changes: 6 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<entry name="widgetElements" type="StringList">
<default>windowCloseButton,windowMaximizeButton,windowMinimizeButton,windowIcon,windowTitle</default>
</entry>
<entry name="overrideElementsMaximized" type="Bool">
<default>false</default>
</entry>
<entry name="widgetElementsMaximized" type="StringList">
<default>windowCloseButton,windowMaximizeButton,windowMinimizeButton,windowIcon,windowTitle</default>
</entry>

<entry name="windowTitleMinimumWidth" type="Int">
<default>0</default>
Expand Down
65 changes: 65 additions & 0 deletions package/contents/ui/config/AddWidgetElement.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* SPDX-FileCopyrightText: 2024 Anton Kharuzhy <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import QtQuick
import QtQuick.Controls
import org.kde.kirigami as Kirigami

ComboBox {
textRole: "name"
valueRole: "value"
displayText: currentText ? i18n(currentText) : ""

model: ListModel {
ListElement {
name: "Add element..."
}

ListElement {
name: "Window close button"
value: "windowCloseButton"
}

ListElement {
name: "Window minimize button"
value: "windowMinimizeButton"
}

ListElement {
name: "Window maximize button"
value: "windowMaximizeButton"
}

ListElement {
name: "Keep window above button"
value: "windowKeepAboveButton"
}

ListElement {
name: "Keep window below button"
value: "windowKeepBelowButton"
}

ListElement {
name: "Shade window button"
value: "windowShadeButton"
}

ListElement {
name: "Window title"
value: "windowTitle"
}

ListElement {
name: "Window Icon"
value: "windowIcon"
}

ListElement {
name: "Spacer"
value: "spacer"
}
}
}
117 changes: 27 additions & 90 deletions package/contents/ui/config/ConfigAppearance.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ KCM.SimpleKCM {
property alias cfg_windowTitleMarginsTop: windowTitleMarginsTop.value
property alias cfg_windowTitleMarginsBottom: windowTitleMarginsBottom.value
property alias cfg_windowTitleMarginsRight: windowTitleMarginsRight.value
property var cfg_widgetElements
property alias cfg_widgetElements: widgetElements.elements
property alias cfg_overrideElementsMaximized: overrideElementsMaximized.checked
property alias cfg_widgetElementsMaximized: widgetElementsMaximized.elements

Kirigami.FormLayout {
anchors.left: parent.left
Expand Down Expand Up @@ -260,55 +262,10 @@ You can install more of regular Aurorae themes for window decorations in System
WidgetElements {
id: widgetElements

Component.onCompleted: function () {
model.ignoreInsertEvent = true;
for (var i = 0; i < cfg_widgetElements.length; i++) {
model.append({
"value": cfg_widgetElements[i]
});
}
model.ignoreInsertEvent = false;
}

model: ListModel {
property bool ignoreInsertEvent: false

function updateConfigFromModel() {
cfg_widgetElements = [];
for (var i = 0; i < count; i++) {
cfg_widgetElements.push(get(i).value);
}
}

onRowsMoved: updateConfigFromModel()
onRowsRemoved: updateConfigFromModel()
onRowsInserted: ignoreInsertEvent || updateConfigFromModel()
}
Kirigami.FormData.label: i18n("Elements:")
}

ComboBox {

// ListElement {
// name: "Show on all desktops button"
// value: "windowAllDesktopsButton"
// }
// ListElement {
// name: "Window application menu button"
// value: "windowAppMenuButton"
// }
// ListElement {
// name: "Window help button"
// value: "windowHelpButton"
// }
// ListElement {
// name: "Window menu button"
// value: "windowMenuButton"
// }

Kirigami.FormData.label: i18n("Add element:")
textRole: "name"
valueRole: "value"
displayText: currentText ? i18n(currentText) : ""
AddWidgetElement {
onCurrentValueChanged: function () {
if (currentValue) {
widgetElements.model.append({
Expand All @@ -317,55 +274,35 @@ You can install more of regular Aurorae themes for window decorations in System
currentIndex = 0;
}
}
}

model: ListModel {
ListElement {
name: "Select..."
}

ListElement {
name: "Window close button"
value: "windowCloseButton"
}

ListElement {
name: "Window minimize button"
value: "windowMinimizeButton"
}

ListElement {
name: "Window maximize button"
value: "windowMaximizeButton"
}
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Override widget elements for maximized windows")
}

ListElement {
name: "Keep window above button"
value: "windowKeepAboveButton"
}
CheckBox {
id: overrideElementsMaximized

ListElement {
name: "Keep window below button"
value: "windowKeepBelowButton"
}
text: i18n("override")
}

ListElement {
name: "Shade window button"
value: "windowShadeButton"
}
WidgetElements {
id: widgetElementsMaximized

ListElement {
name: "Window title"
value: "windowTitle"
}
Kirigami.FormData.label: i18n("Elements:")
enabled: overrideElementsMaximized.checked
}

ListElement {
name: "Window Icon"
value: "windowIcon"
}
AddWidgetElement {
enabled: overrideElementsMaximized.checked

ListElement {
name: "Spacer"
value: "spacer"
onCurrentValueChanged: function () {
if (currentValue) {
widgetElementsMaximized.model.append({
"value": currentValue
});
currentIndex = 0;
}
}
}
Expand Down
41 changes: 37 additions & 4 deletions package/contents/ui/config/WidgetElements.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,49 @@ RowLayout {

property alias model: sortableItemsRow.model
property var iconSize: Kirigami.Units.iconSizes.medium
property var elements: []

Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false

Layout.fillWidth: true
Kirigami.FormData.label: i18n("Elements:")
Layout.preferredWidth: Kirigami.Units.gridUnit * 21
spacing: 0

Component.onCompleted: function () {
model.ignoreInsertEvent = true;
for (var i = 0; i < elements.length; i++) {
model.append({
"value": elements[i]
});
}
model.ignoreInsertEvent = false;
}

model: ListModel {
property bool ignoreInsertEvent: false

function updateConfigFromModel() {
elements = [];
for (var i = 0; i < count; i++) {
elements.push(get(i).value);
}
}

onRowsMoved: updateConfigFromModel()
onRowsRemoved: updateConfigFromModel()
onRowsInserted: ignoreInsertEvent || updateConfigFromModel()
}

Rectangle {
z: 1
border.color: Kirigami.Theme.textColor
color: Kirigami.Theme.activeBackgroundColor
border.color: Kirigami.Theme.disabledTextColor
color: Kirigami.Theme.backgroundColor
height: Kirigami.Units.iconSizes.medium
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
Layout.margins: 1
radius: 2

SortableItemsRow {
id: sortableItemsRow
Expand Down Expand Up @@ -126,11 +157,13 @@ RowLayout {
id: elementRemoveArea

z: 0
border.color: Kirigami.Theme.textColor
border.color: Kirigami.Theme.disabledTextColor
color: Kirigami.Theme.negativeBackgroundColor
height: Kirigami.Units.iconSizes.medium
width: Kirigami.Units.iconSizes.medium
Layout.alignment: Qt.AlignLeft
Layout.margins: 1
radius: 2

Kirigami.Icon {
anchors.fill: parent
Expand Down
32 changes: 29 additions & 3 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ PlasmoidItem {
id: widgetElementLoader

required property var modelData
property bool repeaterVisible: false

onLoaded: function () {
Utils.copyLayoutConstraint(item, widgetElementLoader);
Expand All @@ -123,7 +124,7 @@ PlasmoidItem {

Binding {
when: status === Loader.Ready
widgetElementLoader.visible: plasmoid.configuration.widgetElementsDisabledMode === WidgetElement.DisabledMode.Hide ? item.enabled : true
widgetElementLoader.visible: repeaterVisible && (plasmoid.configuration.widgetElementsDisabledMode === WidgetElement.DisabledMode.Hide ? item.enabled : true)
}

Binding {
Expand Down Expand Up @@ -323,8 +324,7 @@ PlasmoidItem {
}

Repeater {
id: titleBarList

id: widgetElementsRepeater
property var elements: plasmoid.configuration.widgetElements

onElementsChanged: function () {
Expand All @@ -336,6 +336,32 @@ PlasmoidItem {
}
model: []
delegate: widgetElementLoaderDelegate
visible: !plasmoid.configuration.overrideElementsMaximized || !tasksModel.activeWindow.maximized
onItemAdded: function (index, item) {
item.repeaterVisible = Qt.binding(function () {
return visible;
});
}
}

Repeater {
property var elements: plasmoid.configuration.overrideElementsMaximized ? plasmoid.configuration.widgetElementsMaximized : []

onElementsChanged: function () {
let array = [];
for (var i = 0; i < elements.length; i++) {
array.push(Utils.widgetElementModelFromName(elements[i]));
}
model = array;
}
model: []
delegate: widgetElementLoaderDelegate
visible: !widgetElementsRepeater.visible
onItemAdded: function (index, item) {
item.repeaterVisible = Qt.binding(function () {
return visible;
});
}
}
}
}
2 changes: 1 addition & 1 deletion package/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Id": "com.github.antroids.application-title-bar",
"Name": "Application Title Bar",
"License": "GPL-3.0+",
"Version": "0.4.6",
"Version": "0.5.0",
"Website": "https://github.com/antroids/application-title-bar",
"FormFactors": [
"desktop"
Expand Down

0 comments on commit f9a5373

Please sign in to comment.