diff options
-rw-r--r-- | desktop-utilities/lumina-textedit/ColorDialog.cpp | 59 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/ColorDialog.h | 48 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/ColorDialog.ui | 81 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/MainUI.cpp | 24 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/MainUI.h | 4 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/PlainTextEditor.cpp | 5 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/PlainTextEditor.h | 1 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/lumina-textedit.pro | 10 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/syntaxSupport.cpp | 1 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/syntaxSupport.h | 7 |
10 files changed, 229 insertions, 11 deletions
diff --git a/desktop-utilities/lumina-textedit/ColorDialog.cpp b/desktop-utilities/lumina-textedit/ColorDialog.cpp new file mode 100644 index 00000000..d89bdad0 --- /dev/null +++ b/desktop-utilities/lumina-textedit/ColorDialog.cpp @@ -0,0 +1,59 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "ColorDialog.h" +#include "ui_ColorDialog.h" + +#include <QColorDialog> +#include <QStringList> + +#include <LuminaXDG.h> + +ColorDialog::ColorDialog(QSettings *set, QWidget *parent) : QDialog(parent), ui(new Ui::ColorDialog()){ + ui->setupUi(this); + settings = set; + connect(ui->push_cancel, SIGNAL(clicked()), this, SLOT(close()) ); + connect(ui->push_apply, SIGNAL(clicked()), this, SLOT(saveColors()) ); + connect(ui->push_getcolor, SIGNAL(clicked()), this, SLOT(changeColor()) ); +} + +void ColorDialog::LoadColors(){ + ui->treeWidget->clear(); + QStringList colors = settings->allKeys().filter("colors/"); + + for(int i=0; i<colors.length(); i++){ + QTreeWidgetItem *it = new QTreeWidgetItem(); + it->setText(0, colors[i].section("/",-1)); + it->setText(1, settings->value(colors[i]).toString() ); + it->setBackground(2, QBrush(QColor( it->text(1) ) ) ); + ui->treeWidget->addTopLevelItem(it); + } +} + +void ColorDialog::updateIcons(){ + this->setWindowIcon( LXDG::findIcon("format-fill-color") ); + ui->push_cancel->setIcon( LXDG::findIcon("dialog-cancel") ); + ui->push_apply->setIcon( LXDG::findIcon("dialog-ok") ); + ui->push_getcolor->setIcon( LXDG::findIcon("format-fill-color") ); +} + +void ColorDialog::saveColors(){ + for(int i=0; i<ui->treeWidget->topLevelItemCount(); i++){ + QTreeWidgetItem *it = ui->treeWidget->topLevelItem(i); + settings->setValue("colors/"+it->text(0), it->text(1)); + } + emit colorsChanged(); + this->close(); +} + +void ColorDialog::changeColor(){ + QTreeWidgetItem *it = ui->treeWidget->currentItem(); + if(it==0){ return; } + QColor color = QColorDialog::getColor(QColor( it->text(1)), this, tr("Select Color")); + if(!color.isValid()){ return; } + it->setText(1, color.name()); + it->setBackground(2, QBrush(color)); +}
\ No newline at end of file diff --git a/desktop-utilities/lumina-textedit/ColorDialog.h b/desktop-utilities/lumina-textedit/ColorDialog.h new file mode 100644 index 00000000..2cddd7cf --- /dev/null +++ b/desktop-utilities/lumina-textedit/ColorDialog.h @@ -0,0 +1,48 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_PLAIN_TEXT_EDITOR_COLOR_DIALOG_H +#define _LUMINA_PLAIN_TEXT_EDITOR_COLOR_DIALOG_H + +#include <QDialog> +#include <QSettings> +#include <QWidget> +#include <QCloseEvent> + +namespace Ui{ + class ColorDialog; +}; + +class ColorDialog : public QDialog{ + Q_OBJECT +private: + Ui::ColorDialog *ui; + QSettings *settings; + +public: + ColorDialog(QSettings *set, QWidget *parent); + ~ColorDialog(){} + + void LoadColors(); + +public slots: + void updateIcons(); + +private slots: + void saveColors(); + void changeColor(); + +signals: + void colorsChanged(); + +protected: + void closeEvent(QCloseEvent*){ + //Make sure this window never actually closes until the app is finished + this->hide(); + } +}; + +#endif
\ No newline at end of file diff --git a/desktop-utilities/lumina-textedit/ColorDialog.ui b/desktop-utilities/lumina-textedit/ColorDialog.ui new file mode 100644 index 00000000..de78deee --- /dev/null +++ b/desktop-utilities/lumina-textedit/ColorDialog.ui @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ColorDialog</class> + <widget class="QDialog" name="ColorDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Customize Colors</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QTreeWidget" name="treeWidget"> + <attribute name="headerDefaultSectionSize"> + <number>100</number> + </attribute> + <column> + <property name="text"> + <string>Item Type</string> + </property> + </column> + <column> + <property name="text"> + <string>Color</string> + </property> + </column> + <column> + <property name="text"> + <string>Sample</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="push_getcolor"> + <property name="text"> + <string>Select Color</string> + </property> + </widget> + </item> + <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="push_cancel"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="push_apply"> + <property name="text"> + <string>Apply</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/desktop-utilities/lumina-textedit/MainUI.cpp b/desktop-utilities/lumina-textedit/MainUI.cpp index 86f204bc..4815e281 100644 --- a/desktop-utilities/lumina-textedit/MainUI.cpp +++ b/desktop-utilities/lumina-textedit/MainUI.cpp @@ -15,11 +15,13 @@ #include <QFileDialog> #include <QDir> #include <QKeySequence> +#include <QTimer> MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); settings = new QSettings("lumina-desktop","lumina-textedit"); Custom_Syntax::SetupDefaultColors(settings); //pre-load any color settings as needed + colorDLG = new ColorDialog(settings, this); this->setWindowTitle(tr("Text Editor")); ui->tabWidget->clear(); closeFindS = new QShortcut(QKeySequence(Qt::Key_Escape), this); @@ -53,6 +55,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->tool_replace_all, SIGNAL(clicked()), this, SLOT(replaceAll()) ); connect(ui->line_find, SIGNAL(returnPressed()), this, SLOT(findNext()) ); connect(ui->line_replace, SIGNAL(returnPressed()), this, SLOT(replaceOne()) ); + connect(colorDLG, SIGNAL(colorsChanged()), this, SLOT(UpdateHighlighting()) ); updateIcons(); //Now load the initial size of the window QSize lastSize = settings->value("lastSize",QSize()).toSize(); @@ -94,6 +97,8 @@ void MainUI::updateIcons(){ ui->tool_replace->setIcon(LXDG::findIcon("arrow-down")); ui->tool_replace_all->setIcon(LXDG::findIcon("arrow-down-double")); //ui->tool_find_next->setIcon(LXDG::findIcon("")); + + QTimer::singleShot(0,colorDLG, SLOT(updateIcons()) ); } // ================= @@ -120,7 +125,7 @@ QString MainUI::currentFileDir(){ //================= //Main Actions void MainUI::NewFile(){ - OpenFile("New-"+QString::number(ui->tabWidget->count()+1)); + OpenFile(QString::number(ui->tabWidget->count()+1)+"/"+tr("New File")); } void MainUI::OpenFile(QString file){ @@ -165,9 +170,17 @@ void MainUI::SaveFileAs(){ } void MainUI::UpdateHighlighting(QAction *act){ - PlainTextEditor *cur = currentEditor(); - if(cur==0){ return; } - cur->LoadSyntaxRule(act->text()); + if(act!=0){ + //Single-editor change + PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + cur->LoadSyntaxRule(act->text()); + }else{ + //Have every editor reload the syntax rules (color changes) + for(int i=0; i<ui->tabWidget->count(); i++){ + static_cast<PlainTextEditor*>(ui->tabWidget->widget(i))->updateSyntaxColors(); + } + } } void MainUI::showLineNumbers(bool show){ @@ -187,7 +200,8 @@ void MainUI::wrapLines(bool wrap){ } void MainUI::ModifyColors(){ - + colorDLG->LoadColors(); + colorDLG->showNormal(); } void MainUI::updateTab(QString file){ diff --git a/desktop-utilities/lumina-textedit/MainUI.h b/desktop-utilities/lumina-textedit/MainUI.h index e040591a..a090cde5 100644 --- a/desktop-utilities/lumina-textedit/MainUI.h +++ b/desktop-utilities/lumina-textedit/MainUI.h @@ -13,6 +13,7 @@ #include <QShortcut> #include "PlainTextEditor.h" +#include "ColorDialog.h" namespace Ui{ class MainUI; @@ -31,6 +32,7 @@ public slots: private: Ui::MainUI *ui; + ColorDialog *colorDLG; QSettings *settings; QShortcut *closeFindS; @@ -47,7 +49,7 @@ private slots: void SaveFileAs(); //Other Menu Actions - void UpdateHighlighting(QAction*); + void UpdateHighlighting(QAction *act = 0); void showLineNumbers(bool); void wrapLines(bool); void ModifyColors(); diff --git a/desktop-utilities/lumina-textedit/PlainTextEditor.cpp b/desktop-utilities/lumina-textedit/PlainTextEditor.cpp index 4031eacc..4d5ac7ce 100644 --- a/desktop-utilities/lumina-textedit/PlainTextEditor.cpp +++ b/desktop-utilities/lumina-textedit/PlainTextEditor.cpp @@ -51,6 +51,11 @@ void PlainTextEditor::LoadSyntaxRule(QString type){ SYNTAX->rehighlight(); } +void PlainTextEditor::updateSyntaxColors(){ + SYNTAX->reloadRules(); + SYNTAX->rehighlight(); +} + //File loading/setting options void PlainTextEditor::LoadFile(QString filepath){ this->setWhatsThis(filepath); diff --git a/desktop-utilities/lumina-textedit/PlainTextEditor.h b/desktop-utilities/lumina-textedit/PlainTextEditor.h index e2eb1a3e..12c73ab0 100644 --- a/desktop-utilities/lumina-textedit/PlainTextEditor.h +++ b/desktop-utilities/lumina-textedit/PlainTextEditor.h @@ -24,6 +24,7 @@ public: //Functions for setting up the editor void showLineNumbers(bool show = true); void LoadSyntaxRule(QString type); + void updateSyntaxColors(); //File loading/setting options void LoadFile(QString filepath); diff --git a/desktop-utilities/lumina-textedit/lumina-textedit.pro b/desktop-utilities/lumina-textedit/lumina-textedit.pro index 7896d20c..6794af8e 100644 --- a/desktop-utilities/lumina-textedit/lumina-textedit.pro +++ b/desktop-utilities/lumina-textedit/lumina-textedit.pro @@ -7,15 +7,17 @@ target.path = $${L_BINDIR} HEADERS += MainUI.h \ PlainTextEditor.h \ - syntaxSupport.h + syntaxSupport.h \ + ColorDialog.h SOURCES += main.cpp \ MainUI.cpp \ PlainTextEditor.cpp \ - syntaxSupport.cpp - -FORMS += MainUI.ui + syntaxSupport.cpp \ + ColorDialog.cpp +FORMS += MainUI.ui \ + ColorDialog.ui LIBS += -lLuminaUtils diff --git a/desktop-utilities/lumina-textedit/syntaxSupport.cpp b/desktop-utilities/lumina-textedit/syntaxSupport.cpp index 1e3f796b..a5b07f5d 100644 --- a/desktop-utilities/lumina-textedit/syntaxSupport.cpp +++ b/desktop-utilities/lumina-textedit/syntaxSupport.cpp @@ -46,6 +46,7 @@ QString Custom_Syntax::ruleForFile(QString filename){ void Custom_Syntax::loadRules(QString type){ //NOTE: the "multiLineComment + lasttype = type; rules.clear(); splitrules.clear(); if(type=="C++"){ diff --git a/desktop-utilities/lumina-textedit/syntaxSupport.h b/desktop-utilities/lumina-textedit/syntaxSupport.h index e258aafe..c96c404d 100644 --- a/desktop-utilities/lumina-textedit/syntaxSupport.h +++ b/desktop-utilities/lumina-textedit/syntaxSupport.h @@ -28,6 +28,7 @@ class Custom_Syntax : public QSyntaxHighlighter{ Q_OBJECT private: QSettings *settings; + QString lasttype; QVector<SyntaxRule> rules; QVector<SyntaxRuleSplit> splitrules; @@ -36,12 +37,16 @@ public: settings = set; } ~Custom_Syntax(){} - + static QStringList availableRules(); static QStringList knownColors(); static void SetupDefaultColors(QSettings *settings); static QString ruleForFile(QString filename); void loadRules(QString type); + + void reloadRules(){ + loadRules(lasttype); + } protected: void highlightBlock(const QString &text){ for(int i=0; i<rules.length(); i++){ |