From 53b619c6e80c9efc6993c23ff7b1035e8e101834 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Mon, 7 Jun 2010 03:25:40 +0000 Subject: Theme Editor: Added a preferences dialog and allowed modification of the syntax highlighting and editor colors git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26640 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/editorwindow.cpp | 29 ++-- utils/themeeditor/editorwindow.h | 3 + utils/themeeditor/preferencesdialog.cpp | 164 ++++++++++++++++++++++ utils/themeeditor/preferencesdialog.h | 69 ++++++++++ utils/themeeditor/preferencesdialog.ui | 235 ++++++++++++++++++++++++++++++++ utils/themeeditor/skindocument.cpp | 34 ++++- utils/themeeditor/skindocument.h | 6 + utils/themeeditor/skinhighlighter.cpp | 31 ++++- utils/themeeditor/skinhighlighter.h | 6 +- utils/themeeditor/themeeditor.pro | 9 +- 10 files changed, 563 insertions(+), 23 deletions(-) create mode 100644 utils/themeeditor/preferencesdialog.cpp create mode 100644 utils/themeeditor/preferencesdialog.h create mode 100644 utils/themeeditor/preferencesdialog.ui (limited to 'utils/themeeditor') diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index 91e099ebf7..8e81829a41 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -32,6 +32,7 @@ EditorWindow::EditorWindow(QWidget *parent) : ui(new Ui::EditorWindow) { ui->setupUi(this); + prefs = new PreferencesDialog(this); loadSettings(); setupUI(); setupMenus(); @@ -43,7 +44,7 @@ void EditorWindow::loadSettings() QSettings settings; /* Main Window location */ - settings.beginGroup("MainWindow"); + settings.beginGroup("EditorWindow"); QSize size = settings.value("size").toSize(); QPoint pos = settings.value("position").toPoint(); QByteArray state = settings.value("state").toByteArray(); @@ -65,7 +66,7 @@ void EditorWindow::saveSettings() QSettings settings; /* Saving window and panel positions */ - settings.beginGroup("MainWindow"); + settings.beginGroup("EditorWindow"); settings.setValue("position", pos()); settings.setValue("size", size()); settings.setValue("state", saveState()); @@ -89,6 +90,10 @@ void EditorWindow::setupUI() QObject::connect(ui->fromTree, SIGNAL(pressed()), this, SLOT(updateCurrent())); + /* Connecting the preferences dialog */ + QObject::connect(ui->actionPreferences, SIGNAL(triggered()), + prefs, SLOT(exec())); + } void EditorWindow::setupMenus() @@ -124,15 +129,23 @@ void EditorWindow::setupMenus() } - -void EditorWindow::newTab() +void EditorWindow::addTab(SkinDocument *doc) { - SkinDocument* doc = new SkinDocument; ui->editorTabs->addTab(doc, doc->getTitle()); /* Connecting to title change events */ QObject::connect(doc, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString))); + + /* Connecting to settings change events */ + doc->connectPrefs(prefs); +} + + +void EditorWindow::newTab() +{ + SkinDocument* doc = new SkinDocument; + addTab(doc); } void EditorWindow::shiftTab(int index) @@ -208,10 +221,7 @@ void EditorWindow::openFile() /* Adding a new document for each file name */ SkinDocument* doc = new SkinDocument(current); - ui->editorTabs->addTab(doc, doc->getTitle()); - - QObject::connect(doc, SIGNAL(titleChanged(QString)), - this, SLOT(tabTitleChanged(QString))); + addTab(doc); /* And setting the new default directory */ current.chop(current.length() - current.lastIndexOf('/') - 1); @@ -270,4 +280,5 @@ void EditorWindow::updateCurrent() EditorWindow::~EditorWindow() { delete ui; + delete prefs; } diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h index e7fd96a548..5f39ed35d6 100644 --- a/utils/themeeditor/editorwindow.h +++ b/utils/themeeditor/editorwindow.h @@ -27,6 +27,7 @@ #include "parsetreemodel.h" #include "skinhighlighter.h" #include "skindocument.h" +#include "preferencesdialog.h" namespace Ui { class EditorWindow; @@ -59,8 +60,10 @@ private: void saveSettings(); void setupUI(); void setupMenus(); + void addTab(SkinDocument* doc); Ui::EditorWindow *ui; + PreferencesDialog* prefs; }; #endif // EDITORWINDOW_H diff --git a/utils/themeeditor/preferencesdialog.cpp b/utils/themeeditor/preferencesdialog.cpp new file mode 100644 index 0000000000..4d3ad04495 --- /dev/null +++ b/utils/themeeditor/preferencesdialog.cpp @@ -0,0 +1,164 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "preferencesdialog.h" +#include "ui_preferencesdialog.h" + +#include +#include + +PreferencesDialog::PreferencesDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::PreferencesDialog) +{ + ui->setupUi(this); + setupUI(); + loadSettings(); +} + +PreferencesDialog::~PreferencesDialog() +{ + delete ui; +} + +void PreferencesDialog::loadSettings() +{ + loadColors(); +} + +void PreferencesDialog::loadColors() +{ + + QSettings settings; + + /* The list of buttons from the SkinHighlighter group */ + + settings.beginGroup("SkinHighlighter"); + + commentColor = settings.value("commentColor", + QColor(0, 180, 0)).value(); + setButtonColor(ui->commentButton, commentColor); + + escapedColor = settings.value("escapedColor", + QColor(120,120,120)).value(); + setButtonColor(ui->escapedButton, escapedColor); + + conditionalColor = settings.value("conditionalColor", + QColor(0, 0, 180)).value(); + setButtonColor(ui->conditionalButton, conditionalColor); + + tagColor = settings.value("tagColor", + QColor(180, 0, 0)).value(); + setButtonColor(ui->tagButton, tagColor); + + settings.endGroup(); + + /* Buttons from the editor group */ + settings.beginGroup("SkinDocument"); + + fgColor = settings.value("fgColor", Qt::black).value(); + setButtonColor(ui->fgButton, fgColor); + + bgColor = settings.value("bgColor", Qt::white).value(); + setButtonColor(ui->bgButton, bgColor); + + settings.endGroup(); +} + +void PreferencesDialog::saveSettings() +{ + saveColors(); +} + +void PreferencesDialog::saveColors() +{ + QSettings settings; + + /* Saving the editor colors */ + settings.beginGroup("SkinDocument"); + + settings.setValue("fgColor", fgColor); + settings.setValue("bgColor", bgColor); + + settings.endGroup(); + + /* Saving the highlighting colors */ + settings.beginGroup("SkinHighlighter"); + + settings.setValue("tagColor", tagColor); + settings.setValue("commentColor", commentColor); + settings.setValue("conditionalColor", conditionalColor); + settings.setValue("escapedColor", escapedColor); + + settings.endGroup(); +} + +void PreferencesDialog::setupUI() +{ + /* Connecting color buttons */ + QList buttons; + buttons.append(ui->bgButton); + buttons.append(ui->fgButton); + buttons.append(ui->commentButton); + buttons.append(ui->tagButton); + buttons.append(ui->conditionalButton); + buttons.append(ui->escapedButton); + + for(int i = 0; i < buttons.count(); i++) + QObject::connect(buttons[i], SIGNAL(pressed()), + this, SLOT(colorClicked())); +} + +void PreferencesDialog::colorClicked() +{ + QColor* toEdit = 0; + + if(QObject::sender() == ui->bgButton) + toEdit = &bgColor; + else if(QObject::sender() == ui->fgButton) + toEdit = &fgColor; + else if(QObject::sender() == ui->commentButton) + toEdit = &commentColor; + else if(QObject::sender() == ui->tagButton) + toEdit = &tagColor; + else if(QObject::sender() == ui->conditionalButton) + toEdit = &conditionalColor; + else if(QObject::sender() == ui->escapedButton) + toEdit = &escapedColor; + + if(!toEdit) + return; + + *toEdit = QColorDialog::getColor(*toEdit, this); + setButtonColor(dynamic_cast(QObject::sender()), *toEdit); +} + +void PreferencesDialog::accept() +{ + saveSettings(); + QDialog::accept(); +} + +void PreferencesDialog::reject() +{ + loadSettings(); + QDialog::reject(); +} diff --git a/utils/themeeditor/preferencesdialog.h b/utils/themeeditor/preferencesdialog.h new file mode 100644 index 0000000000..a4adda47d1 --- /dev/null +++ b/utils/themeeditor/preferencesdialog.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * __________ __ ___. + * 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 PREFERENCESDIALOG_H +#define PREFERENCESDIALOG_H + +#include +#include + +namespace Ui { + class PreferencesDialog; +} + +class PreferencesDialog : public QDialog { + Q_OBJECT +public: + PreferencesDialog(QWidget *parent = 0); + ~PreferencesDialog(); + + static void setButtonColor(QPushButton* button, QColor color) + { + QString style = "* { background:" + color.name() + "}"; + button->setStyleSheet(style); + } + +public slots: + void accept(); + void reject(); + +private slots: + void colorClicked(); + +private: + Ui::PreferencesDialog *ui; + + void loadSettings(); + void loadColors(); + void saveSettings(); + void saveColors(); + + void setupUI(); + + QColor fgColor; + QColor bgColor; + QColor commentColor; + QColor escapedColor; + QColor tagColor; + QColor conditionalColor; +}; + +#endif // PREFERENCESDIALOG_H diff --git a/utils/themeeditor/preferencesdialog.ui b/utils/themeeditor/preferencesdialog.ui new file mode 100644 index 0000000000..017e69dd01 --- /dev/null +++ b/utils/themeeditor/preferencesdialog.ui @@ -0,0 +1,235 @@ + + + PreferencesDialog + + + + 0 + 0 + 370 + 370 + + + + Dialog + + + + + + 0 + + + + + 0 + 0 + 352 + 288 + + + + Editor Colors + + + + + + + + Foreground + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + fgButton + + + + + + + Background + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + bgButton + + + + + + + Comment + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + commentButton + + + + + + + Escaped Character + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + escapedButton + + + + + + + Conditional + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + conditionalButton + + + + + + + Tag + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + tagButton + + + + + + + + + + + false + + + Click To Change + + + + + + + false + + + Click To Change + + + + + + + false + + + Click To Change + + + false + + + + + + + false + + + Click To Change + + + + + + + false + + + Click To Change + + + + + + + false + + + Click To Change + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PreferencesDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PreferencesDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/utils/themeeditor/skindocument.cpp b/utils/themeeditor/skindocument.cpp index efb16eeae1..fbb33cc366 100644 --- a/utils/themeeditor/skindocument.cpp +++ b/utils/themeeditor/skindocument.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -61,6 +62,14 @@ SkinDocument::~SkinDocument() delete model; } +void SkinDocument::connectPrefs(PreferencesDialog* prefs) +{ + QObject::connect(prefs, SIGNAL(accepted()), + this, SLOT(colorsChanged())); + QObject::connect(prefs, SIGNAL(accepted()), + highlighter, SLOT(loadSettings())); +} + bool SkinDocument::requestClose() { if(editor->document()->toPlainText() != saved) @@ -106,9 +115,7 @@ void SkinDocument::setupUI() setLayout(layout); /* Attaching the syntax highlighter */ - highlighter = new SkinHighlighter(QColor(0,180,0), QColor(255,0,0), - QColor(0,0,255), QColor(120,120,120), - editor->document()); + highlighter = new SkinHighlighter(editor->document()); /* Setting up the model */ model = new ParseTreeModel(""); @@ -116,6 +123,27 @@ void SkinDocument::setupUI() /* Connecting the editor's signal */ QObject::connect(editor, SIGNAL(textChanged()), this, SLOT(codeChanged())); + + colorsChanged(); +} + +void SkinDocument::colorsChanged() +{ + /* Setting the editor colors */ + QSettings settings; + settings.beginGroup("SkinDocument"); + + QColor fg = settings.value("fgColor", Qt::black).value(); + QColor bg = settings.value("bgColor", Qt::white).value(); + QPalette palette; + palette.setColor(QPalette::All, QPalette::Base, bg); + palette.setColor(QPalette::All, QPalette::Text, fg); + + editor->setPalette(palette); + editor->repaint(); + + settings.endGroup(); + } void SkinDocument::codeChanged() diff --git a/utils/themeeditor/skindocument.h b/utils/themeeditor/skindocument.h index 84d12df6a9..14a71e02a1 100644 --- a/utils/themeeditor/skindocument.h +++ b/utils/themeeditor/skindocument.h @@ -28,6 +28,7 @@ #include "skinhighlighter.h" #include "parsetreemodel.h" +#include "preferencesdialog.h" class SkinDocument : public QWidget { @@ -47,6 +48,8 @@ public: SkinDocument(QString file, QWidget* parent = 0); virtual ~SkinDocument(); + void connectPrefs(PreferencesDialog* prefs); + ParseTreeModel* getModel(){ return model; } QString getTitle(){ return title; } void genCode(){ editor->document()->setPlainText(model->genCode()); } @@ -59,6 +62,9 @@ public: signals: void titleChanged(QString); +public slots: + void colorsChanged(); + private slots: void codeChanged(); diff --git a/utils/themeeditor/skinhighlighter.cpp b/utils/themeeditor/skinhighlighter.cpp index 8289c38a1d..25a479f815 100644 --- a/utils/themeeditor/skinhighlighter.cpp +++ b/utils/themeeditor/skinhighlighter.cpp @@ -21,13 +21,12 @@ #include "skinhighlighter.h" -SkinHighlighter::SkinHighlighter(QColor comment, QColor tag, QColor conditional, - QColor escaped, QTextDocument* doc) - :QSyntaxHighlighter(doc), - escaped(escaped), tag(tag), - conditional(conditional), comment(comment) -{ +#include +SkinHighlighter::SkinHighlighter(QTextDocument* doc) + :QSyntaxHighlighter(doc) +{ + loadSettings(); } SkinHighlighter::~SkinHighlighter() @@ -151,3 +150,23 @@ void SkinHighlighter::highlightBlock(const QString& text) } } } + +void SkinHighlighter::loadSettings() +{ + QSettings settings; + + settings.beginGroup("SkinHighlighter"); + + /* Loading the highlighting colors */ + tag = settings.value("tagColor", QColor(180,0,0)).value(); + conditional = settings.value("conditionalColor", + QColor(0, 0, 180)).value(); + escaped = settings.value("escapedColor", + QColor(120,120,120)).value(); + comment = settings.value("commentColor", + QColor(0, 180, 0)).value(); + + settings.endGroup(); + + rehighlight(); +} diff --git a/utils/themeeditor/skinhighlighter.h b/utils/themeeditor/skinhighlighter.h index 6baa699871..4d5c68ba52 100644 --- a/utils/themeeditor/skinhighlighter.h +++ b/utils/themeeditor/skinhighlighter.h @@ -40,12 +40,14 @@ public: * conditional - The color for conditionals and their delimiters * */ - SkinHighlighter(QColor comment, QColor tag, QColor conditional, - QColor escaped, QTextDocument* doc); + SkinHighlighter(QTextDocument* doc); virtual ~SkinHighlighter(); void highlightBlock(const QString& text); +public slots: + void loadSettings(); + private: QColor escaped; QColor tag; diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index ef32a3e56e..fe83d6bbf5 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -13,7 +13,8 @@ HEADERS += tag_table.h \ parsetreenode.h \ editorwindow.h \ skinhighlighter.h \ - skindocument.h + skindocument.h \ + preferencesdialog.h SOURCES += tag_table.c \ skin_parser.c \ skin_scan.c \ @@ -23,7 +24,8 @@ SOURCES += tag_table.c \ parsetreenode.cpp \ editorwindow.cpp \ skinhighlighter.cpp \ - skindocument.cpp + skindocument.cpp \ + preferencesdialog.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ @@ -31,5 +33,6 @@ OTHER_FILES += README \ resources/document-save.png \ resources/document-open.png \ resources/document-new.png -FORMS += editorwindow.ui +FORMS += editorwindow.ui \ + preferencesdialog.ui RESOURCES += resources.qrc -- cgit v1.2.3