summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/editorwindow.cpp19
-rw-r--r--utils/themeeditor/editorwindow.h6
-rw-r--r--utils/themeeditor/projectfiles.cpp16
-rw-r--r--utils/themeeditor/projectfiles.h8
-rw-r--r--utils/themeeditor/projectmodel.cpp25
-rw-r--r--utils/themeeditor/projectmodel.h9
6 files changed, 64 insertions, 19 deletions
diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp
index d1f3609c50..601e4d85e8 100644
--- a/utils/themeeditor/editorwindow.cpp
+++ b/utils/themeeditor/editorwindow.cpp
@@ -20,6 +20,7 @@
****************************************************************************/
#include "editorwindow.h"
+#include "projectmodel.h"
#include "ui_editorwindow.h"
#include <QDesktopWidget>
@@ -39,6 +40,14 @@ EditorWindow::EditorWindow(QWidget *parent) :
setupMenus();
}
+void EditorWindow::loadTabFromFile(QString fileName)
+{
+ /* Adding a new document for each file name */
+ SkinDocument* doc = new SkinDocument(parseStatus, fileName);
+ addTab(doc);
+
+}
+
void EditorWindow::loadSettings()
{
@@ -225,9 +234,7 @@ void EditorWindow::openFile()
QString current = fileNames[i];
- /* Adding a new document for each file name */
- SkinDocument* doc = new SkinDocument(parseStatus, current);
- addTab(doc);
+ loadTabFromFile(current);
/* And setting the new default directory */
current.chop(current.length() - current.lastIndexOf('/') - 1);
@@ -254,8 +261,12 @@ void EditorWindow::openProject()
if(project)
delete project;
- project = new ProjectModel(fileName);
+ project = new ProjectModel(fileName, this);
ui->projectTree->setModel(project);
+ ui->projectTree->expandAll();
+
+ QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)),
+ project, SLOT(activated(QModelIndex)));
fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1);
settings.setValue("defaultDirectory", fileName);
diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h
index adcee0ece4..32c7d0a057 100644
--- a/utils/themeeditor/editorwindow.h
+++ b/utils/themeeditor/editorwindow.h
@@ -29,7 +29,8 @@
#include "skinhighlighter.h"
#include "skindocument.h"
#include "preferencesdialog.h"
-#include "projectmodel.h"
+
+class ProjectModel;
namespace Ui {
class EditorWindow;
@@ -41,6 +42,9 @@ public:
EditorWindow(QWidget *parent = 0);
~EditorWindow();
+ /* A public function so external widgets can load files */
+ void loadTabFromFile(QString fileName);
+
protected:
virtual void closeEvent(QCloseEvent* event);
diff --git a/utils/themeeditor/projectfiles.cpp b/utils/themeeditor/projectfiles.cpp
index b7168ac47d..f687e23767 100644
--- a/utils/themeeditor/projectfiles.cpp
+++ b/utils/themeeditor/projectfiles.cpp
@@ -22,8 +22,11 @@
#include "projectfiles.h"
ProjectFiles::ProjectFiles(QHash<QString, QString>& settings,
- ProjectNode* parent): parentLink(parent)
+ ProjectModel* model, ProjectNode* parent)
+ : parentLink(parent)
{
+ base = settings.value("themebase");
+
QList<QString> keys;
keys.append("wps");
keys.append("rwps");
@@ -38,7 +41,7 @@ ProjectFiles::ProjectFiles(QHash<QString, QString>& settings,
if(file != "" && file != "-")
{
file.replace("/.rockbox/", "");
- children.append(new ProjectFile(file, this));
+ children.append(new ProjectFile(file, model, this));
}
}
}
@@ -94,10 +97,11 @@ void ProjectFiles::activated()
}
/* Project File functions */
-ProjectFile::ProjectFile(QString file, ProjectNode* parent) :
- parentLink(parent), file(file)
+ProjectFile::ProjectFile(QString file, ProjectModel* model,
+ ProjectNode* parent)
+ :parentLink(parent), file(file)
{
-
+ this->model = model;
}
ProjectFile::~ProjectFile()
@@ -123,5 +127,7 @@ Qt::ItemFlags ProjectFile::flags(int column) const
void ProjectFile::activated()
{
+ QString base = dynamic_cast<ProjectFiles*>(parentLink)->getBase();
+ model->loadFile(base + "/" + file);
}
diff --git a/utils/themeeditor/projectfiles.h b/utils/themeeditor/projectfiles.h
index 96212c8bc6..6fec62882c 100644
--- a/utils/themeeditor/projectfiles.h
+++ b/utils/themeeditor/projectfiles.h
@@ -28,7 +28,8 @@
class ProjectFiles : public ProjectNode
{
public:
- ProjectFiles(QHash<QString, QString>& settings, ProjectNode* parent);
+ ProjectFiles(QHash<QString, QString>& settings, ProjectModel* model,
+ ProjectNode* parent);
virtual ~ProjectFiles();
virtual ProjectNode* parent() const;
@@ -38,9 +39,12 @@ public:
virtual QVariant data(int column) const;
virtual Qt::ItemFlags flags(int column) const;
virtual void activated();
+
+ QString getBase(){ return base; }
private:
ProjectNode* parentLink;
+ QString base;
};
@@ -48,7 +52,7 @@ private:
class ProjectFile: public ProjectNode
{
public:
- ProjectFile(QString file, ProjectNode* parent);
+ ProjectFile(QString file, ProjectModel* model, ProjectNode* parent);
virtual ~ProjectFile();
virtual ProjectNode* parent() const{ return parentLink; }
diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp
index d3a338ea4f..f745139338 100644
--- a/utils/themeeditor/projectmodel.cpp
+++ b/utils/themeeditor/projectmodel.cpp
@@ -22,16 +22,19 @@
#include "projectmodel.h"
#include "projectfiles.h"
+#include "editorwindow.h"
#include <QFile>
#include <QTextStream>
#include <QHash>
#include <QDir>
-ProjectModel::ProjectModel(QString config, QObject *parent) :
- QAbstractItemModel(parent)
+ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow,
+ QObject *parent)
+ : QAbstractItemModel(parent),
+ mainWindow(mainWindow)
{
- root = new ProjectRoot(config);
+ root = new ProjectRoot(config, this);
}
ProjectModel::~ProjectModel()
@@ -120,9 +123,21 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value,
return true;
}
+void ProjectModel::loadFile(QString file)
+{
+ mainWindow->loadTabFromFile(file);
+}
+
+void ProjectModel::activated(const QModelIndex &index)
+{
+ static_cast<ProjectNode*>(index.internalPointer())->activated();
+}
+
/* Constructor and destructor for the root class */
-ProjectRoot::ProjectRoot(QString config)
+ProjectRoot::ProjectRoot(QString config, ProjectModel* model)
{
+ this->model = model;
+
/* Reading the config file */
QFile cfg(config);
cfg.open(QFile::ReadOnly | QFile::Text);
@@ -157,7 +172,7 @@ ProjectRoot::ProjectRoot(QString config)
cfg.close();
/* Showing the files */
- children.append(new ProjectFiles(settings, this));
+ children.append(new ProjectFiles(settings, model, this));
}
diff --git a/utils/themeeditor/projectmodel.h b/utils/themeeditor/projectmodel.h
index 083865a669..f170501a58 100644
--- a/utils/themeeditor/projectmodel.h
+++ b/utils/themeeditor/projectmodel.h
@@ -26,6 +26,7 @@
#include <QHash>
class ProjectNode;
+class EditorWindow;
class ProjectModel : public QAbstractItemModel
{
@@ -38,7 +39,7 @@ public:
return QObject::tr("Project Files (*.cfg);;All Files (*.*)");
}
- ProjectModel(QString config, QObject *parent = 0);
+ ProjectModel(QString config, EditorWindow* mainWindow, QObject *parent = 0);
virtual ~ProjectModel();
QModelIndex index(int row, int column, const QModelIndex& parent) const;
@@ -50,13 +51,16 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
+ void loadFile(QString file);
signals:
public slots:
+ void activated(const QModelIndex& index);
private:
ProjectNode* root;
+ EditorWindow* mainWindow;
};
/* A simple abstract class required for categories */
@@ -75,6 +79,7 @@ public:
protected:
QList<ProjectNode*> children;
+ ProjectModel* model;
};
@@ -82,7 +87,7 @@ protected:
class ProjectRoot : public ProjectNode
{
public:
- ProjectRoot(QString config);
+ ProjectRoot(QString config, ProjectModel* model);
virtual ~ProjectRoot();
virtual ProjectNode* parent() const{ return 0; }