Show notifications in msgbox on double click

This commit is contained in:
Martchus 2017-07-30 20:57:55 +02:00
parent 7f58bd6024
commit d3e2c89a0b
4 changed files with 40 additions and 5 deletions

View File

@ -52,6 +52,7 @@ DbQueryWidget::DbQueryWidget(TagEditorWidget *tagEditorWidget, QWidget *parent)
#endif
m_ui->notificationLabel->setText(tr("Search hasn't been started"));
m_ui->notificationLabel->setContext(tr("MusicBrainz/LyricsWikia notifications"));
m_ui->searchGroupBox->installEventFilter(this);
// initialize buttons

View File

@ -7,7 +7,9 @@
#include <QFontMetrics>
#include <QBrush>
#include <QConicalGradient>
#include <QDebug>
#include <QMessageBox>
#include <QCoreApplication>
#include <QStringBuilder>
#include <cmath>
@ -65,6 +67,14 @@ void NotificationLabel::paintEvent(QPaintEvent *event)
}
}
void NotificationLabel::mouseDoubleClickEvent(QMouseEvent *event)
{
if(m_type == NotificationType::Progress) {
return;
}
showMessageBox();
}
void NotificationLabel::updateAnimation()
{
switch(m_type) {
@ -77,6 +87,15 @@ void NotificationLabel::updateAnimation()
update(iconRect());
}
void NotificationLabel::showMessageBox() const
{
QMessageBox msgbox;
msgbox.setWindowTitle((m_context.isEmpty() ? tr("Notifications") : m_context) % QStringLiteral(" - ") % QCoreApplication::applicationName());
msgbox.setIconPixmap(m_mainPixmap);
msgbox.setText(m_text);
msgbox.exec();
}
QRect NotificationLabel::iconRect() const
{
QRect rect = this->rect();

View File

@ -26,6 +26,7 @@ class NotificationLabel : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString context READ context WRITE setContext)
Q_PROPERTY(NotificationType notificationType READ notificationType WRITE setNotificationType)
Q_PROPERTY(NotificationSubject notificationSubject READ notificationSubject WRITE setNotificationSubject)
Q_PROPERTY(int percentage READ percentage WRITE setPercentage)
@ -35,6 +36,7 @@ public:
explicit NotificationLabel(QWidget *parent = nullptr);
const QString &text() const;
const QString &context() const;
NotificationType notificationType() const;
NotificationSubject notificationSubject() const;
int percentage() const;
@ -46,6 +48,7 @@ public:
public slots:
void setText(const QString &text);
void setContext(const QString &context);
void clearText();
void appendLine(const QString &line);
void setNotificationType(NotificationType value);
@ -55,19 +58,21 @@ public slots:
void setMaxIconSize(int size);
protected:
virtual void paintEvent(QPaintEvent *event);
void paintEvent(QPaintEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
private slots:
void updateAnimation();
void showMessageBox() const;
private:
QRect iconRect() const;
QRect textRect() const;
void setupPixmaps(const QSize &size);
void drawProgressIndicator(QPainter &painter, QRect rect, const QColor &color, int angle);
static void toGrayPixmap(const QPixmap &original, QPixmap grayed);
QString m_text;
QString m_context;
NotificationType m_type;
NotificationSubject m_subject;
int m_percentage;
@ -76,8 +81,6 @@ private:
bool m_pixmapsInvalidated;
QPixmap m_mainPixmap;
QPixmap m_smallPixmap;
QPixmap m_mainPixmapDisabled;
QPixmap m_smallPixmapDisabled;
QTimer m_updateTimer;
int m_animationStep;
};
@ -87,6 +90,16 @@ inline const QString &NotificationLabel::text() const
return m_text;
}
inline const QString &NotificationLabel::context() const
{
return m_context;
}
inline void NotificationLabel::setContext(const QString &context)
{
m_context = context;
}
inline NotificationType NotificationLabel::notificationType() const
{
return m_type;

View File

@ -130,6 +130,8 @@ TagEditorWidget::TagEditorWidget(QWidget *parent) :
// other widgets
updateFileStatusStatus();
m_ui->abortButton->setVisible(false);
m_ui->parsingNotificationWidget->setContext(tr("Parsing notifications"));
m_ui->makingNotificationWidget->setContext(tr("Applying notifications"));
// connect signals and slots, install event filter
// buttons: save, delete, next, close
connect(m_ui->saveButton, &QPushButton::clicked, this, &TagEditorWidget::applyEntriesAndSaveChangings);