diff options
Diffstat (limited to 'application/widgets')
-rw-r--r-- | application/widgets/VersionListView.cpp | 31 | ||||
-rw-r--r-- | application/widgets/VersionListView.h | 16 |
2 files changed, 45 insertions, 2 deletions
diff --git a/application/widgets/VersionListView.cpp b/application/widgets/VersionListView.cpp index fc0bcd0a..1e327534 100644 --- a/application/widgets/VersionListView.cpp +++ b/application/widgets/VersionListView.cpp @@ -65,6 +65,23 @@ void VersionListView::reset() void VersionListView::setEmptyString(QString emptyString) { m_emptyString = emptyString; + updateEmptyViewPort(); +} + +void VersionListView::setEmptyErrorString(QString emptyErrorString) +{ + m_emptyErrorString = emptyErrorString; + updateEmptyViewPort(); +} + +void VersionListView::setEmptyMode(VersionListView::EmptyMode mode) +{ + m_emptyMode = mode; + updateEmptyViewPort(); +} + +void VersionListView::updateEmptyViewPort() +{ if(!m_itemCount) { viewport()->update(); @@ -85,6 +102,18 @@ void VersionListView::paintEvent(QPaintEvent *event) void VersionListView::paintInfoLabel(QPaintEvent *event) { + QString emptyString; + switch(m_emptyMode) + { + case VersionListView::Empty: + return; + case VersionListView::String: + emptyString = m_emptyString; + break; + case VersionListView::ErrorString: + emptyString = m_emptyErrorString; + break; + } //calculate the rect for the overlay QPainter painter(viewport()); painter.setRenderHint(QPainter::Antialiasing, true); @@ -93,7 +122,7 @@ void VersionListView::paintInfoLabel(QPaintEvent *event) QRect bounds = viewport()->geometry(); bounds.moveTop(0); - QTextLayout layout(m_emptyString, font); + QTextLayout layout(emptyString, font); qreal height = 0.0; qreal widthUsed = 0.0; QStringList lines = viewItemTextLayout(layout, bounds.width() - 20, height, widthUsed); diff --git a/application/widgets/VersionListView.h b/application/widgets/VersionListView.h index f33a6fdb..4fcbd8ee 100644 --- a/application/widgets/VersionListView.h +++ b/application/widgets/VersionListView.h @@ -22,11 +22,22 @@ class VersionListView : public QTreeView { Q_OBJECT public: + explicit VersionListView(QWidget *parent = 0); virtual void paintEvent(QPaintEvent *event) override; - void setEmptyString(QString emptyString); virtual void setModel ( QAbstractItemModel* model ); + enum EmptyMode + { + Empty, + String, + ErrorString + }; + + void setEmptyString(QString emptyString); + void setEmptyErrorString(QString emptyErrorString); + void setEmptyMode(EmptyMode mode); + public slots: virtual void reset() override; @@ -36,8 +47,11 @@ protected slots: private: /* methods */ void paintInfoLabel(QPaintEvent *event); + void updateEmptyViewPort(); private: /* variables */ int m_itemCount = 0; QString m_emptyString; + QString m_emptyErrorString; + EmptyMode m_emptyMode = Empty; }; |