From 81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 19 Jul 2019 08:29:31 +0200 Subject: NOISSUE convert accounts page to use a toolbar for the side menu --- application/widgets/VersionListView.cpp | 103 ++++++++++++++------------------ application/widgets/VersionListView.h | 3 +- 2 files changed, 46 insertions(+), 60 deletions(-) (limited to 'application/widgets') diff --git a/application/widgets/VersionListView.cpp b/application/widgets/VersionListView.cpp index 359bd89c..09df75b7 100644 --- a/application/widgets/VersionListView.cpp +++ b/application/widgets/VersionListView.cpp @@ -29,9 +29,8 @@ VersionListView::VersionListView(QWidget *parent) void VersionListView::rowsInserted(const QModelIndex &parent, int start, int end) { - if(!m_itemCount) - viewport()->update(); m_itemCount += end-start+1; + updateEmptyViewPort(); QTreeView::rowsInserted(parent, start, end); } @@ -39,16 +38,14 @@ void VersionListView::rowsInserted(const QModelIndex &parent, int start, int end void VersionListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { m_itemCount -= end-start+1; - if(!m_itemCount) - viewport()->update(); + updateEmptyViewPort(); QTreeView::rowsInserted(parent, start, end); } void VersionListView::setModel(QAbstractItemModel *model) { m_itemCount = model->rowCount(); - if(!m_itemCount) - viewport()->update(); + updateEmptyViewPort(); QTreeView::setModel(model); } @@ -58,7 +55,10 @@ void VersionListView::reset() { m_itemCount = model()->rowCount(); } - viewport()->update(); + else { + m_itemCount = 0; + } + updateEmptyViewPort(); QTreeView::reset(); } @@ -82,6 +82,8 @@ void VersionListView::setEmptyMode(VersionListView::EmptyMode mode) void VersionListView::updateEmptyViewPort() { + setAccessibleDescription(currentEmptyString()); + if(!m_itemCount) { viewport()->update(); @@ -100,77 +102,60 @@ void VersionListView::paintEvent(QPaintEvent *event) } } -void VersionListView::paintInfoLabel(QPaintEvent *event) +QString VersionListView::currentEmptyString() const { - QString emptyString; + if(m_itemCount) { + return QString(); + } switch(m_emptyMode) { + default: case VersionListView::Empty: - return; + return QString(); case VersionListView::String: - emptyString = m_emptyString; - break; + return m_emptyString; case VersionListView::ErrorString: - emptyString = m_emptyErrorString; - break; + return m_emptyErrorString; } +} + + +void VersionListView::paintInfoLabel(QPaintEvent *event) const +{ + QString emptyString = currentEmptyString(); + //calculate the rect for the overlay QPainter painter(viewport()); painter.setRenderHint(QPainter::Antialiasing, true); QFont font("sans", 20); font.setBold(true); - + QRect bounds = viewport()->geometry(); bounds.moveTop(0); - QTextLayout layout(emptyString, font); - qreal height = 0.0; - qreal widthUsed = 0.0; - QStringList lines = viewItemTextLayout(layout, bounds.width() - 20, height, widthUsed); - QRect rect (0,0, widthUsed, height); - rect.setWidth(rect.width()+20); - rect.setHeight(rect.height()+20); - rect.moveCenter(bounds.center()); + auto innerBounds = bounds; + innerBounds.adjust(10, 10, -10, -10); + + QColor background = QApplication::palette().color(QPalette::Foreground); + QColor foreground = QApplication::palette().color(QPalette::Base); + foreground.setAlpha(190); + painter.setFont(font); + auto fontMetrics = painter.fontMetrics(); + auto textRect = fontMetrics.boundingRect(innerBounds, Qt::AlignHCenter | Qt::TextWordWrap, emptyString); + textRect.moveCenter(bounds.center()); + + auto wrapRect = textRect; + wrapRect.adjust(-10, -10, 10, 10); + //check if we are allowed to draw in our area - if (!event->rect().intersects(rect)) { + if (!event->rect().intersects(wrapRect)) { return; } - //draw the letter of the topmost item semitransparent in the middle - QColor background = QApplication::palette().color(QPalette::Foreground); - QColor foreground = QApplication::palette().color(QPalette::Base); - /* - background.setAlpha(128 - scrollFade); - foreground.setAlpha(128 - scrollFade); - */ + painter.setBrush(QBrush(background)); painter.setPen(foreground); - painter.drawRoundedRect(rect, 5.0, 5.0); - foreground.setAlpha(190); + painter.drawRoundedRect(wrapRect, 5.0, 5.0); + painter.setPen(foreground); painter.setFont(font); - painter.drawText(rect, Qt::AlignCenter, lines.join("\n")); - -} - -/* -void ModListView::setModel ( QAbstractItemModel* model ) -{ - QTreeView::setModel ( model ); - auto head = header(); - head->setStretchLastSection(false); - // HACK: this is true for the checkbox column of mod lists - auto string = model->headerData(0,head->orientation()).toString(); - if(!string.size()) - { - head->setSectionResizeMode(0, QHeaderView::ResizeToContents); - head->setSectionResizeMode(1, QHeaderView::Stretch); - for(int i = 2; i < head->count(); i++) - head->setSectionResizeMode(i, QHeaderView::ResizeToContents); - } - else - { - head->setSectionResizeMode(0, QHeaderView::Stretch); - for(int i = 1; i < head->count(); i++) - head->setSectionResizeMode(i, QHeaderView::ResizeToContents); - } + painter.drawText(textRect, Qt::AlignHCenter | Qt::TextWordWrap, emptyString); } -*/ diff --git a/application/widgets/VersionListView.h b/application/widgets/VersionListView.h index d376d9e1..233479bb 100644 --- a/application/widgets/VersionListView.h +++ b/application/widgets/VersionListView.h @@ -46,8 +46,9 @@ protected slots: virtual void rowsInserted(const QModelIndex &parent, int start, int end) override; private: /* methods */ - void paintInfoLabel(QPaintEvent *event); + void paintInfoLabel(QPaintEvent *event) const; void updateEmptyViewPort(); + QString currentEmptyString() const; private: /* variables */ int m_itemCount = 0; -- cgit v1.2.3