2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LINEEDIT_H
|
|
|
|
#define LINEEDIT_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QString>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QSpinBox>
|
2020-09-23 00:52:41 +02:00
|
|
|
#include <QCheckBox>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-10-24 16:08:17 +02:00
|
|
|
#include "ratingwidget.h"
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
class QToolButton;
|
|
|
|
class QPaintDevice;
|
2018-05-01 00:41:33 +02:00
|
|
|
class QPaintEvent;
|
|
|
|
class QResizeEvent;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class LineEditInterface {
|
2020-09-23 00:52:41 +02:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit LineEditInterface(QWidget *widget) : widget_(widget) {}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QWidget *widget() const { return widget_; }
|
|
|
|
|
|
|
|
virtual ~LineEditInterface() {}
|
|
|
|
|
2020-09-23 00:52:41 +02:00
|
|
|
virtual void set_enabled(const bool enabled) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual void set_focus() = 0;
|
2020-09-23 00:52:41 +02:00
|
|
|
|
|
|
|
virtual void clear() = 0;
|
|
|
|
virtual QVariant value() const = 0;
|
|
|
|
virtual void set_value(const QVariant &value) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
virtual QString hint() const = 0;
|
2020-09-23 00:52:41 +02:00
|
|
|
virtual void set_hint(const QString &hint) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual void clear_hint() = 0;
|
|
|
|
|
2020-09-23 00:52:41 +02:00
|
|
|
virtual void set_partially() {}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
protected:
|
2018-02-27 18:06:05 +01:00
|
|
|
QWidget *widget_;
|
2021-06-20 19:04:08 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(LineEditInterface)
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExtendedEditor : public LineEditInterface {
|
2020-09-23 00:52:41 +02:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit ExtendedEditor(QWidget *widget, int extra_right_padding = 0, bool draw_hint = true);
|
2020-06-15 21:55:05 +02:00
|
|
|
~ExtendedEditor() override {}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-09-23 00:52:41 +02:00
|
|
|
virtual bool is_empty() const { return value().toString().isEmpty(); }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
QString hint() const override { return hint_; }
|
2020-09-23 00:52:41 +02:00
|
|
|
void set_hint(const QString &hint) override;
|
2020-06-15 21:55:05 +02:00
|
|
|
void clear_hint() override { set_hint(QString()); }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
bool has_clear_button() const { return has_clear_button_; }
|
2020-09-23 00:52:41 +02:00
|
|
|
void set_clear_button(const bool visible);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
bool has_reset_button() const;
|
2020-09-23 00:52:41 +02:00
|
|
|
void set_reset_button(const bool visible);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
qreal font_point_size() const { return font_point_size_; }
|
2020-09-23 00:52:41 +02:00
|
|
|
void set_font_point_size(const qreal size) { font_point_size_ = size; }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
protected:
|
2018-02-27 18:06:05 +01:00
|
|
|
void Paint(QPaintDevice *device);
|
|
|
|
void Resize();
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
private:
|
2018-02-27 18:06:05 +01:00
|
|
|
void UpdateButtonGeometry();
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
protected:
|
2018-02-27 18:06:05 +01:00
|
|
|
QString hint_;
|
|
|
|
|
|
|
|
bool has_clear_button_;
|
|
|
|
QToolButton *clear_button_;
|
|
|
|
QToolButton *reset_button_;
|
|
|
|
|
|
|
|
int extra_right_padding_;
|
|
|
|
bool draw_hint_;
|
|
|
|
qreal font_point_size_;
|
|
|
|
bool is_rtl_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LineEdit : public QLineEdit, public ExtendedEditor {
|
|
|
|
Q_OBJECT
|
2019-09-15 20:27:32 +02:00
|
|
|
|
|
|
|
Q_PROPERTY(QString hint READ hint WRITE set_hint)
|
|
|
|
Q_PROPERTY(qreal font_point_size READ font_point_size WRITE set_font_point_size)
|
|
|
|
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)
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit LineEdit(QWidget *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// ExtendedEditor
|
2020-06-15 21:55:05 +02:00
|
|
|
void set_enabled(bool enabled) override { QLineEdit::setEnabled(enabled); }
|
2020-09-23 00:52:41 +02:00
|
|
|
|
|
|
|
QVariant value() const override { return QLineEdit::text(); }
|
|
|
|
void set_value(const QVariant &value) override { QLineEdit::setText(value.toString()); }
|
|
|
|
|
|
|
|
public slots:
|
2021-01-26 16:48:04 +01:00
|
|
|
void set_focus() override { QLineEdit::setFocus(); }
|
2020-09-23 00:52:41 +02:00
|
|
|
void clear() override { QLineEdit::clear(); }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
protected:
|
2020-06-15 21:55:05 +02:00
|
|
|
void paintEvent(QPaintEvent*) override;
|
|
|
|
void resizeEvent(QResizeEvent*) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool is_rtl() const { return is_rtl_; }
|
|
|
|
void set_rtl(bool rtl) { is_rtl_ = rtl; }
|
|
|
|
|
|
|
|
private slots:
|
2020-09-23 00:52:41 +02:00
|
|
|
void text_changed(const QString &text);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
signals:
|
2018-02-27 18:06:05 +01:00
|
|
|
void Reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
class TextEdit : public QPlainTextEdit, public ExtendedEditor {
|
|
|
|
Q_OBJECT
|
2019-09-15 20:27:32 +02:00
|
|
|
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)
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit TextEdit(QWidget *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// ExtendedEditor
|
2020-06-15 21:55:05 +02:00
|
|
|
void set_enabled(bool enabled) override { QPlainTextEdit::setEnabled(enabled); }
|
2020-09-23 00:52:41 +02:00
|
|
|
|
|
|
|
QVariant value() const override { return QPlainTextEdit::toPlainText(); }
|
|
|
|
void set_value(const QVariant &value) override { QPlainTextEdit::setPlainText(value.toString()); }
|
|
|
|
|
|
|
|
public slots:
|
2021-01-26 16:48:04 +01:00
|
|
|
void set_focus() override { QPlainTextEdit::setFocus(); }
|
2020-09-23 00:52:41 +02:00
|
|
|
void clear() override { QPlainTextEdit::clear(); }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
protected:
|
2020-06-15 21:55:05 +02:00
|
|
|
void paintEvent(QPaintEvent*) override;
|
|
|
|
void resizeEvent(QResizeEvent*) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
signals:
|
2018-02-27 18:06:05 +01:00
|
|
|
void Reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
class SpinBox : public QSpinBox, public ExtendedEditor {
|
|
|
|
Q_OBJECT
|
2019-09-15 20:27:32 +02:00
|
|
|
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)
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit SpinBox(QWidget *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// QSpinBox
|
2020-06-15 21:55:05 +02:00
|
|
|
QString textFromValue(int val) const override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// ExtendedEditor
|
2020-06-15 21:55:05 +02:00
|
|
|
void set_enabled(bool enabled) override { QSpinBox::setEnabled(enabled); }
|
2020-09-23 00:52:41 +02:00
|
|
|
|
|
|
|
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:
|
2021-01-26 16:48:04 +01:00
|
|
|
void set_focus() override { QSpinBox::setFocus(); }
|
2020-09-23 00:52:41 +02:00
|
|
|
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); }
|
|
|
|
|
|
|
|
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:
|
2021-01-26 16:48:04 +01:00
|
|
|
void set_focus() override { QCheckBox::setFocus(); }
|
2020-09-23 00:52:41 +02:00
|
|
|
void clear() override { QCheckBox::setChecked(false); }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
protected:
|
2020-06-15 21:55:05 +02:00
|
|
|
void paintEvent(QPaintEvent*) override;
|
|
|
|
void resizeEvent(QResizeEvent*) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
signals:
|
2018-02-27 18:06:05 +01:00
|
|
|
void Reset();
|
|
|
|
};
|
|
|
|
|
2021-10-24 16:08:17 +02:00
|
|
|
class RatingBox : public RatingWidget, public ExtendedEditor {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString hint READ hint WRITE set_hint)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit RatingBox(QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
void set_enabled(bool enabled) override { RatingWidget::setEnabled(enabled); }
|
|
|
|
|
|
|
|
QVariant value() const override { return RatingWidget::rating(); }
|
2021-10-30 18:53:14 +02:00
|
|
|
void set_value(const QVariant &value) override { RatingWidget::set_rating(value.toFloat()); }
|
2021-10-24 16:08:17 +02:00
|
|
|
|
2021-10-30 18:53:14 +02:00
|
|
|
void set_partially() override { RatingWidget::set_rating(0.0F); }
|
2021-10-24 16:08:17 +02:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void set_focus() override { RatingWidget::setFocus(); }
|
|
|
|
void clear() override {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
#endif // LINEEDIT_H
|