diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2018-07-20 11:12:02 +0200 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2018-07-20 11:12:02 +0200 |
commit | 329da8795d9a9183830d0c4e0e22ea08d546a4f7 (patch) | |
tree | 2a550aa4a14f0c45e8dfd384cfafecbb24f82aa6 | |
parent | 59eee652c5fea36945a4a8ce2936843bd90d0e1b (diff) |
line ending
-rw-r--r-- | src/main.cpp | 96 | ||||
-rw-r--r-- | src/tikzit.cpp | 422 | ||||
-rw-r--r-- | src/tikzit.h | 282 | ||||
-rw-r--r-- | src/util.cpp | 144 | ||||
-rw-r--r-- | src/util.h | 96 |
5 files changed, 520 insertions, 520 deletions
diff --git a/src/main.cpp b/src/main.cpp index f36cad3..4d6f9a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,48 +1,48 @@ -/*
- 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 <https://www.gnu.org/licenses/>.
-*/
-
-
-/*!
- * \file main.cpp
- *
- * The main entry point for the TikZiT executable.
- */
-
-#include "tikzit.h"
-
-#include <QApplication>
-#include <QMenuBar>
-
-
-
-int main(int argc, char *argv[])
-{
- QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
- //QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
- QApplication a(argc, argv);
- a.setQuitOnLastWindowClosed(false);
- tikzit = new Tikzit();
- tikzit->init(&a);
-
- if (a.arguments().length() > 1) {
- tikzit->open(a.arguments()[1]);
- }
-
- return a.exec();
-}
+/* + 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 <https://www.gnu.org/licenses/>. +*/ + + +/*! + * \file main.cpp + * + * The main entry point for the TikZiT executable. + */ + +#include "tikzit.h" + +#include <QApplication> +#include <QMenuBar> + + + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + //QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); + QApplication a(argc, argv); + a.setQuitOnLastWindowClosed(false); + tikzit = new Tikzit(); + tikzit->init(&a); + + if (a.arguments().length() > 1) { + tikzit->open(a.arguments()[1]); + } + + return a.exec(); +} 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 <https://www.gnu.org/licenses/>.
-*/
-
-#include "tikzit.h"
-#include "tikzassembler.h"
-#include "tikzstyles.h"
-
-#include <QFile>
-#include <QFileDialog>
-#include <QSettings>
-#include <QDebug>
-#include <QMessageBox>
-
-// 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 <https://www.gnu.org/licenses/>. +*/ + +#include "tikzit.h" +#include "tikzassembler.h" +#include "tikzstyles.h" + +#include <QFile> +#include <QFileDialog> +#include <QSettings> +#include <QDebug> +#include <QMessageBox> + +// 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(); +} + + diff --git a/src/tikzit.h b/src/tikzit.h index b450d3f..232a4aa 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -1,141 +1,141 @@ -/*
- 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 <https://www.gnu.org/licenses/>.
-*/
-
-
-/*!
- *
- * \mainpage TikZiT Documentation
- *
- * This is the source code documentation for TikZiT. The global entry point
- * for the TikZiT executable is in main.cpp, whereas the class Tikzit maintains
- * the global application state.
- *
- * The TikZ parser is implemented in flex/bison in the files tikzlexer.l and tikzparser.y.
- *
- * Most of the interesting code for handling user input is in the class TikzScene. Anything
- * that makes a change to the tikz file should be implemented as a QUndoCommand. Currently,
- * these are all in undocommands.h.
- *
- * I've basically been adding documentation as I go. Other bits and pieces can be accessed
- * by searching, or via the class list/class hierarchy links in the menu above.
- *
- */
-
-/*!
- *
- * \class Tikzit
- *
- * Tikzit is the top-level class which maintains the global application state. For convenience,
- * it also holds an instance of the main menu for macOS (or Ubuntu unity) style GUIs which only
- * have one, application-level menu.
- *
- */
-
-#ifndef TIKZIT_H
-#define TIKZIT_H
-
-#include "mainwindow.h"
-#include "mainmenu.h"
-#include "ui_mainmenu.h"
-
-#include "toolpalette.h"
-#include "propertypalette.h"
-#include "stylepalette.h"
-#include "nodestyle.h"
-#include "tikzstyles.h"
-
-#include <QObject>
-#include <QVector>
-#include <QPointF>
-#include <QMenuBar>
-#include <QMainWindow>
-#include <QFont>
-
-// Number of pixels between (0,0) and (1,0) at 100% zoom level. This should be
-// divisible by 8 to avoid rounding errors with e.g. grid-snapping.
-#define GLOBAL_SCALE 40
-#define GLOBAL_SCALEF 40.0f
-#define GLOBAL_SCALEF_INV 0.025f
-#define GRID_N 4
-#define GRID_SEP 10
-#define GRID_SEPF 10.0f
-
-inline QPointF toScreen(QPointF src)
-{ src.setY(-src.y()); src *= GLOBAL_SCALEF; return src; }
-
-inline QPointF fromScreen(QPointF src)
-{ src.setY(-src.y()); src *= GLOBAL_SCALEF_INV; return src; }
-
-inline QRectF rectToScreen(QRectF src)
-{ return QRectF(src.x() * GLOBAL_SCALEF,
- -(src.y()+src.height()) * GLOBAL_SCALEF,
- src.width() * GLOBAL_SCALEF,
- src.height() * GLOBAL_SCALEF); }
-
-inline QRectF rectFromScreen(QRectF src)
-{ return QRectF(src.x() * GLOBAL_SCALEF_INV,
- -(src.y()+src.height()) * GLOBAL_SCALEF_INV,
- src.width() * GLOBAL_SCALEF_INV,
- src.height() * GLOBAL_SCALEF_INV); }
-
-class Tikzit : public QObject {
- Q_OBJECT
-public:
- Tikzit();
- ToolPalette *toolPalette() const;
- PropertyPalette *propertyPalette() const;
-
- MainWindow *activeWindow() const;
- void setActiveWindow(MainWindow *activeWindow);
- void removeWindow(MainWindow *w);
-
- static QFont LABEL_FONT;
-// Ui::MainMenu *_mainMenuUi;
-// QMenuBar *_mainMenu;
-
- void newDoc();
- void open();
- void open(QString fileName);
- void quit();
- void init(QApplication *app);
-
- void openTikzStyles();
- void loadStyles(QString fileName);
- TikzStyles *styles() const;
- QString styleFile() const;
- //StylePalette *stylePalette() const;
-
-public slots:
- void focusChanged(QWidget *old, QWidget *nw);
-private:
- // void createMenu();
-
- MainMenu *_mainMenu;
- ToolPalette *_toolPalette;
- PropertyPalette *_propertyPalette;
- //StylePalette *_stylePalette;
- QVector<MainWindow*> _windows;
- MainWindow *_activeWindow;
- TikzStyles *_styles;
- QString _styleFile;
-
-};
-
-extern Tikzit *tikzit;
-
-#endif // TIKZIT_H
+/* + 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 <https://www.gnu.org/licenses/>. +*/ + + +/*! + * + * \mainpage TikZiT Documentation + * + * This is the source code documentation for TikZiT. The global entry point + * for the TikZiT executable is in main.cpp, whereas the class Tikzit maintains + * the global application state. + * + * The TikZ parser is implemented in flex/bison in the files tikzlexer.l and tikzparser.y. + * + * Most of the interesting code for handling user input is in the class TikzScene. Anything + * that makes a change to the tikz file should be implemented as a QUndoCommand. Currently, + * these are all in undocommands.h. + * + * I've basically been adding documentation as I go. Other bits and pieces can be accessed + * by searching, or via the class list/class hierarchy links in the menu above. + * + */ + +/*! + * + * \class Tikzit + * + * Tikzit is the top-level class which maintains the global application state. For convenience, + * it also holds an instance of the main menu for macOS (or Ubuntu unity) style GUIs which only + * have one, application-level menu. + * + */ + +#ifndef TIKZIT_H +#define TIKZIT_H + +#include "mainwindow.h" +#include "mainmenu.h" +#include "ui_mainmenu.h" + +#include "toolpalette.h" +#include "propertypalette.h" +#include "stylepalette.h" +#include "nodestyle.h" +#include "tikzstyles.h" + +#include <QObject> +#include <QVector> +#include <QPointF> +#include <QMenuBar> +#include <QMainWindow> +#include <QFont> + +// Number of pixels between (0,0) and (1,0) at 100% zoom level. This should be +// divisible by 8 to avoid rounding errors with e.g. grid-snapping. +#define GLOBAL_SCALE 40 +#define GLOBAL_SCALEF 40.0f +#define GLOBAL_SCALEF_INV 0.025f +#define GRID_N 4 +#define GRID_SEP 10 +#define GRID_SEPF 10.0f + +inline QPointF toScreen(QPointF src) +{ src.setY(-src.y()); src *= GLOBAL_SCALEF; return src; } + +inline QPointF fromScreen(QPointF src) +{ src.setY(-src.y()); src *= GLOBAL_SCALEF_INV; return src; } + +inline QRectF rectToScreen(QRectF src) +{ return QRectF(src.x() * GLOBAL_SCALEF, + -(src.y()+src.height()) * GLOBAL_SCALEF, + src.width() * GLOBAL_SCALEF, + src.height() * GLOBAL_SCALEF); } + +inline QRectF rectFromScreen(QRectF src) +{ return QRectF(src.x() * GLOBAL_SCALEF_INV, + -(src.y()+src.height()) * GLOBAL_SCALEF_INV, + src.width() * GLOBAL_SCALEF_INV, + src.height() * GLOBAL_SCALEF_INV); } + +class Tikzit : public QObject { + Q_OBJECT +public: + Tikzit(); + ToolPalette *toolPalette() const; + PropertyPalette *propertyPalette() const; + + MainWindow *activeWindow() const; + void setActiveWindow(MainWindow *activeWindow); + void removeWindow(MainWindow *w); + + static QFont LABEL_FONT; +// Ui::MainMenu *_mainMenuUi; +// QMenuBar *_mainMenu; + + void newDoc(); + void open(); + void open(QString fileName); + void quit(); + void init(QApplication *app); + + void openTikzStyles(); + void loadStyles(QString fileName); + TikzStyles *styles() const; + QString styleFile() const; + //StylePalette *stylePalette() const; + +public slots: + void focusChanged(QWidget *old, QWidget *nw); +private: + // void createMenu(); + + MainMenu *_mainMenu; + ToolPalette *_toolPalette; + PropertyPalette *_propertyPalette; + //StylePalette *_stylePalette; + QVector<MainWindow*> _windows; + MainWindow *_activeWindow; + TikzStyles *_styles; + QString _styleFile; + +}; + +extern Tikzit *tikzit; + +#endif // TIKZIT_H diff --git a/src/util.cpp b/src/util.cpp index 6d75bee..9c699f5 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,72 +1,72 @@ -/*
- 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 <https://www.gnu.org/licenses/>.
-*/
-
-#include "util.h"
-
-float bezierInterpolate(float dist, float c0, float c1, float c2, float c3) {
- float distp = 1 - dist;
- return (distp*distp*distp) * c0 +
- 3 * (distp*distp) * dist * c1 +
- 3 * (dist*dist) * distp * c2 +
- (dist*dist*dist) * c3;
-}
-
-QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3) {
- return QPointF(bezierInterpolate (dist, c0.x(), c1.x(), c2.x(), c3.x()),
- bezierInterpolate (dist, c0.y(), c1.y(), c2.y(), c3.y()));
-}
-
-
-float roundToNearest(float stepSize, float val) {
- if (stepSize==0.0f) return val;
- else return round(val/stepSize)*stepSize;
-}
-
-float radiansToDegrees (float radians) {
- return (radians * 180.0f) / M_PI;
-}
-
-float degreesToRadians(float degrees) {
- return (degrees * M_PI) / 180.0f;
-}
-
-int normaliseAngleDeg (int degrees) {
- while (degrees > 180) {
- degrees -= 360;
- }
- while (degrees <= -180) {
- degrees += 360;
- }
- return degrees;
-}
-
-float normaliseAngleRad (float rads) {
- while (rads > M_PI) {
- rads -= 2 * M_PI;
- }
- while (rads <= -M_PI) {
- rads += 2 * M_PI;
- }
- return rads;
-}
-
-// convert float to string, squashing very small floats to zero
-QString floatToString(float f) {
- if (f >= -0.000001 && f <= 0.000001) return "0";
- else return QString::number(f);
-}
+/* + 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 <https://www.gnu.org/licenses/>. +*/ + +#include "util.h" + +float bezierInterpolate(float dist, float c0, float c1, float c2, float c3) { + float distp = 1 - dist; + return (distp*distp*distp) * c0 + + 3 * (distp*distp) * dist * c1 + + 3 * (dist*dist) * distp * c2 + + (dist*dist*dist) * c3; +} + +QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3) { + return QPointF(bezierInterpolate (dist, c0.x(), c1.x(), c2.x(), c3.x()), + bezierInterpolate (dist, c0.y(), c1.y(), c2.y(), c3.y())); +} + + +float roundToNearest(float stepSize, float val) { + if (stepSize==0.0f) return val; + else return round(val/stepSize)*stepSize; +} + +float radiansToDegrees (float radians) { + return (radians * 180.0f) / M_PI; +} + +float degreesToRadians(float degrees) { + return (degrees * M_PI) / 180.0f; +} + +int normaliseAngleDeg (int degrees) { + while (degrees > 180) { + degrees -= 360; + } + while (degrees <= -180) { + degrees += 360; + } + return degrees; +} + +float normaliseAngleRad (float rads) { + while (rads > M_PI) { + rads -= 2 * M_PI; + } + while (rads <= -M_PI) { + rads += 2 * M_PI; + } + return rads; +} + +// convert float to string, squashing very small floats to zero +QString floatToString(float f) { + if (f >= -0.000001 && f <= 0.000001) return "0"; + else return QString::number(f); +} @@ -1,48 +1,48 @@ -/*
- 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 <https://www.gnu.org/licenses/>.
-*/
-
-/*!
- * Various utility functions, mostly for mathematical calculation.
- */
-
-#ifndef UTIL_H
-#define UTIL_H
-
-#include <QPoint>
-#include <QString>
-#include <cmath>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846264338327950288
-#endif
-
-// interpolate on a cubic bezier curve
-float bezierInterpolate(float dist, float c0, float c1, float c2, float c3);
-QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3);
-
-// rounding
-float roundToNearest(float stepSize, float val);
-float radiansToDegrees (float radians);
-QString floatToString(float f);
-
-// angles
-float degreesToRadians(float degrees);
-int normaliseAngleDeg (int degrees);
-float normaliseAngleRad (float rads);
-
-#endif // UTIL_H
+/* + 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 <https://www.gnu.org/licenses/>. +*/ + +/*! + * Various utility functions, mostly for mathematical calculation. + */ + +#ifndef UTIL_H +#define UTIL_H + +#include <QPoint> +#include <QString> +#include <cmath> + +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327950288 +#endif + +// interpolate on a cubic bezier curve +float bezierInterpolate(float dist, float c0, float c1, float c2, float c3); +QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3); + +// rounding +float roundToNearest(float stepSize, float val); +float radiansToDegrees (float radians); +QString floatToString(float f); + +// angles +float degreesToRadians(float degrees); +int normaliseAngleDeg (int degrees); +float normaliseAngleRad (float rads); + +#endif // UTIL_H |