diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2023-08-02 18:35:35 +0200 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2023-08-02 18:35:35 +0200 |
commit | 1d468ac35ad88d8c77cc83f25e3704d9bd7df01b (patch) | |
tree | 8644b1574c947a1a87c5c7b2567f746cfe17882f /launcher/ui/widgets/PageContainer_p.h | |
parent | ce2ca1381519a2e261d7f76dffa874d559d979c2 (diff) | |
download | PrismLauncher-1d468ac35ad88d8c77cc83f25e3704d9bd7df01b.tar.gz PrismLauncher-1d468ac35ad88d8c77cc83f25e3704d9bd7df01b.tar.bz2 PrismLauncher-1d468ac35ad88d8c77cc83f25e3704d9bd7df01b.zip |
chore: reformat
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher/ui/widgets/PageContainer_p.h')
-rw-r--r-- | launcher/ui/widgets/PageContainer_p.h | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/launcher/ui/widgets/PageContainer_p.h b/launcher/ui/widgets/PageContainer_p.h index da1a66f4..9a7651c7 100644 --- a/launcher/ui/widgets/PageContainer_p.h +++ b/launcher/ui/widgets/PageContainer_p.h @@ -15,21 +15,18 @@ #pragma once -#include <QListView> -#include <QStyledItemDelegate> #include <QEvent> +#include <QListView> #include <QScrollBar> +#include <QStyledItemDelegate> class BasePage; const int pageIconSize = 24; -class PageViewDelegate : public QStyledItemDelegate -{ -public: - PageViewDelegate(QObject *parent) : QStyledItemDelegate(parent) - { - } - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +class PageViewDelegate : public QStyledItemDelegate { + public: + PageViewDelegate(QObject* parent) : QStyledItemDelegate(parent) {} + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { QSize size = QStyledItemDelegate::sizeHint(option, index); size.setHeight(qMax(size.height(), 32)); @@ -37,10 +34,9 @@ public: } }; -class PageModel : public QAbstractListModel -{ -public: - PageModel(QObject *parent = 0) : QAbstractListModel(parent) +class PageModel : public QAbstractListModel { + public: + PageModel(QObject* parent = 0) : QAbstractListModel(parent) { QPixmap empty(pageIconSize, pageIconSize); empty.fill(Qt::transparent); @@ -48,57 +44,47 @@ public: } virtual ~PageModel() {} - int rowCount(const QModelIndex &parent = QModelIndex()) const + int rowCount(const QModelIndex& parent = QModelIndex()) const { return parent.isValid() ? 0 : m_pages.size(); } + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const { - return parent.isValid() ? 0 : m_pages.size(); - } - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const - { - switch (role) - { - case Qt::DisplayRole: - return m_pages.at(index.row())->displayName(); - case Qt::DecorationRole: - { - QIcon icon = m_pages.at(index.row())->icon(); - if (icon.isNull()) - icon = m_emptyIcon; - // HACK: fixes icon stretching on windows. TODO: report Qt bug for this - return QIcon(icon.pixmap(QSize(48,48))); - } + switch (role) { + case Qt::DisplayRole: + return m_pages.at(index.row())->displayName(); + case Qt::DecorationRole: { + QIcon icon = m_pages.at(index.row())->icon(); + if (icon.isNull()) + icon = m_emptyIcon; + // HACK: fixes icon stretching on windows. TODO: report Qt bug for this + return QIcon(icon.pixmap(QSize(48, 48))); + } } return QVariant(); } - void setPages(const QList<BasePage *> &pages) + void setPages(const QList<BasePage*>& pages) { beginResetModel(); m_pages = pages; endResetModel(); } - const QList<BasePage *> &pages() const - { - return m_pages; - } + const QList<BasePage*>& pages() const { return m_pages; } - BasePage * findPageEntryById(QString id) + BasePage* findPageEntryById(QString id) { - for(auto page: m_pages) - { + for (auto page : m_pages) { if (page->id() == id) return page; } return nullptr; } - QList<BasePage *> m_pages; + QList<BasePage*> m_pages; QIcon m_emptyIcon; }; -class PageView : public QListView -{ -public: - PageView(QWidget *parent = 0) : QListView(parent) +class PageView : public QListView { + public: + PageView(QWidget* parent = 0) : QListView(parent) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); setItemDelegate(new PageViewDelegate(this)); @@ -113,10 +99,9 @@ public: return QSize(width, 100); } - virtual bool eventFilter(QObject *obj, QEvent *event) + virtual bool eventFilter(QObject* obj, QEvent* event) { - if (obj == verticalScrollBar() && - (event->type() == QEvent::Show || event->type() == QEvent::Hide)) + if (obj == verticalScrollBar() && (event->type() == QEvent::Show || event->type() == QEvent::Hide)) updateGeometry(); return QListView::eventFilter(obj, event); } |