diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 8d2208c9df..aa3970efdb 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -41,7 +41,6 @@ set(LAUNCHER_UI ${CMAKE_CURRENT_SOURCE_DIR}/ui/importpage.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/settingspage.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/directorypicker.ui - ${CMAKE_SOURCE_DIR}/components/contentselector/contentselector.ui ) source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER}) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index cea2b66331..70efd06090 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -139,7 +139,6 @@ set (OPENCS_RES ${CMAKE_SOURCE_DIR}/files/opencs/resources.qrc ) set (OPENCS_UI - ${CMAKE_SOURCE_DIR}/components/contentselector/contentselector.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/filedialog.ui ) diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 62d476b944..3f75b82487 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -1,5 +1,7 @@ #include "contentselector.hpp" +#include "ui_contentselector.h" + #include #include @@ -9,14 +11,15 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool showOMWScripts) : QObject(parent) + , ui(std::make_unique()) { - ui.setupUi(parent); - ui.addonView->setDragDropMode(QAbstractItemView::InternalMove); + ui->setupUi(parent); + ui->addonView->setDragDropMode(QAbstractItemView::InternalMove); if (!showOMWScripts) { - ui.languageComboBox->setHidden(true); - ui.refreshButton->setHidden(true); + ui->languageComboBox->setHidden(true); + ui->refreshButton->setHidden(true); } buildContentModel(showOMWScripts); @@ -24,21 +27,23 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool show buildAddonView(); } +ContentSelectorView::ContentSelector::~ContentSelector() = default; + void ContentSelectorView::ContentSelector::buildContentModel(bool showOMWScripts) { - QIcon warningIcon(ui.addonView->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(16, 15))); + QIcon warningIcon(ui->addonView->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(16, 15))); mContentModel = new ContentSelectorModel::ContentModel(this, warningIcon, showOMWScripts); } void ContentSelectorView::ContentSelector::buildGameFileView() { - ui.gameFileView->addItem(tr("")); - ui.gameFileView->setVisible(true); + ui->gameFileView->addItem(tr("")); + ui->gameFileView->setVisible(true); - connect(ui.gameFileView, qOverload(&ComboBox::currentIndexChanged), this, + connect(ui->gameFileView, qOverload(&ComboBox::currentIndexChanged), this, &ContentSelector::slotCurrentGameFileIndexChanged); - ui.gameFileView->setCurrentIndex(0); + ui->gameFileView->setCurrentIndex(0); } class AddOnProxyModel : public QSortFilterProxyModel @@ -60,9 +65,34 @@ public: } }; +bool ContentSelectorView::ContentSelector::isGamefileSelected() const +{ + return ui->gameFileView->currentIndex() > 0; +} + +QWidget* ContentSelectorView::ContentSelector::uiWidget() const +{ + return ui->contentGroupBox; +} + +QComboBox* ContentSelectorView::ContentSelector::languageBox() const +{ + return ui->languageComboBox; +} + +QToolButton* ContentSelectorView::ContentSelector::refreshButton() const +{ + return ui->refreshButton; +} + +QLineEdit* ContentSelectorView::ContentSelector::searchFilter() const +{ + return ui->searchFilter; +} + void ContentSelectorView::ContentSelector::buildAddonView() { - ui.addonView->setVisible(true); + ui->addonView->setVisible(true); mAddonProxyModel = new AddOnProxyModel(this); mAddonProxyModel->setFilterRegularExpression(searchFilter()->text()); @@ -70,12 +100,12 @@ void ContentSelectorView::ContentSelector::buildAddonView() mAddonProxyModel->setDynamicSortFilter(true); mAddonProxyModel->setSourceModel(mContentModel); - connect(ui.searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard); - connect(ui.searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged); + connect(ui->searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard); + connect(ui->searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged); - ui.addonView->setModel(mAddonProxyModel); + ui->addonView->setModel(mAddonProxyModel); - connect(ui.addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated); + connect(ui->addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated); connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this, &ContentSelector::signalAddonDataChanged); buildContextMenu(); @@ -83,10 +113,10 @@ void ContentSelectorView::ContentSelector::buildAddonView() void ContentSelectorView::ContentSelector::buildContextMenu() { - ui.addonView->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui.addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu); + ui->addonView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu); - mContextMenu = new QMenu(ui.addonView); + mContextMenu = new QMenu(ui->addonView); mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems())); mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems())); mContextMenu->addAction(tr("&Copy Path(s) to Clipboard"), this, SLOT(slotCopySelectedItemsPaths())); @@ -116,7 +146,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename) if (!filename.isEmpty()) { const ContentSelectorModel::EsmFile* file = mContentModel->item(filename); - index = ui.gameFileView->findText(file->fileName()); + index = ui->gameFileView->findText(file->fileName()); // verify that the current index is also checked in the model if (!mContentModel->setCheckState(filename, true)) @@ -126,7 +156,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename) } } - ui.gameFileView->setCurrentIndex(index); + ui->gameFileView->setCurrentIndex(index); } void ContentSelectorView::ContentSelector::clearCheckStates() @@ -143,7 +173,7 @@ void ContentSelectorView::ContentSelector::setContentList(const QStringList& lis { if (list.isEmpty()) { - slotCurrentGameFileIndexChanged(ui.gameFileView->currentIndex()); + slotCurrentGameFileIndexChanged(ui->gameFileView->currentIndex()); } else mContentModel->setContentList(list); @@ -164,14 +194,14 @@ void ContentSelectorView::ContentSelector::addFiles(const QString& path, bool ne // add any game files to the combo box for (const QString& gameFileName : mContentModel->gameFiles()) { - if (ui.gameFileView->findText(gameFileName) == -1) + if (ui->gameFileView->findText(gameFileName) == -1) { - ui.gameFileView->addItem(gameFileName); + ui->gameFileView->addItem(gameFileName); } } - if (ui.gameFileView->currentIndex() != 0) - ui.gameFileView->setCurrentIndex(0); + if (ui->gameFileView->currentIndex() != 0) + ui->gameFileView->setCurrentIndex(0); mContentModel->uncheckAll(); mContentModel->checkForLoadOrderErrors(); @@ -194,10 +224,10 @@ void ContentSelectorView::ContentSelector::clearFiles() QString ContentSelectorView::ContentSelector::currentFile() const { - QModelIndex currentIdx = ui.addonView->currentIndex(); + QModelIndex currentIdx = ui->addonView->currentIndex(); - if (!currentIdx.isValid() && ui.gameFileView->currentIndex() > 0) - return ui.gameFileView->currentText(); + if (!currentIdx.isValid() && ui->gameFileView->currentIndex() > 0) + return ui->gameFileView->currentText(); QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex()); return mContentModel->data(idx, Qt::DisplayRole).toString(); @@ -225,7 +255,7 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool selected) { - QString fileName = ui.gameFileView->itemText(index); + QString fileName = ui->gameFileView->itemText(index); const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName); if (file != nullptr) { @@ -253,14 +283,14 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QMo void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos) { - QPoint globalPos = ui.addonView->viewport()->mapToGlobal(pos); + QPoint globalPos = ui->addonView->viewport()->mapToGlobal(pos); mContextMenu->exec(globalPos); } void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked) { Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked; - for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes()) + for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes()) { QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index); if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState) @@ -284,7 +314,7 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths() { QClipboard* clipboard = QApplication::clipboard(); QString filepaths; - for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes()) + for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes()) { int row = mAddonProxyModel->mapToSource(index).row(); const ContentSelectorModel::EsmFile* file = mContentModel->item(row); @@ -299,5 +329,5 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths() void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QString& newText) { - ui.addonView->setDragEnabled(newText.isEmpty()); + ui->addonView->setDragEnabled(newText.isEmpty()); } diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 5919d2e516..48377acb86 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -1,13 +1,22 @@ #ifndef CONTENTSELECTOR_HPP #define CONTENTSELECTOR_HPP +#include + +#include #include +#include +#include -#include "ui_contentselector.h" #include class QSortFilterProxyModel; +namespace Ui +{ + class ContentSelector; +} + namespace ContentSelectorView { class ContentSelector : public QObject @@ -23,6 +32,8 @@ namespace ContentSelectorView public: explicit ContentSelector(QWidget* parent = nullptr, bool showOMWScripts = false); + ~ContentSelector() override; + QString currentFile() const; void addFiles(const QString& path, bool newfiles = false); @@ -39,18 +50,18 @@ namespace ContentSelectorView void setGameFile(const QString& filename = QString("")); - bool isGamefileSelected() const { return ui.gameFileView->currentIndex() > 0; } + bool isGamefileSelected() const; - QWidget* uiWidget() const { return ui.contentGroupBox; } + QWidget* uiWidget() const; - QComboBox* languageBox() const { return ui.languageComboBox; } + QComboBox* languageBox() const; - QToolButton* refreshButton() const { return ui.refreshButton; } + QToolButton* refreshButton() const; - QLineEdit* searchFilter() const { return ui.searchFilter; } + QLineEdit* searchFilter() const; private: - Ui::ContentSelector ui; + std::unique_ptr ui; void buildContentModel(bool showOMWScripts); void buildGameFileView();