diff options
-rw-r--r-- | sigmodr/widgets/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigmodr/widgets/ObjectUI.cpp | 85 | ||||
-rw-r--r-- | sigmodr/widgets/ObjectUI.h | 37 | ||||
-rw-r--r-- | sigmodr/widgets/ObjectUIPrivate.cpp | 70 | ||||
-rw-r--r-- | sigmodr/widgets/ObjectUIPrivate.h | 62 |
5 files changed, 165 insertions, 91 deletions
diff --git a/sigmodr/widgets/CMakeLists.txt b/sigmodr/widgets/CMakeLists.txt index 4ba66e43..458babbf 100644 --- a/sigmodr/widgets/CMakeLists.txt +++ b/sigmodr/widgets/CMakeLists.txt @@ -26,6 +26,7 @@ set(sigmodrwidgets_HEADERS MoveUI.h NatureUI.h ObjectUI.h + ObjectUIPrivate.h RulesUI.h SkinUI.h SoundUI.h @@ -63,6 +64,7 @@ set(sigmodrwidgets_SRCS MoveUI.cpp NatureUI.cpp ObjectUI.cpp + ObjectUIPrivate.cpp RulesUI.cpp SkinUI.cpp SoundUI.cpp diff --git a/sigmodr/widgets/ObjectUI.cpp b/sigmodr/widgets/ObjectUI.cpp index 59be2321..c26a6b73 100644 --- a/sigmodr/widgets/ObjectUI.cpp +++ b/sigmodr/widgets/ObjectUI.cpp @@ -22,91 +22,59 @@ #include "ValidationDialog.h" // Sigmod includes -#include <sigmod/Game.h> #include <sigmod/Object.h> // KDE includes #include <KAction> -#include <KDialog> #include <KMenu> -#include <KMessageBox> + +// KDE includes +#include <QtGui/QVBoxLayout> using namespace Sigmod; using namespace Sigmodr::Widgets; -ObjectUI::ObjectUI(QWidget* parent) : +ObjectUI::ObjectUI(Object* object, QWidget* parent) : QWidget(parent), - m_changed(false), - m_validator(NULL), - m_object(NULL), - m_object_mod(NULL) + m_object(object), + m_validator(NULL) { setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(changed(bool)), SLOT(setChanged(bool))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint))); + emit(changed(false)); } ObjectUI::~ObjectUI() { - delete m_object_mod; -} - -void ObjectUI::reload() -{ - refreshGui(); - setGui(); -} - -bool ObjectUI::isChanged() const -{ - return m_changed; } -const Game* ObjectUI::game() const -{ - return m_object->game(); -} - -const Object* ObjectUI::original() const +const Object* ObjectUI::object() const { return m_object; } -Object* ObjectUI::original() +Object* ObjectUI::object() { return m_object; } -const Object* ObjectUI::modified() const -{ - return m_object_mod; -} - -Object* ObjectUI::modified() +void ObjectUI::apply() { - return m_object_mod; + emit(changed(false)); + emit(saved()); } -void ObjectUI::setObjects(Object* original, Object* modified) +void ObjectUI::discard() { - m_object = original; - m_object_mod = modified; - if (m_validator) - delete m_validator; - m_validator = new ValidationDialog(m_object, this); - connect(m_object_mod, SIGNAL(changed()), this, SIGNAL(changed())); - connect(m_object_mod, SIGNAL(changed()), this, SLOT(setGui())); - connect(m_object_mod, SIGNAL(error(QString)), this, SLOT(setGui())); - connect(m_object_mod, SIGNAL(error(QString)), this, SLOT(errorMessage(QString))); - connect(m_object_mod, SIGNAL(warning(QString)), this, SLOT(warningMessage(QString))); - init(); + emit(changed(false)); } -void ObjectUI::init() +void ObjectUI::setWidget(QWidget* widget) { - initGui(); - reload(); - emit(changed(false)); + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(widget); + setLayout(layout); } void ObjectUI::setChanged(const bool changed) @@ -114,20 +82,6 @@ void ObjectUI::setChanged(const bool changed) m_changed = changed; } -void ObjectUI::errorMessage(const QString& message) -{ - KMessageBox::error(this, message, "Error"); -} - -void ObjectUI::warningMessage(const QString& message) -{ - KMessageBox::warningContinueCancel(this, message, "Warning"); -} - -void ObjectUI::refreshGui() -{ -} - void ObjectUI::contextMenu(const QPoint& pos) { KMenu* menu = new KMenu; @@ -145,5 +99,8 @@ void ObjectUI::validate() { if (m_changed) apply(); + if (m_validator) + delete m_validator; + m_validator = new ValidationDialog(m_object, this); m_validator->show(); } diff --git a/sigmodr/widgets/ObjectUI.h b/sigmodr/widgets/ObjectUI.h index 87c9dbe4..54b9cbbb 100644 --- a/sigmodr/widgets/ObjectUI.h +++ b/sigmodr/widgets/ObjectUI.h @@ -42,46 +42,29 @@ class SIGMODRWIDGETS_EXPORT ObjectUI : public QWidget Q_OBJECT public: - ObjectUI(QWidget* parent); + ObjectUI(Sigmod::Object* object, QWidget* parent); virtual ~ObjectUI(); - void reload(); - - bool isChanged() const; - - const Sigmod::Game* game() const; - - const Sigmod::Object* original() const; - Sigmod::Object* original(); - const Sigmod::Object* modified() const; - Sigmod::Object* modified(); + const Sigmod::Object* object() const; + Sigmod::Object* object(); public slots: - virtual void apply() = 0; - virtual void discard() = 0; + virtual void apply(); + virtual void discard(); signals: + void saved(); void changed(bool = true); protected: - void setObjects(Sigmod::Object* original, Sigmod::Object* modified); - - void init(); - protected slots: - void setChanged(const bool changed = true); - void errorMessage(const QString& message); - void warningMessage(const QString& message); + void setWidget(QWidget* widget); - virtual void initGui() = 0; - virtual void refreshGui(); - virtual void setGui() = 0; + Sigmod::Object* const m_object; private: bool m_changed; ValidationDialog* m_validator; - - Sigmod::Object* m_object; - Sigmod::Object* m_object_mod; private slots: - void contextMenu(const QPoint& pos); + void setChanged(const bool changed = true); + void contextMenu(const QPoint& pos); void validate(); }; } diff --git a/sigmodr/widgets/ObjectUIPrivate.cpp b/sigmodr/widgets/ObjectUIPrivate.cpp new file mode 100644 index 00000000..d9975149 --- /dev/null +++ b/sigmodr/widgets/ObjectUIPrivate.cpp @@ -0,0 +1,70 @@ +/* + * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "ObjectUIPrivate.h" + +// Sigmod includes +#include <sigmod/Object.h> + +// KDE includes +#include <KDialog> +#include <KMessageBox> + +// Qt includes +#include <QtCore/QFile> +#include <QtUiTools/QUiLoader> + +using namespace Sigmod; +using namespace Sigmodr::Widgets; + +ObjectUIPrivate::ObjectUIPrivate(Sigmod::Object* object) : + QObject(NULL) +{ + connect(object, SIGNAL(changed()), this, SIGNAL(changed())); + connect(object, SIGNAL(error(QString)), this, SLOT(resetGui())); + connect(object, SIGNAL(error(QString)), this, SLOT(errorMessage(QString))); + connect(object, SIGNAL(warning(QString)), this, SLOT(warningMessage(QString))); +} + +ObjectUIPrivate::~ObjectUIPrivate() +{ +} + +void ObjectUIPrivate::refreshGui() +{ + resetGui(); +} + +QWidget* ObjectUIPrivate::openUiFile(const QString& filename, QWidget* parent) +{ + QFile file(filename); + file.open(QFile::ReadOnly); + QWidget *formWidget = QUiLoader().load(&file, parent); + file.close(); + return formWidget; +} + +void ObjectUIPrivate::errorMessage(const QString& message) +{ + KMessageBox::error(NULL, message, "Error"); +} + +void ObjectUIPrivate::warningMessage(const QString& message) +{ + KMessageBox::warningContinueCancel(NULL, message, "Warning"); +} diff --git a/sigmodr/widgets/ObjectUIPrivate.h b/sigmodr/widgets/ObjectUIPrivate.h new file mode 100644 index 00000000..e075420d --- /dev/null +++ b/sigmodr/widgets/ObjectUIPrivate.h @@ -0,0 +1,62 @@ +/* + * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMODRWIDGETS_OBJECTUIPRIVATE +#define SIGMODRWIDGETS_OBJECTUIPRIVATE + +// Sigmodr widget includes +#include "Global.h" + +// Qt includes +#include <QtCore/QObject> + +// Forward declarations +namespace Sigmod +{ +class Object; +} + +namespace Sigmodr +{ +namespace Widgets +{ +class ObjectUI; + +class SIGMODRWIDGETS_IMPORT ObjectUIPrivate : public QObject +{ + Q_OBJECT + + public: + ObjectUIPrivate(Sigmod::Object* object); + virtual ~ObjectUIPrivate(); + + virtual QWidget* makeWidgets(ObjectUI* widget) = 0; + public slots: + virtual void refreshGui(); + virtual void resetGui() = 0; + signals: + bool changed(); + protected: + QWidget* openUiFile(const QString& filename, QWidget* parent); + protected slots: + void errorMessage(const QString& message); + void warningMessage(const QString& message); +}; +} +} + +#endif |