diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 828b2f2ba..b298f8a14 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -19,7 +19,6 @@ #include "utils/textinputdialog.hpp" #include "components/contentselector/view/contentselector.hpp" -#include "components/contentselector/model/contentmodel.hpp" #include @@ -28,176 +27,59 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , mGameSettings(gameSettings) , mLauncherSettings(launcherSettings) { - setupUi(this); -/* - // QMetaObject::connectSlotsByName(this); + unsigned char flags; - projectGroupBox->hide(); + flags = ContentSelectorView::Flag_Content | ContentSelectorView::Flag_Profile; - // Create a dialog for the new profile name input - mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this); + ContentSelectorView::ContentSelector::configure(this, flags); - connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString))); - - - - buildContentModel(); - buildGameFileView(); - buildAddonView(); - buildProfilesView(); - - - createActions(); setupDataFiles(); + ContentSelectorView::ContentSelector &cSelector = + ContentSelectorView::ContentSelector::instance(); - updateViews();*/ -} - -void DataFilesPage::buildContentModel() -{ - mContentModel = new ContentSelectorModel::ContentModel(); - connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); -} - -void DataFilesPage::buildGameFileView() -{ - mGameFileProxyModel = new QSortFilterProxyModel(this); - mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile)); - mGameFileProxyModel->setFilterRole (Qt::UserRole); - mGameFileProxyModel->setSourceModel (mContentModel); - - gameFileView->setPlaceholderText(QString("Select a game file...")); - gameFileView->setModel(mGameFileProxyModel); - - connect(gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentGameFileIndexChanged(int))); - - gameFileView->setCurrentIndex(-1); - gameFileView->setCurrentIndex(0); -} - -void DataFilesPage::buildAddonView() -{ - mAddonProxyModel = new QSortFilterProxyModel(this); - mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon)); - mAddonProxyModel->setFilterRole (Qt::UserRole); - mAddonProxyModel->setDynamicSortFilter (true); - mAddonProxyModel->setSourceModel (mContentModel); - - addonView->setModel(mAddonProxyModel); + connect (&cSelector, SIGNAL (signalProfileRenamed (QString, QString)), + this, SLOT (slotProfileRenamed (QString, QString))); - connect(addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &))); -} + connect (&cSelector, SIGNAL (signalProfileChanged (QString, QString)), + this, SLOT (slotProfileChanged (QString, QString))); -void DataFilesPage::buildProfilesView() -{ - profilesComboBox->setPlaceholderText(QString("Select a profile...")); - connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); -} + connect (&cSelector, SIGNAL (signalProfileDeleted (QString)), + this, SLOT (slotProfileDeleted (QString))); -void DataFilesPage::updateViews() -{ - // Ensure the columns are hidden because sort() re-enables them - addonView->setColumnHidden(1, true); - addonView->setColumnHidden(2, true); - addonView->setColumnHidden(3, true); - addonView->setColumnHidden(4, true); - addonView->setColumnHidden(5, true); - addonView->setColumnHidden(6, true); - addonView->setColumnHidden(7, true); - addonView->setColumnHidden(8, true); - addonView->resizeColumnsToContents(); -} - -void ContentSelectorView::ContentSelector::addFiles(const QString &path) -{ - // mContentModel->addFiles(path); - //mContentModel->sort(3); // Sort by date accessed - // ui.gameFileView->setCurrentIndex(-1); - // mContentModel->uncheckAll(); -} - -void DataFilesPage::createActions() -{ - // Add the actions to the toolbuttons - newProfileButton->setDefaultAction(newProfileAction); - deleteProfileButton->setDefaultAction(deleteProfileAction); -} - -void DataFilesPage::setupDataFiles() -{ - // Set the encoding to the one found in openmw.cfg or the default - //mContentSelector.setEncoding(mGameSettings.value(QString("encoding"), QString("win1252"))); - - QStringList paths = mGameSettings.getDataDirs(); - - foreach (const QString &path, paths) { - //mContentSelector. - mContentModel->addFiles(path); - } - - QString dataLocal = mGameSettings.getDataLocal(); - if (!dataLocal.isEmpty()) - //mContentSelector. - mContentModel->addFiles(dataLocal); - - // Sort by date accessed for now - //mContentSelector->sort(3); - - QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/")); - QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); - - if (!profiles.isEmpty()) - profilesComboBox->addItems(profiles); - - // Add the current profile if empty - if (profilesComboBox->findText(profile) == -1 && !profile.isEmpty()) - profilesComboBox->addItem(profile); - - if (profilesComboBox->findText(QString("Default")) == -1) - profilesComboBox->addItem(QString("Default")); - - if (profile.isEmpty() || profile == QLatin1String("Default")) { - deleteProfileAction->setEnabled(false); - profilesComboBox->setEditEnabled(false); - profilesComboBox->setCurrentIndex(profilesComboBox->findText(QString("Default"))); - } else { - profilesComboBox->setEditEnabled(true); - profilesComboBox->setCurrentIndex(profilesComboBox->findText(profile)); - } - - // We do this here to prevent deletion of profiles when initializing the combobox - connect(profilesComboBox, SIGNAL(profileRenamed(QString,QString)), this, SLOT(profileRenamed(QString,QString))); - connect(profilesComboBox, SIGNAL(profileChanged(QString,QString)), this, SLOT(profileChanged(QString,QString))); - - loadSettings(); - - gameFileView->setCurrentIndex(-1); + connect (&cSelector, SIGNAL (signalProfileAdded ()), + this, SLOT (slotProfileAdded ())); } void DataFilesPage::loadSettings() { + QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); if (profile.isEmpty()) return; - // mContentSelector. - mContentModel->uncheckAll(); - - QStringList gameFiles = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly); + QStringList files = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly); QStringList addons = mLauncherSettings.values(QString("Profiles/") + profile + QString("/plugin"), Qt::MatchExactly); + + foreach (const QString &file, addons) + files.append(file); + + //ContentSelectorView::ContentSelector::instance().setCheckStates(files); } void DataFilesPage::saveSettings() { - if (mContentModel->rowCount() < 1) - return; + ContentSelectorModel::ContentFileList items = + ContentSelectorView::ContentSelector::instance().selectedFiles(); + + if (items.size() == 0) + return; QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); if (profile.isEmpty()) { - profile = profilesComboBox->currentText(); + profile = ContentSelectorView::ContentSelector::instance().getProfileText(); mLauncherSettings.setValue(QString("Profiles/currentprofile"), profile); } @@ -207,8 +89,6 @@ void DataFilesPage::saveSettings() mGameSettings.remove(QString("master")); mGameSettings.remove(QString("plugin")); - ContentSelectorModel::ContentFileList items = mContentModel->checkedItems(); - foreach(const ContentSelectorModel::EsmFile *item, items) { if (item->gameFiles().size() == 0) { @@ -223,109 +103,18 @@ void DataFilesPage::saveSettings() } -void DataFilesPage::updateOkButton(const QString &text) +void DataFilesPage::slotProfileDeleted (const QString &item) { - // We do this here because we need the profiles combobox text - if (text.isEmpty()) { - mNewProfileDialog->setOkButtonEnabled(false); - return; - } - - (profilesComboBox->findText(text) == -1) - ? mNewProfileDialog->setOkButtonEnabled(true) - : mNewProfileDialog->setOkButtonEnabled(false); -} - -void DataFilesPage::setProfilesComboBoxIndex(int index) -{ - profilesComboBox->setCurrentIndex(index); -} - -QAbstractItemModel* DataFilesPage::profilesComboBoxModel() -{ - return profilesComboBox->model(); -} - -int DataFilesPage::profilesComboBoxIndex() -{ - return profilesComboBox->currentIndex(); -} - -void DataFilesPage::on_newProfileAction_triggered() -{ - if (mNewProfileDialog->exec() == QDialog::Accepted) { - QString profile = mNewProfileDialog->lineEdit()->text(); - profilesComboBox->addItem(profile); - profilesComboBox->setCurrentIndex(profilesComboBox->findText(profile)); - } -} - -void DataFilesPage::on_deleteProfileAction_triggered() -{ - QString profile = profilesComboBox->currentText(); - - if (profile.isEmpty()) - return; - - QMessageBox msgBox(this); - msgBox.setWindowTitle(tr("Delete Profile")); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setStandardButtons(QMessageBox::Cancel); - msgBox.setText(tr("Are you sure you want to delete %0?").arg(profile)); - - QAbstractButton *deleteButton = - msgBox.addButton(tr("Delete"), QMessageBox::ActionRole); - - msgBox.exec(); - - if (msgBox.clickedButton() == deleteButton) { - mLauncherSettings.remove(QString("Profiles/") + profile + QString("/master")); - mLauncherSettings.remove(QString("Profiles/") + profile + QString("/plugin")); - - // Remove the profile from the combobox - profilesComboBox->removeItem(profilesComboBox->findText(profile)); - } -} - -void DataFilesPage::setPluginsCheckstates(Qt::CheckState state) -{ - if (!addonView->selectionModel()->hasSelection()) { - return; - } - - QModelIndexList indexes = addonView->selectionModel()->selectedIndexes(); - - foreach (const QModelIndex &index, indexes) - { - if (!index.isValid()) - return; - - QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index); - - if (!sourceIndex.isValid()) - return; - - //bool isChecked = ( state == Qt::Checked ); - - mContentModel->setData(sourceIndex, state, Qt::CheckStateRole); - } + mLauncherSettings.remove(QString("Profiles/") + item + QString("/master")); + mLauncherSettings.remove(QString("Profiles/") + item + QString("/plugin")); } -void DataFilesPage::profileChanged(const QString &previous, const QString ¤t) +void DataFilesPage::slotProfileChanged(const QString &previous, const QString ¤t) { - // Prevent the deletion of the default profile - if (current == QLatin1String("Default")) { - deleteProfileAction->setEnabled(false); - profilesComboBox->setEditEnabled(false); - } else { - deleteProfileAction->setEnabled(true); - profilesComboBox->setEditEnabled(true); - } - if (previous.isEmpty()) return; - if (profilesComboBox->findText(previous) == -1) + if (ContentSelectorView::ContentSelector::instance().getProfileIndex (previous) == -1) return; // Profile was deleted // Store the previous profile @@ -336,7 +125,7 @@ void DataFilesPage::profileChanged(const QString &previous, const QString &curre loadSettings(); } -void DataFilesPage::profileRenamed(const QString &previous, const QString ¤t) +void DataFilesPage::slotProfileRenamed(const QString &previous, const QString ¤t) { if (previous.isEmpty()) return; @@ -350,56 +139,55 @@ void DataFilesPage::profileRenamed(const QString &previous, const QString &curre mLauncherSettings.remove(QString("Profiles/") + previous + QString("/plugin")); // Remove the profile from the combobox - profilesComboBox->removeItem(profilesComboBox->findText(previous)); + ContentSelectorView::ContentSelector::instance().removeProfile (previous); loadSettings(); - } -//////////////////////////// -QStringList DataFilesPage::checkedItemsPaths() +void DataFilesPage::slotProfileAdded() { - QStringList itemPaths; + TextInputDialog newDialog (tr("New Profile"), tr("Profile name:"), this); - foreach( const ContentSelectorModel::EsmFile *file, mContentModel->checkedItems()) - itemPaths << file->path(); + // connect(mNewDialog->lineEdit(), SIGNAL(textChanged(QString)), + // this, SLOT(updateOkButton(QString))); - return itemPaths; + if (newDialog.exec() == QDialog::Accepted) + { + QString profile = newDialog.lineEdit()->text(); + + ContentSelectorView::ContentSelector + ::instance().addProfile(profile, true); + } } -void DataFilesPage::slotCurrentProfileIndexChanged(int index) +void DataFilesPage::setProfilesComboBoxIndex(int index) { - emit profileChanged(index); + ContentSelectorView::ContentSelector::instance().setProfileIndex(index); } -void DataFilesPage::slotCurrentGameFileIndexChanged(int index) +void DataFilesPage::setupDataFiles() { - static int oldIndex = -1; + ContentSelectorView::ContentSelector &cSelector = + ContentSelectorView::ContentSelector::instance(); + + QStringList paths = mGameSettings.getDataDirs(); - QAbstractItemModel *const model = gameFileView->model(); - QSortFilterProxyModel *proxy = dynamic_cast(model); + foreach (const QString &path, paths) + cSelector.addFiles(path); - if (proxy) - proxy->setDynamicSortFilter(false); + QString dataLocal = mGameSettings.getDataLocal(); - if (oldIndex > -1) - model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); + if (!dataLocal.isEmpty()) + cSelector.addFiles(dataLocal); - oldIndex = index; + QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/")); + QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); - model->setData(model->index(index, 0), true, Qt::UserRole + 1); - if (proxy) - proxy->setDynamicSortFilter(true); -} + foreach (const QString &item, profiles) + cSelector.addProfile (item); -void DataFilesPage::slotAddonTableItemClicked(const QModelIndex &index) -{ - QAbstractItemModel *const model = addonView->model(); - //QSortFilterProxyModel *proxy = dynamic_cast(model); + cSelector.addProfile (profile, true); - if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) - model->setData(index, Qt::Checked, Qt::CheckStateRole); - else - model->setData(index, Qt::Unchecked, Qt::CheckStateRole); + loadSettings(); } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 9c7b0538e..6ed5d9ce9 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -4,9 +4,6 @@ #include #include -#include "ui_datafilespage.h" -#include "components/contentselector/view/contentselector.hpp" - class QSortFilterProxyModel; class QAbstractItemModel; class QAction; @@ -19,7 +16,7 @@ class LauncherSettings; namespace Files { struct ConfigurationManager; } -class DataFilesPage : public QWidget, private Ui::DataFilesPage +class DataFilesPage : public QWidget { Q_OBJECT @@ -36,58 +33,33 @@ signals: void profileChanged(int index); public slots: - void setProfilesComboBoxIndex(int index); + //void showContextMenu(const QPoint &point); - //void showContextMenu(const QPoint &point); - void profileChanged(const QString &previous, const QString ¤t); - void profileRenamed(const QString &previous, const QString ¤t); - void updateOkButton(const QString &text); - void updateViews(); - // Action slots - void on_newProfileAction_triggered(); - void on_deleteProfileAction_triggered(); private slots: + void slotProfileAdded(); + void slotProfileChanged(const QString &previous, const QString ¤t); + void slotProfileRenamed(const QString &previous, const QString ¤t); + void slotProfileDeleted(const QString &item); + void setProfilesComboBoxIndex(int index); + private: QMenu *mContextMenu; - //ContentSelectorView::ContentSelector mContentSelector; - ContentSelectorModel::ContentModel *mContentModel; + Files::ConfigurationManager &mCfgMgr; GameSettings &mGameSettings; LauncherSettings &mLauncherSettings; - TextInputDialog *mNewProfileDialog; - QSortFilterProxyModel *mGameFileProxyModel; - QSortFilterProxyModel *mAddonProxyModel; - void setPluginsCheckstates(Qt::CheckState state); - void createActions(); void setupDataFiles(); void setupConfig(); void readConfig(); void loadSettings(); - - ////////////////////////////////////// - void buildContentModel(); - void buildGameFileView(); - void buildAddonView(); - void buildProfilesView(); - - //void addFiles(const QString &path); - - QStringList checkedItemsPaths(); - -private slots: - void slotCurrentProfileIndexChanged(int index); - void slotCurrentGameFileIndexChanged(int index); - void slotAddonTableItemClicked(const QModelIndex &index); - - }; #endif diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 032f70916..311e3a25c 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -106,10 +106,10 @@ void MainDialog::createPages() mPlayPage = new PlayPage(this); mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this); mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, mLauncherSettings, this); - +/// reimplement datafilespage functions to provide access // Set the combobox of the play page to imitate the combobox on the datafilespage - mPlayPage->setProfilesComboBoxModel(mDataFilesPage->profilesComboBoxModel()); - mPlayPage->setProfilesComboBoxIndex(mDataFilesPage->profilesComboBoxIndex()); + // mPlayPage->setProfilesComboBoxModel(mDataFilesPage->profilesComboBoxModel()); + // mPlayPage->setProfilesComboBoxIndex(mDataFilesPage->profilesComboBoxIndex()); // Add the pages to the stacked widget pagesWidget->addWidget(mPlayPage); diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 00547a2ba..9ae12c7a7 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -43,8 +43,7 @@ opencs_units_noqt (model/tools opencs_units (view/doc - viewmanager view operations operation subview startup filedialog newgame filewidget - adjusterwidget + viewmanager view operations operation subview startup filedialog newgame ) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index fc9168e2e..401f3839f 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -124,7 +124,7 @@ void CS::Editor::openFiles() { std::vector files; - foreach (const QString &path, mFileDialog.selectedFilepaths()) { + foreach (const QString &path, mFileDialog.selectedFilePaths()) { files.push_back(path.toStdString()); } @@ -139,7 +139,7 @@ void CS::Editor::createNewFile() { std::vector files; - foreach (const QString &path, mFileDialog.selectedFilepaths()) { + foreach (const QString &path, mFileDialog.selectedFilePaths()) { files.push_back(path.toStdString()); } diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 5a97a7a26..b1b72dc1f 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -37,9 +37,16 @@ QString CSVDoc::FileDialog::filename() return ContentSelectorView::ContentSelector::instance().filename(); } -QStringList CSVDoc::FileDialog::selectedFilepaths() +QStringList CSVDoc::FileDialog::selectedFilePaths() { - return ContentSelectorView::ContentSelector::instance().selectedFiles(); + QStringList filePaths; + + foreach (ContentSelectorModel::EsmFile *file, ContentSelectorView::ContentSelector:: + instance().selectedFiles() ) + { + filePaths.append(file->fileName()); + } + return filePaths; } void CSVDoc::FileDialog::showDialog() diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 88d408b5c..acc35189d 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -41,7 +41,7 @@ namespace CSVDoc void addFiles (const QString &path); QString filename(); - QStringList selectedFilepaths(); + QStringList selectedFilePaths(); private: diff --git a/apps/opencs/view/doc/newgame.cpp b/apps/opencs/view/doc/newgame.cpp index 98681c499..265b98305 100644 --- a/apps/opencs/view/doc/newgame.cpp +++ b/apps/opencs/view/doc/newgame.cpp @@ -7,8 +7,8 @@ #include #include -#include "filewidget.hpp" -#include "adjusterwidget.hpp" +#include "components/contentselector/view/filewidget.hpp" +#include "components/contentselector/view/adjusterwidget.hpp" CSVDoc::NewGameDialogue::NewGameDialogue() { diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 7053bb973..ebce4578b 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -84,6 +84,7 @@ if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) model/naturalsort model/contentmodel view/profilescombobox view/comboboxlineedit view/lineedit view/contentselector + view/filewidget view/adjusterwidget ) include(${QT_USE_FILE}) diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/components/contentselector/view/adjusterwidget.cpp similarity index 100% rename from apps/opencs/view/doc/adjusterwidget.cpp rename to components/contentselector/view/adjusterwidget.cpp diff --git a/apps/opencs/view/doc/adjusterwidget.hpp b/components/contentselector/view/adjusterwidget.hpp similarity index 100% rename from apps/opencs/view/doc/adjusterwidget.hpp rename to components/contentselector/view/adjusterwidget.hpp diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index d9caea3be..cb0774f68 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -1,7 +1,7 @@ #include "contentselector.hpp" -#include "../model/contentmodel.hpp" #include "../model/esmfile.hpp" +#include "lineedit.hpp" #include @@ -9,10 +9,11 @@ #include #include #include +#include #include -#include "../../../apps/opencs/view/doc/filewidget.hpp" -#include "../../../apps/opencs/view/doc/adjusterwidget.hpp" +#include "filewidget.hpp" +#include "adjusterwidget.hpp" ContentSelectorView::ContentSelector *ContentSelectorView::ContentSelector::mInstance = 0; QStringList ContentSelectorView::ContentSelector::mFilePaths; @@ -25,6 +26,7 @@ void ContentSelectorView::ContentSelector::configure(QWidget *subject, unsigned ContentSelectorView::ContentSelector& ContentSelectorView::ContentSelector::instance() { + assert(mInstance); return *mInstance; } @@ -33,6 +35,7 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned QWidget(parent), mFlags (flags), mAdjusterWidget (0), mFileWidget (0) { + ui.setupUi (this); parent->setLayout(new QGridLayout()); @@ -41,15 +44,23 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned buildContentModel(); buildGameFileView(); buildAddonView(); - buildProfilesView(); buildNewAddonView(); buildLoadAddonView(); + buildProfilesView(); /* //mContentModel->sort(3); // Sort by date accessed */ } +QString ContentSelectorView::ContentSelector::getNewProfileName() +{ + // Create a dialog for the new profile name input + //mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this); + + //connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString))); + return ""; +} bool ContentSelectorView::ContentSelector::isFlagged(SelectorFlags flag) const { @@ -123,8 +134,17 @@ void ContentSelectorView::ContentSelector::buildProfilesView() return; } - ui.profilesComboBox->setPlaceholderText(QString("Select a profile...")); - connect(ui.profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); + // Add the actions to the toolbuttons + ui.newProfileButton->setDefaultAction (ui.newProfileAction); + ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction); + + ui.profilesComboBox->addItem ("Default"); + ui.profilesComboBox->setPlaceholderText (QString("Select a profile...")); + + connect (ui.profilesComboBox, SIGNAL (currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); + connect (ui.profilesComboBox, SIGNAL (profileRenamed(QString,QString)), this, SIGNAL(signalProfileRenamed(QString,QString))); + connect (ui.profilesComboBox, SIGNAL (profileChanged(QString,QString)), this, SIGNAL(signalProfileChanged(QString,QString))); + connect (ui.profilesComboBox, SIGNAL (signalProfileTextChanged(QString)), this, SLOT (slotProfileTextChanged (QString))); } void ContentSelectorView::ContentSelector::buildLoadAddonView() @@ -136,7 +156,6 @@ void ContentSelectorView::ContentSelector::buildLoadAddonView() } ui.projectCreateButton->setVisible (false); - // ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Open | QDialogButtonBox::Cancel); ui.projectGroupBox->setTitle (""); connect(ui.projectButtonBox, SIGNAL(accepted()), this, SIGNAL(accepted())); @@ -172,6 +191,17 @@ void ContentSelectorView::ContentSelector::buildNewAddonView() connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected())); } +void ContentSelectorView::ContentSelector::setCheckStates(const QStringList &list) +{ + if (list.isEmpty()) + return; + + mContentModel->uncheckAll(); + + foreach (const QString &file, list) + mContentModel->setCheckState(file, Qt::Checked); +} + QString ContentSelectorView::ContentSelector::filename() const { QString filepath = ""; @@ -182,7 +212,7 @@ QString ContentSelectorView::ContentSelector::filename() const return filepath; } -QStringList ContentSelectorView::ContentSelector::selectedFiles() const +QStringList ContentSelectorView::ContentSelector::selectedFilePaths() const { QStringList filePaths; @@ -195,6 +225,15 @@ QStringList ContentSelectorView::ContentSelector::selectedFiles() const return filePaths; } +ContentSelectorModel::ContentFileList + ContentSelectorView::ContentSelector::selectedFiles() const +{ + if (mContentModel) + return mContentModel->checkedItems(); + + return ContentSelectorModel::ContentFileList(); +} + void ContentSelectorView::ContentSelector::addFiles(const QString &path) { @@ -209,6 +248,55 @@ void ContentSelectorView::ContentSelector::addFiles(const QString &path) } } +void ContentSelectorView::ContentSelector::removeProfile(const QString &item) +{ + int idx = ui.profilesComboBox->findText(item); + + if (idx != -1) + ui.profilesComboBox->removeItem(idx); +} + +int ContentSelectorView::ContentSelector::getProfileIndex ( const QString &item) const +{ + return ui.profilesComboBox->findText (item); +} + +void ContentSelectorView::ContentSelector::setProfileIndex(int index) +{ + if (index >=0 && index < ui.profilesComboBox->count()) + ui.profilesComboBox->setCurrentIndex(index); +} + +void ContentSelectorView::ContentSelector::addProfile (const QString &item, bool setAsCurrent) +{ + if (item.isEmpty()) + return; + + if (ui.profilesComboBox->findText(item) == -1) + ui.profilesComboBox->addItem(item); + + if (setAsCurrent) + ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(item)); + + enableProfilesComboBox(); +} + +QString ContentSelectorView::ContentSelector::getProfileText() const +{ + return ui.profilesComboBox->currentText(); +} + +void ContentSelectorView::ContentSelector::enableProfilesComboBox() +{ + if (!ui.profilesComboBox->isEnabled()) + ui.profilesComboBox->setEnabled(true); + + if (!ui.deleteProfileAction->isEnabled()) + ui.deleteProfileAction->setEnabled(true); + + ui.projectButtonBox->button(QDialogButtonBox::Open)->setEnabled (true); +} + QStringList ContentSelectorView::ContentSelector::checkedItemsPaths() { QStringList itemPaths; @@ -221,6 +309,12 @@ QStringList ContentSelectorView::ContentSelector::checkedItemsPaths() void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index) { + //don't allow deleting "Default" profile + bool success = (ui.profilesComboBox->itemText(index) == "Default"); + + ui.deleteProfileAction->setEnabled(success); + ui.profilesComboBox->setEditEnabled(success); + emit signalProfileChanged(index); } @@ -247,6 +341,14 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i slotUpdateCreateButton(true); } +void ContentSelectorView::ContentSelector::slotProfileTextChanged(const QString &text) +{ + QPushButton *opnBtn = ui.projectButtonBox->button(QDialogButtonBox::Open); + + if (opnBtn->isEnabled()) + opnBtn->setEnabled (false); +} + void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index) { QAbstractItemModel *const model = ui.addonView->model(); @@ -257,16 +359,6 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QMode model->setData(index, Qt::Unchecked, Qt::CheckStateRole); } -void ContentSelectorView::ContentSelector::slotUpdateOpenButton(const QStringList &items) -{ - QPushButton *openButton = ui.projectButtonBox->button(QDialogButtonBox::Open); - - if (!openButton) - return; - - openButton->setEnabled(!items.isEmpty()); -} - void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool) { //enable only if a game file is selected and the adjuster widget is non-empty @@ -278,3 +370,44 @@ void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool) ui.projectCreateButton->setEnabled(validGameFile && validFilename); } + + +void ContentSelectorView::ContentSelector::on_newProfileAction_triggered() +{ + emit signalProfileAdded(); +} + +void ContentSelectorView::ContentSelector::on_deleteProfileAction_triggered() +{ + QString profile = ui.profilesComboBox->currentText(); + + if (profile.isEmpty()) + return; + + QMessageBox msgBox(this); + msgBox.setWindowTitle(tr("Delete Profile")); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setText(tr("Are you sure you want to delete %0?").arg(profile)); + + QAbstractButton *deleteButton = + msgBox.addButton(tr("Delete"), QMessageBox::ActionRole); + + msgBox.exec(); + + if (msgBox.clickedButton() != deleteButton) + return; + + // Remove the profile from the combobox + ui.profilesComboBox->removeItem(ui.profilesComboBox->findText(profile)); + + //signal for removal from model + emit signalProfileDeleted (profile); +} +/* +void ContentSelectorView::ContentSelector::slotUpdateOkButton(const QString &text) +{ + bool success = (ui.profilesComboBox->findText(text) == -1); + + mNewDialog->setOkButtonEnabled(success); +}*/ diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 48c3ae103..caf9cc670 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -4,10 +4,10 @@ #include #include "ui_datafilespage.h" - -namespace ContentSelectorModel { class ContentModel; } +#include "../model/contentmodel.hpp" class QSortFilterProxyModel; +class TextInputDialog; namespace CSVDoc { @@ -36,6 +36,8 @@ namespace ContentSelectorView CSVDoc::FileWidget *mFileWidget; CSVDoc::AdjusterWidget *mAdjusterWidget; + TextInputDialog *mNewDialog; + protected: ContentSelectorModel::ContentModel *mContentModel; @@ -43,19 +45,28 @@ namespace ContentSelectorView QSortFilterProxyModel *mAddonProxyModel; public: + explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content); static void configure(QWidget *subject, unsigned char flags = Flag_Content); static ContentSelector &instance(); static void addFiles(const QString &path); - void setCheckState(QModelIndex index, QSortFilterProxyModel *model); + void setCheckStates (const QStringList &list); QStringList checkedItemsPaths(); + ContentSelectorModel::ContentFileList *CheckedItems(); + QString filename() const; - QStringList selectedFiles() const; + ContentSelectorModel::ContentFileList selectedFiles() const; + QStringList selectedFilePaths() const; + + void addProfile (const QString &item, bool setAsCurrent = false); + void removeProfile (const QString &item); + int getProfileIndex (const QString &item) const; + void setProfileIndex (int index); + QString getProfileText() const; private: - explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content); Ui::DataFilesPage ui; void buildContentModel(); @@ -66,6 +77,8 @@ namespace ContentSelectorView void buildLoadAddonView(); bool isFlagged(SelectorFlags flag) const; + QString getNewProfileName(); + void enableProfilesComboBox(); signals: void accepted(); @@ -76,14 +89,24 @@ namespace ContentSelectorView void signalCreateButtonClicked(); + void signalProfileRenamed(QString,QString); + void signalProfileChanged(QString,QString); + void signalProfileDeleted(QString); + void signalProfileAdded(); + private slots: + void slotProfileTextChanged (const QString &text); void slotCurrentProfileIndexChanged(int index); void slotCurrentGameFileIndexChanged(int index); void slotAddonTableItemClicked(const QModelIndex &index); void slotUpdateCreateButton (bool); - void slotUpdateOpenButton(const QStringList &items); + // void slotUpdateOpenButton(const QStringList &items); + + // Action slots + void on_newProfileAction_triggered(); + void on_deleteProfileAction_triggered(); }; } diff --git a/apps/opencs/view/doc/filewidget.cpp b/components/contentselector/view/filewidget.cpp similarity index 100% rename from apps/opencs/view/doc/filewidget.cpp rename to components/contentselector/view/filewidget.cpp diff --git a/apps/opencs/view/doc/filewidget.hpp b/components/contentselector/view/filewidget.hpp similarity index 100% rename from apps/opencs/view/doc/filewidget.hpp rename to components/contentselector/view/filewidget.hpp diff --git a/components/contentselector/view/profilescombobox.cpp b/components/contentselector/view/profilescombobox.cpp index cb0ba7b77..29001189d 100644 --- a/components/contentselector/view/profilescombobox.cpp +++ b/components/contentselector/view/profilescombobox.cpp @@ -45,6 +45,9 @@ void ContentSelectorView::ProfilesComboBox::setEditEnabled(bool editable) connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString))); + + connect (lineEdit(), SIGNAL(textChanged(QString)), this, + SIGNAL (signalProfileTextChanged (QString))); } void ContentSelectorView::ProfilesComboBox::slotTextChanged(const QString &text) diff --git a/components/contentselector/view/profilescombobox.hpp b/components/contentselector/view/profilescombobox.hpp index d81c1e6a5..560c42c10 100644 --- a/components/contentselector/view/profilescombobox.hpp +++ b/components/contentselector/view/profilescombobox.hpp @@ -17,10 +17,12 @@ namespace ContentSelectorView void setPlaceholderText (const QString &text); signals: + void signalProfileTextChanged (const QString &item); void profileChanged(const QString &previous, const QString ¤t); void profileRenamed(const QString &oldName, const QString &newName); private slots: + void slotEditingFinished(); void slotIndexChanged(int index); void slotTextChanged(const QString &text); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 949407759..73d7a4902 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -7,7 +7,7 @@ 0 0 518 - 313 + 424 @@ -26,6 +26,9 @@ Content + + 3 + @@ -116,6 +119,18 @@ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + 3 + + + 6 + + + 6 + + + 0 + @@ -143,18 +158,17 @@ - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Open - - - false + + + 0 + 0 + + Create @@ -209,7 +223,7 @@ 3 - 9 + 6 0 @@ -220,7 +234,7 @@ - true + false @@ -228,6 +242,11 @@ 0 + + + Default + + @@ -262,6 +281,13 @@ + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Open + + + @@ -280,6 +306,9 @@ + + false +