1
0
Fork 0
forked from len0rd/rockbox

Theme Editor: Working on the project viewer infrastructure

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26714 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-09 07:51:22 +00:00
parent 6efc8d5bc1
commit ceddd2f1e8
8 changed files with 226 additions and 16 deletions

View file

@ -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;
}

View file

@ -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 */

View file

@ -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>

View file

@ -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()
{
}

View file

@ -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

View file

@ -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];
}

View file

@ -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

View file

@ -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 \