Theme Editor: Changed color to colour in preferences. Made parse tree viewer alternate line colors and auto-scroll/expand with cursor in editor window. Implemented TabContent abstract class so that more than just skin documents can be loaded in tabs. Made SkinDocument implement TabContent. Began implementing ConfigDocument for editing configuration files.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26851 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-15 06:54:58 +00:00
parent 1d4dc9b3b0
commit 2e320f66f4
13 changed files with 435 additions and 46 deletions

View file

@ -0,0 +1,125 @@
#include "configdocument.h"
#include "ui_configdocument.h"
ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file,
QWidget *parent)
: TabContent(parent),
ui(new Ui::ConfigDocument),
filePath(file)
{
ui->setupUi(this);
QMap<QString, QString>::iterator i;
for(i = settings.begin(); i != settings.end(); i++)
addRow(i.key(), i.value());
saved = toPlainText();
QObject::connect(ui->addKeyButton, SIGNAL(pressed()),
this, SLOT(addClicked()));
}
ConfigDocument::~ConfigDocument()
{
delete ui;
}
void ConfigDocument::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
QString ConfigDocument::title() const
{
QStringList decompose = filePath.split("/");
return decompose.last();
}
void ConfigDocument::save()
{
}
void ConfigDocument::saveAs()
{
}
bool ConfigDocument::requestClose()
{
}
QString ConfigDocument::toPlainText() const
{
QString buffer = "";
for(int i = 0; i < keys.count(); i++)
{
buffer += keys[i]->text();
buffer += ":";
buffer += values[i]->text();
buffer += "\n";
}
return buffer;
}
void ConfigDocument::addRow(QString key, QString value)
{
QHBoxLayout* layout = new QHBoxLayout();
QLineEdit* keyEdit = new QLineEdit(key, this);
QLineEdit* valueEdit = new QLineEdit(value, this);
QPushButton* delButton = new QPushButton(tr("-"), this);
layout->addWidget(keyEdit);
layout->addWidget(valueEdit);
layout->addWidget(delButton);
delButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
delButton->setMaximumWidth(35);
QObject::connect(delButton, SIGNAL(clicked()),
this, SLOT(deleteClicked()));
ui->configBoxes->addLayout(layout);
containers.append(layout);
keys.append(keyEdit);
values.append(valueEdit);
deleteButtons.append(delButton);
}
void ConfigDocument::deleteClicked()
{
QPushButton* button = dynamic_cast<QPushButton*>(sender());
int row = deleteButtons.indexOf(button);
deleteButtons[row]->deleteLater();
keys[row]->deleteLater();
values[row]->deleteLater();
containers[row]->deleteLater();
deleteButtons.removeAt(row);
keys.removeAt(row);
values.removeAt(row);
containers.removeAt(row);
if(saved != toPlainText())
emit titleChanged(title() + "*");
else
emit titleChanged(title());
}
void ConfigDocument::addClicked()
{
addRow(tr("Key"), tr("Value"));
}

View file

@ -0,0 +1,54 @@
#ifndef CONFIGDOCUMENT_H
#define CONFIGDOCUMENT_H
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QWidget>
#include <QMap>
#include "tabcontent.h"
namespace Ui {
class ConfigDocument;
}
class ConfigDocument : public TabContent {
Q_OBJECT
public:
ConfigDocument(QMap<QString, QString>& settings, QString file,
QWidget *parent = 0);
virtual ~ConfigDocument();
TabType type() const{ return TabContent::Config; }
QString file() const{ return filePath; }
QString title() const;
QString toPlainText() const;
void save();
void saveAs();
bool requestClose();
protected:
void changeEvent(QEvent *e);
private:
Ui::ConfigDocument *ui;
QList<QHBoxLayout*> containers;
QList<QLineEdit*> keys;
QList<QLineEdit*> values;
QList<QPushButton*> deleteButtons;
QString filePath;
QString saved;
void addRow(QString key, QString value);
private slots:
void deleteClicked();
void addClicked();
};
#endif // CONFIGDOCUMENT_H

View file

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigDocument</class>
<widget class="QWidget" name="ConfigDocument">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>299</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>402</width>
<height>244</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QVBoxLayout" name="configBoxes"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addKeyButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -40,14 +40,14 @@ EditorWindow::EditorWindow(QWidget *parent) :
setupMenus();
}
void EditorWindow::loadTabFromFile(QString fileName)
void EditorWindow::loadTabFromSkinFile(QString fileName)
{
/* Checking to see if the file is already open */
for(int i = 0; i < ui->editorTabs->count(); i++)
{
SkinDocument* current = dynamic_cast<SkinDocument*>
TabContent* current = dynamic_cast<TabContent*>
(ui->editorTabs->widget(i));
if(current->getFile() == fileName)
if(current->file() == fileName)
{
ui->editorTabs->setCurrentIndex(i);
return;
@ -61,6 +61,27 @@ void EditorWindow::loadTabFromFile(QString fileName)
}
void EditorWindow::loadConfigTab(ConfigDocument* doc)
{
for(int i = 0; i < ui->editorTabs->count(); i++)
{
TabContent* current = dynamic_cast<TabContent*>
(ui->editorTabs->widget(i));
if(current->file() == doc->file())
{
ui->editorTabs->setCurrentIndex(i);
doc->deleteLater();
return;
}
}
addTab(doc);
ui->editorTabs->setCurrentWidget(doc);
QObject::connect(doc, SIGNAL(titleChanged(QString)),
this, SLOT(tabTitleChanged(QString)));
}
void EditorWindow::loadSettings()
{
@ -153,16 +174,19 @@ void EditorWindow::setupMenus()
this, SLOT(openProject()));
}
void EditorWindow::addTab(SkinDocument *doc)
void EditorWindow::addTab(TabContent *doc)
{
ui->editorTabs->addTab(doc, doc->getTitle());
ui->editorTabs->addTab(doc, doc->title());
/* Connecting to title change events */
QObject::connect(doc, SIGNAL(titleChanged(QString)),
this, SLOT(tabTitleChanged(QString)));
QObject::connect(doc, SIGNAL(lineChanged(int)),
this, SLOT(lineChanged(int)));
/* Connecting to settings change events */
doc->connectPrefs(prefs);
if(doc->type() == TabContent::Skin)
dynamic_cast<SkinDocument*>(doc)->connectPrefs(prefs);
}
@ -175,7 +199,9 @@ void EditorWindow::newTab()
void EditorWindow::shiftTab(int index)
{
if(index < 0)
TabContent* widget = dynamic_cast<TabContent*>
(ui->editorTabs->currentWidget());
if(index < 0 || widget->type() != TabContent::Skin)
{
ui->parseTree->setModel(0);
ui->actionSave_Document->setEnabled(false);
@ -187,8 +213,7 @@ void EditorWindow::shiftTab(int index)
else
{
/* Syncing the tree view and the status bar */
SkinDocument* doc = dynamic_cast<SkinDocument*>
(ui->editorTabs->currentWidget());
SkinDocument* doc = dynamic_cast<SkinDocument*>(widget);
ui->parseTree->setModel(doc->getModel());
parseStatus->setText(doc->getStatus());
@ -197,12 +222,15 @@ void EditorWindow::shiftTab(int index)
ui->actionClose_Document->setEnabled(true);
ui->actionToolbarSave->setEnabled(true);
ui->fromTree->setEnabled(true);
sizeColumns();
}
}
bool EditorWindow::closeTab(int index)
{
SkinDocument* widget = dynamic_cast<SkinDocument*>
TabContent* widget = dynamic_cast<TabContent*>
(ui->editorTabs->widget(index));
if(widget->requestClose())
{
@ -222,13 +250,13 @@ void EditorWindow::closeCurrent()
void EditorWindow::saveCurrent()
{
if(ui->editorTabs->currentIndex() >= 0)
dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->save();
dynamic_cast<TabContent*>(ui->editorTabs->currentWidget())->save();
}
void EditorWindow::saveCurrentAs()
{
if(ui->editorTabs->currentIndex() >= 0)
dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->saveAs();
dynamic_cast<TabContent*>(ui->editorTabs->currentWidget())->saveAs();
}
void EditorWindow::openFile()
@ -248,7 +276,7 @@ void EditorWindow::openFile()
QString current = fileNames[i];
loadTabFromFile(current);
loadTabFromSkinFile(current);
/* And setting the new default directory */
current.chop(current.length() - current.lastIndexOf('/') - 1);
@ -292,7 +320,7 @@ void EditorWindow::openProject()
void EditorWindow::tabTitleChanged(QString title)
{
SkinDocument* sender = dynamic_cast<SkinDocument*>(QObject::sender());
TabContent* sender = dynamic_cast<TabContent*>(QObject::sender());
ui->editorTabs->setTabText(ui->editorTabs->indexOf(sender), title);
}
@ -334,6 +362,44 @@ void EditorWindow::updateCurrent()
(ui->editorTabs->currentWidget())->genCode();
}
void EditorWindow::lineChanged(int line)
{
ui->parseTree->collapseAll();
ParseTreeModel* model = dynamic_cast<ParseTreeModel*>
(ui->parseTree->model());
expandLine(model, QModelIndex(), line);
sizeColumns();
}
void EditorWindow::expandLine(ParseTreeModel* model, QModelIndex parent,
int line)
{
for(int i = 0; i < model->rowCount(parent); i++)
{
QModelIndex data = model->index(i, ParseTreeModel::lineColumn, parent);
QModelIndex recurse = model->index(i, 0, parent);
expandLine(model, recurse, line);
if(model->data(data, Qt::DisplayRole) == line)
{
ui->parseTree->expand(parent);
ui->parseTree->expand(data);
ui->parseTree->scrollTo(parent, QAbstractItemView::PositionAtTop);
}
}
}
void EditorWindow::sizeColumns()
{
/* Setting the column widths */
ui->parseTree->resizeColumnToContents(ParseTreeModel::lineColumn);
ui->parseTree->resizeColumnToContents(ParseTreeModel::typeColumn);
ui->parseTree->resizeColumnToContents(ParseTreeModel::valueColumn);
}
EditorWindow::~EditorWindow()
{
delete ui;

View file

@ -28,22 +28,27 @@
#include "parsetreemodel.h"
#include "skinhighlighter.h"
#include "skindocument.h"
#include "configdocument.h"
#include "preferencesdialog.h"
class ProjectModel;
class TabContent;
namespace Ui {
namespace Ui
{
class EditorWindow;
}
class EditorWindow : public QMainWindow {
class EditorWindow : public QMainWindow
{
Q_OBJECT
public:
EditorWindow(QWidget *parent = 0);
~EditorWindow();
/* A public function so external widgets can load files */
void loadTabFromFile(QString fileName);
void loadTabFromSkinFile(QString fileName);
void loadConfigTab(ConfigDocument* doc);
protected:
virtual void closeEvent(QCloseEvent* event);
@ -60,6 +65,7 @@ private slots:
void openProject();
void tabTitleChanged(QString title);
void updateCurrent(); /* Generates code in the current tab */
void lineChanged(int line); /* Used for auto-expand */
private:
/* Setup functions */
@ -67,7 +73,9 @@ private:
void saveSettings();
void setupUI();
void setupMenus();
void addTab(SkinDocument* doc);
void addTab(TabContent* doc);
void expandLine(ParseTreeModel* model, QModelIndex parent, int line);
void sizeColumns();
Ui::EditorWindow *ui;
PreferencesDialog* prefs;

View file

@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>628</width>
<height>27</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -126,7 +126,11 @@
<widget class="QWidget" name="dockWidgetContents_3">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTreeView" name="parseTree"/>
<widget class="QTreeView" name="parseTree">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fromTree">

View file

@ -64,7 +64,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Foreground Color</string>
<string>Foreground Colour</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
@ -91,7 +91,7 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Background Color</string>
<string>Background Colour</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
@ -118,7 +118,7 @@
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Error Color</string>
<string>Error Colour</string>
</property>
<property name="buddy">
<cstring>errorButton</cstring>

View file

@ -113,6 +113,12 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
void ProjectModel::activated(const QModelIndex &index)
{
mainWindow->loadTabFromFile(settings.value("themebase", "")
+ "/" + files[index.row()]);
if(index.row() == 0)
mainWindow->loadConfigTab(new ConfigDocument(settings,
settings.value("themebase",
"") + "/" +
files[index.row()]));
else
mainWindow->loadTabFromSkinFile(settings.value("themebase", "")
+ "/" + files[index.row()]);
}

View file

@ -44,6 +44,8 @@ public:
int rowCount(const QModelIndex& parent) const;
QVariant data(const QModelIndex &index, int role) const;
QString getSetting(QString key){ return settings.value(key, ""); }
signals:
public slots:

View file

@ -9,10 +9,10 @@
*
* Copyright (C) 2010 Robert Bieber
*
* This program is free software; you can redistribute it and/or
* This program is free software; 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.
* of the License, or (at your optiyouon) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
@ -30,11 +30,11 @@
#include <iostream>
SkinDocument::SkinDocument(QLabel* statusLabel, QWidget *parent) :
QWidget(parent), statusLabel(statusLabel)
TabContent(parent), statusLabel(statusLabel)
{
setupUI();
title = "Untitled";
titleText = "Untitled";
fileName = "";
saved = "";
parseStatus = tr("Empty document");
@ -42,7 +42,7 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QWidget *parent) :
}
SkinDocument::SkinDocument(QLabel* statusLabel, QString file, QWidget *parent):
QWidget(parent), fileName(file), statusLabel(statusLabel)
TabContent(parent), fileName(file), statusLabel(statusLabel)
{
setupUI();
blockUpdate = false;
@ -60,7 +60,7 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QString file, QWidget *parent):
/* Setting the title */
QStringList decomposed = fileName.split('/');
title = decomposed.last();
titleText = decomposed.last();
}
SkinDocument::~SkinDocument()
@ -86,7 +86,7 @@ bool SkinDocument::requestClose()
/* Spawning the "Are you sure?" dialog */
QMessageBox confirm(this);
confirm.setWindowTitle(tr("Confirm Close"));
confirm.setText(title + tr(" has been modified."));
confirm.setText(titleText + tr(" has been modified."));
confirm.setInformativeText(tr("Do you want to save your changes?"));
confirm.setStandardButtons(QMessageBox::Save | QMessageBox::Discard
| QMessageBox::Cancel);
@ -192,6 +192,10 @@ void SkinDocument::cursorChanged()
parseStatus = tr("Errors in document");
statusLabel->setText(parseStatus);
}
else
{
emit lineChanged(editor->textCursor().blockNumber() + 1);
}
}
@ -245,9 +249,9 @@ void SkinDocument::codeChanged()
}
if(editor->document()->toPlainText() != saved)
emit titleChanged(title + QChar('*'));
emit titleChanged(titleText + QChar('*'));
else
emit titleChanged(title);
emit titleChanged(titleText);
cursorChanged();
@ -269,8 +273,8 @@ void SkinDocument::save()
saved = editor->document()->toPlainText();
QStringList decompose = fileName.split('/');
title = decompose.last();
emit titleChanged(title);
titleText = decompose.last();
emit titleChanged(titleText);
}
@ -301,7 +305,7 @@ void SkinDocument::saveAs()
saved = editor->document()->toPlainText();
QStringList decompose = fileName.split('/');
title = decompose[decompose.count() - 1];
emit titleChanged(title);
titleText = decompose[decompose.count() - 1];
emit titleChanged(titleText);
}

View file

@ -30,8 +30,9 @@
#include "parsetreemodel.h"
#include "preferencesdialog.h"
#include "codeeditor.h"
#include "tabcontent.h"
class SkinDocument : public QWidget
class SkinDocument : public TabContent
{
Q_OBJECT
public:
@ -52,8 +53,8 @@ public:
void connectPrefs(PreferencesDialog* prefs);
ParseTreeModel* getModel(){ return model; }
QString getFile(){ return fileName; }
QString getTitle(){ return title; }
QString file() const{ return fileName; }
QString title() const{ return titleText; }
QString getStatus(){ return parseStatus; }
void genCode(){ editor->document()->setPlainText(model->genCode()); }
@ -62,8 +63,9 @@ public:
bool requestClose();
TabType type() const{ return Skin; }
signals:
void titleChanged(QString);
public slots:
void settingsChanged();
@ -75,7 +77,7 @@ private slots:
private:
void setupUI();
QString title;
QString titleText;
QString fileName;
QString saved;
QString parseStatus;

View file

@ -0,0 +1,35 @@
#ifndef TABCONTENT_H
#define TABCONTENT_H
#include <QWidget>
class TabContent : public QWidget
{
Q_OBJECT
public:
enum TabType
{
Skin,
Config
};
TabContent(QWidget *parent = 0): QWidget(parent){ }
virtual TabType type() const = 0;
virtual QString title() const = 0;
virtual QString file() const = 0;
virtual void save() = 0;
virtual void saveAs() = 0;
virtual bool requestClose() = 0;
signals:
void titleChanged(QString);
void lineChanged(int);
public slots:
};
#endif // TABCONTENT_H

View file

@ -16,7 +16,9 @@ HEADERS += tag_table.h \
skindocument.h \
preferencesdialog.h \
codeeditor.h \
projectmodel.h
projectmodel.h \
tabcontent.h \
configdocument.h
SOURCES += tag_table.c \
skin_parser.c \
skin_scan.c \
@ -29,7 +31,8 @@ SOURCES += tag_table.c \
skindocument.cpp \
preferencesdialog.cpp \
codeeditor.cpp \
projectmodel.cpp
projectmodel.cpp \
configdocument.cpp
OTHER_FILES += README \
resources/windowicon.png \
resources/appicon.xcf \
@ -38,5 +41,6 @@ OTHER_FILES += README \
resources/document-open.png \
resources/document-new.png
FORMS += editorwindow.ui \
preferencesdialog.ui
preferencesdialog.ui \
configdocument.ui
RESOURCES += resources.qrc