From b51bef0d98687c95d35f69a8b02b5b2fac6d48a5 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 27 Oct 2013 20:21:19 -0500 Subject: [PATCH] fixed missing adjuster widget in file dialog open view --- apps/opencs/view/doc/adjusterwidget.cpp | 13 +++++++++- apps/opencs/view/doc/adjusterwidget.hpp | 11 +++++++++ apps/opencs/view/doc/filedialog.cpp | 24 ++++++++++++------- apps/opencs/view/doc/filedialog.hpp | 14 +++-------- .../contentselector/view/contentselector.cpp | 12 ++++++++-- .../contentselector/view/contentselector.hpp | 2 ++ 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp index b1eec63c3..332d46075 100644 --- a/apps/opencs/view/doc/adjusterwidget.cpp +++ b/apps/opencs/view/doc/adjusterwidget.cpp @@ -11,7 +11,7 @@ #include CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent) -: QWidget (parent), mValid (false) + : QWidget (parent), mValid (false), mAction (ContentAction_Undefined) { QHBoxLayout *layout = new QHBoxLayout (this); @@ -30,6 +30,11 @@ CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent) setLayout (layout); } +void CSVDoc::AdjusterWidget::setAction (ContentAction action) +{ + mAction = action; +} + void CSVDoc::AdjusterWidget::setLocalData (const boost::filesystem::path& localData) { mLocalData = localData; @@ -51,6 +56,12 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) { QString message; + if (mAction == ContentAction_Undefined) + { + throw std::runtime_error("ContentAction_Undefined when AdjusterWidget::setName() called."); + return; + } + if (name.isEmpty()) { mValid = false; diff --git a/apps/opencs/view/doc/adjusterwidget.hpp b/apps/opencs/view/doc/adjusterwidget.hpp index 461cfb345..627f89c1f 100644 --- a/apps/opencs/view/doc/adjusterwidget.hpp +++ b/apps/opencs/view/doc/adjusterwidget.hpp @@ -9,21 +9,32 @@ class QLabel; namespace CSVDoc { + enum ContentAction + { + ContentAction_New, + ContentAction_Edit, + ContentAction_Undefined + }; + class AdjusterWidget : public QWidget { Q_OBJECT + public: + boost::filesystem::path mLocalData; QLabel *mMessage; QLabel *mIcon; bool mValid; boost::filesystem::path mResultPath; + ContentAction mAction; public: AdjusterWidget (QWidget *parent = 0); void setLocalData (const boost::filesystem::path& localData); + void setAction (ContentAction action); bool isValid() const; diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 903e78cf1..57b61ff8b 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -53,17 +53,19 @@ void CSVDoc::FileDialog::setLocalData (const boost::filesystem::path& localData) mAdjusterWidget->setLocalData (localData); } -void CSVDoc::FileDialog::showDialog(DialogType dialogType) +void CSVDoc::FileDialog::showDialog (ContentAction action) { - mDialogType = dialogType; + mAction = action; - switch (mDialogType) + ui.projectGroupBoxLayout->insertWidget (0, mAdjusterWidget); + + switch (mAction) { - case DialogType_New: + case ContentAction_New: buildNewFileView(); break; - case DialogType_Open: + case ContentAction_Edit: buildOpenFileView(); break; default: @@ -95,7 +97,6 @@ void CSVDoc::FileDialog::buildNewFileView() mFileWidget->extensionLabelIsVisible(true); ui.projectGroupBoxLayout->insertWidget (0, mFileWidget); - ui.projectGroupBoxLayout->insertWidget (1, mAdjusterWidget); connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)), mAdjusterWidget, SLOT (setName (const QString&, bool))); @@ -110,12 +111,12 @@ void CSVDoc::FileDialog::buildOpenFileView() { setWindowTitle(tr("Open")); ui.projectGroupBox->setTitle (QString("")); - ui.projectGroupBox->layout()->addWidget (mAdjusterWidget); - - mAdjusterWidget->setVisible (false); ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false); + connect (mSelector, SIGNAL (signalAddonFileSelected (int)), this, SLOT (slotUpdateAcceptButton (int))); + connect (mSelector, SIGNAL (signalAddonFileUnselected (int)), this, SLOT (slotUpdateAcceptButton (int))); + connect (ui.projectButtonBox, SIGNAL (accepted()), this, SLOT (slotOpenFile())); } @@ -135,6 +136,11 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool) if (mDialogType == DialogType_New) success = success && !(name.isEmpty()); + else + { + ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back(); + mAdjusterWidget->setName (file->fileName(), !file->isGameFile()); + } ui.projectButtonBox->button (QDialogButtonBox::Ok)->setEnabled (success); } diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 777ee31e4..d9fd56943 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -5,6 +5,7 @@ #include #include +#include "adjusterwidget.hpp" #ifndef CS_QT_BOOST_FILESYSTEM_PATH_DECLARED #define CS_QT_BOOST_FILESYSTEM_PATH_DECLARED @@ -24,32 +25,23 @@ namespace ContentSelectorView namespace CSVDoc { class FileWidget; - class AdjusterWidget; class FileDialog : public QDialog { Q_OBJECT - public: - - enum DialogType - { - DialogType_New, - DialogType_Open - }; - private: ContentSelectorView::ContentSelector *mSelector; Ui::FileDialog ui; - DialogType mDialogType; + ContentAction mAction; FileWidget *mFileWidget; AdjusterWidget *mAdjusterWidget; public: explicit FileDialog(QWidget *parent = 0); - void showDialog (DialogType dialogType); + void showDialog (ContentAction action); void addFiles (const QString &path); diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 33b31b00c..b9e518931 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -151,8 +151,16 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QMode { QAbstractItemModel *const model = ui.addonView->model(); + Qt::CheckState checkState = Qt::Unchecked; + if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) - model->setData(index, Qt::Checked, Qt::CheckStateRole); + checkState = Qt::Checked; + + model->setData(index, checkState, Qt::CheckStateRole); + + if (checkState == Qt::Checked) + emit signalAddonFileSelected (index.row()); else - model->setData(index, Qt::Unchecked, Qt::CheckStateRole); + emit signalAddonFileUnselected (index.row()); + } diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 1e24a5523..da1c39973 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -54,6 +54,8 @@ namespace ContentSelectorView signals: void signalCurrentGamefileIndexChanged (int); + void signalAddonFileSelected (int); + void signalAddonFileUnselected (int); private slots: