summaryrefslogtreecommitdiffstats
path: root/application/widgets
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-07-19 08:29:31 +0200
committerPetr Mrázek <peterix@gmail.com>2019-07-19 08:29:31 +0200
commit81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437 (patch)
tree858ec55495ab095db3ff97ba5a7ad8344c51843e /application/widgets
parent3d5869e1cfc56aa1a8cc7b884fad0600cecc9e69 (diff)
downloadMultiMC-81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437.tar
MultiMC-81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437.tar.gz
MultiMC-81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437.tar.lz
MultiMC-81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437.tar.xz
MultiMC-81fdde6fddd0cb2bd0d2f4e69452a4c1f2742437.zip
NOISSUE convert accounts page to use a toolbar for the side menu
Diffstat (limited to 'application/widgets')
-rw-r--r--application/widgets/VersionListView.cpp103
-rw-r--r--application/widgets/VersionListView.h3
2 files changed, 46 insertions, 60 deletions
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;