Add compilation to edit tag dialog
This commit is contained in:
@@ -71,19 +71,21 @@ ExtendedEditor::ExtendedEditor(QWidget *widget, int extra_right_padding, bool dr
|
||||
reset_button_->setFocusPolicy(Qt::NoFocus);
|
||||
reset_button_->hide();
|
||||
|
||||
widget->connect(clear_button_, SIGNAL(clicked()), widget, SLOT(clear()));
|
||||
widget->connect(clear_button_, SIGNAL(clicked()), widget, SLOT(setFocus()));
|
||||
if (qobject_cast<QLineEdit*>(widget) || qobject_cast<QPlainTextEdit*>(widget) || qobject_cast<QSpinBox*>(widget)) {
|
||||
widget->connect(clear_button_, SIGNAL(clicked()), widget, SLOT(clear()));
|
||||
}
|
||||
|
||||
UpdateButtonGeometry();
|
||||
|
||||
}
|
||||
|
||||
void ExtendedEditor::set_hint(const QString& hint) {
|
||||
void ExtendedEditor::set_hint(const QString &hint) {
|
||||
hint_ = hint;
|
||||
widget_->update();
|
||||
}
|
||||
|
||||
void ExtendedEditor::set_clear_button(bool visible) {
|
||||
void ExtendedEditor::set_clear_button(const bool visible) {
|
||||
has_clear_button_ = visible;
|
||||
clear_button_->setVisible(visible);
|
||||
UpdateButtonGeometry();
|
||||
@@ -93,7 +95,7 @@ bool ExtendedEditor::has_reset_button() const {
|
||||
return reset_button_->isVisible();
|
||||
}
|
||||
|
||||
void ExtendedEditor::set_reset_button(bool visible) {
|
||||
void ExtendedEditor::set_reset_button(const bool visible) {
|
||||
reset_button_->setVisible(visible);
|
||||
UpdateButtonGeometry();
|
||||
}
|
||||
@@ -161,7 +163,7 @@ LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent), ExtendedEditor(this) {
|
||||
connect(this, SIGNAL(textChanged(QString)), SLOT(text_changed(QString)));
|
||||
}
|
||||
|
||||
void LineEdit::text_changed(const QString& text) {
|
||||
void LineEdit::text_changed(const QString &text) {
|
||||
|
||||
if (text.isEmpty()) {
|
||||
// Consider empty string as LTR
|
||||
@@ -222,8 +224,26 @@ void SpinBox::resizeEvent(QResizeEvent *e) {
|
||||
Resize();
|
||||
}
|
||||
|
||||
CheckBox::CheckBox(QWidget *parent)
|
||||
: QCheckBox(parent), ExtendedEditor(this, 14, false)
|
||||
{
|
||||
connect(reset_button_, SIGNAL(clicked()), SIGNAL(Reset()));
|
||||
}
|
||||
|
||||
void CheckBox::paintEvent(QPaintEvent *e) {
|
||||
QCheckBox::paintEvent(e);
|
||||
Paint(this);
|
||||
}
|
||||
|
||||
void CheckBox::resizeEvent(QResizeEvent *e) {
|
||||
QCheckBox::resizeEvent(e);
|
||||
Resize();
|
||||
}
|
||||
|
||||
QString SpinBox::textFromValue(int val) const {
|
||||
|
||||
if (val <= 0 && !hint_.isEmpty())
|
||||
return "-";
|
||||
return QSpinBox::textFromValue(val);
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
|
||||
class QToolButton;
|
||||
class QPaintDevice;
|
||||
@@ -37,6 +38,7 @@ class QPaintEvent;
|
||||
class QResizeEvent;
|
||||
|
||||
class LineEditInterface {
|
||||
|
||||
public:
|
||||
explicit LineEditInterface(QWidget *widget) : widget_(widget) {}
|
||||
|
||||
@@ -44,40 +46,43 @@ class LineEditInterface {
|
||||
|
||||
virtual ~LineEditInterface() {}
|
||||
|
||||
virtual void clear() { set_text(QString()); }
|
||||
virtual void set_enabled(const bool enabled) = 0;
|
||||
virtual void set_focus() = 0;
|
||||
virtual QString text() const = 0;
|
||||
virtual void set_text(const QString& text) = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
virtual QVariant value() const = 0;
|
||||
virtual void set_value(const QVariant &value) = 0;
|
||||
|
||||
virtual QString hint() const = 0;
|
||||
virtual void set_hint(const QString& hint) = 0;
|
||||
virtual void set_hint(const QString &hint) = 0;
|
||||
virtual void clear_hint() = 0;
|
||||
|
||||
virtual void set_enabled(bool enabled) = 0;
|
||||
virtual void set_partially() {}
|
||||
|
||||
protected:
|
||||
QWidget *widget_;
|
||||
};
|
||||
|
||||
class ExtendedEditor : public LineEditInterface {
|
||||
|
||||
public:
|
||||
explicit ExtendedEditor(QWidget *widget, int extra_right_padding = 0, bool draw_hint = true);
|
||||
~ExtendedEditor() override {}
|
||||
|
||||
virtual bool is_empty() const { return text().isEmpty(); }
|
||||
virtual bool is_empty() const { return value().toString().isEmpty(); }
|
||||
|
||||
QString hint() const override { return hint_; }
|
||||
void set_hint(const QString& hint) override;
|
||||
void set_hint(const QString &hint) override;
|
||||
void clear_hint() override { set_hint(QString()); }
|
||||
|
||||
bool has_clear_button() const { return has_clear_button_; }
|
||||
void set_clear_button(bool visible);
|
||||
void set_clear_button(const bool visible);
|
||||
|
||||
bool has_reset_button() const;
|
||||
void set_reset_button(bool visible);
|
||||
void set_reset_button(const bool visible);
|
||||
|
||||
qreal font_point_size() const { return font_point_size_; }
|
||||
void set_font_point_size(qreal size) { font_point_size_ = size; }
|
||||
void set_font_point_size(const qreal size) { font_point_size_ = size; }
|
||||
|
||||
protected:
|
||||
void Paint(QPaintDevice *device);
|
||||
@@ -111,10 +116,14 @@ class LineEdit : public QLineEdit, public ExtendedEditor {
|
||||
explicit LineEdit(QWidget *parent = nullptr);
|
||||
|
||||
// ExtendedEditor
|
||||
void set_focus() override { QLineEdit::setFocus(); }
|
||||
QString text() const override { return QLineEdit::text(); }
|
||||
void set_text(const QString& text) override { QLineEdit::setText(text); }
|
||||
void set_enabled(bool enabled) override { QLineEdit::setEnabled(enabled); }
|
||||
void set_focus() override { QLineEdit::setFocus(); }
|
||||
|
||||
QVariant value() const override { return QLineEdit::text(); }
|
||||
void set_value(const QVariant &value) override { QLineEdit::setText(value.toString()); }
|
||||
|
||||
public slots:
|
||||
void clear() override { QLineEdit::clear(); }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
@@ -125,7 +134,7 @@ class LineEdit : public QLineEdit, public ExtendedEditor {
|
||||
void set_rtl(bool rtl) { is_rtl_ = rtl; }
|
||||
|
||||
private slots:
|
||||
void text_changed(const QString& text);
|
||||
void text_changed(const QString &text);
|
||||
|
||||
signals:
|
||||
void Reset();
|
||||
@@ -141,10 +150,14 @@ class TextEdit : public QPlainTextEdit, public ExtendedEditor {
|
||||
explicit TextEdit(QWidget *parent = nullptr);
|
||||
|
||||
// ExtendedEditor
|
||||
void set_focus() override { QPlainTextEdit::setFocus(); }
|
||||
QString text() const override { return QPlainTextEdit::toPlainText(); }
|
||||
void set_text(const QString& text) override { QPlainTextEdit::setPlainText(text); }
|
||||
void set_enabled(bool enabled) override { QPlainTextEdit::setEnabled(enabled); }
|
||||
void set_focus() override { QPlainTextEdit::setFocus(); }
|
||||
|
||||
QVariant value() const override { return QPlainTextEdit::toPlainText(); }
|
||||
void set_value(const QVariant &value) override { QPlainTextEdit::setPlainText(value.toString()); }
|
||||
|
||||
public slots:
|
||||
void clear() override { QPlainTextEdit::clear(); }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
@@ -167,11 +180,44 @@ class SpinBox : public QSpinBox, public ExtendedEditor {
|
||||
QString textFromValue(int val) const override;
|
||||
|
||||
// ExtendedEditor
|
||||
bool is_empty() const override { return text().isEmpty() || text() == "0"; }
|
||||
void set_focus() override { QSpinBox::setFocus(); }
|
||||
QString text() const override { return QSpinBox::text(); }
|
||||
void set_text(const QString& text) override { QSpinBox::setValue(text.toInt()); }
|
||||
void set_enabled(bool enabled) override { QSpinBox::setEnabled(enabled); }
|
||||
void set_focus() override { QSpinBox::setFocus(); }
|
||||
|
||||
QVariant value() const override { return QSpinBox::value(); }
|
||||
void set_value(const QVariant &value) override { QSpinBox::setValue(value.toInt()); }
|
||||
bool is_empty() const override { return text().isEmpty() || text() == "0"; }
|
||||
|
||||
public slots:
|
||||
void clear() override { QSpinBox::clear(); }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
|
||||
signals:
|
||||
void Reset();
|
||||
};
|
||||
|
||||
class CheckBox : public QCheckBox, public ExtendedEditor {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString hint READ hint WRITE set_hint)
|
||||
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button)
|
||||
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button)
|
||||
|
||||
public:
|
||||
explicit CheckBox(QWidget *parent = nullptr);
|
||||
|
||||
// ExtendedEditor
|
||||
void set_enabled(bool enabled) override { QCheckBox::setEnabled(enabled); }
|
||||
void set_focus() override { QCheckBox::setFocus(); }
|
||||
|
||||
bool is_empty() const override { return text().isEmpty() || text() == "0"; }
|
||||
QVariant value() const override { return QCheckBox::isChecked(); }
|
||||
void set_value(const QVariant &value) override { QCheckBox::setCheckState(value.toBool() ? Qt::Checked : Qt::Unchecked); }
|
||||
void set_partially() override { QCheckBox::setCheckState(Qt::PartiallyChecked); }
|
||||
|
||||
public slots:
|
||||
void clear() override { QCheckBox::setChecked(false); }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
|
||||
Reference in New Issue
Block a user