Warning, /office/klevernotes/src/contents/ui/dialogs/tableMakerDialog/TableMakerDialog.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2023 Louis Schul <schul9louis@gmail.com>
0003
0004 import QtQuick 2.15
0005 import QtQuick.Layouts 1.15
0006 import QtQuick.Templates 2.15
0007 import QtQuick.Controls 2.15 as Controls
0008
0009 import org.kde.kirigami 2.19 as Kirigami
0010 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0011
0012 Kirigami.Dialog {
0013 id: scrollableDialog
0014
0015 property int rowCount: 1
0016 property int columnCount: 1
0017 property string alignment: optionsColumn.isExpended ? alignmentBox.currentValue : "left"
0018 property int hoveredRow: 0
0019 property int hoveredColumn: 0
0020 property bool isHovered: false
0021
0022 title: i18nc("@title:dialog, table => an html table", "Table creation")
0023
0024 width: Kirigami.Units.gridUnit * 15
0025 padding: 0
0026
0027 onRowCountChanged: if (rowCount !== rowSpin.value) {
0028 rowSpin.value = rowCount
0029 }
0030 onColumnCountChanged: if (columnCount !== columnSpin.value) {
0031 columnSpin.value = columnCount
0032 }
0033
0034 ColumnLayout {
0035 id: itemLayout
0036
0037 property int generalTiming: Kirigami.Units.longDuration
0038
0039 height: Kirigami.Units.gridUnit * 21
0040 spacing: 0
0041
0042 Controls.Label {
0043 text: i18nc("@label, display the final size of the table %1 is the number of row and %2 the number of column","Size: %1 x %2", rowCount, columnCount)
0044
0045 Layout.alignment: Qt.AlignTop
0046 Layout.preferredHeight: Kirigami.Units.gridUnit * 3
0047 Layout.leftMargin: Kirigami.Units.gridUnit
0048 Layout.rightMargin: Kirigami.Units.gridUnit
0049 }
0050
0051 GridLayout {
0052 id: mainHolder
0053
0054 rows: 10
0055 columns: 5
0056 rowSpacing: 0
0057 columnSpacing: 0
0058
0059 Layout.preferredHeight: Kirigami.Units.gridUnit * 15
0060 Layout.alignment: Qt.AlignTop || Qt.AlignHCenter
0061 Layout.margins: 0
0062 Layout.leftMargin: Kirigami.Units.largeSpacing * 3
0063 Layout.rightMargin: Kirigami.Units.largeSpacing * 3
0064
0065 states: State {
0066 name: "invisible"
0067 when: optionsColumn.isExpended
0068
0069 PropertyChanges { target: mainHolder; Layout.preferredHeight: 0 }
0070 PropertyChanges { target: mainHolder; opacity: 0 }
0071 }
0072
0073 Behavior on Layout.preferredHeight {
0074 NumberAnimation { duration: itemLayout.generalTiming }
0075 }
0076 Behavior on opacity {
0077 NumberAnimation { duration: itemLayout.generalTiming - 20 }
0078 }
0079
0080 Repeater {
0081 model: mainHolder.rows * mainHolder.columns
0082
0083 delegate: ItemDelegate {
0084 id: box
0085
0086 readonly property int visualColumn: (index % mainHolder.columns) + 1
0087 readonly property int visualRow: ((index - visualColumn + 1) / mainHolder.columns) + 1
0088
0089 property bool insideSelectedBound: visualRow <= scrollableDialog.rowCount && visualColumn <= scrollableDialog.columnCount
0090
0091 property bool insideHoveredBound: scrollableDialog.isHovered
0092 ? (visualRow <= scrollableDialog.hoveredRow && visualColumn <= scrollableDialog.hoveredColumn)
0093 : false
0094
0095
0096 Layout.fillWidth: true
0097 Layout.fillHeight: true
0098
0099 focusPolicy: Qt.StrongFocus
0100 hoverEnabled: true
0101
0102 background: Rectangle {
0103 color: {
0104 let colorOpacity = 0.7;
0105 let selectedColor = Kirigami.Theme.textColor
0106
0107 if (box.pressed ||
0108 box.insideSelectedBound && box.insideHoveredBound ||
0109 !scrollableDialog.isHovered && box.insideSelectedBound
0110 ) {
0111 selectedColor = Kirigami.Theme.highlightColor
0112 colorOpacity = 0.7;
0113 } else if (box.insideHoveredBound) {
0114 selectedColor = Kirigami.Theme.highlightColor
0115 colorOpacity = 0.5;
0116 }
0117
0118 return Qt.rgba(selectedColor.r, selectedColor.g, selectedColor.b, colorOpacity)
0119 }
0120
0121 border.width: 1
0122 border.color: Kirigami.Theme.backgroundColor
0123
0124 Behavior on color {
0125 ColorAnimation { duration: Kirigami.Units.shortDuration }
0126 }
0127 }
0128
0129 onHoveredChanged: {
0130 scrollableDialog.isHovered = hovered
0131 if (hovered) {
0132 scrollableDialog.hoveredRow = visualRow
0133 scrollableDialog.hoveredColumn = visualColumn
0134 } else {
0135 scrollableDialog.hoveredRow = 0
0136 scrollableDialog.hoveredColumn = 0
0137 }
0138 }
0139 onClicked: {
0140 scrollableDialog.rowCount = visualRow
0141 scrollableDialog.columnCount = visualColumn
0142 }
0143 }
0144 }
0145 }
0146
0147 Kirigami.Separator {
0148 Layout.fillWidth: true
0149 Layout.topMargin: Kirigami.Units.smallSpacing
0150 }
0151
0152 UpDownButtonDelegate {
0153 id: optionButton
0154
0155 text: i18nc("@label:button", "More options")
0156 arrowDirection: optionsColumn.isExpended ? Qt.DownArrow : Qt.UpArrow
0157
0158 Layout.fillWidth: true
0159 Layout.preferredHeight: Kirigami.Units.gridUnit * 3
0160 Layout.alignment: optionsColumn.isExpended ? Qt.AlignTop : Qt.AlignBottom
0161 Layout.bottomMargin: optionsColumn.isExpended ? 0 : -Kirigami.Units.smallSpacing
0162
0163
0164 onClicked: {
0165 optionsColumn.isExpended = !optionsColumn.isExpended
0166
0167 if (scrollableDialog.rowCount > mainHolder.rows) scrollableDialog.rowCount = mainHolder.rows
0168 if (scrollableDialog.columnCount > mainHolder.columns) scrollableDialog.columnCount = mainHolder.columns
0169 }
0170 }
0171
0172 Kirigami.Separator {
0173 Layout.fillWidth: true
0174 Layout.bottomMargin: Kirigami.Units.smallSpacing
0175 visible: optionsColumn.isExpended
0176 }
0177
0178 Item {
0179 id: optionsColumn
0180
0181 property bool isExpended: false
0182
0183 Layout.fillWidth: true
0184 Layout.preferredHeight: 0
0185 Layout.alignment: Qt.AlignBottom
0186 opacity: 0
0187
0188 states: State {
0189 name: "visible"
0190 when: optionsColumn.isExpended
0191 PropertyChanges { target: optionsColumn; Layout.preferredHeight: Kirigami.Units.gridUnit * 15 }
0192 PropertyChanges { target: optionsColumn; opacity: 1 }
0193 }
0194
0195 Behavior on Layout.preferredHeight {
0196 NumberAnimation { duration: itemLayout.generalTiming }
0197 }
0198 Behavior on opacity {
0199 NumberAnimation { duration: itemLayout.generalTiming - 20}
0200 }
0201
0202 ColumnLayout {
0203 anchors.fill: parent
0204 spacing: Kirigami.Units.smallSpacing
0205
0206 FormCard.FormSpinBoxDelegate {
0207 id: rowSpin
0208
0209 label: i18nc("@label:spinbox, name, 'a row'", "Row")
0210 from: 1
0211
0212 Layout.fillWidth: true
0213 Layout.preferredHeight: parent.height / 3
0214
0215 onValueChanged: if (scrollableDialog.rowCount !== value) scrollableDialog.rowCount = value
0216 }
0217
0218 FormCard.FormSpinBoxDelegate {
0219 id: columnSpin
0220
0221 label: i18nc("@label:spinbox, name, 'a column'", "Column")
0222 from: 1
0223
0224 Layout.fillWidth: true
0225 Layout.preferredHeight: parent.height / 3
0226
0227 onValueChanged: if (scrollableDialog.columnCount !== value) scrollableDialog.columnCount = value
0228 }
0229
0230 FormCard.FormComboBoxDelegate {
0231 id: alignmentBox
0232
0233 text: i18nc("@label:combobox", "Alignment :")
0234
0235 textRole: "text"
0236 valueRole: "value"
0237 model: [
0238 { text: i18nc("@entry:combobox, alignment name", "Left"), value: "left" },
0239 { text: i18nc("@entry:combobox, alignment name", "Center"), value: "center" },
0240 { text: i18nc("@entry:combobox, alignment name", "Right"), value: "right" }
0241 ]
0242 currentIndex: 0
0243
0244 Layout.fillWidth: true
0245 Layout.preferredHeight: parent.height / 3
0246 }
0247 }
0248 }
0249 }
0250
0251 standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
0252
0253 onClosed: {
0254 rowCount = 1
0255 columnCount = 1
0256 optionsColumn.isExpended = false
0257 }
0258 }