Skip to content

Commit

Permalink
add check all box
Browse files Browse the repository at this point in the history
  • Loading branch information
moonshadow565 committed Aug 27, 2022
1 parent d425681 commit 3636f74
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/qml/CSLOLModsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ ColumnLayout {

property string search: ""

property int checkedAll: Qt.PartiallyChecked

signal modRemoved(string fileName)

signal modExport(string fileName)
Expand Down Expand Up @@ -145,6 +147,7 @@ ColumnLayout {
let obj = model.get(i)
model.setProperty(i, "Enabled", mods[obj["FileName"]] === true)
}
checkedUpdate()
}

function updateModInfo_model(fileName, info, model) {
Expand Down Expand Up @@ -176,6 +179,52 @@ ColumnLayout {
return -1;
}

function checkAll(doEnable) {
for(let i = 0; i < cslolModsViewModel.count; i++) {
let obj = cslolModsViewModel.get(i)
if (obj["Enabled"] !== doEnable) {
cslolModsViewModel.setProperty(i, "Enabled", doEnable)
}
}
for(let j = 0; j < cslolModsViewModel2.count; j++) {
let obj = cslolModsViewModel2.get(j)
if (obj["Enabled"] !== doEnable) {
cslolModsViewModel2.setProperty(i, "Enabled", doEnable)
}
}
}

function checkedUpdate() {
let hasEnabled = false
let hasDisabled = false
for(let i = 0; i < cslolModsViewModel.count; i++) {
let obj = cslolModsViewModel.get(i)
if (obj["Enabled"]) {
hasEnabled = true;
} else {
hasDisabled = true;
}
}
for(let j = 0; j < cslolModsViewModel2.count; j++) {
let obj = cslolModsViewModel2.get(j)
if (obj["Enabled"]) {
hasEnabled = true;
} else {
hasDisabled = true;
}
}
let newState = Qt.PartiallyChecked
if (hasEnabled && !hasDisabled) {
newState = Qt.Checked;
}
if (!hasEnabled && hasDisabled) {
newState = Qt.Unchecked;
}
if (newState != cslolModsView.checkedAll) {
cslolModsView.checkedAll = newState;
}
}

ListModel {
id: cslolModsViewModel
}
Expand Down Expand Up @@ -240,6 +289,7 @@ ColumnLayout {
onCheckedChanged: {
if (checked != installed) {
cslolModsViewModel.setProperty(index, "Enabled", checked)
cslolModsView.checkedUpdate()
}
}
ToolTip {
Expand Down
15 changes: 15 additions & 0 deletions src/qml/CSLOLToolBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ ToolBar {
property alias profilesCurrentIndex: profilesComboBox.currentIndex
property alias profilesCurrentName: profilesComboBox.currentText
property alias menuButtonHeight: mainMenuButton.height
property alias enableAllState: enableAllCheckbox.checkState
property alias enableAllChecked: enableAllCheckbox.checked


signal openSideMenu()
signal saveProfileAndRun(bool run)
Expand Down Expand Up @@ -52,6 +55,18 @@ ToolBar {
Qt.openUrlExternally("https://github.com/morilli")
}
}
CheckBox {
id: enableAllCheckbox
tristate: true
checkState: Qt.PartiallyChecked
nextCheckState: function() {
return checkState === Qt.Checked ? Qt.Unchecked : Qt.Checked
}
ToolTip {
text: qsTr("Enable all mods")
visible: parent.hovered
}
}
ToolButton {
text: qsTr("Save")
onClicked: cslolToolBar.saveProfileAndRun(false)
Expand Down
11 changes: 11 additions & 0 deletions src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ ApplicationWindow {
onRemoveProfile: function() {
cslolTools.deleteProfile(cslolToolBar.profilesCurrentName)
}

onEnableAllCheckedChanged: {
if (cslolToolBar.enableAllState !== Qt.PartiallyChecked) {
cslolModsView.checkAll(enableAllChecked)
}
}
}

CSLOLDialogSettings {
Expand Down Expand Up @@ -166,6 +172,11 @@ ApplicationWindow {
cslolDialogNewMod.clear()
}
}
onCheckedAllChanged: {
if (cslolToolBar.enableAllState !== checkedAll) {
cslolToolBar.enableAllState = checkedAll
}
}
}

footer: CSLOLStatusBar {
Expand Down

0 comments on commit 3636f74

Please sign in to comment.