diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-07 03:25:40 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-07 03:25:40 +0000 |
commit | 53b619c6e80c9efc6993c23ff7b1035e8e101834 (patch) | |
tree | 7bca9e3845748332c0e6288b5704e9b004f41a22 /utils | |
parent | fbfdaf5c79c664a6ec47b1c3a131577e77efbbd0 (diff) |
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
Diffstat (limited to 'utils')
-rw-r--r-- | utils/themeeditor/editorwindow.cpp | 29 | ||||
-rw-r--r-- | utils/themeeditor/editorwindow.h | 3 | ||||
-rw-r--r-- | utils/themeeditor/preferencesdialog.cpp | 164 | ||||
-rw-r--r-- | utils/themeeditor/preferencesdialog.h | 69 | ||||
-rw-r--r-- | utils/themeeditor/preferencesdialog.ui | 235 | ||||
-rw-r--r-- | utils/themeeditor/skindocument.cpp | 34 | ||||
-rw-r--r-- | utils/themeeditor/skindocument.h | 6 | ||||
-rw-r--r-- | utils/themeeditor/skinhighlighter.cpp | 31 | ||||
-rw-r--r-- | utils/themeeditor/skinhighlighter.h | 6 | ||||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 9 |
10 files changed, 563 insertions, 23 deletions
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 <QSettings> +#include <QColorDialog> + +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<QColor>(); + setButtonColor(ui->commentButton, commentColor); + + escapedColor = settings.value("escapedColor", + QColor(120,120,120)).value<QColor>(); + setButtonColor(ui->escapedButton, escapedColor); + + conditionalColor = settings.value("conditionalColor", + QColor(0, 0, 180)).value<QColor>(); + setButtonColor(ui->conditionalButton, conditionalColor); + + tagColor = settings.value("tagColor", + QColor(180, 0, 0)).value<QColor>(); + setButtonColor(ui->tagButton, tagColor); + + settings.endGroup(); + + /* Buttons from the editor group */ + settings.beginGroup("SkinDocument"); + + fgColor = settings.value("fgColor", Qt::black).value<QColor>(); + setButtonColor(ui->fgButton, fgColor); + + bgColor = settings.value("bgColor", Qt::white).value<QColor>(); + 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<QPushButton*> 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<QPushButton*>(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 <QDialog> +#include <QPushButton> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PreferencesDialog</class> + <widget class="QDialog" name="PreferencesDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>370</width> + <height>370</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QToolBox" name="prefsGroups"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="highlighting"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>352</width> + <height>288</height> + </rect> + </property> + <attribute name="label"> + <string>Editor Colors</string> + </attribute> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Foreground</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>fgButton</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Background</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>bgButton</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Comment</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>commentButton</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Escaped Character</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>escapedButton</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Conditional</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>conditionalButton</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Tag</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>tagButton</cstring> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QPushButton" name="fgButton"> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Click To Change</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="bgButton"> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Click To Change</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="commentButton"> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Click To Change</string> + </property> + <property name="flat"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="escapedButton"> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Click To Change</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="conditionalButton"> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Click To Change</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="tagButton"> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Click To Change</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>PreferencesDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>PreferencesDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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 <QFile> #include <QSettings> +#include <QColor> #include <QMessageBox> #include <QFileDialog> @@ -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>(); + QColor bg = settings.value("bgColor", Qt::white).value<QColor>(); + 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 <QSettings> +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<QColor>(); + conditional = settings.value("conditionalColor", + QColor(0, 0, 180)).value<QColor>(); + escaped = settings.value("escapedColor", + QColor(120,120,120)).value<QColor>(); + comment = settings.value("commentColor", + QColor(0, 180, 0)).value<QColor>(); + + 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 |