From 61b5f0c973fb9d91f8023664c95bfc5570e2f474 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Tue, 8 Jun 2010 21:30:28 +0000 Subject: [PATCH] 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 --- utils/themeeditor/editorwindow.cpp | 11 ++- utils/themeeditor/editorwindow.h | 2 + utils/themeeditor/editorwindow.ui | 18 +++-- utils/themeeditor/projectmodel.cpp | 114 +++++++++++++++++++++++++++++ utils/themeeditor/projectmodel.h | 72 ++++++++++++++++++ utils/themeeditor/themeeditor.pro | 6 +- 6 files changed, 209 insertions(+), 14 deletions(-) create mode 100644 utils/themeeditor/projectmodel.cpp create mode 100644 utils/themeeditor/projectmodel.h 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 @@ 0 0 628 - 25 + 27 @@ -49,6 +49,7 @@ + @@ -100,9 +101,9 @@ - + - Files + Project 1 @@ -110,7 +111,7 @@ - + @@ -175,7 +176,7 @@ false - &File Panel + P&roject Panel @@ -277,9 +278,14 @@ Save + + + Open P&roject + + - fileTree + projectTree skinPreview parseTree fromTree 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(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 + (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(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 + (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 + +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 \