diff options
author | Treeki <treeki@gmail.com> | 2012-08-05 17:35:52 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-08-05 17:35:52 +0200 |
commit | 3b2fb505d58f28f0ce9b4de121f12fc924c1ec0c (patch) | |
tree | 2f6a0303927dbb2b16205e74034255cb70a7d1d4 | |
parent | cee09c07899dfec32672e7e2d175972530a7dfd4 (diff) | |
download | LayoutStudio-3b2fb505d58f28f0ce9b4de121f12fc924c1ec0c.tar.gz LayoutStudio-3b2fb505d58f28f0ce9b4de121f12fc924c1ec0c.zip |
getting further... basic read-only Scene Graph model/widget
-rw-r--r-- | LayoutStudio.pro | 6 | ||||
-rw-r--r-- | lslayoutwindow.cpp | 52 | ||||
-rw-r--r-- | lslayoutwindow.h | 23 | ||||
-rw-r--r-- | lsmainwindow.cpp | 1 | ||||
-rw-r--r-- | lsscenemodel.cpp | 60 | ||||
-rw-r--r-- | lsscenemodel.h | 29 |
6 files changed, 167 insertions, 4 deletions
diff --git a/LayoutStudio.pro b/LayoutStudio.pro index 1ec2b7d..2a27df3 100644 --- a/LayoutStudio.pro +++ b/LayoutStudio.pro @@ -37,7 +37,8 @@ SOURCES += main.cpp \ layoutgl/widget.cpp \ wii/texpalette.cpp \ lspackagemodel.cpp \ - lslayoutwindow.cpp + lslayoutwindow.cpp \ + lsscenemodel.cpp HEADERS += lsmainwindow.h \ lsglobals.h \ lyt/packagebase.h \ @@ -73,7 +74,8 @@ HEADERS += lsmainwindow.h \ wii/texpalette.h \ wii/gx.h \ lspackagemodel.h \ - lslayoutwindow.h + lslayoutwindow.h \ + lsscenemodel.h FORMS += RESOURCES += resources.qrc diff --git a/lslayoutwindow.cpp b/lslayoutwindow.cpp index 25baf41..518d022 100644 --- a/lslayoutwindow.cpp +++ b/lslayoutwindow.cpp @@ -1,4 +1,5 @@ #include "lslayoutwindow.h" +#include "lsscenemodel.h" #include <QGridLayout> #include <QFormLayout> #include <QGroupBox> @@ -32,6 +33,9 @@ LSLayoutWindow::LSLayoutWindow(LYTPackageBase *pkg, const QString &layoutName, Q sizeForm->addRow("Width", m_widthBox); sizeForm->addRow("Height", m_heightBox); + connect(m_widthBox, SIGNAL(valueChanged(double)), SLOT(handleWidthChanged(double))); + connect(m_heightBox, SIGNAL(valueChanged(double)), SLOT(handleHeightChanged(double))); + QGroupBox *matGroup = new QGroupBox("Materials", this); QGroupBox *grpGroup = new QGroupBox("Groups", this); @@ -40,7 +44,53 @@ LSLayoutWindow::LSLayoutWindow(LYTPackageBase *pkg, const QString &layoutName, Q sgrid->addWidget(grpGroup, 1, 1, 1, 1); sgrid->setRowStretch(1, 1); - m_tabWidget->addTab(w, "Settings"); + m_tabWidget->addTab(w, "Layout"); + + // prepare the Scene Graph tab + w = new QWidget(this); + QGridLayout *ggrid = new QGridLayout(w); + + m_searchBox = new QLineEdit(this); + m_searchBox->setPlaceholderText("Search panes..."); + + m_clearSearchButton = new QPushButton("Clear", this); + + m_sceneGraph = new QTreeView(this); + m_sceneGraph->setHeaderHidden(true); + m_sceneSearchList = new QListView(this); + m_sceneListSwitcher = new QStackedLayout; + m_sceneListSwitcher->addWidget(m_sceneGraph); + m_sceneListSwitcher->addWidget(m_sceneSearchList); + + ggrid->addWidget(m_searchBox, 0, 0, 1, 1); + ggrid->addWidget(m_clearSearchButton, 0, 1, 1, 1); + ggrid->addLayout(m_sceneListSwitcher, 1, 0, 1, 2); + + m_tabWidget->addTab(w, "Scene Graph"); + + + // get the resource + m_layout = new LYTLayout(*m_package, m_layoutName); + + m_widthBox->setValue(m_layout->width); + m_heightBox->setValue(m_layout->height); + + m_sceneGraph->setModel(new LSSceneModel(m_layout, this)); + m_sceneGraph->expandAll(); + + setWindowTitle(m_layoutName); +} + +LSLayoutWindow::~LSLayoutWindow() { + delete m_layout; } +void LSLayoutWindow::handleWidthChanged(double v) { + m_layout->width = v; +} + +void LSLayoutWindow::handleHeightChanged(double v) { + m_layout->height = v; +} + diff --git a/lslayoutwindow.h b/lslayoutwindow.h index 51158a0..e83a034 100644 --- a/lslayoutwindow.h +++ b/lslayoutwindow.h @@ -4,25 +4,46 @@ #include <QMainWindow> #include <QTabWidget> #include <QDoubleSpinBox> +#include <QTreeView> +#include <QStackedLayout> +#include <QPushButton> +#include <QLineEdit> +#include <QListView> #include "lyt/packagebase.h" +#include "lyt/layout.h" class LSLayoutWindow : public QMainWindow { Q_OBJECT public: explicit LSLayoutWindow(LYTPackageBase *pkg, const QString &layoutName, QWidget *parent = 0); + ~LSLayoutWindow(); QString layoutName() const { return m_layoutName; } // TODO: set layoutname method + LYTLayout *editedLayout() const { return m_layout; } + private: QString m_layoutName; LYTPackageBase *m_package; + LYTLayout *m_layout; QTabWidget *m_tabWidget; // settings QDoubleSpinBox *m_widthBox, *m_heightBox; - + + // scene graph + QStackedLayout *m_sceneListSwitcher; + QLineEdit *m_searchBox; + QPushButton *m_clearSearchButton; + QTreeView *m_sceneGraph; + QListView *m_sceneSearchList; + +private slots: + void handleWidthChanged(double v); + void handleHeightChanged(double v); + signals: public slots: diff --git a/lsmainwindow.cpp b/lsmainwindow.cpp index 4e6af5f..71b374b 100644 --- a/lsmainwindow.cpp +++ b/lsmainwindow.cpp @@ -32,6 +32,7 @@ LSMainWindow::LSMainWindow(QWidget *parent) : QMainWindow(parent) { createActions(); m_view = new QTreeView(this); + m_view->setHeaderHidden(true); setCentralWidget(m_view); connect(m_view, SIGNAL(activated(QModelIndex)), SLOT(handleItemActivated(QModelIndex))); diff --git a/lsscenemodel.cpp b/lsscenemodel.cpp new file mode 100644 index 0000000..7450368 --- /dev/null +++ b/lsscenemodel.cpp @@ -0,0 +1,60 @@ +#include "lsscenemodel.h" + +LSSceneModel::LSSceneModel(LYTLayout *layout, QObject *parent) : + QAbstractItemModel(parent) +{ + m_layout = layout; +} + + +QModelIndex LSSceneModel::index(int row, int column, const QModelIndex &parent) const { + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + if (!parent.isValid()) + return createIndex(row, column, m_layout->rootPane); + + // what's the parent..? + LYTPane *parentPane = (LYTPane*)parent.internalPointer(); + LYTPane *pane = parentPane->children.at(row); + return createIndex(row, column, pane); +} + +QModelIndex LSSceneModel::parent(const QModelIndex &child) const { + if (!child.isValid()) + return QModelIndex(); + + LYTPane *childPane = (LYTPane*)child.internalPointer(); + LYTPane *parentPane = childPane->parent; + if (parentPane) { + LYTPane *parentParentPane = parentPane->parent; + int index = parentParentPane ? parentParentPane->children.indexOf(parentPane) : 0; + return createIndex(index, 0, parentPane); + } else { + return QModelIndex(); + } +} + +int LSSceneModel::rowCount(const QModelIndex &parent) const { + if (!parent.isValid()) { + return 1; // the root pane + } + + LYTPane *parentPane = (LYTPane*)parent.internalPointer(); + return parentPane->children.count(); +} + +int LSSceneModel::columnCount(const QModelIndex &parent) const { + return 1; +} + +QVariant LSSceneModel::data(const QModelIndex &index, int role) const { + LYTPane *pane = (LYTPane*)index.internalPointer(); + if (pane) { + switch (role) { + case Qt::DisplayRole: + return pane->name; + } + } + return QVariant(); +} diff --git a/lsscenemodel.h b/lsscenemodel.h new file mode 100644 index 0000000..3a26fc1 --- /dev/null +++ b/lsscenemodel.h @@ -0,0 +1,29 @@ +#ifndef LSSCENEMODEL_H +#define LSSCENEMODEL_H + +#include <QAbstractItemModel> +#include "lyt/layout.h" + +class LSSceneModel : public QAbstractItemModel { + Q_OBJECT +public: + explicit LSSceneModel(LYTLayout *layout, QObject *parent = 0); + + LYTLayout *layout() const { return m_layout; } + + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &child) const; + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + +private: + LYTLayout *m_layout; + +signals: + +public slots: + +}; + +#endif // LSSCENEMODEL_H |