tageditor/gui/picturepreviewselection.h

121 lines
3.2 KiB
C
Raw Normal View History

2015-04-22 19:33:53 +02:00
#ifndef COVEREDIT_H
#define COVEREDIT_H
2015-09-06 20:20:00 +02:00
#include "./previousvaluehandling.h"
2015-04-22 19:33:53 +02:00
#include <tagparser/tag.h>
#include <QWidget>
#include <memory>
QT_FORWARD_DECLARE_CLASS(QEvent)
QT_FORWARD_DECLARE_CLASS(QGraphicsScene)
QT_FORWARD_DECLARE_CLASS(QGraphicsTextItem)
QT_FORWARD_DECLARE_CLASS(QGraphicsPixmapItem)
QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem)
2015-04-22 19:33:53 +02:00
2018-03-06 23:10:13 +01:00
namespace TagParser {
2015-04-22 19:33:53 +02:00
class Tag;
class TagValue;
2016-07-11 21:34:05 +02:00
DECLARE_ENUM_CLASS(KnownField, unsigned int);
2018-03-07 01:18:01 +01:00
} // namespace TagParser
2015-04-22 19:33:53 +02:00
namespace QtGui {
2016-07-11 21:34:05 +02:00
DECLARE_ENUM_CLASS(PreviousValueHandling, int);
2015-04-22 19:33:53 +02:00
namespace Ui {
class PicturePreviewSelection;
}
2018-03-07 01:18:01 +01:00
class PicturePreviewSelection : public QWidget {
2015-04-22 19:33:53 +02:00
Q_OBJECT
public:
2018-03-07 01:18:01 +01:00
explicit PicturePreviewSelection(
TagParser::Tag *tag = nullptr, TagParser::KnownField field = TagParser::KnownField::Invalid, QWidget *parent = nullptr);
~PicturePreviewSelection();
2018-03-07 01:18:01 +01:00
2018-03-06 23:10:13 +01:00
TagParser::Tag *tag() const;
TagParser::KnownField field() const;
2015-04-22 19:33:53 +02:00
public slots:
2018-03-06 23:10:13 +01:00
void setTagField(TagParser::Tag *tag, TagParser::KnownField field, PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
void setValue(const TagParser::TagValue &value, PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
2015-04-22 19:33:53 +02:00
void apply();
void clear();
void addOfSelectedType();
void addOfSelectedType(const QString &path);
2015-04-22 19:33:53 +02:00
void removeSelected();
void extractSelected();
void displaySelected();
void changeMimeTypeOfSelected();
void setCoverButtonsHidden(bool hideCoverButtons);
2015-04-22 19:33:53 +02:00
signals:
void pictureChanged();
protected:
void changeEvent(QEvent *event);
void resizeEvent(QResizeEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
2015-04-22 19:33:53 +02:00
private slots:
void typeSwitched(int index);
void updateDescription(int newIndex);
void updateDescription(int lastIndex, int newIndex);
void updatePreview(int index);
void showContextMenu();
2015-04-22 19:33:53 +02:00
private:
void setup(PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
std::unique_ptr<Ui::PicturePreviewSelection> m_ui;
QGraphicsScene *m_scene;
QGraphicsTextItem *m_textItem;
QPixmap m_pixmap;
QGraphicsPixmapItem *m_pixmapItem;
QGraphicsRectItem *m_rectItem;
2018-03-06 23:10:13 +01:00
TagParser::Tag *m_tag;
TagParser::KnownField m_field;
QList<TagParser::TagValue> m_values;
int m_currentTypeIndex;
2015-04-22 19:33:53 +02:00
};
/*!
* \brief Returns the tied tag if one is assigned; returns nullptr otherwise.
*
* This might have been set initially using the constructor or using the setTagField() method.
*/
2018-03-06 23:10:13 +01:00
inline TagParser::Tag *PicturePreviewSelection::tag() const
2015-04-22 19:33:53 +02:00
{
return m_tag;
}
/*!
* \brief Returns the field. This is commonly KnownField::Cover.
*/
2018-03-06 23:10:13 +01:00
inline TagParser::KnownField PicturePreviewSelection::field() const
2015-04-22 19:33:53 +02:00
{
return m_field;
}
/*!
* \brief Sets the specified \a tag, \a field and \a previousValueHandling.
*
* If \a tag is nullptr the widget is disabled. The widget will be re-setup.
*/
2018-03-06 23:10:13 +01:00
inline void PicturePreviewSelection::setTagField(TagParser::Tag *tag, TagParser::KnownField field, PreviousValueHandling previousValueHandling)
2015-04-22 19:33:53 +02:00
{
m_tag = tag;
m_field = field;
setup(previousValueHandling);
}
2018-03-07 01:18:01 +01:00
} // namespace QtGui
2015-04-22 19:33:53 +02:00
#endif // COVEREDIT_H