diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | sigtools/BaseModel.cpp | 55 | ||||
-rw-r--r-- | sigtools/BaseModel.h | 61 | ||||
-rw-r--r-- | sigtools/CMakeLists.txt | 54 | ||||
-rw-r--r-- | sigtools/Global.h | 37 | ||||
-rw-r--r-- | sigtools/PluginDelegate.cpp | 47 | ||||
-rw-r--r-- | sigtools/PluginDelegate.h | 46 | ||||
-rw-r--r-- | sigtools/PluginModel.cpp | 100 | ||||
-rw-r--r-- | sigtools/PluginModel.h | 68 | ||||
-rw-r--r-- | sigtools/PluginTree.cpp | 54 | ||||
-rw-r--r-- | sigtools/PluginTree.h | 62 | ||||
-rw-r--r-- | sigtools/RootPluginModel.cpp | 57 | ||||
-rw-r--r-- | sigtools/RootPluginModel.h | 51 |
13 files changed, 693 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3348f9e8..a7a61508 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ add_subdirectory(sigmod) macro_optional_add_subdirectory(sigmodr) add_subdirectory(sigscript) add_subdirectory(sigencore) +add_subdirectory(sigtools) macro_optional_add_subdirectory(sigbattle) macro_optional_add_subdirectory(signet) macro_optional_add_subdirectory(sigworld) diff --git a/sigtools/BaseModel.cpp b/sigtools/BaseModel.cpp new file mode 100644 index 00000000..47c732b6 --- /dev/null +++ b/sigtools/BaseModel.cpp @@ -0,0 +1,55 @@ +/* + * 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 "BaseModel.h" + +// KDE includes +#include <KMessageBox> +#include <KUrl> + +// Qt includes +#include <QtCore/QFile> + +using namespace Sigtools; + +BaseModel::BaseModel(BaseModel* parent) : + m_parent(parent) +{ +} + +BaseModel::~BaseModel() +{ +} + +QVariant BaseModel::data(const int role) const +{ + Q_UNUSED(role) + return QVariant(); +} + +BaseModel* BaseModel::parent() +{ + return m_parent; +} + +int BaseModel::indexNumber() const +{ + if (m_parent) + return m_parent->findChild(const_cast<BaseModel*>(this)); + return -1; +} diff --git a/sigtools/BaseModel.h b/sigtools/BaseModel.h new file mode 100644 index 00000000..af8d8064 --- /dev/null +++ b/sigtools/BaseModel.h @@ -0,0 +1,61 @@ +/* + * 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 SIGTOOLS_BASEMODEL +#define SIGTOOLS_BASEMODEL + +// Sigtools includes +#include "Global.h" + +// Qt includes +#include <QtCore/QString> +#include <QtCore/QVariant> + +// Forward declarations +class QPainter; +class QStyleOptionViewItem; + +namespace Sigtools +{ +class SIGTOOLS_NO_EXPORT BaseModel : public QObject +{ + Q_OBJECT + + public: + BaseModel(BaseModel* parent); + virtual ~BaseModel(); + + BaseModel* parent(); + + QVariant data(const int role = Qt::DisplayRole) const; + virtual int rowCount() const = 0; + + virtual Qt::ItemFlags flags() const = 0; + + virtual void paint(QPainter* painter, const QStyleOptionViewItem& option) const = 0; + virtual QSize sizeHint(const QStyleOptionViewItem& option) const = 0; + + virtual BaseModel* childItem(const int row) = 0; + int indexNumber() const; + protected: + virtual int findChild(BaseModel* model) const = 0; + + BaseModel* m_parent; +}; +} + +#endif diff --git a/sigtools/CMakeLists.txt b/sigtools/CMakeLists.txt new file mode 100644 index 00000000..8efc8d11 --- /dev/null +++ b/sigtools/CMakeLists.txt @@ -0,0 +1,54 @@ +project(sigtools) + +set(sigtools_HEADERS + Global.h + PluginTree.h +) +set(sigtools_SRCS + BaseModel.cpp + PluginTree.cpp + PluginDelegate.cpp + PluginModel.cpp + RootPluginModel.cpp +) + +kde4_add_library(sigtools + SHARED + ${sigtools_SRCS} +) +set_target_properties(sigtools + PROPERTIES + VERSION ${SIGEN_VERSION} + SOVERSION ${SIGEN_SOVERSION} +) +target_link_libraries(sigtools + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + sigmod +) +target_link_libraries(sigtools LINK_INTERFACE_LIBRARIES + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + sigmod +) + +install( + TARGETS + sigtools + EXPORT + sigen_EXPORTS + DESTINATION + ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} + COMPONENT + runtime +) + +install( + FILES + ${sigtools_HEADERS} + DESTINATION + ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/${PROJECT_NAME} + COMPONENT + development +) diff --git a/sigtools/Global.h b/sigtools/Global.h new file mode 100644 index 00000000..08cbfce8 --- /dev/null +++ b/sigtools/Global.h @@ -0,0 +1,37 @@ +/* + * Copyright 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 SIGTOOLS_GLOBAL +#define SIGTOOLS_GLOBAL + +// KDE includes +#include <kdemacros.h> + +#ifndef SIGTOOLS_EXPORT +# ifdef MAKE_SIGTOOLS_LIB +# define SIGTOOLS_EXPORT KDE_EXPORT +# else +# define SIGTOOLS_EXPORT KDE_IMPORT +# endif +# define SIGTOOLS_NO_EXPORT KDE_NO_EXPORT +#endif + +#ifndef SIGTOOLS_EXPORT_DEPRECATED +# define SIGTOOLS_EXPORT_DEPRECATED KDE_DEPRECATED SIGTOOLS_EXPORT +#endif + +#endif diff --git a/sigtools/PluginDelegate.cpp b/sigtools/PluginDelegate.cpp new file mode 100644 index 00000000..9a16e86c --- /dev/null +++ b/sigtools/PluginDelegate.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 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 "PluginDelegate.h" + +// Sigtools includes +#include "BaseModel.h" +#include "PluginModel.h" +#include "PluginTree.h" + +using namespace Sigtools; + +PluginDelegate::PluginDelegate(PluginTree* parent) : + QAbstractItemDelegate(parent), + m_view(parent) +{ +} + +void PluginDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + PluginModel* model = qobject_cast<PluginModel*>(m_view->model()); + if (model) + model->getItem(index)->paint(painter, option); +} + +QSize PluginDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + PluginModel* model = qobject_cast<PluginModel*>(m_view->model()); + if (model) + return model->getItem(index)->sizeHint(option); + return QSize(); +} diff --git a/sigtools/PluginDelegate.h b/sigtools/PluginDelegate.h new file mode 100644 index 00000000..0fb0c6ad --- /dev/null +++ b/sigtools/PluginDelegate.h @@ -0,0 +1,46 @@ +/* + * Copyright 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 SIGTOOLS_PLUGINDELEGATE +#define SIGTOOLS_PLUGINDELEGATE + +// Sigtools includes +#include "Global.h" + +// Qt includes +#include <QtGui/QAbstractItemDelegate> + +namespace Sigtools +{ +// Forward declarations +class PluginTree; + +class SIGTOOLS_NO_EXPORT PluginDelegate : public QAbstractItemDelegate +{ + Q_OBJECT + + public: + PluginDelegate(PluginTree* parent); + + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; + private: + PluginTree* m_view; +}; +} + +#endif diff --git a/sigtools/PluginModel.cpp b/sigtools/PluginModel.cpp new file mode 100644 index 00000000..711c8fc2 --- /dev/null +++ b/sigtools/PluginModel.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 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 "PluginModel.h" + +// Sigtools includes +#include "BaseModel.h" +#include "PluginTree.h" +#include "RootPluginModel.h" + +// Qt includes +#include <QtGui/QIcon> + +using namespace Sigtools; + +PluginModel::PluginModel(PluginTree* browser) : + QAbstractItemModel(browser), + m_root(new RootPluginModel) +{ +} + +PluginModel::~PluginModel() +{ + delete m_root; +} + +QModelIndex PluginModel::index(const int row, const int column, const QModelIndex& parent) const +{ + if ((row < -1) || (column < -1)) + return QModelIndex(); + if (row == -1) + return createIndex(row, 0, m_root); + BaseModel* model = getItem(parent); + if ((model->rowCount() <= row) || (1 <= column)) + return QModelIndex(); + return createIndex(row, 0, model->childItem(row)); +} + +QVariant PluginModel::data(const QModelIndex& index, const int role) const +{ + Q_UNUSED(index) + Q_UNUSED(role) + return QVariant(); +} + +QModelIndex PluginModel::parent(const QModelIndex& index) const +{ + if (!index.isValid()) + return QModelIndex(); + BaseModel* parent = static_cast<BaseModel*>(index.internalPointer())->parent(); + if (!parent || (parent == m_root)) + return QModelIndex(); + return createIndex(parent->indexNumber(), 0, parent); +} + +int PluginModel::rowCount(const QModelIndex& parent) const +{ + return getItem(parent)->rowCount(); +} + +int PluginModel::columnCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent) + return 1; +} + +Qt::ItemFlags PluginModel::flags(const QModelIndex& index) const +{ + Qt::ItemFlags flags = QAbstractItemModel::flags(index); + if (index.isValid()) + flags |= static_cast<BaseModel*>(index.internalPointer())->flags(); + return flags; +} + +BaseModel* PluginModel::getItem(const QModelIndex& index) const +{ + if (index.isValid()) + return static_cast<BaseModel*>(index.internalPointer()); + return m_root; +} + +void PluginModel::addPlugin(const QString& type, KService::Ptr service) +{ + m_root->addPlugin(type, service); +} diff --git a/sigtools/PluginModel.h b/sigtools/PluginModel.h new file mode 100644 index 00000000..32457455 --- /dev/null +++ b/sigtools/PluginModel.h @@ -0,0 +1,68 @@ +/* + * Copyright 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 SIGTOOLS_PLUGINMODEL +#define SIGTOOLS_PLUGINMODEL + +// Sigtools includes +#include "Global.h" + +// KDE includes +#include <KPluginInfo> + +// Qt includes +#include <QtCore/QList> +#include <QtCore/QPair> +#include <QtCore/QAbstractItemModel> +#include <QtGui/QIcon> + +// Forward declarations +class KPluginFactory; + +namespace Sigtools +{ +class BaseModel; +class PluginTree; +class RootPluginModel; + +class SIGTOOLS_NO_EXPORT PluginModel : public QAbstractItemModel +{ + Q_OBJECT + + public: + PluginModel(PluginTree* browser); + ~PluginModel(); + + QVariant data(const QModelIndex& index, int role) const; + + QModelIndex index(int row, int column, const QModelIndex& parent) const; + QModelIndex parent(const QModelIndex& index) const; + + int rowCount(const QModelIndex& parent = QModelIndex()) const; + int columnCount(const QModelIndex& parent = QModelIndex()) const; + + Qt::ItemFlags flags(const QModelIndex& index) const; + + BaseModel* getItem(const QModelIndex& index) const; + + void addPlugin(const QString& type, KService::Ptr service); + private: + RootPluginModel* m_root; +}; +} + +#endif diff --git a/sigtools/PluginTree.cpp b/sigtools/PluginTree.cpp new file mode 100644 index 00000000..fb881761 --- /dev/null +++ b/sigtools/PluginTree.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 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 "PluginTree.h" + +// Sigtools includes +#include "PluginDelegate.h" +#include "PluginModel.h" + +// Sigencore plugin includes +#include <sigencore/plugins/ArenaPlugin.h> + +// KDE includes +#include <KPluginInfo> +#include <KServiceTypeTrader> + +// Qt includes +#include <QtGui/QHeaderView> +#include <QtGui/QTreeWidget> + +using namespace Sigtools; + +PluginTree::PluginTree(const QStringList& types, QWidget* parent) : + QTreeView(parent), + m_model(new PluginModel(this)) +{ + setSelectionBehavior(SelectItems); + setSelectionMode(SingleSelection); + foreach (const QString& type, types) + loadServiceType(type); + setModel(m_model); +} + +void PluginTree::loadServiceType(const QString& type) +{ + KService::List services = KServiceTypeTrader::self()->query(type, "[X-Sigen-MinVersion] <= 000101"); + foreach (KService::Ptr service, services) + m_model->addPlugin(type, service); +} diff --git a/sigtools/PluginTree.h b/sigtools/PluginTree.h new file mode 100644 index 00000000..d4336364 --- /dev/null +++ b/sigtools/PluginTree.h @@ -0,0 +1,62 @@ +/* + * Copyright 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 SIGTOOLS_PLUGINTREE +#define SIGTOOLS_PLUGINTREE + +// Sigtools includes +#include "Global.h" + +// KDE includes +#include <KService> + +// Qt includes +#include <QtGui/QTreeView> + +// Forward declarations +namespace Sigmod +{ +class Game; +} +namespace Sigscript +{ +class GameWrapper; +} +namespace Sigencore +{ +class Arena; +class Canvas; +} + +namespace Sigtools +{ +class PluginModel; + +class SIGTOOLS_EXPORT PluginTree : public QTreeView +{ + Q_OBJECT + + public: + PluginTree(const QStringList& types, QWidget* parent); + private: + void loadServiceType(const QString& type); + + PluginModel* m_model; +}; +} + +#endif diff --git a/sigtools/RootPluginModel.cpp b/sigtools/RootPluginModel.cpp new file mode 100644 index 00000000..13aa5ea3 --- /dev/null +++ b/sigtools/RootPluginModel.cpp @@ -0,0 +1,57 @@ +/* + * 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 "RootPluginModel.h" + +// Qt includes +#include <QtCore/QSize> + +using namespace Sigtools; + +RootPluginModel::RootPluginModel() : + BaseModel(NULL) +{ +} + +int RootPluginModel::rowCount() const +{ +} + +Qt::ItemFlags RootPluginModel::flags() const +{ +} + +void RootPluginModel::paint(QPainter* painter, const QStyleOptionViewItem& option) const +{ +} + +QSize RootPluginModel::sizeHint(const QStyleOptionViewItem& option) const +{ +} + +BaseModel* RootPluginModel::childItem(const int row) +{ +} + +void RootPluginModel::addPlugin(const QString& type, KService::Ptr service) +{ +} + +int RootPluginModel::findChild(BaseModel* model) const +{ +} diff --git a/sigtools/RootPluginModel.h b/sigtools/RootPluginModel.h new file mode 100644 index 00000000..1b2bfb50 --- /dev/null +++ b/sigtools/RootPluginModel.h @@ -0,0 +1,51 @@ +/* + * 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 SIGTOOLS_ROOTPLUGINMODEL +#define SIGTOOLS_ROOTPLUGINMODEL + +// Sigtools includes +#include "BaseModel.h" + +// KDE includes +#include <KService> + +namespace Sigtools +{ +class SIGTOOLS_NO_EXPORT RootPluginModel : public BaseModel +{ + Q_OBJECT + + public: + RootPluginModel(); + + int rowCount() const; + + Qt::ItemFlags flags() const; + + void paint(QPainter* painter, const QStyleOptionViewItem& option) const; + QSize sizeHint(const QStyleOptionViewItem& option) const; + + BaseModel* childItem(const int row); + + void addPlugin(const QString& type, KService::Ptr service); + protected: + int findChild(BaseModel* model) const; +}; +} + +#endif |