From 37fb157f895897e75629c1042b2153935930aab5 Mon Sep 17 00:00:00 2001 From: bieber Date: Wed, 9 Jun 2010 07:51:22 +0000 Subject: [PATCH] Theme Editor: Working on the project viewer infrastructure git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26714 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/editorwindow.cpp | 36 ++++++++++++++++-- utils/themeeditor/editorwindow.h | 1 + utils/themeeditor/editorwindow.ui | 12 +++++- utils/themeeditor/projectfiles.cpp | 77 ++++++++++++++++++++++++++++++++++++++ utils/themeeditor/projectfiles.h | 46 +++++++++++++++++++++++ utils/themeeditor/projectmodel.cpp | 22 +++++++++-- utils/themeeditor/projectmodel.h | 42 ++++++++++++++++++--- utils/themeeditor/themeeditor.pro | 6 ++- 8 files changed, 226 insertions(+), 16 deletions(-) create mode 100644 utils/themeeditor/projectfiles.cpp create mode 100644 utils/themeeditor/projectfiles.h diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index 518428180..d1f3609c5 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -33,7 +33,7 @@ EditorWindow::EditorWindow(QWidget *parent) : { ui->setupUi(this); prefs = new PreferencesDialog(this); - project = new ProjectModel(); + project = 0; loadSettings(); setupUI(); setupMenus(); @@ -94,9 +94,6 @@ void EditorWindow::setupUI() parseStatus = new QLabel(this); ui->statusbar->addPermanentWidget(parseStatus); - /* Setting up the project viewer */ - ui->projectTree->setModel(project); - } void EditorWindow::setupMenus() @@ -130,6 +127,8 @@ void EditorWindow::setupMenus() QObject::connect(ui->actionToolbarOpen, SIGNAL(triggered()), this, SLOT(openFile())); + QObject::connect(ui->actionOpen_Project, SIGNAL(triggered()), + this, SLOT(openProject())); } void EditorWindow::addTab(SkinDocument *doc) @@ -239,6 +238,33 @@ void EditorWindow::openFile() settings.endGroup(); } +void EditorWindow::openProject() +{ + QString fileName; + QSettings settings; + + settings.beginGroup("ProjectModel"); + QString directory = settings.value("defaultDirectory", "").toString(); + fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), directory, + ProjectModel::fileFilter()); + + if(QFile::exists(fileName)) + { + + if(project) + delete project; + + project = new ProjectModel(fileName); + ui->projectTree->setModel(project); + + fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); + settings.setValue("defaultDirectory", fileName); + + } + + settings.endGroup(); + +} void EditorWindow::tabTitleChanged(QString title) { @@ -288,4 +314,6 @@ EditorWindow::~EditorWindow() { delete ui; delete prefs; + if(project) + delete project; } diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h index f8a04b0b7..adcee0ece 100644 --- a/utils/themeeditor/editorwindow.h +++ b/utils/themeeditor/editorwindow.h @@ -53,6 +53,7 @@ private slots: void saveCurrent(); void saveCurrentAs(); void openFile(); + void openProject(); void tabTitleChanged(QString title); void updateCurrent(); /* Generates code in the current tab */ diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui index 1aa53549a..30d1da087 100644 --- a/utils/themeeditor/editorwindow.ui +++ b/utils/themeeditor/editorwindow.ui @@ -111,7 +111,14 @@ - + + + false + + + false + + @@ -282,6 +289,9 @@ Open P&roject + + Ctrl+Shift+O + diff --git a/utils/themeeditor/projectfiles.cpp b/utils/themeeditor/projectfiles.cpp new file mode 100644 index 000000000..441ff1169 --- /dev/null +++ b/utils/themeeditor/projectfiles.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "projectfiles.h" + +ProjectFiles::ProjectFiles(ProjectNode* parent): parentLink(parent) +{ +} + +ProjectFiles::~ProjectFiles() +{ + for(int i = 0; i < children.count(); i++) + delete children[i]; +} + +ProjectNode* ProjectFiles::parent() const +{ + return parentLink; +} + +ProjectNode* ProjectFiles::child(int row) const +{ + if(row >= 0 && row < children.count()) + return children[row]; + + return 0; +} + +int ProjectFiles::numChildren() const +{ + return children.count(); +} + +int ProjectFiles::row() const +{ + return parentLink->indexOf(const_cast(this)); +} + +QVariant ProjectFiles::data(int column) const +{ + if(column == 0) + return QObject::tr("Project Files"); + else + return QVariant(); +} + +Qt::ItemFlags ProjectFiles::flags(int column) const +{ + if(column == 0) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return 0; +} + +void ProjectFiles::activated() +{ + +} + diff --git a/utils/themeeditor/projectfiles.h b/utils/themeeditor/projectfiles.h new file mode 100644 index 000000000..5fcbff73b --- /dev/null +++ b/utils/themeeditor/projectfiles.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * 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 PROJECTFILES_H +#define PROJECTFILES_H + +#include "projectmodel.h" + +class ProjectFiles : public ProjectNode +{ +public: + ProjectFiles(ProjectNode* parent); + virtual ~ProjectFiles(); + + virtual ProjectNode* parent() const; + virtual ProjectNode* child(int row) const; + virtual int numChildren() const; + virtual int row() const; + virtual QVariant data(int column) const; + virtual Qt::ItemFlags flags(int column) const; + virtual void activated(); + +private: + ProjectNode* parentLink; + +}; + +#endif // PROJECTFILES_H diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp index 8a26aa326..aeca1c76a 100644 --- a/utils/themeeditor/projectmodel.cpp +++ b/utils/themeeditor/projectmodel.cpp @@ -21,11 +21,12 @@ #include "projectmodel.h" +#include "projectfiles.h" -ProjectModel::ProjectModel(QObject *parent) : +ProjectModel::ProjectModel(QString config, QObject *parent) : QAbstractItemModel(parent) { - + root = new ProjectRoot(config); } ProjectModel::~ProjectModel() @@ -59,7 +60,7 @@ QModelIndex ProjectModel::parent(const QModelIndex &child) const ProjectNode* foundParent = static_cast (child.internalPointer())->parent(); - if(foundParent == root) + if(foundParent == 0) return QModelIndex(); return createIndex(foundParent->row(), 0, foundParent); @@ -104,7 +105,8 @@ QVariant ProjectModel::headerData(int col, Qt::Orientation orientation, Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const { - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return static_cast + (index.internalPointer())->flags(index.column()); } bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, @@ -112,3 +114,15 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, { return true; } + +/* Constructor and destructor for the root class */ +ProjectRoot::ProjectRoot(QString config) +{ + children.append(new ProjectFiles(this)); +} + +ProjectRoot::~ProjectRoot() +{ + for(int i = 0; i < children.count(); i++) + delete children[i]; +} diff --git a/utils/themeeditor/projectmodel.h b/utils/themeeditor/projectmodel.h index e3bf93dcb..62cf00818 100644 --- a/utils/themeeditor/projectmodel.h +++ b/utils/themeeditor/projectmodel.h @@ -32,7 +32,12 @@ Q_OBJECT public: static const int numColumns = 1; - ProjectModel(QObject *parent = 0); + static QString fileFilter() + { + return QObject::tr("Project Files (*.cfg);;All Files (*.*)"); + } + + ProjectModel(QString config, QObject *parent = 0); virtual ~ProjectModel(); QModelIndex index(int row, int column, const QModelIndex& parent) const; @@ -51,7 +56,6 @@ public slots: private: ProjectNode* root; - }; /* A simple abstract class required for categories */ @@ -63,10 +67,38 @@ public: 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; + virtual Qt::ItemFlags flags(int column) const = 0; + virtual void activated() = 0; + + int indexOf(ProjectNode* child){ return children.indexOf(child); } + +protected: + QList children; }; +/* A simple implementation of ProjectNode for the root */ +class ProjectRoot : public ProjectNode +{ +public: + ProjectRoot(QString config); + virtual ~ProjectRoot(); + + virtual ProjectNode* parent() const{ return 0; } + virtual ProjectNode* child(int row) const + { + if(row >= 0 && row < children.count()) + return children[row]; + else + return 0; + } + virtual int numChildren() const{ return children.count(); } + virtual int row() const{ return 0; } + virtual QVariant data(int column) const{ return QVariant(); } + virtual Qt::ItemFlags flags(int column) const{ return 0; } + virtual void activated(){ } + +}; + + #endif // PROJECTMODEL_H diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 128f56996..d78ea681a 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -16,7 +16,8 @@ HEADERS += tag_table.h \ skindocument.h \ preferencesdialog.h \ codeeditor.h \ - projectmodel.h + projectmodel.h \ + projectfiles.h SOURCES += tag_table.c \ skin_parser.c \ skin_scan.c \ @@ -29,7 +30,8 @@ SOURCES += tag_table.c \ skindocument.cpp \ preferencesdialog.cpp \ codeeditor.cpp \ - projectmodel.cpp + projectmodel.cpp \ + projectfiles.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ -- 2.11.4.GIT