mirror of
https://github.com/UltimMC/Launcher.git
synced 2026-01-04 22:30:07 +00:00
GH-2552 Make the filter part of the version widget
This commit is contained in:
@@ -1,76 +1,65 @@
|
||||
#include "VersionSelectWidget.h"
|
||||
#include <QProgressBar>
|
||||
#include <QVBoxLayout>
|
||||
#include "VersionListView.h"
|
||||
#include <QHeaderView>
|
||||
#include <VersionProxyModel.h>
|
||||
#include <dialogs/CustomMessageBox.h>
|
||||
#include "ui_VersionSelectWidget.h"
|
||||
|
||||
#include "BaseVersion.h"
|
||||
#include "dialogs/CustomMessageBox.h"
|
||||
#include "VersionProxyModel.h"
|
||||
|
||||
VersionSelectWidget::VersionSelectWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent), ui(new Ui::VersionSelectWidget)
|
||||
{
|
||||
setObjectName(QStringLiteral("VersionSelectWidget"));
|
||||
verticalLayout = new QVBoxLayout(this);
|
||||
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
|
||||
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_proxyModel = new VersionProxyModel(this);
|
||||
ui->setupUi(this);
|
||||
ui->listView->setModel(m_proxyModel);
|
||||
|
||||
listView = new VersionListView(this);
|
||||
listView->setObjectName(QStringLiteral("listView"));
|
||||
listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
listView->setAlternatingRowColors(true);
|
||||
listView->setRootIsDecorated(false);
|
||||
listView->setItemsExpandable(false);
|
||||
listView->setWordWrap(true);
|
||||
listView->header()->setCascadingSectionResizes(true);
|
||||
listView->header()->setStretchLastSection(false);
|
||||
listView->setModel(m_proxyModel);
|
||||
verticalLayout->addWidget(listView);
|
||||
ui->loadProgressBar->setVisible(false);
|
||||
|
||||
sneakyProgressBar = new QProgressBar(this);
|
||||
sneakyProgressBar->setObjectName(QStringLiteral("sneakyProgressBar"));
|
||||
sneakyProgressBar->setFormat(QStringLiteral("%p%"));
|
||||
verticalLayout->addWidget(sneakyProgressBar);
|
||||
sneakyProgressBar->setHidden(true);
|
||||
connect(listView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &VersionSelectWidget::currentRowChanged);
|
||||
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
connect(ui->listView->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
||||
this, &VersionSelectWidget::currentRowChanged);
|
||||
connect(ui->releasesCheckbox, &QCheckBox::stateChanged, this, &VersionSelectWidget::filterChanged);
|
||||
connect(ui->snapshotsCheckbox, &QCheckBox::stateChanged, this, &VersionSelectWidget::filterChanged);
|
||||
connect(ui->oldSnapshotsCheckbox, &QCheckBox::stateChanged, this, &VersionSelectWidget::filterChanged);
|
||||
connect(ui->betasCheckbox, &QCheckBox::stateChanged, this, &VersionSelectWidget::filterChanged);
|
||||
connect(ui->alphasCheckbox, &QCheckBox::stateChanged, this, &VersionSelectWidget::filterChanged);
|
||||
connect(ui->refreshButton, &QPushButton::clicked, this, &VersionSelectWidget::loadList);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setCurrentVersion(const QString& version)
|
||||
{
|
||||
m_currentVersion = version;
|
||||
m_proxyModel->setCurrentVersion(version);
|
||||
m_currentVersion = version;
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setEmptyString(QString emptyString)
|
||||
{
|
||||
listView->setEmptyString(emptyString);
|
||||
ui->listView->setEmptyString(emptyString);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setEmptyErrorString(QString emptyErrorString)
|
||||
{
|
||||
listView->setEmptyErrorString(emptyErrorString);
|
||||
ui->listView->setEmptyErrorString(emptyErrorString);
|
||||
}
|
||||
|
||||
VersionSelectWidget::~VersionSelectWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setResizeOn(int column)
|
||||
{
|
||||
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents);
|
||||
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents);
|
||||
resizeOnColumn = column;
|
||||
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::initialize(BaseVersionList *vlist)
|
||||
{
|
||||
m_vlist = vlist;
|
||||
m_proxyModel->setSourceModel(vlist);
|
||||
listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
|
||||
if (!m_vlist->isLoaded())
|
||||
{
|
||||
@@ -80,7 +69,7 @@ void VersionSelectWidget::initialize(BaseVersionList *vlist)
|
||||
{
|
||||
if (m_proxyModel->rowCount() == 0)
|
||||
{
|
||||
listView->setEmptyMode(VersionListView::String);
|
||||
ui->listView->setEmptyMode(VersionListView::String);
|
||||
}
|
||||
preselect();
|
||||
}
|
||||
@@ -106,16 +95,16 @@ void VersionSelectWidget::loadList()
|
||||
{
|
||||
loadTask->start();
|
||||
}
|
||||
sneakyProgressBar->setHidden(false);
|
||||
ui->loadProgressBar->setHidden(false);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::onTaskSucceeded()
|
||||
{
|
||||
if (m_proxyModel->rowCount() == 0)
|
||||
{
|
||||
listView->setEmptyMode(VersionListView::String);
|
||||
ui->listView->setEmptyMode(VersionListView::String);
|
||||
}
|
||||
sneakyProgressBar->setHidden(true);
|
||||
ui->loadProgressBar->setHidden(true);
|
||||
preselect();
|
||||
loadTask = nullptr;
|
||||
}
|
||||
@@ -128,8 +117,8 @@ void VersionSelectWidget::onTaskFailed(const QString& reason)
|
||||
|
||||
void VersionSelectWidget::changeProgress(qint64 current, qint64 total)
|
||||
{
|
||||
sneakyProgressBar->setMaximum(total);
|
||||
sneakyProgressBar->setValue(current);
|
||||
ui->loadProgressBar->setMaximum(total);
|
||||
ui->loadProgressBar->setValue(current);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::currentRowChanged(const QModelIndex& current, const QModelIndex&)
|
||||
@@ -158,8 +147,9 @@ void VersionSelectWidget::selectCurrent()
|
||||
if(idx.isValid())
|
||||
{
|
||||
preselectedAlready = true;
|
||||
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
||||
ui->listView->selectionModel()->setCurrentIndex(idx,
|
||||
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
ui->listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,8 +159,9 @@ void VersionSelectWidget::selectRecommended()
|
||||
if(idx.isValid())
|
||||
{
|
||||
preselectedAlready = true;
|
||||
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
||||
ui->listView->selectionModel()->setCurrentIndex(idx,
|
||||
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
ui->listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +172,7 @@ bool VersionSelectWidget::hasVersions() const
|
||||
|
||||
BaseVersionPtr VersionSelectWidget::selectedVersion() const
|
||||
{
|
||||
auto currentIndex = listView->selectionModel()->currentIndex();
|
||||
auto currentIndex = ui->listView->selectionModel()->currentIndex();
|
||||
auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole);
|
||||
return variant.value<BaseVersionPtr>();
|
||||
}
|
||||
@@ -200,3 +191,25 @@ void VersionSelectWidget::setFilter(BaseVersionList::ModelRoles role, Filter *fi
|
||||
{
|
||||
m_proxyModel->setFilter(role, filter);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::filterChanged()
|
||||
{
|
||||
QStringList out;
|
||||
if(ui->alphasCheckbox->isChecked())
|
||||
out << "(old_alpha)";
|
||||
if(ui->betasCheckbox->isChecked())
|
||||
out << "(old_beta)";
|
||||
if(ui->snapshotsCheckbox->isChecked())
|
||||
out << "(snapshot)";
|
||||
if(ui->oldSnapshotsCheckbox->isChecked())
|
||||
out << "(old_snapshot)";
|
||||
if(ui->releasesCheckbox->isChecked())
|
||||
out << "(release)";
|
||||
auto regexp = out.join('|');
|
||||
setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setFilterBoxVisible(bool visible)
|
||||
{
|
||||
ui->filterBox->setVisible(visible);
|
||||
}
|
||||
@@ -25,6 +25,11 @@ class QVBoxLayout;
|
||||
class QProgressBar;
|
||||
class Filter;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class VersionSelectWidget;
|
||||
}
|
||||
|
||||
class VersionSelectWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -50,6 +55,7 @@ public:
|
||||
void setEmptyString(QString emptyString);
|
||||
void setEmptyErrorString(QString emptyErrorString);
|
||||
void setResizeOn(int column);
|
||||
void setFilterBoxVisible(bool visible);
|
||||
|
||||
signals:
|
||||
void selectedVersionChanged(BaseVersionPtr version);
|
||||
@@ -62,6 +68,7 @@ private slots:
|
||||
void onTaskFailed(const QString &reason);
|
||||
void changeProgress(qint64 current, qint64 total);
|
||||
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &);
|
||||
void filterChanged();
|
||||
|
||||
private:
|
||||
void preselect();
|
||||
@@ -74,8 +81,5 @@ private:
|
||||
Task * loadTask;
|
||||
bool preselectedAlready = false;
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout = nullptr;
|
||||
VersionListView *listView = nullptr;
|
||||
QProgressBar *sneakyProgressBar = nullptr;
|
||||
Ui::VersionSelectWidget *ui;
|
||||
};
|
||||
|
||||
150
application/widgets/VersionSelectWidget.ui
Normal file
150
application/widgets/VersionSelectWidget.ui
Normal file
@@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VersionSelectWidget</class>
|
||||
<widget class="QWidget" name="VersionSelectWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>740</width>
|
||||
<height>614</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="sideBox">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="filterBox" native="true">
|
||||
<layout class="QVBoxLayout" name="_2">
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Filter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="releasesCheckbox">
|
||||
<property name="text">
|
||||
<string>Releases</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="snapshotsCheckbox">
|
||||
<property name="text">
|
||||
<string>Snapshots</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="oldSnapshotsCheckbox">
|
||||
<property name="text">
|
||||
<string>Old Snapshots</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="betasCheckbox">
|
||||
<property name="text">
|
||||
<string>Betas</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="alphasCheckbox">
|
||||
<property name="text">
|
||||
<string>Alphas</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="refreshButton">
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QProgressBar" name="loadProgressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="VersionListView" name="listView">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="headerHidden">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="headerCascadingSectionResizes">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>VersionListView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>widgets/VersionListView.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user