diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-08 21:30:28 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-08 21:30:28 +0000 |
commit | 61b5f0c973fb9d91f8023664c95bfc5570e2f474 (patch) | |
tree | 67c92fc88abb2345263907a48404a13d6ecfe74a | |
parent | 007ef43a506d495953b6bbc8838fc439224fd0a1 (diff) |
Theme Editor: Began implementing classes to display project files and settings in the project panel
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26706 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/themeeditor/editorwindow.cpp | 11 | ||||
-rw-r--r-- | utils/themeeditor/editorwindow.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/editorwindow.ui | 18 | ||||
-rw-r--r-- | utils/themeeditor/projectmodel.cpp | 114 | ||||
-rw-r--r-- | utils/themeeditor/projectmodel.h | 72 | ||||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 6 |
6 files changed, 209 insertions, 14 deletions
diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index cc2a0fb350..5184281809 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -33,6 +33,7 @@ EditorWindow::EditorWindow(QWidget *parent) : { ui->setupUi(this); prefs = new PreferencesDialog(this); + project = new ProjectModel(); loadSettings(); setupUI(); setupMenus(); @@ -75,11 +76,6 @@ void EditorWindow::saveSettings() void EditorWindow::setupUI() { - /* Displaying some files to test the file tree view */ - QFileSystemModel* model = new QFileSystemModel; - model->setRootPath(QDir::currentPath()); - ui->fileTree->setModel(model); - /* Connecting the tab bar signals */ QObject::connect(ui->editorTabs, SIGNAL(currentChanged(int)), this, SLOT(shiftTab(int))); @@ -98,6 +94,9 @@ void EditorWindow::setupUI() parseStatus = new QLabel(this); ui->statusbar->addPermanentWidget(parseStatus); + /* Setting up the project viewer */ + ui->projectTree->setModel(project); + } void EditorWindow::setupMenus() @@ -250,7 +249,7 @@ void EditorWindow::tabTitleChanged(QString title) void EditorWindow::showPanel() { if(sender() == ui->actionFile_Panel) - ui->fileDock->setVisible(true); + ui->projectDock->setVisible(true); if(sender() == ui->actionPreview_Panel) ui->skinPreviewDock->setVisible(true); if(sender() == ui->actionDisplay_Panel) diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h index 3bab704bb6..f8a04b0b70 100644 --- a/utils/themeeditor/editorwindow.h +++ b/utils/themeeditor/editorwindow.h @@ -29,6 +29,7 @@ #include "skinhighlighter.h" #include "skindocument.h" #include "preferencesdialog.h" +#include "projectmodel.h" namespace Ui { class EditorWindow; @@ -66,6 +67,7 @@ private: Ui::EditorWindow *ui; PreferencesDialog* prefs; QLabel* parseStatus; + ProjectModel* project; }; #endif // EDITORWINDOW_H diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui index b25243f254..1aa53549af 100644 --- a/utils/themeeditor/editorwindow.ui +++ b/utils/themeeditor/editorwindow.ui @@ -40,7 +40,7 @@ <x>0</x> <y>0</y> <width>628</width> - <height>25</height> + <height>27</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -49,6 +49,7 @@ </property> <addaction name="actionNew_Document"/> <addaction name="actionOpen_Document"/> + <addaction name="actionOpen_Project"/> <addaction name="separator"/> <addaction name="actionClose_Document"/> <addaction name="separator"/> @@ -100,9 +101,9 @@ <addaction name="actionToolbarOpen"/> <addaction name="actionToolbarSave"/> </widget> - <widget class="QDockWidget" name="fileDock"> + <widget class="QDockWidget" name="projectDock"> <property name="windowTitle"> - <string>Files</string> + <string>Project</string> </property> <attribute name="dockWidgetArea"> <number>1</number> @@ -110,7 +111,7 @@ <widget class="QWidget" name="dockWidgetContents_2"> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> - <widget class="QTreeView" name="fileTree"/> + <widget class="QTreeView" name="projectTree"/> </item> </layout> </widget> @@ -175,7 +176,7 @@ <bool>false</bool> </property> <property name="text"> - <string>&File Panel</string> + <string>P&roject Panel</string> </property> </action> <action name="actionPreview_Panel"> @@ -277,9 +278,14 @@ <string>Save</string> </property> </action> + <action name="actionOpen_Project"> + <property name="text"> + <string>Open P&roject</string> + </property> + </action> </widget> <tabstops> - <tabstop>fileTree</tabstop> + <tabstop>projectTree</tabstop> <tabstop>skinPreview</tabstop> <tabstop>parseTree</tabstop> <tabstop>fromTree</tabstop> diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp new file mode 100644 index 0000000000..8a26aa3263 --- /dev/null +++ b/utils/themeeditor/projectmodel.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * 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 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#include "projectmodel.h" + +ProjectModel::ProjectModel(QObject *parent) : + QAbstractItemModel(parent) +{ + +} + +ProjectModel::~ProjectModel() +{ + if(root) + delete root; +} + +QModelIndex ProjectModel::index(int row, int column, + const QModelIndex& parent) const +{ + + if(!hasIndex(row, column, parent)) + return QModelIndex(); + + ProjectNode* foundParent = root; + if(parent.isValid()) + foundParent = static_cast<ProjectNode*>(parent.internalPointer()); + + if(row < foundParent->numChildren() && row >= 0) + return createIndex(row, column, foundParent->child(row)); + else + return QModelIndex(); +} + +QModelIndex ProjectModel::parent(const QModelIndex &child) const +{ + if(!child.isValid()) + return QModelIndex(); + + ProjectNode* foundParent = static_cast<ProjectNode*> + (child.internalPointer())->parent(); + + if(foundParent == root) + return QModelIndex(); + + return createIndex(foundParent->row(), 0, foundParent); +} + +int ProjectModel::rowCount(const QModelIndex &parent) const +{ + if(!root) + return 0; + + if(!parent.isValid()) + return root->numChildren(); + + if(parent.column() != 0) + return 0; + + return static_cast<ProjectNode*>(parent.internalPointer())->numChildren(); +} + +int ProjectModel::columnCount(const QModelIndex &parent) const +{ + return numColumns; +} + +QVariant ProjectModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + if(role != Qt::DisplayRole) + return QVariant(); + + return static_cast<ProjectNode*> + (index.internalPointer())->data(index.column()); +} + +QVariant ProjectModel::headerData(int col, Qt::Orientation orientation, + int role) const +{ + return QVariant(); +} + +Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const +{ + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, + int role) +{ + return true; +} diff --git a/utils/themeeditor/projectmodel.h b/utils/themeeditor/projectmodel.h new file mode 100644 index 0000000000..e3bf93dcb5 --- /dev/null +++ b/utils/themeeditor/projectmodel.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * 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 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef PROJECTMODEL_H +#define PROJECTMODEL_H + +#include <QAbstractItemModel> + +class ProjectNode; + +class ProjectModel : public QAbstractItemModel +{ +Q_OBJECT +public: + static const int numColumns = 1; + + ProjectModel(QObject *parent = 0); + virtual ~ProjectModel(); + + 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; + QVariant headerData(int col, Qt::Orientation orientation, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); + + +signals: + +public slots: + +private: + ProjectNode* root; + +}; + +/* A simple abstract class required for categories */ +class ProjectNode +{ +public: + virtual ProjectNode* parent() const = 0; + virtual ProjectNode* child(int row) const = 0; + virtual int numChildren() const = 0; + virtual int row() const = 0; + virtual QVariant data(int column) const = 0; + virtual QString title() const = 0; + virtual Qt::ItemFlags flags(const QModelIndex& index) const = 0; + virtual void activated(const QModelIndex& index) = 0; + +}; + +#endif // PROJECTMODEL_H diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index e0fcdc09d5..128f56996d 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -15,7 +15,8 @@ HEADERS += tag_table.h \ skinhighlighter.h \ skindocument.h \ preferencesdialog.h \ - codeeditor.h + codeeditor.h \ + projectmodel.h SOURCES += tag_table.c \ skin_parser.c \ skin_scan.c \ @@ -27,7 +28,8 @@ SOURCES += tag_table.c \ skinhighlighter.cpp \ skindocument.cpp \ preferencesdialog.cpp \ - codeeditor.cpp + codeeditor.cpp \ + projectmodel.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ |