summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-09 07:51:22 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-09 07:51:22 +0000
commitceddd2f1e87fd884d9a9af59b20e47353085dff5 (patch)
tree9033568d130dc138cc18bad7907c181a05725acc /utils/themeeditor
parent6efc8d5bc16fd2a73731ba17c7f6a03cf2b9b582 (diff)
downloadrockbox-ceddd2f1e87fd884d9a9af59b20e47353085dff5.tar.gz
rockbox-ceddd2f1e87fd884d9a9af59b20e47353085dff5.tar.bz2
rockbox-ceddd2f1e87fd884d9a9af59b20e47353085dff5.zip
Theme Editor: Working on the project viewer infrastructure
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26714 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/editorwindow.cpp36
-rw-r--r--utils/themeeditor/editorwindow.h1
-rw-r--r--utils/themeeditor/editorwindow.ui12
-rw-r--r--utils/themeeditor/projectfiles.cpp77
-rw-r--r--utils/themeeditor/projectfiles.h46
-rw-r--r--utils/themeeditor/projectmodel.cpp22
-rw-r--r--utils/themeeditor/projectmodel.h42
-rw-r--r--utils/themeeditor/themeeditor.pro6
8 files changed, 226 insertions, 16 deletions
diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp
index 5184281809..d1f3609c50 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 f8a04b0b70..adcee0ece4 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 1aa53549af..30d1da087f 100644
--- a/utils/themeeditor/editorwindow.ui
+++ b/utils/themeeditor/editorwindow.ui
@@ -111,7 +111,14 @@
<widget class="QWidget" name="dockWidgetContents_2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
- <widget class="QTreeView" name="projectTree"/>
+ <widget class="QTreeView" name="projectTree">
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ </widget>
</item>
</layout>
</widget>
@@ -282,6 +289,9 @@
<property name="text">
<string>Open P&amp;roject</string>
</property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+O</string>
+ </property>
</action>
</widget>
<tabstops>
diff --git a/utils/themeeditor/projectfiles.cpp b/utils/themeeditor/projectfiles.cpp
new file mode 100644
index 0000000000..441ff1169e
--- /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<ProjectFiles*>(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 0000000000..5fcbff73b2
--- /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 8a26aa3263..aeca1c76a7 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<ProjectNode*>
(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<ProjectNode*>
+ (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 e3bf93dcb5..62cf00818c 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<ProjectNode*> 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 128f56996d..d78ea681a6 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 \