Warning, /graphics/spectacle/src/Gui/AnnotationOptionsToolBarContents.qml is written in an unsupported language. File is not indexed.
0001 /* SPDX-FileCopyrightText: 2022 Noah Davis <noahadvs@gmail.com> 0002 * SPDX-License-Identifier: LGPL-2.0-or-later 0003 */ 0004 0005 import QtQuick 0006 import QtQuick.Controls as QQC 0007 import QtQuick.Templates as T 0008 import org.kde.kirigami as Kirigami 0009 import org.kde.spectacle.private 0010 import "Annotations" 0011 0012 Row { 0013 id: root 0014 readonly property bool useSelectionOptions: AnnotationDocument.tool.type === AnnotationTool.SelectTool || (AnnotationDocument.tool.type === AnnotationTool.TextTool && AnnotationDocument.selectedItem.options & AnnotationTool.TextOption) 0015 property int displayMode: QQC.AbstractButton.TextBesideIcon 0016 property int focusPolicy: Qt.StrongFocus 0017 readonly property bool mirrored: effectiveLayoutDirection === Qt.RightToLeft 0018 0019 clip: childrenRect.width > width || childrenRect.height > height 0020 spacing: Kirigami.Units.mediumSpacing 0021 0022 Timer { 0023 id: commitChangesTimer 0024 interval: 250 0025 onTriggered: AnnotationDocument.selectedItem.commitChanges() 0026 } 0027 0028 Connections { 0029 target: AnnotationDocument 0030 function onSelectedItemWrapperChanged() { 0031 commitChangesTimer.stop() 0032 } 0033 } 0034 0035 component ToolButton: QQC.ToolButton { 0036 implicitHeight: QmlUtils.iconTextButtonHeight 0037 width: display === QQC.ToolButton.IconOnly ? height : implicitWidth 0038 focusPolicy: root.focusPolicy 0039 display: root.displayMode 0040 QQC.ToolTip.text: text 0041 QQC.ToolTip.visible: (hovered || pressed) && display === QQC.ToolButton.IconOnly 0042 QQC.ToolTip.delay: Kirigami.Units.toolTipDelay 0043 } 0044 0045 Loader { // stroke 0046 id: strokeLoader 0047 anchors.verticalCenter: parent.verticalCenter 0048 visible: active 0049 active: useSelectionOptions ? 0050 AnnotationDocument.selectedItem.options & AnnotationTool.StrokeOption 0051 : AnnotationDocument.tool.options & AnnotationTool.StrokeOption 0052 sourceComponent: Row { 0053 spacing: root.spacing 0054 0055 QQC.CheckBox { 0056 anchors.verticalCenter: parent.verticalCenter 0057 text: i18n("Stroke:") 0058 checked: colorRect.color.a > 0 0059 onToggled: if (root.useSelectionOptions) { 0060 AnnotationDocument.selectedItem.strokeColor.a = checked 0061 } else { 0062 AnnotationDocument.tool.strokeColor.a = checked 0063 } 0064 } 0065 0066 QQC.SpinBox { 0067 id: spinBox 0068 function setStrokeWidth() { 0069 if (root.useSelectionOptions 0070 && AnnotationDocument.selectedItem.strokeWidth !== spinBox.value) { 0071 AnnotationDocument.selectedItem.strokeWidth = spinBox.value 0072 commitChangesTimer.restart() 0073 } else { 0074 AnnotationDocument.tool.strokeWidth = spinBox.value 0075 } 0076 } 0077 anchors.verticalCenter: parent.verticalCenter 0078 from: fillLoader.active ? 0 : 1 0079 to: 99 0080 stepSize: 1 0081 value: root.useSelectionOptions ? 0082 AnnotationDocument.selectedItem.strokeWidth 0083 : AnnotationDocument.tool.strokeWidth 0084 textFromValue: (value, locale) => { 0085 // we don't use the locale here because the px suffix 0086 // needs to be treated as a translatable string, which 0087 // doesn't take into account the locale passed in here. 0088 // but it's going to be the application locale 0089 // which ki18n uses so it doesn't matter that much 0090 // unless someone decides to set the locale for a specific 0091 // part of spectacle in the future. 0092 return i18ncp("px: pixels", "%1px", "%1px", Math.round(value)) 0093 } 0094 valueFromText: (text, locale) => { 0095 return Number.fromLocaleString(locale, text.replace(/\D/g,'')) 0096 } 0097 QQC.ToolTip.text: i18n("Stroke Width") 0098 QQC.ToolTip.visible: hovered 0099 QQC.ToolTip.delay: Kirigami.Units.toolTipDelay 0100 // not using onValueModified because of https://bugreports.qt.io/browse/QTBUG-91281 0101 onValueChanged: Qt.callLater(setStrokeWidth) 0102 Binding { 0103 target: spinBox.contentItem 0104 property: "horizontalAlignment" 0105 value: Text.AlignRight 0106 restoreMode: Binding.RestoreNone 0107 } 0108 } 0109 0110 ToolButton { 0111 anchors.verticalCenter: parent.verticalCenter 0112 display: QQC.ToolButton.IconOnly 0113 QQC.ToolTip.text: i18n("Stroke Color") 0114 Rectangle { // should we use some kind of image provider instead? 0115 id: colorRect 0116 anchors.centerIn: parent 0117 width: Kirigami.Units.gridUnit 0118 height: Kirigami.Units.gridUnit 0119 radius: height / 2 0120 color: root.useSelectionOptions ? 0121 AnnotationDocument.selectedItem.strokeColor 0122 : AnnotationDocument.tool.strokeColor 0123 border.color: Qt.rgba(parent.palette.windowText.r, 0124 parent.palette.windowText.g, 0125 parent.palette.windowText.b, 0.5) 0126 border.width: 1 0127 } 0128 onClicked: { 0129 contextWindow.showColorDialog(AnnotationTool.StrokeOption) 0130 } 0131 } 0132 } 0133 } 0134 0135 QQC.ToolSeparator { 0136 anchors.verticalCenter: parent.verticalCenter 0137 visible: strokeLoader.visible && fillLoader.visible 0138 height: QmlUtils.iconTextButtonHeight 0139 } 0140 0141 Loader { // fill 0142 id: fillLoader 0143 anchors.verticalCenter: parent.verticalCenter 0144 visible: active 0145 active: useSelectionOptions ? 0146 AnnotationDocument.selectedItem.options & AnnotationTool.FillOption 0147 : AnnotationDocument.tool.options & AnnotationTool.FillOption 0148 sourceComponent: Row { 0149 spacing: root.spacing 0150 0151 QQC.CheckBox { 0152 anchors.verticalCenter: parent.verticalCenter 0153 text: i18n("Fill:") 0154 checked: colorRect.color.a > 0 0155 onToggled: if (root.useSelectionOptions) { 0156 AnnotationDocument.selectedItem.fillColor.a = checked 0157 } else { 0158 AnnotationDocument.tool.fillColor.a = checked 0159 } 0160 } 0161 0162 ToolButton { 0163 anchors.verticalCenter: parent.verticalCenter 0164 display: QQC.ToolButton.IconOnly 0165 QQC.ToolTip.text: i18n("Fill Color") 0166 Rectangle { 0167 id: colorRect 0168 anchors.centerIn: parent 0169 width: Kirigami.Units.gridUnit 0170 height: Kirigami.Units.gridUnit 0171 radius: height / 2 0172 color: root.useSelectionOptions ? 0173 AnnotationDocument.selectedItem.fillColor 0174 : AnnotationDocument.tool.fillColor 0175 border.color: Qt.rgba(parent.palette.windowText.r, 0176 parent.palette.windowText.g, 0177 parent.palette.windowText.b, 0.5) 0178 border.width: 1 0179 } 0180 onClicked: { 0181 contextWindow.showColorDialog(AnnotationTool.FillOption) 0182 } 0183 } 0184 } 0185 } 0186 0187 QQC.ToolSeparator { 0188 anchors.verticalCenter: parent.verticalCenter 0189 visible: fillLoader.visible && fontLoader.visible 0190 height: QmlUtils.iconTextButtonHeight 0191 } 0192 0193 Loader { // font 0194 id: fontLoader 0195 anchors.verticalCenter: parent.verticalCenter 0196 visible: active 0197 active: useSelectionOptions ? 0198 AnnotationDocument.selectedItem.options & AnnotationTool.FontOption 0199 : AnnotationDocument.tool.options & AnnotationTool.FontOption 0200 sourceComponent: Row { 0201 spacing: root.spacing 0202 0203 QQC.Label { 0204 leftPadding: root.mirrored ? 0 : parent.spacing 0205 rightPadding: root.mirrored ? parent.spacing : 0 0206 width: contextWindow.dprRound(implicitWidth) 0207 anchors.verticalCenter: parent.verticalCenter 0208 text: i18n("Font:") 0209 } 0210 0211 ToolButton { 0212 anchors.verticalCenter: parent.verticalCenter 0213 implicitWidth: contextWindow.dprRound(implicitContentWidth) 0214 display: QQC.ToolButton.TextOnly 0215 contentItem: QQC.Label { 0216 readonly property font currentFont: root.useSelectionOptions ? 0217 AnnotationDocument.selectedItem.font 0218 : AnnotationDocument.tool.font 0219 leftPadding: Kirigami.Units.mediumSpacing 0220 rightPadding: leftPadding 0221 font.family: currentFont.family 0222 font.styleName: currentFont.styleName 0223 text: font.styleName !== "" ? 0224 i18ncp("%2 font family, %3 font style name, %1 font point size", "%2 %3 %1pt", "%2 %3 %1pts", currentFont.pointSize, font.family, font.styleName) : 0225 i18ncp("%2 font family %1 font point size", "%2 %1pt", "%2 %1pts", currentFont.pointSize, font.family) 0226 elide: Text.ElideNone 0227 wrapMode: Text.NoWrap 0228 horizontalAlignment: Text.AlignHCenter 0229 verticalAlignment: Text.AlignVCenter 0230 } 0231 onClicked: contextWindow.showFontDialog() 0232 } 0233 0234 ToolButton { 0235 anchors.verticalCenter: parent.verticalCenter 0236 display: QQC.ToolButton.IconOnly 0237 QQC.ToolTip.text: i18n("Font Color") 0238 Rectangle { 0239 id: colorRect 0240 anchors.centerIn: parent 0241 width: Kirigami.Units.gridUnit 0242 height: Kirigami.Units.gridUnit 0243 radius: height / 2 0244 color: root.useSelectionOptions ? 0245 AnnotationDocument.selectedItem.fontColor 0246 : AnnotationDocument.tool.fontColor 0247 border.color: Qt.rgba(parent.palette.windowText.r, 0248 parent.palette.windowText.g, 0249 parent.palette.windowText.b, 0.5) 0250 border.width: 1 0251 } 0252 onClicked: { 0253 contextWindow.showColorDialog(AnnotationTool.FontOption) 0254 } 0255 } 0256 } 0257 } 0258 0259 QQC.ToolSeparator { 0260 anchors.verticalCenter: parent.verticalCenter 0261 visible: fontLoader.visible && numberLoader.visible 0262 height: QmlUtils.iconTextButtonHeight 0263 } 0264 0265 Loader { // stroke 0266 id: numberLoader 0267 anchors.verticalCenter: parent.verticalCenter 0268 visible: active 0269 active: useSelectionOptions ? 0270 AnnotationDocument.selectedItem.options & AnnotationTool.NumberOption 0271 : AnnotationDocument.tool.options & AnnotationTool.NumberOption 0272 sourceComponent: Row { 0273 spacing: root.spacing 0274 0275 QQC.Label { 0276 leftPadding: root.mirrored ? 0 : parent.spacing 0277 rightPadding: root.mirrored ? parent.spacing : 0 0278 width: contextWindow.dprRound(implicitWidth) 0279 anchors.verticalCenter: parent.verticalCenter 0280 text: i18n("Number:") 0281 } 0282 0283 QQC.SpinBox { 0284 id: spinBox 0285 readonly property int number: root.useSelectionOptions ? 0286 AnnotationDocument.selectedItem.number : AnnotationDocument.tool.number 0287 anchors.verticalCenter: parent.verticalCenter 0288 function setNumber() { 0289 if (root.useSelectionOptions 0290 && AnnotationDocument.selectedItem.number !== spinBox.value) { 0291 AnnotationDocument.selectedItem.number = spinBox.value 0292 commitChangesTimer.restart() 0293 } else { 0294 AnnotationDocument.tool.number = spinBox.value 0295 } 0296 } 0297 from: -99 0298 to: Math.max(999, number + 1) 0299 stepSize: 1 0300 value: number 0301 QQC.ToolTip.text: i18n("Number for number annotations") 0302 QQC.ToolTip.visible: hovered 0303 QQC.ToolTip.delay: Kirigami.Units.toolTipDelay 0304 // not using onValueModified because of https://bugreports.qt.io/browse/QTBUG-91281 0305 onValueChanged: Qt.callLater(setNumber) 0306 Binding { 0307 target: spinBox.contentItem 0308 property: "horizontalAlignment" 0309 value: Text.AlignRight 0310 restoreMode: Binding.RestoreNone 0311 } 0312 } 0313 } 0314 } 0315 0316 QQC.ToolSeparator { 0317 anchors.verticalCenter: parent.verticalCenter 0318 visible: shadowCheckBox.visible 0319 height: QmlUtils.iconTextButtonHeight 0320 } 0321 0322 QQC.CheckBox { 0323 id: shadowCheckBox 0324 anchors.verticalCenter: parent.verticalCenter 0325 visible: root.useSelectionOptions ? 0326 AnnotationDocument.selectedItem.options & AnnotationTool.ShadowOption 0327 : AnnotationDocument.tool.options & AnnotationTool.ShadowOption 0328 text: i18n("Shadow") 0329 checked: { 0330 if (AnnotationDocument.tool.type === AnnotationTool.TextTool && AnnotationDocument.selectedItem.options & AnnotationTool.TextOption) { 0331 return AnnotationDocument.tool.shadow; 0332 } else if (root.useSelectionOptions) { 0333 return AnnotationDocument.selectedItem.shadow; 0334 } else { 0335 return AnnotationDocument.tool.shadow; 0336 } 0337 } 0338 onToggled: { 0339 let changed = false 0340 if (AnnotationDocument.tool.type === AnnotationTool.TextTool && AnnotationDocument.selectedItem.options & AnnotationTool.TextOption) { 0341 changed = AnnotationDocument.selectedItem.shadow !== checked 0342 AnnotationDocument.selectedItem.shadow = checked; 0343 AnnotationDocument.tool.shadow = checked; 0344 } else if (root.useSelectionOptions) { 0345 changed = AnnotationDocument.selectedItem.shadow !== checked 0346 AnnotationDocument.selectedItem.shadow = checked; 0347 } else { 0348 AnnotationDocument.tool.shadow = checked; 0349 } 0350 if (changed) { 0351 commitChangesTimer.restart(); 0352 } 0353 } 0354 } 0355 }