diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 49dedd829..18c555a24 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -11,6 +11,9 @@ set(LAUNCHER settings/launchersettings.cpp utils/checkablemessagebox.cpp + utils/profilescombobox.cpp + utils/textinputdialog.cpp + utils/lineedit.cpp ${CMAKE_SOURCE_DIR}/files/launcher/launcher.rc ) @@ -31,6 +34,9 @@ set(LAUNCHER_HEADER settings/settingsbase.hpp utils/checkablemessagebox.hpp + utils/profilescombobox.hpp + utils/textinputdialog.hpp + utils/lineedit.hpp ) if(NOT WIN32) LIST(APPEND LAUNCHER_HEADER unshieldthread.hpp) @@ -45,7 +51,11 @@ set(LAUNCHER_HEADER_MOC playpage.hpp textslotmsgbox.hpp + utils/textinputdialog.hpp utils/checkablemessagebox.hpp + utils/profilescombobox.hpp + utils/lineedit.hpp + ) if(NOT WIN32) @@ -58,6 +68,7 @@ set(LAUNCHER_UI ${CMAKE_SOURCE_DIR}/files/ui/graphicspage.ui ${CMAKE_SOURCE_DIR}/files/ui/mainwindow.ui ${CMAKE_SOURCE_DIR}/files/ui/playpage.ui + ${CMAKE_SOURCE_DIR}/files/ui/contentselector.ui ) source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER}) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index a705ae37d..2140caaf9 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -5,14 +5,16 @@ #include #include #include +#include #include #include -#include #include -#include + +#include "utils/textinputdialog.hpp" +#include "utils/profilescombobox.hpp" #include "settings/gamesettings.hpp" #include "settings/launchersettings.hpp" @@ -25,45 +27,30 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam , mLauncherSettings(launcherSettings) , QWidget(parent) { - setObjectName ("DataFilesPage"); - - unsigned char flags; + ui.setupUi (this); - flags = ContentSelectorView::Flag_Content | ContentSelectorView::Flag_Profile; - - ContentSelectorView::ContentSelector::configure(this, flags); - mSelector = &ContentSelectorView::ContentSelector::instance(); + setObjectName ("DataFilesPage"); + mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget); + buildView(); setupDataFiles(); - - - connect (mSelector, SIGNAL (signalProfileRenamed (QString, QString)), - this, SLOT (slotProfileRenamed (QString, QString))); - - connect (mSelector, SIGNAL (signalProfileChangedByUser (QString, QString)), - this, SLOT (slotProfileChangedByUser (QString, QString))); - - connect (mSelector, SIGNAL (signalProfileDeleted (QString)), - this, SLOT (slotProfileDeleted (QString))); - - connect (mSelector, SIGNAL (signalAddNewProfile (QString)), - this, SLOT (slotAddNewProfile (QString))); } void DataFilesPage::loadSettings() { - QString profileName = mSelector->getProfileText(); + QString profileName = ui.profilesComboBox->currentText(); QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/game"), Qt::MatchExactly); QStringList addons = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/addon"), Qt::MatchExactly); mSelector->clearCheckStates(); - if (files.size() > 0) - mSelector->setGameFile(files.at(0)); - else - mSelector->setGameFile(); + QString gameFile (""); + if (files.size()>0) + gameFile = files.at (0); + + mSelector->setGameFile(gameFile); mSelector->setCheckStates(addons); } @@ -72,7 +59,7 @@ void DataFilesPage::saveSettings(const QString &profile) QString profileName = profile; if (profileName.isEmpty()) - profileName = mSelector->getProfileText(); + profileName = ui.profilesComboBox->currentText(); //retrieve the files selected for the profile ContentSelectorModel::ContentFileList items = mSelector->selectedFiles(); @@ -83,7 +70,7 @@ void DataFilesPage::saveSettings(const QString &profile) mGameSettings.remove(QString("addon")); //set the value of the current profile (not necessarily the profile being saved!) - mLauncherSettings.setValue(QString("Profiles/currentprofile"), mSelector->getProfileText()); + mLauncherSettings.setValue(QString("Profiles/currentprofile"), ui.profilesComboBox->currentText()); foreach(const ContentSelectorModel::EsmFile *item, items) { @@ -98,39 +85,64 @@ void DataFilesPage::saveSettings(const QString &profile) } +void DataFilesPage::buildView() +{ + ui.verticalLayout->insertWidget (0, mSelector->uiWidget()); + + //tool buttons + ui.newProfileButton->setToolTip ("Create a new profile"); + ui.deleteProfileButton->setToolTip ("Delete an existing profile"); + + //combo box + ui.profilesComboBox->addItem ("Default"); + ui.profilesComboBox->setPlaceholderText (QString("Select a profile...")); + + // Add the actions to the toolbuttons + ui.newProfileButton->setDefaultAction (ui.newProfileAction); + ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction); + + //establish connections + connect (ui.profilesComboBox, SIGNAL (currentIndexChanged(int)), + this, SLOT (slotProfileChanged(int))); + + connect (ui.profilesComboBox, SIGNAL (profileRenamed(QString, QString)), + this, SLOT (slotProfileRenamed(QString, QString))); + + connect (ui.profilesComboBox, SIGNAL (signalProfileChanged(QString, QString)), + this, SLOT (slotProfileChangedByUser(QString, QString))); +} + void DataFilesPage::removeProfile(const QString &profile) { mLauncherSettings.remove(QString("Profiles/") + profile + QString("/game")); mLauncherSettings.remove(QString("Profiles/") + profile + QString("/addon")); } -void DataFilesPage::changeProfiles(const QString &previous, const QString ¤t, bool savePrevious) +void DataFilesPage::setProfile(int index, bool savePrevious) { - //abort if no change (typically a duplicate signal) - if (previous == current) - return; + if (index >= -1 && index < ui.profilesComboBox->count()) + { + QString previous = ui.profilesComboBox->itemText(ui.profilesComboBox->currentIndex()); + QString current = ui.profilesComboBox->itemText(index); - int index = -1; + setProfile (previous, current, savePrevious); + } +} - if (!previous.isEmpty()) - index = mSelector->getProfileIndex(previous); +void DataFilesPage::setProfile (const QString &previous, const QString ¤t, bool savePrevious) +{ + //abort if no change (poss. duplicate signal) + if (previous == current) + return; - // Store the previous profile if it exists - if ( (index != -1) && savePrevious) - saveSettings(previous); + if (!previous.isEmpty() && savePrevious) + saveSettings (previous); - loadSettings(); -} + ui.profilesComboBox->setCurrentIndex (ui.profilesComboBox->findText (current)); -void DataFilesPage::slotAddNewProfile(const QString &profile) -{ - saveSettings(); - mSelector->clearCheckStates(); - mSelector->addProfile(profile, true); - mSelector->setGameFile(); - saveSettings(); + loadSettings(); - emit signalProfileChanged(mSelector->getProfileIndex(profile)); + checkForDefaultProfile(); } void DataFilesPage::slotProfileDeleted (const QString &item) @@ -140,8 +152,8 @@ void DataFilesPage::slotProfileDeleted (const QString &item) void DataFilesPage::slotProfileChangedByUser(const QString &previous, const QString ¤t) { - changeProfiles(previous, current); - emit signalProfileChanged(mSelector->getProfileIndex(current)); + setProfile(previous, current, true); + emit signalProfileChanged (ui.profilesComboBox->findText(current)); } void DataFilesPage::slotProfileRenamed(const QString &previous, const QString ¤t) @@ -160,7 +172,7 @@ void DataFilesPage::slotProfileRenamed(const QString &previous, const QString &c void DataFilesPage::slotProfileChanged(int index) { - mSelector->setProfile(index); + setProfile (index, true); } void DataFilesPage::setupDataFiles() @@ -178,21 +190,92 @@ void DataFilesPage::setupDataFiles() QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/")); QString profile = mLauncherSettings.value(QString("Profiles/currentprofile")); - foreach (const QString &item, profiles) - mSelector->addProfile (item); + addProfile (item, false); - mSelector->addProfile (profile, true); + addProfile (profile, true); loadSettings(); } -QAbstractItemModel *DataFilesPage::profilesModel() const +void DataFilesPage::on_newProfileAction_triggered() { - return mSelector->profilesModel(); + TextInputDialog newDialog (tr("New Profile"), tr("Profile name:"), this); + + if (newDialog.exec() != QDialog::Accepted) + return; + + QString profile = newDialog.getText(); + + if (profile.isEmpty()) + return; + + saveSettings(); + + mSelector->clearCheckStates(); + + addProfile(profile, true); + + mSelector->setGameFile(); + + saveSettings(); + + emit signalProfileChanged (ui.profilesComboBox->findText(profile)); +} + +void DataFilesPage::addProfile (const QString &profile, bool setAsCurrent) +{ + if (profile.isEmpty()) + return; + + if (ui.profilesComboBox->findText (profile) != -1) + return; + + ui.profilesComboBox->addItem (profile); + + if (setAsCurrent) + setProfile (ui.profilesComboBox->findText (profile), false); } -int DataFilesPage::profilesIndex() const +void DataFilesPage::on_deleteProfileAction_triggered() { - return mSelector->getProfileIndex(mSelector->getProfileText()); + QString profile = ui.profilesComboBox->currentText(); + + if (profile.isEmpty()) + return; + + if (!showDeleteMessageBox (profile)) + return; + + // Remove the profile from the combobox + ui.profilesComboBox->removeItem (ui.profilesComboBox->findText (profile)); + + loadSettings(); + + checkForDefaultProfile(); +} + +void DataFilesPage::checkForDefaultProfile() +{ + //don't allow deleting "Default" profile + bool success = (ui.profilesComboBox->currentText() != "Default"); + + ui.deleteProfileAction->setEnabled (success); + ui.profilesComboBox->setEditEnabled (success); +} + +bool DataFilesPage::showDeleteMessageBox (const QString &text) +{ + 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(text)); + + QAbstractButton *deleteButton = + msgBox.addButton(tr("Delete"), QMessageBox::ActionRole); + + msgBox.exec(); + + return (msgBox.clickedButton() == deleteButton); } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 47e28493d..cc054a4e4 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -1,6 +1,7 @@ #ifndef DATAFILESPAGE_H #define DATAFILESPAGE_H +#include "ui_datafilespage.h" #include #include @@ -12,7 +13,7 @@ class QMenu; class TextInputDialog; class GameSettings; class LauncherSettings; - +class ProfilesComboBox; namespace Files { struct ConfigurationManager; } namespace ContentSelectorView { class ContentSelector; } @@ -22,32 +23,37 @@ class DataFilesPage : public QWidget Q_OBJECT ContentSelectorView::ContentSelector *mSelector; + Ui::DataFilesPage ui; public: - DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent = 0); + explicit DataFilesPage (Files::ConfigurationManager &cfg, GameSettings &gameSettings, + LauncherSettings &launcherSettings, QWidget *parent = 0); + + QAbstractItemModel* profilesModel() const + { return ui.profilesComboBox->model(); } - QAbstractItemModel* profilesModel() const; - int profilesIndex() const; + int profilesIndex() const + { return ui.profilesComboBox->currentIndex(); } - void writeConfig(QString profile = QString()); + //void writeConfig(QString profile = QString()); void saveSettings(const QString &profile = ""); void loadSettings(); signals: - void signalProfileChanged(int index); + void signalProfileChanged (int index); public slots: - //void showContextMenu(const QPoint &point); - + void slotProfileChanged (int index); private slots: - void slotAddNewProfile(const QString &profile); void slotProfileChangedByUser(const QString &previous, const QString ¤t); - void slotProfileChanged(int); void slotProfileRenamed(const QString &previous, const QString ¤t); void slotProfileDeleted(const QString &item); + void on_newProfileAction_triggered(); + void on_deleteProfileAction_triggered(); + private: QMenu *mContextMenu; @@ -59,11 +65,16 @@ private: void setPluginsCheckstates(Qt::CheckState state); + void buildView(); void setupDataFiles(); void setupConfig(); void readConfig(); + void setProfile (int index, bool savePrevious); + void setProfile (const QString &previous, const QString ¤t, bool savePrevious); void removeProfile (const QString &profile); - void changeProfiles(const QString &previous, const QString ¤t, bool savePrevious = true); + bool showDeleteMessageBox (const QString &text); + void addProfile (const QString &profile, bool setAsCurrent); + void checkForDefaultProfile(); }; #endif diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index fe9ca141e..e514755fe 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -485,7 +485,7 @@ bool MainDialog::setupGameSettings() foreach (const QString path, mGameSettings.getDataDirs()) { QDir dir(path); QStringList filters; - filters << "*.esp" << "*.esm"; + filters << "*.esp" << "*.esm" << "*.omwgame" << "*.omwaddon"; if (!dir.entryList(filters).isEmpty()) dataDirs.append(path); diff --git a/components/contentselector/view/comboboxlineedit.cpp b/apps/launcher/utils/lineedit.cpp similarity index 58% rename from components/contentselector/view/comboboxlineedit.cpp rename to apps/launcher/utils/lineedit.cpp index df647a4a0..348707580 100644 --- a/components/contentselector/view/comboboxlineedit.cpp +++ b/apps/launcher/utils/lineedit.cpp @@ -1,10 +1,12 @@ -#include -#include +#include "lineedit.hpp" -#include "comboboxlineedit.hpp" - -ContentSelectorView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) +LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent) +{ + setupClearButton(); +} + +void LineEdit::setupClearButton() { mClearButton = new QToolButton(this); QPixmap pixmap(":images/clear.png"); @@ -15,13 +17,9 @@ ContentSelectorView::ComboBoxLineEdit::ComboBoxLineEdit(QWidget *parent) mClearButton->hide(); connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&))); - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - - setObjectName(QString("ComboBoxLineEdit")); - setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1)); } -void ContentSelectorView::ComboBoxLineEdit::resizeEvent(QResizeEvent *) +void LineEdit::resizeEvent(QResizeEvent *) { QSize sz = mClearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); @@ -29,7 +27,7 @@ void ContentSelectorView::ComboBoxLineEdit::resizeEvent(QResizeEvent *) (rect().bottom() + 1 - sz.height())/2); } -void ContentSelectorView::ComboBoxLineEdit::updateClearButton(const QString& text) +void LineEdit::updateClearButton(const QString& text) { mClearButton->setVisible(!text.isEmpty()); } diff --git a/components/contentselector/view/lineedit.hpp b/apps/launcher/utils/lineedit.hpp similarity index 54% rename from components/contentselector/view/lineedit.hpp rename to apps/launcher/utils/lineedit.hpp index ab1c37203..2dd7da32b 100644 --- a/components/contentselector/view/lineedit.hpp +++ b/apps/launcher/utils/lineedit.hpp @@ -11,29 +11,32 @@ #define LINEEDIT_H #include +#include +#include +#include class QToolButton; -namespace ContentSelectorView +class LineEdit : public QLineEdit { - class LineEdit : public QLineEdit - { - Q_OBJECT + Q_OBJECT - QString mPlaceholderText; + QString mPlaceholderText; - public: - LineEdit(QWidget *parent = 0); +public: + LineEdit(QWidget *parent = 0); - protected: - void resizeEvent(QResizeEvent *); +protected: + void resizeEvent(QResizeEvent *); - private slots: - void updateClearButton(const QString &text); +private slots: + void updateClearButton(const QString &text); + +protected: + QToolButton *mClearButton; + + void setupClearButton(); +}; - private: - QToolButton *mClearButton; - }; -} #endif // LIENEDIT_H diff --git a/components/contentselector/view/profilescombobox.cpp b/apps/launcher/utils/profilescombobox.cpp similarity index 60% rename from components/contentselector/view/profilescombobox.cpp rename to apps/launcher/utils/profilescombobox.cpp index 0e9905df4..c14330724 100644 --- a/components/contentselector/view/profilescombobox.cpp +++ b/apps/launcher/utils/profilescombobox.cpp @@ -5,23 +5,17 @@ #include #include "profilescombobox.hpp" -#include "comboboxlineedit.hpp" -ContentSelectorView::ProfilesComboBox::ProfilesComboBox(QWidget *parent) : - QComboBox(parent) +ProfilesComboBox::ProfilesComboBox(QWidget *parent) : + ContentSelectorView::ComboBox(parent) { - mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore - setEditEnabled(true); - setValidator(mValidator); - setCompleter(0); - connect(this, SIGNAL(activated(int)), this, SLOT(slotIndexChangedByUser(int))); setInsertPolicy(QComboBox::NoInsert); } -void ContentSelectorView::ProfilesComboBox::setEditEnabled(bool editable) +void ProfilesComboBox::setEditEnabled(bool editable) { if (isEditable() == editable) return; @@ -37,6 +31,7 @@ void ContentSelectorView::ProfilesComboBox::setEditEnabled(bool editable) setValidator(mValidator); ComboBoxLineEdit *edit = new ComboBoxLineEdit(this); + setLineEdit(edit); setCompleter(0); @@ -50,7 +45,7 @@ void ContentSelectorView::ProfilesComboBox::setEditEnabled(bool editable) SIGNAL (signalProfileTextChanged (QString))); } -void ContentSelectorView::ProfilesComboBox::slotTextChanged(const QString &text) +void ProfilesComboBox::slotTextChanged(const QString &text) { QPalette *palette = new QPalette(); palette->setColor(QPalette::Text,Qt::red); @@ -64,7 +59,7 @@ void ContentSelectorView::ProfilesComboBox::slotTextChanged(const QString &text) } } -void ContentSelectorView::ProfilesComboBox::slotEditingFinished() +void ProfilesComboBox::slotEditingFinished() { QString current = currentText(); QString previous = itemText(currentIndex()); @@ -85,7 +80,7 @@ void ContentSelectorView::ProfilesComboBox::slotEditingFinished() emit(profileRenamed(previous, current)); } -void ContentSelectorView::ProfilesComboBox::slotIndexChangedByUser(int index) +void ProfilesComboBox::slotIndexChangedByUser(int index) { if (index == -1) return; @@ -94,23 +89,11 @@ void ContentSelectorView::ProfilesComboBox::slotIndexChangedByUser(int index) mOldProfile = currentText(); } -void ContentSelectorView::ProfilesComboBox::paintEvent(QPaintEvent *) +ProfilesComboBox::ComboBoxLineEdit::ComboBoxLineEdit (QWidget *parent) + : LineEdit (parent) { - QStylePainter painter(this); - painter.setPen(palette().color(QPalette::Text)); - - // draw the combobox frame, focusrect and selected etc. - QStyleOptionComboBox opt; - initStyleOption(&opt); - painter.drawComplexControl(QStyle::CC_ComboBox, opt); - - // draw the icon and text - if (!opt.editable && currentIndex() == -1) // <<< we adjust the text displayed when nothing is selected - opt.currentText = mPlaceholderText; - painter.drawControl(QStyle::CE_ComboBoxLabel, opt); -} + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); -void ContentSelectorView::ProfilesComboBox::setPlaceholderText(const QString &text) -{ - mPlaceholderText = text; + setObjectName(QString("ComboBoxLineEdit")); + setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1)); } diff --git a/apps/launcher/utils/profilescombobox.hpp b/apps/launcher/utils/profilescombobox.hpp new file mode 100644 index 000000000..1e27f66a9 --- /dev/null +++ b/apps/launcher/utils/profilescombobox.hpp @@ -0,0 +1,40 @@ +#ifndef PROFILESCOMBOBOX_HPP +#define PROFILESCOMBOBOX_HPP + +#include "components/contentselector/view/combobox.hpp" +#include "lineedit.hpp" + +class QString; + +class ProfilesComboBox : public ContentSelectorView::ComboBox +{ + Q_OBJECT + +public: + class ComboBoxLineEdit : public LineEdit + { + public: + explicit ComboBoxLineEdit (QWidget *parent = 0); + }; + +public: + + explicit ProfilesComboBox(QWidget *parent = 0); + void setEditEnabled(bool editable); + +signals: + void signalProfileTextChanged(const QString &item); + void signalProfileChanged(const QString &previous, const QString ¤t); + void signalProfileChanged(int index); + void profileRenamed(const QString &oldName, const QString &newName); + +private slots: + + void slotEditingFinished(); + void slotIndexChangedByUser(int index); + void slotTextChanged(const QString &text); + +private: + QString mOldProfile; +}; +#endif // PROFILESCOMBOBOX_HPP diff --git a/components/contentselector/view/textinputdialog.cpp b/apps/launcher/utils/textinputdialog.cpp similarity index 77% rename from components/contentselector/view/textinputdialog.cpp rename to apps/launcher/utils/textinputdialog.cpp index 6bb92f113..9957e7dda 100644 --- a/components/contentselector/view/textinputdialog.cpp +++ b/apps/launcher/utils/textinputdialog.cpp @@ -7,8 +7,6 @@ #include #include -#include - TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWidget *parent) : QDialog(parent) { @@ -20,7 +18,7 @@ TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWid // Line edit QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore - mLineEdit = new ContentSelectorView::LineEdit(this); + mLineEdit = new DialogLineEdit(this); mLineEdit->setValidator(validator); mLineEdit->setCompleter(0); @@ -74,3 +72,16 @@ void TextInputDialog::slotUpdateOkButton(QString text) mLineEdit->setPalette(*palette); } } + +TextInputDialog::DialogLineEdit::DialogLineEdit (QWidget *parent) : + LineEdit (parent) +{ + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + + setObjectName(QString("LineEdit")); + setStyleSheet(QString("LineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1)); + QSize msz = minimumSizeHint(); + setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2), + qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2)); + +} diff --git a/components/contentselector/view/textinputdialog.hpp b/apps/launcher/utils/textinputdialog.hpp similarity index 66% rename from components/contentselector/view/textinputdialog.hpp rename to apps/launcher/utils/textinputdialog.hpp index a0b7e350a..148bbd152 100644 --- a/components/contentselector/view/textinputdialog.hpp +++ b/apps/launcher/utils/textinputdialog.hpp @@ -3,23 +3,30 @@ #include -class QDialogButtonBox; +#include "lineedit.hpp" -namespace ContentSelectorView { - class LineEdit; -} +class QDialogButtonBox; +class LineEdit; class TextInputDialog : public QDialog { Q_OBJECT - ContentSelectorView::LineEdit *mLineEdit; + class DialogLineEdit : public LineEdit + { + public: + explicit DialogLineEdit (QWidget *parent = 0); + }; + + DialogLineEdit *mLineEdit; QDialogButtonBox *mButtonBox; public: explicit TextInputDialog(const QString& title, const QString &text, QWidget *parent = 0); + ~TextInputDialog () {} + QString getText() const; int exec(); diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 9ae12c7a7..bc78352d4 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -44,6 +44,7 @@ opencs_units_noqt (model/tools opencs_units (view/doc viewmanager view operations operation subview startup filedialog newgame + filewidget adjusterwidget ) @@ -122,11 +123,13 @@ opencs_units (view/filter set (OPENCS_US ) -set (OPENCS_RES ../../files/opencs/resources.qrc - ../../files/launcher/launcher.qrc +set (OPENCS_RES ${CMAKE_SOURCE_DIR}/files/opencs/resources.qrc + ${CMAKE_SOURCE_DIR}/files/launcher/launcher.qrc ) -set (OPENCS_UI ../../files/ui/datafilespage.ui +set (OPENCS_UI + ${CMAKE_SOURCE_DIR}/files/ui/contentselector.ui + ${CMAKE_SOURCE_DIR}/files/ui/filedialog.ui ) source_group (opencs FILES ${OPENCS_SRC} ${OPENCS_HDR}) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index ae10ec642..e78357bc5 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -109,15 +109,13 @@ void CS::Editor::createGame() void CS::Editor::createAddon() { mStartup.hide(); - - mFileDialog.newFile(); + mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_New); } void CS::Editor::loadDocument() { mStartup.hide(); - - mFileDialog.openFile(); + mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_Open); } void CS::Editor::openFiles() diff --git a/components/contentselector/view/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp similarity index 100% rename from components/contentselector/view/adjusterwidget.cpp rename to apps/opencs/view/doc/adjusterwidget.cpp diff --git a/components/contentselector/view/adjusterwidget.hpp b/apps/opencs/view/doc/adjusterwidget.hpp similarity index 100% rename from components/contentselector/view/adjusterwidget.hpp rename to apps/opencs/view/doc/adjusterwidget.hpp diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 2017ab103..49e90ec81 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -12,81 +12,120 @@ #include #include -#include -#include +#include "components/contentselector/model/esmfile.hpp" #include "components/contentselector/view/contentselector.hpp" +#include "filewidget.hpp" +#include "adjusterwidget.hpp" #include CSVDoc::FileDialog::FileDialog(QWidget *parent) : - QDialog(parent), - mOpenFileFlags (ContentSelectorView::Flag_Content | ContentSelectorView::Flag_LoadAddon), - mNewFileFlags (ContentSelectorView::Flag_Content | ContentSelectorView::Flag_NewAddon) - + QDialog(parent), mSelector (0) { + ui.setupUi (this); resize(400, 400); -} -void CSVDoc::FileDialog::addFiles(const QString &path) -{ - ContentSelectorView::ContentSelector::addFiles(path); + setObjectName ("FileDialog"); + mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget); } -QString CSVDoc::FileDialog::filename() +void CSVDoc::FileDialog::addFiles(const QString &path) { - return ContentSelectorView::ContentSelector::instance().projectFilename(); + mSelector->addFiles(path); } QStringList CSVDoc::FileDialog::selectedFilePaths() { QStringList filePaths; - foreach (ContentSelectorModel::EsmFile *file, ContentSelectorView::ContentSelector:: - instance().selectedFiles() ) - { + foreach (ContentSelectorModel::EsmFile *file, mSelector->selectedFiles() ) filePaths.append(file->path()); - } + return filePaths; } -void CSVDoc::FileDialog::showDialog() +void CSVDoc::FileDialog::showDialog(DialogType dialogType) { + mDialogType = dialogType; + + switch (mDialogType) + { + case DialogType_New: + buildNewFileView(); + break; + + case DialogType_Open: + buildOpenFileView(); + break; + default: + break; + } + show(); raise(); activateWindow(); } -void CSVDoc::FileDialog::openFile() +void CSVDoc::FileDialog::buildNewFileView() { - setWindowTitle(tr("Open")); + setWindowTitle(tr("Create a new addon")); - ContentSelectorView::ContentSelector::configure(this, mOpenFileFlags); + QPushButton* createButton = ui.projectButtonBox->button (QDialogButtonBox::Ok); + createButton->setText ("Create"); + createButton->setEnabled (false); - connect (&ContentSelectorView::ContentSelector::instance(), - SIGNAL (accepted()), this, SIGNAL (openFiles())); + mFileWidget = new FileWidget (this); - connect (&ContentSelectorView::ContentSelector::instance(), - SIGNAL (rejected()), this, SLOT (slotRejected())); + mFileWidget->setType (true); + mFileWidget->extensionLabelIsVisible(true); - showDialog(); -} + ui.projectGroupBoxLayout->insertWidget (0, mFileWidget); -void CSVDoc::FileDialog::newFile() -{ - setWindowTitle(tr("New")); + connect (mFileWidget, SIGNAL (nameChanged(const QString &, bool)), + this, SLOT (slotUpdateCreateButton(const QString &, bool))); + + connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)), + this, SLOT (slotUpdateCreateButton (int))); - ContentSelectorView::ContentSelector::configure(this, mNewFileFlags); + connect (ui.projectButtonBox, SIGNAL (accepted()), this, SIGNAL (createNewFile())); - connect (&ContentSelectorView::ContentSelector::instance(), - SIGNAL (accepted()), this, SIGNAL (createNewFile())); + connect (ui.projectButtonBox, SIGNAL (rejected()), this, SLOT (slotRejected())); +} - connect (&ContentSelectorView::ContentSelector::instance(), - SIGNAL (rejected()), this, SLOT (slotRejected())); +void CSVDoc::FileDialog::buildOpenFileView() +{ + setWindowTitle(tr("Open")); + ui.projectGroupBox->setTitle (QString("")); - showDialog(); + connect (ui.projectButtonBox, SIGNAL (accepted()), this, SIGNAL (openFiles())); + connect (ui.projectButtonBox, SIGNAL (rejected()), this , SIGNAL (rejected())); } void CSVDoc::FileDialog::slotRejected() { close(); } + +void CSVDoc::FileDialog::slotUpdateCreateButton (int) +{ + slotUpdateCreateButton (mFileWidget->getName(), true); +} + +void CSVDoc::FileDialog::slotUpdateCreateButton(const QString &name, bool) +{ + if (!(mDialogType == DialogType_New)) + return; + + bool success = (!name.isEmpty() && mSelector->selectedFiles().size() > 0); + + ui.projectButtonBox->button (QDialogButtonBox::Ok)->setEnabled (success); +} + +QString CSVDoc::FileDialog::filename() const +{ + if (mDialogType == DialogType_New) + return mFileWidget->getName(); + + return QString (""); +} + diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index acc35189d..78883791e 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -3,49 +3,54 @@ #include #include -#include "../../../../components/contentselector/view/contentselector.hpp" -class QDialogButtonBox; -class QSortFilterProxyModel; -class QAbstractItemModel; -class QPushButton; -class QStringList; -class QString; -class QMenu; -class QLabel; +#include "ui_filedialog.h" class DataFilesModel; class PluginsProxyModel; - - namespace ContentSelectorView { - class LineEdit; + class ContentSelector; } namespace CSVDoc { + class FileWidget; + class FileDialog : public QDialog { Q_OBJECT - unsigned char mOpenFileFlags; - unsigned char mNewFileFlags; + public: + + enum DialogType + { + DialogType_New, + DialogType_Open + }; + + private: + + ContentSelectorView::ContentSelector *mSelector; + Ui::FileDialog ui; + DialogType mDialogType; + FileWidget *mFileWidget; public: + explicit FileDialog(QWidget *parent = 0); + void showDialog (DialogType dialogType); - void openFile(); - void newFile(); void addFiles (const QString &path); - QString filename(); + QString filename() const; QStringList selectedFilePaths(); private: - void showDialog(); + void buildNewFileView(); + void buildOpenFileView(); signals: @@ -58,6 +63,9 @@ namespace CSVDoc private slots: + void slotUpdateCreateButton (int); + void slotUpdateCreateButton (const QString &, bool); + }; } #endif // FILEDIALOG_HPP diff --git a/components/contentselector/view/filewidget.cpp b/apps/opencs/view/doc/filewidget.cpp similarity index 100% rename from components/contentselector/view/filewidget.cpp rename to apps/opencs/view/doc/filewidget.cpp diff --git a/components/contentselector/view/filewidget.hpp b/apps/opencs/view/doc/filewidget.hpp similarity index 100% rename from components/contentselector/view/filewidget.hpp rename to apps/opencs/view/doc/filewidget.hpp diff --git a/apps/opencs/view/doc/newgame.cpp b/apps/opencs/view/doc/newgame.cpp index 265b98305..98681c499 100644 --- a/apps/opencs/view/doc/newgame.cpp +++ b/apps/opencs/view/doc/newgame.cpp @@ -7,8 +7,8 @@ #include #include -#include "components/contentselector/view/filewidget.hpp" -#include "components/contentselector/view/adjusterwidget.hpp" +#include "filewidget.hpp" +#include "adjusterwidget.hpp" CSVDoc::NewGameDialogue::NewGameDialogue() { diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 103c6f412..acb70b04d 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -74,7 +74,7 @@ add_component_dir (loadinglistener loadinglistener ) -set (ESM_UI ${CMAKE_SOURCE_DIR}/files/ui/datafilespage.ui +set (ESM_UI ${CMAKE_SOURCE_DIR}/files/ui/contentselector.ui ) find_package(Qt4 COMPONENTS QtCore QtGui) @@ -82,11 +82,7 @@ if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) add_component_qt_dir (contentselector model/modelitem model/esmfile model/naturalsort model/contentmodel - view/profilescombobox view/comboboxlineedit - view/lineedit view/contentselector - view/filewidget view/adjusterwidget - view/textinputdialog - + view/combobox view/contentselector ) include(${QT_USE_FILE}) diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index 8bb052d3d..accc149cb 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -399,6 +399,10 @@ void ContentSelectorModel::ContentModel::addFile(EsmFile *file) beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); mFiles.append(file); endInsertRows(); + + QModelIndex idx = index (mFiles.size() - 2, 0, QModelIndex()); + + emit dataChanged (idx, idx); } void ContentSelectorModel::ContentModel::addFiles(const QString &path) @@ -466,6 +470,7 @@ void ContentSelectorModel::ContentModel::sortFiles() //iterate each file, obtaining a reference to it's gamefiles list for (int i = 0; i < fileCount; i++) { + QModelIndex idx1 = index (i, 0, QModelIndex()); const QStringList &gamefiles = mFiles.at(i)->gameFiles(); //iterate each file after the current file, verifying that none of it's //dependencies appear. @@ -474,6 +479,11 @@ void ContentSelectorModel::ContentModel::sortFiles() if (gamefiles.contains(mFiles.at(j)->fileName())) { mFiles.move(j, i); + + QModelIndex idx2 = index (j, 0, QModelIndex()); + + emit dataChanged (idx1, idx2); + movedFiles = true; } } diff --git a/components/contentselector/view/combobox.cpp b/components/contentselector/view/combobox.cpp new file mode 100644 index 000000000..1d773b62d --- /dev/null +++ b/components/contentselector/view/combobox.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +#include "combobox.hpp" + +ContentSelectorView::ComboBox::ComboBox(QWidget *parent) : + QComboBox(parent) +{ + mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore + setValidator(mValidator); + setCompleter(0); + setEnabled (true); + + setInsertPolicy(QComboBox::NoInsert); +} + +void ContentSelectorView::ComboBox::paintEvent(QPaintEvent *) +{ + QStylePainter painter(this); + painter.setPen(palette().color(QPalette::Text)); + + // draw the combobox frame, focusrect and selected etc. + QStyleOptionComboBox opt; + initStyleOption(&opt); + painter.drawComplexControl(QStyle::CC_ComboBox, opt); + + // draw the icon and text + if (!opt.editable && currentIndex() == -1) // <<< we adjust the text displayed when nothing is selected + opt.currentText = mPlaceholderText; + painter.drawControl(QStyle::CE_ComboBoxLabel, opt); +} + +void ContentSelectorView::ComboBox::setPlaceholderText(const QString &text) +{ + mPlaceholderText = text; +} diff --git a/components/contentselector/view/combobox.hpp b/components/contentselector/view/combobox.hpp new file mode 100644 index 000000000..e3888af2c --- /dev/null +++ b/components/contentselector/view/combobox.hpp @@ -0,0 +1,30 @@ +#ifndef COMBOBOX_HPP +#define COMBOBOX_HPP + +#include +#include + +class QString; +class QRegExpValidator; + +namespace ContentSelectorView +{ + class ComboBox : public QComboBox + { + Q_OBJECT + + public: + explicit ComboBox (QWidget *parent = 0); + + void setPlaceholderText(const QString &text); + + private: + QString mPlaceholderText; + + protected: + void paintEvent(QPaintEvent *); + QRegExpValidator *mValidator; + }; +} + +#endif // COMBOBOX_HPP diff --git a/components/contentselector/view/comboboxlineedit.hpp b/components/contentselector/view/comboboxlineedit.hpp deleted file mode 100644 index 1aef2f57b..000000000 --- a/components/contentselector/view/comboboxlineedit.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (c) 2007 Trolltech ASA -** -** Use, modification and distribution is allowed without limitation, -** warranty, liability or support of any kind. -** -****************************************************************************/ - -#ifndef LINEEDIT_H -#define LINEEDIT_H - -#include - -class QToolButton; - -namespace ContentSelectorView -{ - class ComboBoxLineEdit : public QLineEdit - { - Q_OBJECT - - public: - ComboBoxLineEdit(QWidget *parent = 0); - - protected: - void resizeEvent(QResizeEvent *); - - private slots: - void updateClearButton(const QString &text); - - private: - QToolButton *mClearButton; - }; -} -#endif // LIENEDIT_H - diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 6965c948e..7a7e1fd9d 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -1,7 +1,6 @@ #include "contentselector.hpp" #include "../model/esmfile.hpp" -#include "lineedit.hpp" #include @@ -11,45 +10,16 @@ #include #include -#include "filewidget.hpp" -#include "adjusterwidget.hpp" -#include "textinputdialog.hpp" - #include -ContentSelectorView::ContentSelector *ContentSelectorView::ContentSelector::mInstance = 0; -QStringList ContentSelectorView::ContentSelector::mFilePaths; - -void ContentSelectorView::ContentSelector::configure(QWidget *subject, unsigned char flags) -{ - assert(!mInstance); - mInstance = new ContentSelector (subject, flags); -} - -ContentSelectorView::ContentSelector& ContentSelectorView::ContentSelector::instance() +ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) : + QObject(parent) { - - assert(mInstance); - return *mInstance; -} - -ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned char flags) : - QWidget(parent), mFlags (flags), - mAdjusterWidget (0), mFileWidget (0), - mIgnoreProfileSignal (false) -{ - - ui.setupUi (this); - - parent->setLayout(new QGridLayout()); - parent->layout()->addWidget(this); + ui.setupUi (parent); buildContentModel(); buildGameFileView(); buildAddonView(); - buildNewAddonView(); - buildLoadAddonView(); - buildProfilesView(); /* //mContentModel->sort(3); // Sort by date accessed @@ -57,16 +27,8 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned */ } -bool ContentSelectorView::ContentSelector::isFlagged(SelectorFlags flag) const -{ - return (mFlags & flag); -} - void ContentSelectorView::ContentSelector::buildContentModel() { - if (!isFlagged (Flag_Content)) - return; - mContentModel = new ContentSelectorModel::ContentModel(); if (mFilePaths.size()>0) @@ -83,12 +45,6 @@ void ContentSelectorView::ContentSelector::buildContentModel() void ContentSelectorView::ContentSelector::buildGameFileView() { - if (!isFlagged (Flag_Content)) - { - ui.gameFileView->setVisible(false); - return; - } - ui.gameFileView->setVisible (true); mGameFileProxyModel = new QSortFilterProxyModel(this); @@ -99,19 +55,17 @@ void ContentSelectorView::ContentSelector::buildGameFileView() ui.gameFileView->setPlaceholderText(QString("Select a game file...")); ui.gameFileView->setModel(mGameFileProxyModel); - connect (ui.gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT (slotCurrentGameFileIndexChanged(int))); + connect (ui.gameFileView, SIGNAL(currentIndexChanged(int)), + this, SLOT (slotCurrentGameFileIndexChanged(int))); + + connect (ui.gameFileView, SIGNAL (currentIndexChanged (int)), + this, SIGNAL (signalCurrentGamefileIndexChanged (int))); ui.gameFileView->setCurrentIndex(-1); } void ContentSelectorView::ContentSelector::buildAddonView() { - if (!isFlagged (Flag_Content)) - { - ui.addonView->setVisible(false); - return; - } - ui.addonView->setVisible (true); mAddonProxyModel = new QSortFilterProxyModel(this); @@ -123,91 +77,9 @@ void ContentSelectorView::ContentSelector::buildAddonView() ui.addonView->setModel(mAddonProxyModel); connect(ui.addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &))); -} - -void ContentSelectorView::ContentSelector::buildProfilesView() -{ - if (!isFlagged (Flag_Profile)) - { - ui.profileGroupBox->setVisible(false); - return; - } - - ui.profileGroupBox->setVisible (true); - - // Add the actions to the toolbuttons - ui.newProfileButton->setDefaultAction (ui.newProfileAction); - ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction); - - //enable ui elements - ui.profilesComboBox->addItem ("Default"); - ui.profilesComboBox->setPlaceholderText (QString("Select a profile...")); - - if (!ui.profilesComboBox->isEnabled()) - ui.profilesComboBox->setEnabled(true); - - if (!ui.deleteProfileAction->isEnabled()) - ui.deleteProfileAction->setEnabled(true); - - //establish connections - 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 (signalProfileChanged(QString,QString)), this, SIGNAL(signalProfileChangedByUser(QString,QString))); - connect (ui.profilesComboBox, SIGNAL (signalProfileTextChanged(QString)), this, SLOT (slotProfileTextChanged (QString))); - - ui.profileGroupBox->setVisible (true); - ui.projectButtonBox->setVisible (false); -} - -void ContentSelectorView::ContentSelector::buildLoadAddonView() -{ - if (!isFlagged (Flag_LoadAddon)) - { - if (!isFlagged (Flag_NewAddon)) - ui.projectGroupBox->setVisible (false); - - return; - } - - ui.projectGroupBox->setVisible (true); - ui.projectCreateButton->setVisible (false); - ui.projectGroupBox->setTitle (""); - - connect(ui.projectButtonBox, SIGNAL(accepted()), this, SIGNAL(accepted())); - connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected())); -} - -void ContentSelectorView::ContentSelector::buildNewAddonView() -{ - if (!isFlagged (Flag_NewAddon)) - { - if (!isFlagged (Flag_LoadAddon)) - ui.projectGroupBox->setVisible (false); - - return; - } - - ui.projectGroupBox->setVisible (true); - - mFileWidget = new CSVDoc::FileWidget (this); - mAdjusterWidget = new CSVDoc::AdjusterWidget (this); - - mFileWidget->setType(true); - mFileWidget->extensionLabelIsVisible(false); - - ui.fileWidgetFrame->layout()->addWidget(mFileWidget); - ui.adjusterWidgetFrame->layout()->addWidget(mAdjusterWidget); - - ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel); - ui.projectButtonBox->addButton(ui.projectCreateButton, QDialogButtonBox::ActionRole); - - connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)), - mAdjusterWidget, SLOT (setName (const QString&, bool))); - - connect (mAdjusterWidget, SIGNAL (stateChanged(bool)), this, SLOT (slotUpdateCreateButton(bool))); - connect(ui.projectCreateButton, SIGNAL(clicked()), this, SIGNAL(accepted())); - connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected())); + for (int i = 0; i < mAddonProxyModel->rowCount(); ++i) + qDebug() << mAddonProxyModel->data(mAddonProxyModel->index(i,0,QModelIndex())); } void ContentSelectorView::ContentSelector::setGameFile(const QString &filename) @@ -239,16 +111,6 @@ void ContentSelectorView::ContentSelector::setCheckStates(const QStringList &lis mContentModel->setCheckState(file, Qt::Checked); } -QString ContentSelectorView::ContentSelector::projectFilename() const -{ - QString filepath = ""; - - if (mAdjusterWidget) - filepath = QString::fromAscii(mAdjusterWidget->getPath().c_str()); - - return filepath; -} - ContentSelectorModel::ContentFileList ContentSelectorView::ContentSelector::selectedFiles() const { @@ -261,65 +123,10 @@ ContentSelectorModel::ContentFileList void ContentSelectorView::ContentSelector::addFiles(const QString &path) { - // if the model hasn't been instantiated, queue the path - if (!mInstance) - mFilePaths.append(path); - else - { - mInstance->mContentModel->addFiles(path); - mInstance->ui.gameFileView->setCurrentIndex(-1); - } -} - -int ContentSelectorView::ContentSelector::getProfileIndex ( const QString &item) const -{ - return ui.profilesComboBox->findText (item); -} - -void ContentSelectorView::ContentSelector::addProfile (const QString &item, bool setAsCurrent) -{ - if (item.isEmpty()) - return; - - QString previous = ui.profilesComboBox->currentText(); - - if (ui.profilesComboBox->findText(item) == -1) - ui.profilesComboBox->addItem(item); - - if (setAsCurrent) - setProfile (ui.profilesComboBox->findText(item)); -} - -void ContentSelectorView::ContentSelector::setProfile(int index) -{ - //programmatic change requires second call to non-signalized "slot" since no signal responses - //occur for programmatic changes to the profilesComboBox. - if (index >= -1 && index < ui.profilesComboBox->count()) - { - QString previous = ui.profilesComboBox->itemText(ui.profilesComboBox->currentIndex()); - QString current = ui.profilesComboBox->itemText(index); - - ui.profilesComboBox->setCurrentIndex(index); - } -} - -QString ContentSelectorView::ContentSelector::getProfileText() const -{ - return ui.profilesComboBox->currentText(); -} - -QAbstractItemModel *ContentSelectorView::ContentSelector::profilesModel() const -{ - return ui.profilesComboBox->model(); -} - -void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index) -{ - //don't allow deleting "Default" profile - bool success = (ui.profilesComboBox->itemText(index) != "Default"); + mContentModel->addFiles(path); - ui.deleteProfileAction->setEnabled(success); - ui.profilesComboBox->setEditEnabled(success); + if (ui.gameFileView->currentIndex() != -1) + ui.gameFileView->setCurrentIndex(-1); } void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index) @@ -341,16 +148,6 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i if (proxy) proxy->setDynamicSortFilter(true); - - 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) @@ -362,53 +159,3 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QMode else model->setData(index, Qt::Unchecked, Qt::CheckStateRole); } - -void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool) -{ - //enable only if a game file is selected and the adjuster widget is non-empty - bool validGameFile = (ui.gameFileView->currentIndex() != -1); - bool validFilename = false; - - if (mAdjusterWidget) - validFilename = mAdjusterWidget->isValid(); - - ui.projectCreateButton->setEnabled(validGameFile && validFilename); -} - -void ContentSelectorView::ContentSelector::on_newProfileAction_triggered() -{ - TextInputDialog newDialog (tr("New Profile"), tr("Profile name:"), this); - - if (newDialog.exec() == QDialog::Accepted) - emit signalAddNewProfile(newDialog.getText()); -} - -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); - - slotCurrentProfileIndexChanged(ui.profilesComboBox->currentIndex()); -} diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 64b9b3732..0882abfb7 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -3,38 +3,19 @@ #include -#include "ui_datafilespage.h" +#include "ui_contentselector.h" #include "../model/contentmodel.hpp" class QSortFilterProxyModel; -namespace CSVDoc -{ - class FileWidget; - class AdjusterWidget; -} namespace ContentSelectorView { - enum SelectorFlags - { - Flag_Content = 0x01, // gamefile combobox & addon list view - Flag_NewAddon = 0x02, // enable project button box (Create/Cancel) and file/adjuster widgets - Flag_LoadAddon = 0x04, // enable project button box (Open/Cancel) - Flag_Profile = 0x08 // enable profile combo box - }; - class ContentSelector : public QWidget + class ContentSelector : public QObject { Q_OBJECT - unsigned char mFlags; - bool mIgnoreProfileSignal; - - static ContentSelector *mInstance; - static QStringList mFilePaths; - - CSVDoc::FileWidget *mFileWidget; - CSVDoc::AdjusterWidget *mAdjusterWidget; + QStringList mFilePaths; protected: @@ -44,64 +25,39 @@ namespace ContentSelectorView public: - explicit ContentSelector(QWidget *parent = 0, unsigned char flags = Flag_Content); + explicit ContentSelector(QWidget *parent = 0); - static void configure(QWidget *subject, unsigned char flags = Flag_Content); - static ContentSelector &instance(); - static void addFiles(const QString &path); + void addFiles(const QString &path); void clearCheckStates(); void setCheckStates (const QStringList &list); - ContentSelectorModel::ContentFileList *CheckedItems(); - QString projectFilename() const; ContentSelectorModel::ContentFileList selectedFiles() const; - QAbstractItemModel *profilesModel() const; - void setGameFile (const QString &filename = ""); - void addProfile (const QString &item, bool setAsCurrent = false); - void setProfile (int index); - int getProfileIndex (const QString &item) const; - QString getProfileText() const; + void setGameFile (const QString &filename = QString("")); + + bool isGamefileSelected() const + { return ui.gameFileView->currentIndex() != -1; } + + QWidget *uiWidget() const + { return ui.contentGroupBox; } private: - Ui::DataFilesPage ui; + Ui::ContentSelector ui; void buildContentModel(); void buildGameFileView(); void buildAddonView(); - void buildProfilesView(); - void buildNewAddonView(); - void buildLoadAddonView(); - - bool isFlagged(SelectorFlags flag) const; signals: - - void accepted(); - void rejected(); - - void signalCreateButtonClicked(); - - void signalProfileRenamed(QString,QString); - void signalProfileChangedByUser(QString,QString); - void signalProfileDeleted(QString); - void signalAddNewProfile(QString); + void signalCurrentGamefileIndexChanged (int); private slots: - void slotProfileTextChanged (const QString &text); - void slotCurrentProfileIndexChanged(int index); void slotCurrentGameFileIndexChanged(int index); void slotAddonTableItemClicked(const QModelIndex &index); - - void slotUpdateCreateButton (bool); - - // Action slots - void on_newProfileAction_triggered(); - void on_deleteProfileAction_triggered(); }; } diff --git a/components/contentselector/view/lineedit.cpp b/components/contentselector/view/lineedit.cpp deleted file mode 100644 index b6fdfa805..000000000 --- a/components/contentselector/view/lineedit.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include - -#include "lineedit.hpp" - -ContentSelectorView::LineEdit::LineEdit(QWidget *parent) - : QLineEdit(parent) -{ - mClearButton = new QToolButton(this); - QPixmap pixmap(":images/clear.png"); - mClearButton->setIcon(QIcon(pixmap)); - mClearButton->setIconSize(pixmap.size()); - mClearButton->setCursor(Qt::ArrowCursor); - mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); - mClearButton->hide(); - connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear())); - connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&))); - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - - setObjectName(QString("LineEdit")); - setStyleSheet(QString("LineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1)); - QSize msz = minimumSizeHint(); - setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2), - qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2)); -} - -void ContentSelectorView::LineEdit::resizeEvent(QResizeEvent *) -{ - QSize sz = mClearButton->sizeHint(); - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - mClearButton->move(rect().right() - frameWidth - sz.width(), - (rect().bottom() + 1 - sz.height())/2); -} - -void ContentSelectorView::LineEdit::updateClearButton(const QString& text) -{ - mClearButton->setVisible(!text.isEmpty()); -} diff --git a/components/contentselector/view/profilescombobox.hpp b/components/contentselector/view/profilescombobox.hpp deleted file mode 100644 index fc87a94b4..000000000 --- a/components/contentselector/view/profilescombobox.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef PROFILESCOMBOBOX_HPP -#define PROFILESCOMBOBOX_HPP - -#include -#include -class QString; -class QRegExpValidator; - -namespace ContentSelectorView -{ - class ProfilesComboBox : public QComboBox - { - Q_OBJECT - public: - explicit ProfilesComboBox(QWidget *parent = 0); - void setEditEnabled(bool editable); - void setPlaceholderText(const QString &text); - // void indexChanged(int index); - - signals: - void signalProfileTextChanged(const QString &item); - void signalProfileChanged(const QString &previous, const QString ¤t); - void signalProfileChanged(int index); - void profileRenamed(const QString &oldName, const QString &newName); - - private slots: - - void slotEditingFinished(); - void slotIndexChangedByUser(int index); - void slotTextChanged(const QString &text); - - private: - QString mOldProfile; - QString mPlaceholderText; - QRegExpValidator *mValidator; - - protected: - void paintEvent(QPaintEvent *); - }; -} - -#endif // PROFILESCOMBOBOX_HPP diff --git a/files/ui/contentselector.ui b/files/ui/contentselector.ui new file mode 100644 index 000000000..b9b5ba5a0 --- /dev/null +++ b/files/ui/contentselector.ui @@ -0,0 +1,111 @@ + + + ContentSelector + + + + 0 + 0 + 518 + 436 + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + 0 + + + + + Content + + + + 3 + + + + + false + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + true + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + QAbstractItemView::DragDrop + + + Qt::MoveAction + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + Qt::ElideLeft + + + false + + + false + + + true + + + false + + + + + + + + + + + ContentSelectorView::ComboBox + QComboBox +
components/contentselector/view/combobox.hpp
+
+
+ + +
diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 0cafd606a..eb5ebc61d 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -7,7 +7,7 @@ 0 0 518 - 436 + 108 @@ -21,188 +21,7 @@ - - - Content - - - - 3 - - - - - - - false - - - - - - - - - - - - 0 - 0 - - - - Qt::DefaultContextMenu - - - true - - - QAbstractItemView::NoEditTriggers - - - true - - - false - - - QAbstractItemView::DragDrop - - - Qt::MoveAction - - - true - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - Qt::ElideLeft - - - false - - - false - - - true - - - false - - - - - - - - - - - - - - - 0 - 0 - - - - Project - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - 3 - - - 6 - - - 6 - - - 0 - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - - 0 - - - 0 - - - - - - - - false - - - - 0 - 0 - - - - Create - - - - - - - - - - - 1 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - - 0 - - - 0 - - - + @@ -232,9 +51,9 @@ 6 - + - false + true @@ -242,6 +61,9 @@ 0 + + Select a profiile + @@ -276,13 +98,6 @@ - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Open - - - @@ -332,9 +147,9 @@ - ContentSelectorView::ProfilesComboBox + ProfilesComboBox QComboBox -
components/contentselector/view/profilescombobox.hpp
+
apps/launcher/utils/profilescombobox.hpp
diff --git a/files/ui/filedialog.ui b/files/ui/filedialog.ui new file mode 100644 index 000000000..114345e53 --- /dev/null +++ b/files/ui/filedialog.ui @@ -0,0 +1,73 @@ + + + FileDialog + + + + 0 + 0 + 518 + 108 + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + + + + + + Qt::NoFocus + + + Project Name + + + false + + + + 6 + + + 3 + + + 6 + + + 0 + + + 6 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + + + +