diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-01-05 04:05:08 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-01-05 04:05:08 +0100 |
commit | e1bd1c614519974d7bfc0efc8dcbfafa9418e2fa (patch) | |
tree | 2592a85455ff45925eaa19e8023061a5089be89a /application/dialogs | |
parent | 4c0db2b99decf407b1f5cf0afc6f29db87ac03ca (diff) | |
download | MultiMC-e1bd1c614519974d7bfc0efc8dcbfafa9418e2fa.tar MultiMC-e1bd1c614519974d7bfc0efc8dcbfafa9418e2fa.tar.gz MultiMC-e1bd1c614519974d7bfc0efc8dcbfafa9418e2fa.tar.lz MultiMC-e1bd1c614519974d7bfc0efc8dcbfafa9418e2fa.tar.xz MultiMC-e1bd1c614519974d7bfc0efc8dcbfafa9418e2fa.zip |
NOISSUE feature complete setup wizard
Diffstat (limited to 'application/dialogs')
-rw-r--r-- | application/dialogs/VersionSelectDialog.cpp | 168 | ||||
-rw-r--r-- | application/dialogs/VersionSelectDialog.h | 36 | ||||
-rw-r--r-- | application/dialogs/VersionSelectDialog.ui | 120 |
3 files changed, 71 insertions, 253 deletions
diff --git a/application/dialogs/VersionSelectDialog.cpp b/application/dialogs/VersionSelectDialog.cpp index 50b543db..8290d6d6 100644 --- a/application/dialogs/VersionSelectDialog.cpp +++ b/application/dialogs/VersionSelectDialog.cpp @@ -14,9 +14,12 @@ */ #include "VersionSelectDialog.h" -#include "ui_VersionSelectDialog.h" -#include <QHeaderView> +#include <QtWidgets/QButtonGroup> +#include <QtWidgets/QDialogButtonBox> +#include <QtWidgets/QHBoxLayout> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QVBoxLayout> #include <dialogs/ProgressDialog.h> #include "CustomMessageBox.h" @@ -27,165 +30,102 @@ #include <QDebug> #include "MultiMC.h" #include <VersionProxyModel.h> +#include <widgets/VersionSelectWidget.h> -VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, - bool cancelable) - : QDialog(parent), ui(new Ui::VersionSelectDialog) +VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, bool cancelable) + : QDialog(parent) { - ui->setupUi(this); + setObjectName(QStringLiteral("VersionSelectDialog")); + resize(400, 347); + m_verticalLayout = new QVBoxLayout(this); + m_verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + + m_versionWidget = new VersionSelectWidget(vlist, parent); + m_verticalLayout->addWidget(m_versionWidget); + + m_horizontalLayout = new QHBoxLayout(); + m_horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); + + m_refreshButton = new QPushButton(this); + m_refreshButton->setObjectName(QStringLiteral("refreshButton")); + m_horizontalLayout->addWidget(m_refreshButton); + + m_buttonBox = new QDialogButtonBox(this); + m_buttonBox->setObjectName(QStringLiteral("buttonBox")); + m_buttonBox->setOrientation(Qt::Horizontal); + m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + m_horizontalLayout->addWidget(m_buttonBox); + + m_verticalLayout->addLayout(m_horizontalLayout); + + retranslate(); + + QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + QMetaObject::connectSlotsByName(this); setWindowModality(Qt::WindowModal); setWindowTitle(title); m_vlist = vlist; - m_proxyModel = new VersionProxyModel(this); - m_proxyModel->setSourceModel(vlist); - - ui->listView->setModel(m_proxyModel); - ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); - ui->sneakyProgressBar->setHidden(true); - if (!cancelable) { - ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); + m_buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); } } -void VersionSelectDialog::setEmptyString(QString emptyString) +void VersionSelectDialog::retranslate() { - ui->listView->setEmptyString(emptyString); + // FIXME: overrides custom title given in constructor! + setWindowTitle(QApplication::translate("VersionSelectDialog", "Choose Version", Q_NULLPTR)); + m_refreshButton->setToolTip(QApplication::translate("VersionSelectDialog", "Reloads the version list.", Q_NULLPTR)); + m_refreshButton->setText(QApplication::translate("VersionSelectDialog", "&Refresh", Q_NULLPTR)); } -void VersionSelectDialog::setEmptyErrorString(QString emptyErrorString) +void VersionSelectDialog::setEmptyString(QString emptyString) { - ui->listView->setEmptyErrorString(emptyErrorString); + m_versionWidget->setEmptyString(emptyString); } -VersionSelectDialog::~VersionSelectDialog() +void VersionSelectDialog::setEmptyErrorString(QString emptyErrorString) { - delete ui; + m_versionWidget->setEmptyErrorString(emptyErrorString); } void VersionSelectDialog::setResizeOn(int column) { - ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents); - resizeOnColumn = column; - ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); + m_versionWidget->setResizeOn(column); } int VersionSelectDialog::exec() { QDialog::open(); - if (!m_vlist->isLoaded()) - { - loadList(); - } - else - { - if (m_proxyModel->rowCount() == 0) - { - ui->listView->setEmptyMode(VersionListView::String); - } - preselect(); - } + m_versionWidget->initialize(); return QDialog::exec(); } -void VersionSelectDialog::closeEvent(QCloseEvent * event) -{ - if(loadTask) - { - loadTask->abort(); - loadTask->deleteLater(); - loadTask = nullptr; - } - QDialog::closeEvent(event); -} - -void VersionSelectDialog::loadList() -{ - if(loadTask) - { - return; - } - loadTask = m_vlist->getLoadTask(); - if (!loadTask) - { - return; - } - connect(loadTask, &Task::finished, this, &VersionSelectDialog::onTaskFinished); - connect(loadTask, &Task::progress, this, &VersionSelectDialog::changeProgress); - loadTask->start(); - ui->sneakyProgressBar->setHidden(false); -} - -void VersionSelectDialog::onTaskFinished() -{ - if (!loadTask->successful()) - { - CustomMessageBox::selectable(this, tr("Error"), - tr("List update failed:\n%1").arg(loadTask->failReason()), - QMessageBox::Warning)->show(); - if (m_proxyModel->rowCount() == 0) - { - ui->listView->setEmptyMode(VersionListView::ErrorString); - } - } - else if (m_proxyModel->rowCount() == 0) - { - ui->listView->setEmptyMode(VersionListView::String); - } - ui->sneakyProgressBar->setHidden(true); - loadTask->deleteLater(); - loadTask = nullptr; - preselect(); -} - -void VersionSelectDialog::changeProgress(qint64 current, qint64 total) -{ - ui->sneakyProgressBar->setMaximum(total); - ui->sneakyProgressBar->setValue(current); -} - -void VersionSelectDialog::preselect() -{ - if(preselectedAlready) - return; - preselectedAlready = true; - selectRecommended(); -} - void VersionSelectDialog::selectRecommended() { - auto idx = m_proxyModel->getRecommended(); - if(idx.isValid()) - { - ui->listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); - ui->listView->scrollTo(idx, QAbstractItemView::PositionAtCenter); - } + m_versionWidget->selectRecommended(); } BaseVersionPtr VersionSelectDialog::selectedVersion() const { - auto currentIndex = ui->listView->selectionModel()->currentIndex(); - auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole); - return variant.value<BaseVersionPtr>(); + return m_versionWidget->selectedVersion(); } void VersionSelectDialog::on_refreshButton_clicked() { - loadList(); + m_versionWidget->loadList(); } void VersionSelectDialog::setExactFilter(BaseVersionList::ModelRoles role, QString filter) { - m_proxyModel->setFilter(role, filter, true); + m_versionWidget->setExactFilter(role, filter); } void VersionSelectDialog::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter) { - m_proxyModel->setFilter(role, filter, false); + m_versionWidget->setFuzzyFilter(role, filter); } - -#include "VersionSelectDialog.moc" diff --git a/application/dialogs/VersionSelectDialog.h b/application/dialogs/VersionSelectDialog.h index 6b83535e..8916ce59 100644 --- a/application/dialogs/VersionSelectDialog.h +++ b/application/dialogs/VersionSelectDialog.h @@ -18,8 +18,15 @@ #include <QDialog> #include <QSortFilterProxyModel> + #include "BaseVersionList.h" +class QVBoxLayout; +class QHBoxLayout; +class QDialogButtonBox; +class VersionSelectWidget; +class QPushButton; + namespace Ui { class VersionSelectDialog; @@ -32,14 +39,10 @@ class VersionSelectDialog : public QDialog Q_OBJECT public: - explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0, - bool cancelable = true); - ~VersionSelectDialog(); - - virtual int exec(); + explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0, bool cancelable = true); + virtual ~VersionSelectDialog() {}; - //! Starts a task that loads the list. - void loadList(); + int exec() override; BaseVersionPtr selectedVersion() const; @@ -50,22 +53,19 @@ public: void setResizeOn(int column); void setUseLatest(const bool useLatest); -protected: - virtual void closeEvent ( QCloseEvent* ); - -private -slots: +private slots: void on_refreshButton_clicked(); - void onTaskFinished(); - void changeProgress(qint64 current, qint64 total); - private: - void preselect(); + void retranslate(); void selectRecommended(); private: - Ui::VersionSelectDialog *ui = nullptr; + VersionSelectWidget *m_versionWidget = nullptr; + QVBoxLayout *m_verticalLayout = nullptr; + QHBoxLayout *m_horizontalLayout = nullptr; + QPushButton *m_refreshButton = nullptr; + QDialogButtonBox *m_buttonBox = nullptr; BaseVersionList *m_vlist = nullptr; @@ -74,6 +74,4 @@ private: int resizeOnColumn = 0; Task * loadTask = nullptr; - - bool preselectedAlready = false; }; diff --git a/application/dialogs/VersionSelectDialog.ui b/application/dialogs/VersionSelectDialog.ui deleted file mode 100644 index 420e853d..00000000 --- a/application/dialogs/VersionSelectDialog.ui +++ /dev/null @@ -1,120 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>VersionSelectDialog</class> - <widget class="QDialog" name="VersionSelectDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>347</height> - </rect> - </property> - <property name="windowTitle"> - <string>Choose Version</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="VersionListView" name="listView"> - <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> - <attribute name="headerCascadingSectionResizes"> - <bool>true</bool> - </attribute> - <attribute name="headerStretchLastSection"> - <bool>false</bool> - </attribute> - </widget> - </item> - <item> - <widget class="QProgressBar" name="sneakyProgressBar"> - <property name="value"> - <number>24</number> - </property> - <property name="format"> - <string notr="true">%p%</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QPushButton" name="refreshButton"> - <property name="toolTip"> - <string>Reloads the version list.</string> - </property> - <property name="text"> - <string>&Refresh</string> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>VersionListView</class> - <extends>QTreeView</extends> - <header>widgets/VersionListView.h</header> - </customwidget> - </customwidgets> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>VersionSelectDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>257</x> - <y>290</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>VersionSelectDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>325</x> - <y>290</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> |