EditTagDialog: Make reset feedback work by calling

`set_reset_button()` in `UpdateModifiedField()` and catering for
  non-text in `IsValueModified()` (-1 original being same as 0);
  use new `ExtendedEditor::set_font()`;
  connect reset for "rating".
  Make "comment" `tabChangesFocus` to keep tab chain.
ExtendedEditor: New `set_font()` to get emboldened font to work and
  make reset feedback work for `CheckBox` and `RatingBox` by
  overriding `Resize()`.
RatingWidget: Allow tabbed focus and implement keyboard input.
This commit is contained in:
gitlost
2025-05-19 22:27:25 +01:00
committed by Jonas Kvinge
parent a86ba4dffc
commit 340bc21537
6 changed files with 157 additions and 22 deletions

View File

@@ -37,12 +37,18 @@
#include <QFlags>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QGuiApplication>
#include "core/iconloader.h"
#include "lineedit.h"
using namespace Qt::Literals::StringLiterals;
namespace {
constexpr int kClearIconSize = 16;
constexpr int kResetIconSize = 16;
} // namespace
ExtendedEditor::ExtendedEditor(QWidget *widget, int extra_right_padding, bool draw_hint)
: LineEditInterface(widget),
has_clear_button_(true),
@@ -54,7 +60,7 @@ ExtendedEditor::ExtendedEditor(QWidget *widget, int extra_right_padding, bool dr
is_rtl_(false) {
clear_button_->setIcon(IconLoader::Load(u"edit-clear-locationbar-ltr"_s));
clear_button_->setIconSize(QSize(16, 16));
clear_button_->setIconSize(QSize(kClearIconSize, kClearIconSize));
clear_button_->setCursor(Qt::ArrowCursor);
clear_button_->setStyleSheet(u"QToolButton { border: none; padding: 0px; }"_s);
clear_button_->setToolTip(QWidget::tr("Clear"));
@@ -64,7 +70,7 @@ ExtendedEditor::ExtendedEditor(QWidget *widget, int extra_right_padding, bool dr
opt.initFrom(widget);
reset_button_->setIcon(widget->style()->standardIcon(QStyle::SP_DialogResetButton, &opt, widget));
reset_button_->setIconSize(QSize(16, 16));
reset_button_->setIconSize(QSize(kResetIconSize, kResetIconSize));
reset_button_->setCursor(Qt::ArrowCursor);
reset_button_->setStyleSheet(u"QToolButton { border: none; padding: 0px; }"_s);
reset_button_->setToolTip(QWidget::tr("Reset"));
@@ -220,9 +226,21 @@ SpinBox::SpinBox(QWidget *parent)
: QSpinBox(parent),
ExtendedEditor(this, 14, false) {
if (QGuiApplication::isRightToLeft()) {
extra_right_padding_ = 0; // Up/down arrows on left
}
QObject::connect(reset_button_, &QToolButton::clicked, this, &SpinBox::Reset);
}
QString SpinBox::textFromValue(int val) const {
if (val <= 0 && !hint_.isEmpty()) {
return u"-"_s;
}
return QSpinBox::textFromValue(val);
}
void SpinBox::paintEvent(QPaintEvent *e) {
QSpinBox::paintEvent(e);
Paint(this);
@@ -234,8 +252,10 @@ void SpinBox::resizeEvent(QResizeEvent *e) {
}
CheckBox::CheckBox(QWidget *parent)
: QCheckBox(parent), ExtendedEditor(this, 14, false) {
: QCheckBox(parent), ExtendedEditor(this, 4, false) {
has_clear_button_ = false;
is_rtl_ = QGuiApplication::isRightToLeft();
QObject::connect(reset_button_, &QToolButton::clicked, this, &CheckBox::Reset);
}
@@ -250,20 +270,46 @@ void CheckBox::resizeEvent(QResizeEvent *e) {
Resize();
}
QString SpinBox::textFromValue(int val) const {
void CheckBox::Resize() {
if (val <= 0 && !hint_.isEmpty()) {
return u"-"_s;
const QSize sz = widget_->sizeHint();
const int frame_width = widget_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
const int y = (rect().height() - sz.height()) / 2 - frame_width; // Less frame width as outside
if (!is_rtl_) {
reset_button_->move(frame_width + sz.width() + extra_right_padding_, y); // Using `extra_right_padding_` as how far to right of checkbox
}
else {
reset_button_->move(rect().width() - (frame_width + sz.width() + kResetIconSize + extra_right_padding_), y);
}
return QSpinBox::textFromValue(val);
}
RatingBox::RatingBox(QWidget *parent)
: RatingWidget(parent),
ExtendedEditor(this) {
ExtendedEditor(this, 6) {
clear_button_->hide();
reset_button_->hide();
has_clear_button_ = false;
QObject::connect(reset_button_, &QToolButton::clicked, this, &RatingBox::Reset);
}
void RatingBox::paintEvent(QPaintEvent *e) {
RatingWidget::paintEvent(e);
Paint(this);
}
void RatingBox::resizeEvent(QResizeEvent *e) {
RatingWidget::resizeEvent(e);
Resize();
}
void RatingBox::Resize() {
const QSize sz = widget_->sizeHint();
const int frame_width = widget_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
const int y = (rect().height() - sz.height()) / 2 + frame_width; // Plus frame width as inside
reset_button_->move(frame_width + rect().width() - (kResetIconSize + extra_right_padding_), y);
}