Limit number of errors displayed in db query widget
This commit is contained in:
parent
0c6dcc4adc
commit
978de4f101
|
@ -53,6 +53,7 @@ DbQueryWidget::DbQueryWidget(TagEditorWidget *tagEditorWidget, QWidget *parent)
|
|||
|
||||
m_ui->notificationLabel->setText(tr("Search hasn't been started"));
|
||||
m_ui->notificationLabel->setContext(tr("MusicBrainz/LyricsWikia notifications"));
|
||||
m_ui->notificationLabel->setMaxLineCount(5);
|
||||
m_ui->searchGroupBox->installEventFilter(this);
|
||||
|
||||
// initialize buttons
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
|
||||
namespace QtGui {
|
||||
|
||||
const QChar NotificationLabel::s_bulletPoint(0x2022);
|
||||
const QString NotificationLabel::s_bulletLine(QStringLiteral("\n• "));
|
||||
|
||||
NotificationLabel::NotificationLabel(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_type(NotificationType::Information),
|
||||
|
@ -23,7 +26,9 @@ NotificationLabel::NotificationLabel(QWidget *parent) :
|
|||
m_minIconSize(25),
|
||||
m_maxIconSize(25),
|
||||
m_pixmapsInvalidated(true),
|
||||
m_animationStep(0)
|
||||
m_animationStep(0),
|
||||
m_maxLineCount(infiniteLines),
|
||||
m_currentLineCount(0)
|
||||
{
|
||||
connect(&m_updateTimer, &QTimer::timeout, this, &NotificationLabel::updateAnimation);
|
||||
m_updateTimer.setInterval(80);
|
||||
|
@ -174,6 +179,25 @@ void NotificationLabel::drawProgressIndicator(QPainter &painter, QRect rect, con
|
|||
}
|
||||
}
|
||||
|
||||
void NotificationLabel::applyMaxLineCount()
|
||||
{
|
||||
if(m_maxLineCount == infiniteLines || m_currentLineCount < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newStart = 0;
|
||||
for(; m_currentLineCount > m_maxLineCount; --m_currentLineCount) {
|
||||
const int nextBullet = m_text.indexOf(s_bulletLine, newStart);
|
||||
if(nextBullet < 0) {
|
||||
break;
|
||||
}
|
||||
newStart = nextBullet;
|
||||
}
|
||||
if(newStart) {
|
||||
m_text.remove(0, newStart + 1);
|
||||
}
|
||||
}
|
||||
|
||||
QSize NotificationLabel::sizeHint() const
|
||||
{
|
||||
const QFontMetrics fm(fontMetrics());
|
||||
|
@ -195,6 +219,7 @@ void NotificationLabel::setText(const QString &text)
|
|||
{
|
||||
const bool updateTooltip = toolTip().isEmpty() || toolTip() == m_text;
|
||||
m_text = text;
|
||||
m_currentLineCount = 1;
|
||||
updateGeometry();
|
||||
update(textRect());
|
||||
if(updateTooltip) {
|
||||
|
@ -208,6 +233,7 @@ void NotificationLabel::clearText()
|
|||
setToolTip(QString());
|
||||
}
|
||||
m_text.clear();
|
||||
m_currentLineCount = 0;
|
||||
updateGeometry();
|
||||
update(textRect());
|
||||
}
|
||||
|
@ -217,13 +243,16 @@ void NotificationLabel::appendLine(const QString &line)
|
|||
const bool updateTooltip = toolTip().isEmpty() || toolTip() == m_text;
|
||||
if(m_text.isEmpty()) {
|
||||
m_text = line;
|
||||
m_currentLineCount = 1;
|
||||
} else {
|
||||
if(!m_text.startsWith(QStringLiteral("•"))) {
|
||||
m_text.insert(0, QStringLiteral("• "));
|
||||
if(!m_text.startsWith(s_bulletPoint)) {
|
||||
m_text = s_bulletPoint % QChar(' ') % m_text % s_bulletLine % line;
|
||||
} else {
|
||||
m_text = m_text % s_bulletLine % line;
|
||||
}
|
||||
m_text.append(QStringLiteral("\n• "));
|
||||
m_text.append(line);
|
||||
++m_currentLineCount;
|
||||
}
|
||||
applyMaxLineCount();
|
||||
updateGeometry();
|
||||
update(textRect());
|
||||
if(updateTooltip) {
|
||||
|
@ -271,6 +300,12 @@ void NotificationLabel::setMaxIconSize(int size)
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void NotificationLabel::setMaxLineCount(std::size_t maxLineCount)
|
||||
{
|
||||
m_maxLineCount = maxLineCount;
|
||||
applyMaxLineCount();
|
||||
}
|
||||
|
||||
void NotificationLabel::setMinIconSize(int size)
|
||||
{
|
||||
m_minIconSize = size;
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QPixmap>
|
||||
#include <QTimer>
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
enum class NotificationType
|
||||
|
@ -32,6 +34,9 @@ class NotificationLabel : public QWidget
|
|||
Q_PROPERTY(int percentage READ percentage WRITE setPercentage)
|
||||
Q_PROPERTY(int minIconSize READ minIconSize WRITE setMinIconSize)
|
||||
Q_PROPERTY(int maxIconSize READ maxIconSize WRITE setMaxIconSize)
|
||||
Q_PROPERTY(std::size_t maxLineCount READ maxLineCount WRITE setMaxLineCount)
|
||||
Q_PROPERTY(std::size_t currentLineCount READ currentLineCount)
|
||||
|
||||
public:
|
||||
explicit NotificationLabel(QWidget *parent = nullptr);
|
||||
|
||||
|
@ -42,6 +47,8 @@ public:
|
|||
int percentage() const;
|
||||
int minIconSize() const;
|
||||
int maxIconSize() const;
|
||||
std::size_t maxLineCount() const;
|
||||
std::size_t currentLineCount() const;
|
||||
|
||||
virtual QSize sizeHint() const;
|
||||
virtual QSize minimumSizeHint() const;
|
||||
|
@ -56,6 +63,7 @@ public slots:
|
|||
void setPercentage(int percentage);
|
||||
void setMinIconSize(int size);
|
||||
void setMaxIconSize(int size);
|
||||
void setMaxLineCount(std::size_t maxLineCount);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
@ -70,7 +78,12 @@ private:
|
|||
QRect textRect() const;
|
||||
void setupPixmaps(const QSize &size);
|
||||
void drawProgressIndicator(QPainter &painter, QRect rect, const QColor &color, int angle);
|
||||
void applyMaxLineCount();
|
||||
|
||||
public:
|
||||
static constexpr std::size_t infiniteLines = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
QString m_context;
|
||||
NotificationType m_type;
|
||||
|
@ -83,6 +96,10 @@ private:
|
|||
QPixmap m_smallPixmap;
|
||||
QTimer m_updateTimer;
|
||||
int m_animationStep;
|
||||
std::size_t m_maxLineCount;
|
||||
std::size_t m_currentLineCount;
|
||||
static const QChar s_bulletPoint;
|
||||
static const QString s_bulletLine;
|
||||
};
|
||||
|
||||
inline const QString &NotificationLabel::text() const
|
||||
|
@ -125,6 +142,16 @@ inline int NotificationLabel::maxIconSize() const
|
|||
return m_maxIconSize;
|
||||
}
|
||||
|
||||
inline std::size_t NotificationLabel::maxLineCount() const
|
||||
{
|
||||
return m_maxLineCount;
|
||||
}
|
||||
|
||||
inline std::size_t NotificationLabel::currentLineCount() const
|
||||
{
|
||||
return m_currentLineCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // NOTIFICATIONLABEL_H
|
||||
|
|
Loading…
Reference in New Issue