From 329da8795d9a9183830d0c4e0e22ea08d546a4f7 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 20 Jul 2018 11:12:02 +0200 Subject: line ending --- src/tikzit.cpp | 422 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 211 insertions(+), 211 deletions(-) (limited to 'src/tikzit.cpp') diff --git a/src/tikzit.cpp b/src/tikzit.cpp index e4b3b95..9a4e166 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -1,211 +1,211 @@ -/* - TikZiT - a GUI diagram editor for TikZ - Copyright (C) 2018 Aleks Kissinger - - 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 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "tikzit.h" -#include "tikzassembler.h" -#include "tikzstyles.h" - -#include -#include -#include -#include -#include - -// application-level instance of Tikzit -Tikzit *tikzit; - -// font to use for node labels -QFont Tikzit::LABEL_FONT("Courrier", 9); - -Tikzit::Tikzit() : _styleFile("[default]"), _activeWindow(0) -{ -} - -void Tikzit::init(QApplication *app) -{ - QSettings settings("tikzit", "tikzit"); - _mainMenu = new MainMenu(); - QMainWindow *dummy = new QMainWindow(); - - _toolPalette = new ToolPalette(dummy); - _propertyPalette = new PropertyPalette(dummy); - //_stylePalette = new StylePalette(dummy); - _styles = new TikzStyles(this); - - //_stylePalette->show(); - _windows << new MainWindow(); - _windows[0]->show(); - - QString styleFile = settings.value("previous-tikzstyles-file").toString(); - if (!styleFile.isEmpty()) loadStyles(styleFile); - - //connect(app, &QApplication::focusChanged, this, &focusChanged); -} - -//QMenuBar *Tikzit::mainMenu() const -//{ -// return _mainMenu; -//} - -ToolPalette *Tikzit::toolPalette() const -{ - return _toolPalette; -} - -PropertyPalette *Tikzit::propertyPalette() const -{ - return _propertyPalette; -} - -void Tikzit::newDoc() -{ - MainWindow *w = new MainWindow(); - w->show(); - _windows << w; -} - -MainWindow *Tikzit::activeWindow() const -{ - return _activeWindow; -} - -void Tikzit::setActiveWindow(MainWindow *activeWindow) -{ - _activeWindow = activeWindow; -} - -void Tikzit::removeWindow(MainWindow *w) -{ - _windows.removeAll(w); - if (_activeWindow == w) { - if (_windows.isEmpty()) { - _activeWindow = 0; - // TODO: check if we should quit when last window closed - quit(); - } else _activeWindow = _windows[0]; - } -} - -void Tikzit::open() -{ - QSettings settings("tikzit", "tikzit"); - QString fileName = QFileDialog::getOpenFileName(0, - tr("Open File"), - settings.value("previous-file-path").toString(), - tr("TiKZ Files (*.tikz)")); - - open(fileName); -} - -void Tikzit::open(QString fileName) -{ - if (!fileName.isEmpty()) { - if (_windows.size() == 1 && - _windows[0]->tikzDocument()->isClean() && - _windows[0]->tikzDocument()->shortName().isEmpty()) - { - _windows[0]->open(fileName); - _windows[0]->show(); - } - else { - MainWindow *w = new MainWindow(); - w->show(); - w->open(fileName); - _windows << w; - } - } -} - -void Tikzit::openTikzStyles() { - QSettings settings("tikzit", "tikzit"); - QString fileName = QFileDialog::getOpenFileName(0, - tr("Open File"), - settings.value("previous-tikzstyles-path").toString(), - tr("TiKZ Style Files (*.tikzstyles)")); - - if (!fileName.isEmpty()) { - loadStyles(fileName); - } -} - -void Tikzit::loadStyles(QString fileName) -{ - QSettings settings("tikzit", "tikzit"); - QFile file(fileName); - if (file.open(QIODevice::ReadOnly)) { - QFileInfo fi(file); - settings.setValue("previous-tikzstyles-path", fi.absolutePath()); - settings.setValue("previous-tikzstyles-file", fileName); - _styleFile = fi.fileName(); - QTextStream in(&file); - QString styleTikz = in.readAll(); - file.close(); - - _styles->clear(); - TikzAssembler ass(_styles); - bool parseSuccess = ass.parse(styleTikz); - if (parseSuccess) { - qDebug() << "parse successful"; - } else { - qDebug() << "parse failed"; - } - //_stylePalette->reloadStyles(); - - foreach (MainWindow *w, _windows) { - w->tikzScene()->reloadStyles(); - } - - } else { - settings.setValue("previous-tikzstyles-file", ""); - QMessageBox::warning(0, "Style file not found.", "Could not open style file: '" + fileName + "', reverting to default."); - } -} - -QString Tikzit::styleFile() const -{ - return _styleFile; -} - -void Tikzit::focusChanged(QWidget *old, QWidget *nw) -{ -// foreach (MainWindow *w, _windows) { -// if (w->isActiveWindow()) { -// _stylePalette->raise(); -// break; -// } -// } -} - -//StylePalette *Tikzit::stylePalette() const -//{ -// return _stylePalette; -//} - - -TikzStyles *Tikzit::styles() const -{ - return _styles; -} - -void Tikzit::quit() -{ - //_stylePalette->close(); - QApplication::quit(); -} - - +/* + TikZiT - a GUI diagram editor for TikZ + Copyright (C) 2018 Aleks Kissinger + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "tikzit.h" +#include "tikzassembler.h" +#include "tikzstyles.h" + +#include +#include +#include +#include +#include + +// application-level instance of Tikzit +Tikzit *tikzit; + +// font to use for node labels +QFont Tikzit::LABEL_FONT("Courrier", 9); + +Tikzit::Tikzit() : _styleFile("[default]"), _activeWindow(0) +{ +} + +void Tikzit::init(QApplication *app) +{ + QSettings settings("tikzit", "tikzit"); + _mainMenu = new MainMenu(); + QMainWindow *dummy = new QMainWindow(); + + _toolPalette = new ToolPalette(dummy); + _propertyPalette = new PropertyPalette(dummy); + //_stylePalette = new StylePalette(dummy); + _styles = new TikzStyles(this); + + //_stylePalette->show(); + _windows << new MainWindow(); + _windows[0]->show(); + + QString styleFile = settings.value("previous-tikzstyles-file").toString(); + if (!styleFile.isEmpty()) loadStyles(styleFile); + + //connect(app, &QApplication::focusChanged, this, &focusChanged); +} + +//QMenuBar *Tikzit::mainMenu() const +//{ +// return _mainMenu; +//} + +ToolPalette *Tikzit::toolPalette() const +{ + return _toolPalette; +} + +PropertyPalette *Tikzit::propertyPalette() const +{ + return _propertyPalette; +} + +void Tikzit::newDoc() +{ + MainWindow *w = new MainWindow(); + w->show(); + _windows << w; +} + +MainWindow *Tikzit::activeWindow() const +{ + return _activeWindow; +} + +void Tikzit::setActiveWindow(MainWindow *activeWindow) +{ + _activeWindow = activeWindow; +} + +void Tikzit::removeWindow(MainWindow *w) +{ + _windows.removeAll(w); + if (_activeWindow == w) { + if (_windows.isEmpty()) { + _activeWindow = 0; + // TODO: check if we should quit when last window closed + quit(); + } else _activeWindow = _windows[0]; + } +} + +void Tikzit::open() +{ + QSettings settings("tikzit", "tikzit"); + QString fileName = QFileDialog::getOpenFileName(0, + tr("Open File"), + settings.value("previous-file-path").toString(), + tr("TiKZ Files (*.tikz)")); + + open(fileName); +} + +void Tikzit::open(QString fileName) +{ + if (!fileName.isEmpty()) { + if (_windows.size() == 1 && + _windows[0]->tikzDocument()->isClean() && + _windows[0]->tikzDocument()->shortName().isEmpty()) + { + _windows[0]->open(fileName); + _windows[0]->show(); + } + else { + MainWindow *w = new MainWindow(); + w->show(); + w->open(fileName); + _windows << w; + } + } +} + +void Tikzit::openTikzStyles() { + QSettings settings("tikzit", "tikzit"); + QString fileName = QFileDialog::getOpenFileName(0, + tr("Open File"), + settings.value("previous-tikzstyles-path").toString(), + tr("TiKZ Style Files (*.tikzstyles)")); + + if (!fileName.isEmpty()) { + loadStyles(fileName); + } +} + +void Tikzit::loadStyles(QString fileName) +{ + QSettings settings("tikzit", "tikzit"); + QFile file(fileName); + if (file.open(QIODevice::ReadOnly)) { + QFileInfo fi(file); + settings.setValue("previous-tikzstyles-path", fi.absolutePath()); + settings.setValue("previous-tikzstyles-file", fileName); + _styleFile = fi.fileName(); + QTextStream in(&file); + QString styleTikz = in.readAll(); + file.close(); + + _styles->clear(); + TikzAssembler ass(_styles); + bool parseSuccess = ass.parse(styleTikz); + if (parseSuccess) { + qDebug() << "parse successful"; + } else { + qDebug() << "parse failed"; + } + //_stylePalette->reloadStyles(); + + foreach (MainWindow *w, _windows) { + w->tikzScene()->reloadStyles(); + } + + } else { + settings.setValue("previous-tikzstyles-file", ""); + QMessageBox::warning(0, "Style file not found.", "Could not open style file: '" + fileName + "', reverting to default."); + } +} + +QString Tikzit::styleFile() const +{ + return _styleFile; +} + +void Tikzit::focusChanged(QWidget *old, QWidget *nw) +{ +// foreach (MainWindow *w, _windows) { +// if (w->isActiveWindow()) { +// _stylePalette->raise(); +// break; +// } +// } +} + +//StylePalette *Tikzit::stylePalette() const +//{ +// return _stylePalette; +//} + + +TikzStyles *Tikzit::styles() const +{ + return _styles; +} + +void Tikzit::quit() +{ + //_stylePalette->close(); + QApplication::quit(); +} + + -- cgit v1.2.3