From 6d78f47d310f69242a88c4e279b49a659d378066 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 17 Oct 2026 11:13:43 +0200 Subject: qtmaildir settings: a colour picker for colour fields An account's chip colour and each tag colour were #rrggbb typed by hand. A swatch beside each now shows the colour and opens Qt's own ColorDialog, which writes the choice back as #rrggbb; typing still works. The add-tag row has one too, filling its field. Setting.qml gains a colour flag rather than a second component, since a colour key is an ordinary text key with a swatch. Co-Authored-By: Claude Opus 5.5 --- desktop/modules/qtmaildir/ColourPick.qml | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 desktop/modules/qtmaildir/ColourPick.qml (limited to 'desktop/modules/qtmaildir/ColourPick.qml') diff --git a/desktop/modules/qtmaildir/ColourPick.qml b/desktop/modules/qtmaildir/ColourPick.qml new file mode 100644 index 0000000..96933a9 --- /dev/null +++ b/desktop/modules/qtmaildir/ColourPick.qml @@ -0,0 +1,53 @@ +// Copyright (C) 2026 Danilo M. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import QtQuick +import QtQuick.Dialogs +import "../.." + +// A swatch of the current colour that opens the platform's colour dialog. +// picked carries the choice as #rrggbb, the form qtmaildir.conf uses. +Rectangle { + id: pick + property string colour: "" + signal picked(string hex) + + width: 34; height: 34 + radius: 8 + color: /^#[0-9a-fA-F]{6}$/.test(pick.colour) ? pick.colour : Theme.surface + border.width: 1 + border.color: area.containsMouse ? Theme.accent : Qt.alpha(Theme.text, 0.2) + + Text { + anchors.centerIn: parent + visible: !/^#[0-9a-fA-F]{6}$/.test(pick.colour) + // nf-fa-eyedropper, present in Inconsolata Nerd Font. + text: "" + font { family: Theme.iconFamily; pixelSize: Theme.fontSize - 2 } + color: Theme.subtext + } + + MouseArea { + id: area + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: dialog.open() + } + + ColorDialog { + id: dialog + selectedColor: /^#[0-9a-fA-F]{6}$/.test(pick.colour) ? pick.colour : "#808080" + // toString() is #rrggbb for an opaque colour, and the dialog offers + // no alpha unless asked to; the slice is a guard all the same. + onAccepted: pick.picked(selectedColor.toString().slice(0, 7)) + } +} -- cgit v1.2.3