tageditor/gui/tagfieldedit.h

146 lines
4.7 KiB
C
Raw Normal View History

2015-04-22 19:33:53 +02:00
#ifndef QTGUI_TAGFIELDLINEEDIT_H
#define QTGUI_TAGFIELDLINEEDIT_H
2015-09-06 20:20:00 +02:00
#include "./previousvaluehandling.h"
2015-04-22 19:33:53 +02:00
#include <c++utilities/application/global.h>
#include <QPair>
#include <QWidget>
2016-07-11 21:34:05 +02:00
QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
QT_FORWARD_DECLARE_CLASS(QLabel)
2015-04-22 19:33:53 +02:00
2019-07-07 12:00:16 +02:00
#define TAGEDITOR_ENUM_CLASS enum class
2018-03-06 23:10:13 +01:00
namespace TagParser {
2015-04-22 19:33:53 +02:00
class TagValue;
2016-07-11 21:34:05 +02:00
class Tag;
2019-07-07 12:00:16 +02:00
TAGEDITOR_ENUM_CLASS KnownField : unsigned int;
TAGEDITOR_ENUM_CLASS TagDataType : unsigned int;
TAGEDITOR_ENUM_CLASS TagTextEncoding : unsigned int;
2018-03-07 01:18:01 +01:00
} // namespace TagParser
2019-07-07 12:00:16 +02:00
#undef TAGEDITOR_ENUM_CLASS
2015-04-22 19:33:53 +02:00
2019-06-10 22:49:46 +02:00
namespace QtUtilities {
2015-04-22 19:33:53 +02:00
class ButtonOverlay;
class ClearLineEdit;
class ClearComboBox;
class ClearSpinBox;
class ClearPlainTextEdit;
class IconButton;
2019-06-12 20:47:44 +02:00
} // namespace QtUtilities
2015-04-22 19:33:53 +02:00
namespace QtGui {
class PicturePreviewSelection;
2018-03-07 01:18:01 +01:00
class TagFieldEdit : public QWidget {
2015-04-22 19:33:53 +02:00
Q_OBJECT
public:
2018-03-06 23:10:13 +01:00
explicit TagFieldEdit(const QList<TagParser::Tag *> &tags, TagParser::KnownField field, QWidget *parent = nullptr);
~TagFieldEdit() override;
2015-04-22 19:33:53 +02:00
2018-03-06 23:10:13 +01:00
const QList<TagParser::Tag *> &tags() const;
TagParser::KnownField field() const;
2018-03-07 01:18:01 +01:00
void setTagField(const QList<TagParser::Tag *> &tags, TagParser::KnownField field,
PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear, bool preventUiUpdate = false);
2018-03-06 23:10:13 +01:00
TagParser::TagValue value(TagParser::TagTextEncoding encoding, bool includeDescription) const;
bool setValue(const TagParser::TagValue &value, PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
2015-04-22 19:33:53 +02:00
bool hasDescription() const;
2018-03-06 23:10:13 +01:00
bool canApply(TagParser::KnownField field) const;
2019-05-28 23:59:38 +02:00
bool isLocked() const;
void setLocked(bool locked);
void toggleLocked();
bool hasAutoCorrectionBeenApplied() const;
2015-04-22 19:33:53 +02:00
2020-03-08 14:04:29 +01:00
public Q_SLOTS:
2015-04-22 19:33:53 +02:00
void clear();
void apply();
void restore();
void setCoverButtonsHidden(bool hideCoverButtons);
2015-04-22 19:33:53 +02:00
2020-03-09 18:46:08 +01:00
Q_SIGNALS:
2015-04-22 19:33:53 +02:00
void returnPressed();
protected:
2019-06-01 12:45:12 +02:00
bool eventFilter(QObject *obj, QEvent *event) override;
2015-04-22 19:33:53 +02:00
2020-03-08 14:04:29 +01:00
private Q_SLOTS:
2015-04-22 19:33:53 +02:00
void handleRestoreButtonClicked();
void handleRestoreButtonDestroyed(QObject *obj = nullptr);
2019-05-28 23:59:38 +02:00
void handleLockButtonDestroyed(QObject *obj = nullptr);
2015-04-22 19:33:53 +02:00
private:
2018-03-06 23:10:13 +01:00
TagParser::TagDataType determineDataType();
2015-04-22 19:33:53 +02:00
void setupUi();
2019-06-10 22:49:46 +02:00
QtUtilities::ClearLineEdit *setupLineEdit();
QtUtilities::ClearPlainTextEdit *setupPlainTextEdit();
QtUtilities::ClearComboBox *setupGenreComboBox();
QtUtilities::ClearSpinBox *setupSpinBox();
QPair<QtUtilities::ClearSpinBox *, QtUtilities::ClearSpinBox *> &setupPositionInSetSpinBoxes();
2015-04-22 19:33:53 +02:00
PicturePreviewSelection *setupPictureSelection();
QWidget *setupFileSelection();
2019-06-10 22:49:46 +02:00
QtUtilities::ClearLineEdit *setupDescriptionLineEdit();
2015-04-22 19:33:53 +02:00
QLabel *setupTypeNotSupportedLabel();
bool updateValue(PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
bool updateValue(TagParser::Tag *tag, PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
bool updateValue(
2018-03-07 01:18:01 +01:00
const TagParser::TagValue &value, PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear, bool resetRestoreButton = true);
QAction *setupRestoreAction();
QAction *setupLockAction();
void showRestoreAction();
QString applyAutoCorrection(const QString &textValue);
2015-04-22 19:33:53 +02:00
void concretizePreviousValueHandling(PreviousValueHandling &previousValueHandling);
QVBoxLayout *m_layout;
2018-03-06 23:10:13 +01:00
const QList<TagParser::Tag *> *m_tags;
TagParser::KnownField m_field;
TagParser::TagDataType m_dataType;
2015-04-22 19:33:53 +02:00
QList<QWidget *> m_widgets;
2019-06-10 22:49:46 +02:00
QtUtilities::ClearLineEdit *m_lineEdit;
QtUtilities::ClearComboBox *m_comboBox;
QPair<QtUtilities::ClearSpinBox *, QtUtilities::ClearSpinBox *> m_spinBoxes;
2015-04-22 19:33:53 +02:00
PicturePreviewSelection *m_pictureSelection;
2019-06-10 22:49:46 +02:00
QtUtilities::ClearPlainTextEdit *m_plainTextEdit;
QtUtilities::ClearLineEdit *m_descriptionLineEdit;
QAction *m_restoreAction;
QAction *m_lockAction;
2019-05-28 23:59:38 +02:00
bool m_isLocked;
bool m_autoCorrectionApplied;
2015-04-22 19:33:53 +02:00
};
/// \brief Returns the currently assigned tags.
2018-03-06 23:10:13 +01:00
inline const QList<TagParser::Tag *> &TagFieldEdit::tags() const
2015-04-22 19:33:53 +02:00
{
return *m_tags;
}
/// \brief Returns the currently assigned field.
2018-03-06 23:10:13 +01:00
inline TagParser::KnownField TagFieldEdit::field() const
2015-04-22 19:33:53 +02:00
{
return m_field;
}
/// \brief Returns whether the tag field edit is locked to keep the current value when switching files.
2019-05-28 23:59:38 +02:00
inline bool TagFieldEdit::isLocked() const
{
return m_isLocked;
}
/// \brief Toggles whether the tag field edit is locked to keep the current value when switching files.
2019-05-28 23:59:38 +02:00
inline void TagFieldEdit::toggleLocked()
{
setLocked(!isLocked());
}
/// \brief Returns whether auto correction has been applied.
inline bool TagFieldEdit::hasAutoCorrectionBeenApplied() const
{
return m_autoCorrectionApplied;
}
2018-03-07 01:18:01 +01:00
} // namespace QtGui
2015-04-22 19:33:53 +02:00
#endif // QTGUI_TAGFIELDLINEEDIT_H