diff --git a/utils/themeeditor/configdocument.cpp b/utils/themeeditor/configdocument.cpp new file mode 100644 index 0000000000..95daec0b60 --- /dev/null +++ b/utils/themeeditor/configdocument.cpp @@ -0,0 +1,125 @@ +#include "configdocument.h" +#include "ui_configdocument.h" + +ConfigDocument::ConfigDocument(QMap& settings, QString file, + QWidget *parent) + : TabContent(parent), + ui(new Ui::ConfigDocument), + filePath(file) +{ + ui->setupUi(this); + + QMap::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(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")); +} diff --git a/utils/themeeditor/configdocument.h b/utils/themeeditor/configdocument.h new file mode 100644 index 0000000000..2f4c2501a1 --- /dev/null +++ b/utils/themeeditor/configdocument.h @@ -0,0 +1,54 @@ +#ifndef CONFIGDOCUMENT_H +#define CONFIGDOCUMENT_H + +#include +#include +#include +#include +#include + +#include "tabcontent.h" + +namespace Ui { + class ConfigDocument; +} + +class ConfigDocument : public TabContent { + Q_OBJECT +public: + ConfigDocument(QMap& 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 containers; + QList keys; + QList values; + QList deleteButtons; + + QString filePath; + QString saved; + + void addRow(QString key, QString value); + +private slots: + void deleteClicked(); + void addClicked(); +}; + +#endif // CONFIGDOCUMENT_H diff --git a/utils/themeeditor/configdocument.ui b/utils/themeeditor/configdocument.ui new file mode 100644 index 0000000000..e2f9e7fb21 --- /dev/null +++ b/utils/themeeditor/configdocument.ui @@ -0,0 +1,79 @@ + + + ConfigDocument + + + + 0 + 0 + 422 + 299 + + + + Form + + + + + + true + + + + + 0 + 0 + 402 + 244 + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 35 + 16777215 + + + + + + + + + + + + + + + diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index 93cf3641f0..3603b24af1 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -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 + TabContent* current = dynamic_cast (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 + (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(doc)->connectPrefs(prefs); } @@ -175,7 +199,9 @@ void EditorWindow::newTab() void EditorWindow::shiftTab(int index) { - if(index < 0) + TabContent* widget = dynamic_cast + (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 - (ui->editorTabs->currentWidget()); + SkinDocument* doc = dynamic_cast(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 + TabContent* widget = dynamic_cast (ui->editorTabs->widget(index)); if(widget->requestClose()) { @@ -222,13 +250,13 @@ void EditorWindow::closeCurrent() void EditorWindow::saveCurrent() { if(ui->editorTabs->currentIndex() >= 0) - dynamic_cast(ui->editorTabs->currentWidget())->save(); + dynamic_cast(ui->editorTabs->currentWidget())->save(); } void EditorWindow::saveCurrentAs() { if(ui->editorTabs->currentIndex() >= 0) - dynamic_cast(ui->editorTabs->currentWidget())->saveAs(); + dynamic_cast(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(QObject::sender()); + TabContent* sender = dynamic_cast(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 + (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; diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h index 32c7d0a057..7e62caadf2 100644 --- a/utils/themeeditor/editorwindow.h +++ b/utils/themeeditor/editorwindow.h @@ -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; diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui index 61b5f222a5..06c7d422bd 100644 --- a/utils/themeeditor/editorwindow.ui +++ b/utils/themeeditor/editorwindow.ui @@ -40,7 +40,7 @@ 0 0 628 - 27 + 25 @@ -126,7 +126,11 @@ - + + + true + + diff --git a/utils/themeeditor/preferencesdialog.ui b/utils/themeeditor/preferencesdialog.ui index c6594caa41..1da7811b62 100644 --- a/utils/themeeditor/preferencesdialog.ui +++ b/utils/themeeditor/preferencesdialog.ui @@ -64,7 +64,7 @@ - Foreground Color + Foreground Colour Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -91,7 +91,7 @@ - Background Color + Background Colour Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -118,7 +118,7 @@ - Error Color + Error Colour errorButton diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp index 925be81950..2df4c0af00 100644 --- a/utils/themeeditor/projectmodel.cpp +++ b/utils/themeeditor/projectmodel.cpp @@ -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()]); } diff --git a/utils/themeeditor/projectmodel.h b/utils/themeeditor/projectmodel.h index d577f00a69..6623917420 100644 --- a/utils/themeeditor/projectmodel.h +++ b/utils/themeeditor/projectmodel.h @@ -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: diff --git a/utils/themeeditor/skindocument.cpp b/utils/themeeditor/skindocument.cpp index 9a9bf5c85f..82c7106051 100644 --- a/utils/themeeditor/skindocument.cpp +++ b/utils/themeeditor/skindocument.cpp @@ -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 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); } diff --git a/utils/themeeditor/skindocument.h b/utils/themeeditor/skindocument.h index 79db8b648a..c6449ca627 100644 --- a/utils/themeeditor/skindocument.h +++ b/utils/themeeditor/skindocument.h @@ -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; diff --git a/utils/themeeditor/tabcontent.h b/utils/themeeditor/tabcontent.h new file mode 100644 index 0000000000..1b153f7df5 --- /dev/null +++ b/utils/themeeditor/tabcontent.h @@ -0,0 +1,35 @@ +#ifndef TABCONTENT_H +#define TABCONTENT_H + +#include + +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 diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 128f56996d..c336edf2f5 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -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