diff options
author | Ken Moore <moorekou@gmail.com> | 2016-04-19 10:11:44 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2016-04-19 10:11:44 -0400 |
commit | fbfc3e91cc6efa39a174b4cc65a14c89440844a3 (patch) | |
tree | c88bcaa66708f7d109b08e34a2d8424c041007d0 /desktop-utilities/lumina-textedit/MainUI.cpp | |
parent | Get almost everything else setup and functional. Now tabs can be closed/opene... (diff) | |
download | lumina-fbfc3e91cc6efa39a174b4cc65a14c89440844a3.tar.gz lumina-fbfc3e91cc6efa39a174b4cc65a14c89440844a3.tar.bz2 lumina-fbfc3e91cc6efa39a174b4cc65a14c89440844a3.zip |
Get a lot more of lumina-textedit done. Almost everything is complete now except for the color-selection dialog.
Diffstat (limited to 'desktop-utilities/lumina-textedit/MainUI.cpp')
-rw-r--r-- | desktop-utilities/lumina-textedit/MainUI.cpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/desktop-utilities/lumina-textedit/MainUI.cpp b/desktop-utilities/lumina-textedit/MainUI.cpp index f3e29d30..53fa0ca6 100644 --- a/desktop-utilities/lumina-textedit/MainUI.cpp +++ b/desktop-utilities/lumina-textedit/MainUI.cpp @@ -10,12 +10,15 @@ #include "syntaxSupport.h" #include <LuminaXDG.h> +#include <LuminaUtils.h> #include <QFileDialog> #include <QDir> 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 this->setWindowTitle(tr("Text Editor")); ui->tabWidget->clear(); //Update the menu of available syntax highlighting modes @@ -23,17 +26,25 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ for(int i=0; i<smodes.length(); i++){ ui->menuSyntax_Highlighting->addAction(smodes[i]); } + ui->actionLine_Numbers->setChecked( settings->value("showLineNumbers",true).toBool() ); //Setup any connections connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()) ); connect(ui->actionNew_File, SIGNAL(triggered()), this, SLOT(NewFile()) ); connect(ui->actionOpen_File, SIGNAL(triggered()), this, SLOT(OpenFile()) ); + connect(ui->actionClose_File, SIGNAL(triggered()), this, SLOT(CloseFile()) ); connect(ui->actionSave_File, SIGNAL(triggered()), this, SLOT(SaveFile()) ); connect(ui->actionSave_File_As, SIGNAL(triggered()), this, SLOT(SaveFileAs()) ); connect(ui->menuSyntax_Highlighting, SIGNAL(triggered(QAction*)), this, SLOT(UpdateHighlighting(QAction*)) ); connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged()) ); connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosed(int)) ); connect(ui->actionLine_Numbers, SIGNAL(toggled(bool)), this, SLOT(showLineNumbers(bool)) ); + connect(ui->actionCustomize_Colors, SIGNAL(triggered()), this, SLOT(ModifyColors()) ); updateIcons(); + //Now load the initial size of the window + QSize lastSize = settings->value("lastSize",QSize()).toSize(); + if(lastSize.width() > this->sizeHint().width() && lastSize.height() > this->sizeHint().height() ){ + this->resize(lastSize); + } } MainUI::~MainUI(){ @@ -42,24 +53,23 @@ MainUI::~MainUI(){ void MainUI::LoadArguments(QStringList args){ //CLI arguments for(int i=0; i<args.length(); i++){ - + OpenFile( LUtils::PathToAbsolute(args[i]) ); } - - /*if(ui->tabWidget->count()<1){ - NewFile(); - }*/ } // ================= // PUBLIC SLOTS //================= void MainUI::updateIcons(){ + this->setWindowIcon( LXDG::findIcon("document-edit") ); ui->actionClose->setIcon(LXDG::findIcon("application-exit") ); ui->actionNew_File->setIcon(LXDG::findIcon("document-new") ); ui->actionOpen_File->setIcon(LXDG::findIcon("document-open") ); + ui->actionClose_File->setIcon(LXDG::findIcon("document-close") ); ui->actionSave_File->setIcon(LXDG::findIcon("document-save") ); ui->actionSave_File_As->setIcon(LXDG::findIcon("document-save-as") ); ui->menuSyntax_Highlighting->setIcon( LXDG::findIcon("format-text-color") ); + ui->actionCustomize_Colors->setIcon( LXDG::findIcon("format-fill-color") ); } @@ -100,7 +110,7 @@ void MainUI::OpenFile(QString file){ files << file; } for(int i=0; i<files.length(); i++){ - PlainTextEditor *edit = new PlainTextEditor(this); + PlainTextEditor *edit = new PlainTextEditor(settings, this); connect(edit, SIGNAL(FileLoaded(QString)), this, SLOT(updateTab(QString)) ); connect(edit, SIGNAL(UnsavedChanges(QString)), this, SLOT(updateTab(QString)) ); ui->tabWidget->addTab(edit, files[i].section("/",-1)); @@ -112,6 +122,11 @@ void MainUI::OpenFile(QString file){ } } +void MainUI::CloseFile(){ + int index = ui->tabWidget->currentIndex(); + if(index>=0){ tabClosed(index); } +} + void MainUI::SaveFile(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } @@ -131,18 +146,31 @@ void MainUI::UpdateHighlighting(QAction *act){ } void MainUI::showLineNumbers(bool show){ + settings->setValue("showLineNumbers",show); for(int i=0; i<ui->tabWidget->count(); i++){ PlainTextEditor *edit = static_cast<PlainTextEditor*>(ui->tabWidget->widget(i)); edit->showLineNumbers(show); } } +void MainUI::ModifyColors(){ + +} + void MainUI::updateTab(QString file){ - PlainTextEditor *cur = currentEditor(); + PlainTextEditor *cur = 0; + int index = -1; + for(int i=0; i<ui->tabWidget->count(); i++){ + PlainTextEditor *tmp = static_cast<PlainTextEditor*>(ui->tabWidget->widget(i)); + if(tmp->currentFile()==file){ + cur = tmp; + index = i; + break; + } + } if(cur==0){ return; } //should never happen - int index = ui->tabWidget->currentIndex(); - if(index<0){ index = 0; } //FALLBACK - use the first tab bool changes = cur->hasChange(); + //qDebug() << "Update Tab:" << file << cur << changes; ui->tabWidget->setTabText(index,(changes ? "*" : "") + file.section("/",-1)); ui->actionSave_File->setEnabled(changes); ui->actionSave_File_As->setEnabled(changes); |