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:
parent
6efc8d5bc1
commit
ceddd2f1e8
8 changed files with 226 additions and 16 deletions
|
@ -33,7 +33,7 @@ EditorWindow::EditorWindow(QWidget *parent) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
prefs = new PreferencesDialog(this);
|
prefs = new PreferencesDialog(this);
|
||||||
project = new ProjectModel();
|
project = 0;
|
||||||
loadSettings();
|
loadSettings();
|
||||||
setupUI();
|
setupUI();
|
||||||
setupMenus();
|
setupMenus();
|
||||||
|
@ -94,9 +94,6 @@ void EditorWindow::setupUI()
|
||||||
parseStatus = new QLabel(this);
|
parseStatus = new QLabel(this);
|
||||||
ui->statusbar->addPermanentWidget(parseStatus);
|
ui->statusbar->addPermanentWidget(parseStatus);
|
||||||
|
|
||||||
/* Setting up the project viewer */
|
|
||||||
ui->projectTree->setModel(project);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWindow::setupMenus()
|
void EditorWindow::setupMenus()
|
||||||
|
@ -130,6 +127,8 @@ void EditorWindow::setupMenus()
|
||||||
QObject::connect(ui->actionToolbarOpen, SIGNAL(triggered()),
|
QObject::connect(ui->actionToolbarOpen, SIGNAL(triggered()),
|
||||||
this, SLOT(openFile()));
|
this, SLOT(openFile()));
|
||||||
|
|
||||||
|
QObject::connect(ui->actionOpen_Project, SIGNAL(triggered()),
|
||||||
|
this, SLOT(openProject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWindow::addTab(SkinDocument *doc)
|
void EditorWindow::addTab(SkinDocument *doc)
|
||||||
|
@ -239,6 +238,33 @@ void EditorWindow::openFile()
|
||||||
settings.endGroup();
|
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)
|
void EditorWindow::tabTitleChanged(QString title)
|
||||||
{
|
{
|
||||||
|
@ -288,4 +314,6 @@ EditorWindow::~EditorWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
delete prefs;
|
delete prefs;
|
||||||
|
if(project)
|
||||||
|
delete project;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ private slots:
|
||||||
void saveCurrent();
|
void saveCurrent();
|
||||||
void saveCurrentAs();
|
void saveCurrentAs();
|
||||||
void openFile();
|
void openFile();
|
||||||
|
void openProject();
|
||||||
void tabTitleChanged(QString title);
|
void tabTitleChanged(QString title);
|
||||||
void updateCurrent(); /* Generates code in the current tab */
|
void updateCurrent(); /* Generates code in the current tab */
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,14 @@
|
||||||
<widget class="QWidget" name="dockWidgetContents_2">
|
<widget class="QWidget" name="dockWidgetContents_2">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -282,6 +289,9 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Open P&roject</string>
|
<string>Open P&roject</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Shift+O</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
|
|
77
utils/themeeditor/projectfiles.cpp
Normal file
77
utils/themeeditor/projectfiles.cpp
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
46
utils/themeeditor/projectfiles.h
Normal file
46
utils/themeeditor/projectfiles.h
Normal 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
|
|
@ -21,11 +21,12 @@
|
||||||
|
|
||||||
|
|
||||||
#include "projectmodel.h"
|
#include "projectmodel.h"
|
||||||
|
#include "projectfiles.h"
|
||||||
|
|
||||||
ProjectModel::ProjectModel(QObject *parent) :
|
ProjectModel::ProjectModel(QString config, QObject *parent) :
|
||||||
QAbstractItemModel(parent)
|
QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
|
root = new ProjectRoot(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectModel::~ProjectModel()
|
ProjectModel::~ProjectModel()
|
||||||
|
@ -59,7 +60,7 @@ QModelIndex ProjectModel::parent(const QModelIndex &child) const
|
||||||
ProjectNode* foundParent = static_cast<ProjectNode*>
|
ProjectNode* foundParent = static_cast<ProjectNode*>
|
||||||
(child.internalPointer())->parent();
|
(child.internalPointer())->parent();
|
||||||
|
|
||||||
if(foundParent == root)
|
if(foundParent == 0)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex(foundParent->row(), 0, foundParent);
|
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
|
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,
|
bool ProjectModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
|
@ -112,3 +114,15 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
{
|
{
|
||||||
return true;
|
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];
|
||||||
|
}
|
||||||
|
|
|
@ -32,7 +32,12 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static const int numColumns = 1;
|
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();
|
virtual ~ProjectModel();
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
||||||
|
@ -51,7 +56,6 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProjectNode* root;
|
ProjectNode* root;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A simple abstract class required for categories */
|
/* A simple abstract class required for categories */
|
||||||
|
@ -63,10 +67,38 @@ public:
|
||||||
virtual int numChildren() const = 0;
|
virtual int numChildren() const = 0;
|
||||||
virtual int row() const = 0;
|
virtual int row() const = 0;
|
||||||
virtual QVariant data(int column) const = 0;
|
virtual QVariant data(int column) const = 0;
|
||||||
virtual QString title() const = 0;
|
virtual Qt::ItemFlags flags(int column) const = 0;
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const = 0;
|
virtual void activated() = 0;
|
||||||
virtual void activated(const QModelIndex& index) = 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
|
#endif // PROJECTMODEL_H
|
||||||
|
|
|
@ -16,7 +16,8 @@ HEADERS += tag_table.h \
|
||||||
skindocument.h \
|
skindocument.h \
|
||||||
preferencesdialog.h \
|
preferencesdialog.h \
|
||||||
codeeditor.h \
|
codeeditor.h \
|
||||||
projectmodel.h
|
projectmodel.h \
|
||||||
|
projectfiles.h
|
||||||
SOURCES += tag_table.c \
|
SOURCES += tag_table.c \
|
||||||
skin_parser.c \
|
skin_parser.c \
|
||||||
skin_scan.c \
|
skin_scan.c \
|
||||||
|
@ -29,7 +30,8 @@ SOURCES += tag_table.c \
|
||||||
skindocument.cpp \
|
skindocument.cpp \
|
||||||
preferencesdialog.cpp \
|
preferencesdialog.cpp \
|
||||||
codeeditor.cpp \
|
codeeditor.cpp \
|
||||||
projectmodel.cpp
|
projectmodel.cpp \
|
||||||
|
projectfiles.cpp
|
||||||
OTHER_FILES += README \
|
OTHER_FILES += README \
|
||||||
resources/windowicon.png \
|
resources/windowicon.png \
|
||||||
resources/appicon.xcf \
|
resources/appicon.xcf \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue