From e8b06cb33e6fbe6c614cd52575dd1514a4a00781 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 30 Oct 2018 17:31:58 +0100 Subject: started popple --- src/gui/previewwindow.cpp | 14 ++++++++++++++ src/gui/previewwindow.h | 22 ++++++++++++++++++++++ src/gui/previewwindow.ui | 18 ++++++++++++++++++ tikzit.pro | 9 ++++++--- 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/gui/previewwindow.cpp create mode 100644 src/gui/previewwindow.h create mode 100644 src/gui/previewwindow.ui diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp new file mode 100644 index 0000000..945c77e --- /dev/null +++ b/src/gui/previewwindow.cpp @@ -0,0 +1,14 @@ +#include "previewwindow.h" +#include "ui_previewwindow.h" + +PreviewWindow::PreviewWindow(QWidget *parent) : + QDialog(parent), + ui(new Ui::PreviewWindow) +{ + ui->setupUi(this); +} + +PreviewWindow::~PreviewWindow() +{ + delete ui; +} diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h new file mode 100644 index 0000000..5c4a384 --- /dev/null +++ b/src/gui/previewwindow.h @@ -0,0 +1,22 @@ +#ifndef PREVIEWWINDOW_H +#define PREVIEWWINDOW_H + +#include + +namespace Ui { +class PreviewWindow; +} + +class PreviewWindow : public QDialog +{ + Q_OBJECT + +public: + explicit PreviewWindow(QWidget *parent = nullptr); + ~PreviewWindow(); + +private: + Ui::PreviewWindow *ui; +}; + +#endif // PREVIEWWINDOW_H diff --git a/src/gui/previewwindow.ui b/src/gui/previewwindow.ui new file mode 100644 index 0000000..59224aa --- /dev/null +++ b/src/gui/previewwindow.ui @@ -0,0 +1,18 @@ + + PreviewWindow + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + diff --git a/tikzit.pro b/tikzit.pro index 9fa1d15..6052fcf 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -75,7 +75,8 @@ SOURCES += src/gui/mainwindow.cpp \ src/data/tikzstyles.cpp \ src/data/style.cpp \ src/gui/styleeditor.cpp \ - src/data/stylelist.cpp + src/data/stylelist.cpp \ + src/gui/previewwindow.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -101,13 +102,15 @@ HEADERS += src/gui/mainwindow.h \ src/data/tikzstyles.h \ src/data/style.h \ src/gui/styleeditor.h \ - src/data/stylelist.h + src/data/stylelist.h \ + src/gui/previewwindow.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ src/gui/mainmenu.ui \ src/gui/stylepalette.ui \ - src/gui/styleeditor.ui + src/gui/styleeditor.ui \ + src/gui/previewwindow.ui INCLUDEPATH += src src/gui src/data -- cgit v1.2.3 From 32b48a7fff0413832fd412da2f270a003255b050 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 19 Nov 2018 08:25:12 +0100 Subject: added cmake support --- CMakeLists.txt | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ba0eee5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,102 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(tikzit LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +#set(CMAKE_AUTOUIC ON) + +find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Network) +find_package(BISON) +find_package(FLEX) + +include_directories( + ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/src/data + ${PROJECT_SOURCE_DIR}/src/gui +) + +BISON_TARGET(PARSER src/data/tikzparser.y ${CMAKE_CURRENT_BINARY_DIR}/tikzparser.parser.cpp) +FLEX_TARGET(LEXER src/data/tikzlexer.l ${CMAKE_CURRENT_BINARY_DIR}/tikzlexer.lexer.cpp) +ADD_FLEX_BISON_DEPENDENCY(LEXER PARSER) +cmake_policy(SET CMP0071 NEW) # run AUTOXXX on generated files ('NEW' default behaviour) + +set(SOURCES + src/data/edge.cpp + src/data/graph.cpp + src/data/graphelementdata.cpp + src/data/graphelementproperty.cpp + src/data/node.cpp + src/data/style.cpp + src/data/stylelist.cpp + src/data/tikzassembler.cpp + src/data/tikzdocument.cpp + src/data/tikzstyles.cpp + src/gui/commands.cpp + src/gui/edgeitem.cpp + src/gui/mainmenu.cpp + src/gui/mainwindow.cpp + src/gui/nodeitem.cpp + src/gui/propertypalette.cpp + src/gui/styleeditor.cpp + src/gui/stylepalette.cpp + src/gui/tikzscene.cpp + src/gui/tikzview.cpp + src/gui/toolpalette.cpp + src/gui/undocommands.cpp + src/main.cpp + src/tikzit.cpp + src/util.cpp +) + +set(HEADERS + src/data/edge.h + src/data/graph.h + src/data/graphelementdata.h + src/data/graphelementproperty.h + src/data/node.h + src/data/style.h + src/data/stylelist.h + src/data/tikzassembler.h + src/data/tikzdocument.h + src/data/tikzparserdefs.h + src/data/tikzstyles.h + src/gui/commands.h + src/gui/edgeitem.h + src/gui/mainmenu.h + src/gui/mainwindow.h + src/gui/nodeitem.h + src/gui/propertypalette.h + src/gui/styleeditor.h + src/gui/stylepalette.h + src/gui/tikzscene.h + src/gui/tikzview.h + src/gui/toolpalette.h + src/gui/undocommands.h + src/tikzit.h + src/util.h +) + +set(FORMS + src/gui/mainmenu.ui + src/gui/mainwindow.ui + src/gui/propertypalette.ui + src/gui/styleeditor.ui + src/gui/stylepalette.ui +) + +qt5_wrap_ui(FORM_HEADERS ${FORMS}) +qt5_add_resources(QT_RESOURCES tikzit.qrc) + + + +add_executable(tikzit + ${SOURCES} + ${HEADERS} + ${FORM_HEADERS} + ${FLEX_LEXER_OUTPUTS} + ${BISON_PARSER_OUTPUTS} + ${QT_RESOURCES}) + +target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network) -- cgit v1.2.3 From bf25ab82947e6aa9411a0bee67c66e10aaec4e73 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 19 Nov 2018 10:54:20 +0100 Subject: added build directory to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0fb2e43..2c5a2d5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ tex/sample/sample.pdf *.sublime-* src-old GeneratedFiles +build .vs debug release -- cgit v1.2.3 From 644eca3d05377c8dcc74b42cf93d87dde9f9dce2 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 21 Nov 2018 18:38:11 +0100 Subject: deferred deletion for tikzstyles (#43) --- src/tikzit.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tikzit.cpp b/src/tikzit.cpp index c9286c9..1c3ba23 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -190,7 +190,7 @@ void Tikzit::newTikzStyles() if (dialog.exec() && !dialog.selectedFiles().isEmpty()) { QString fileName = dialog.selectedFiles()[0]; - TikzStyles *st = new TikzStyles; + TikzStyles *st = new TikzStyles(this); if (st->saveStyles(fileName)) { QFileInfo fi(fileName); @@ -198,7 +198,7 @@ void Tikzit::newTikzStyles() _styleFilePath = fi.absoluteFilePath(); settings.setValue("previous-tikzstyles-file", fileName); settings.setValue("previous-tikzstyles-path", fi.absolutePath()); - delete _styles; + _styles->deleteLater(); _styles = st; foreach (MainWindow *w, _windows) { @@ -310,7 +310,7 @@ bool Tikzit::loadStyles(QString fileName) if (st->loadStyles(fileName)) { _styleFile = fi.fileName(); _styleFilePath = fi.absoluteFilePath(); - delete _styles; + _styles->deleteLater(); _styles = st; foreach (MainWindow *w, _windows) { -- cgit v1.2.3 From dd6ab70ee19210c83869e53ef6003f00df15bbbd Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 22 Nov 2018 09:54:45 +0100 Subject: minor --- src/main.cpp | 12 ++---------- src/tikzit.h | 1 + 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 99d23e9..7a282e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,6 @@ along with this program. If not, see . */ - /*! * \file main.cpp * @@ -31,21 +30,17 @@ #include #include -// #ifdef Q_OS_WIN -// #include -// #endif - int main(int argc, char *argv[]) { // #ifdef Q_OS_WIN // SetProcessDPIAware(); // #endif -// QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + // QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); // dummy application for detecting DPI QApplication *a0 = new QApplication(argc, argv); -// qDebug() << "physical DPI" << QApplication::screens()[0]->physicalDotsPerInch(); + // qDebug() << "physical DPI" << QApplication::screens()[0]->physicalDotsPerInch(); if (QApplication::screens()[0]->physicalDotsPerInch() >= 100) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -58,14 +53,11 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); - - tikzit = new Tikzit(); tikzit->init(); qDebug() << a.arguments().length(); - if (a.arguments().length() > 1) { tikzit->open(a.arguments()[1]); } diff --git a/src/tikzit.h b/src/tikzit.h index d36a940..5fed22c 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -80,6 +80,7 @@ #define GRID_SEP 10 #define GRID_SEPF 10.0f + inline QPointF toScreen(QPointF src) { src.setY(-src.y()); src *= GLOBAL_SCALEF; return src; } -- cgit v1.2.3 From e51b93cac7213ffd6448f7c27070ac0da7e89b6f Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 22 Nov 2018 10:03:55 +0100 Subject: added comment --- tikzit.pro | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tikzit.pro b/tikzit.pro index 9fa1d15..4f0c4d5 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -1,8 +1,4 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2017-01-11T17:30:16 -# -#------------------------------------------------- +# CONFIG += debug QT += core gui widgets network -- cgit v1.2.3 From d6c0003f7589e83c8f9ac6734f9b27554358a9f5 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 22 Nov 2018 22:09:15 +0100 Subject: deferred deletion for all (potential) listeners --- src/data/edge.cpp | 14 +++++--------- src/data/edge.h | 1 - src/data/graph.cpp | 3 ++- src/data/graphelementdata.cpp | 6 ------ src/data/graphelementdata.h | 2 -- src/data/node.cpp | 9 +++------ src/data/node.h | 1 - src/data/tikzdocument.cpp | 13 ++++--------- src/data/tikzdocument.h | 1 - 9 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/data/edge.cpp b/src/data/edge.cpp index 0ae566b..a9acd85 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -26,7 +26,7 @@ Edge::Edge(Node *s, Node *t, QObject *parent) : QObject(parent), _source(s), _target(t) { - _data = new GraphElementData(); + _data = new GraphElementData(this); _edgeNode = 0; _dirty = true; @@ -47,12 +47,6 @@ Edge::Edge(Node *s, Node *t, QObject *parent) : updateControls(); } -Edge::~Edge() -{ - delete _data; - delete _edgeNode; -} - /*! * @brief Edge::copy makes a deep copy of an edge. * @param nodeTable is an optional pointer to a table mapping the old source/target @@ -103,8 +97,9 @@ GraphElementData *Edge::data() const void Edge::setData(GraphElementData *data) { - delete _data; + GraphElementData *oldData = _data; _data = data; + oldData->deleteLater(); setAttributesFromData(); } @@ -148,8 +143,9 @@ Node *Edge::edgeNode() const void Edge::setEdgeNode(Node *edgeNode) { - if (_edgeNode != 0) delete _edgeNode; + Node *oldEdgeNode = _edgeNode; _edgeNode = edgeNode; + if (oldEdgeNode != 0) oldEdgeNode->deleteLater(); } bool Edge::hasEdgeNode() diff --git a/src/data/edge.h b/src/data/edge.h index ad71364..5d26b3e 100644 --- a/src/data/edge.h +++ b/src/data/edge.h @@ -31,7 +31,6 @@ class Edge : public QObject Q_OBJECT public: explicit Edge(Node *s, Node *t, QObject *parent = 0); - ~Edge(); Edge *copy(QMap *nodeTable = 0); Node *source() const; diff --git a/src/data/graph.cpp b/src/data/graph.cpp index bba2061..da7b345 100644 --- a/src/data/graph.cpp +++ b/src/data/graph.cpp @@ -152,8 +152,9 @@ GraphElementData *Graph::data() const void Graph::setData(GraphElementData *data) { - delete _data; + GraphElementData *oldData = _data; _data = data; + oldData->deleteLater(); } const QVector &Graph::nodes() diff --git a/src/data/graphelementdata.cpp b/src/data/graphelementdata.cpp index 810ebd6..f743bc5 100644 --- a/src/data/graphelementdata.cpp +++ b/src/data/graphelementdata.cpp @@ -23,18 +23,12 @@ GraphElementData::GraphElementData(QVector init, QObject *parent) : QAbstractItemModel(parent) { - root = new GraphElementProperty(); _properties = init; } GraphElementData::GraphElementData(QObject *parent) : QAbstractItemModel(parent) { - root = new GraphElementProperty(); } -GraphElementData::~GraphElementData() -{ - delete root; -} GraphElementData *GraphElementData::copy() { diff --git a/src/data/graphelementdata.h b/src/data/graphelementdata.h index 23f0466..b1311d7 100644 --- a/src/data/graphelementdata.h +++ b/src/data/graphelementdata.h @@ -34,7 +34,6 @@ public: explicit GraphElementData(QVector init, QObject *parent = 0); explicit GraphElementData(QObject *parent = 0); - ~GraphElementData(); GraphElementData *copy(); void setProperty(QString key, QString value); void unsetProperty(QString key); @@ -78,7 +77,6 @@ public slots: private: QVector _properties; - GraphElementProperty *root; }; #endif // GRAPHELEMENTDATA_H diff --git a/src/data/node.cpp b/src/data/node.cpp index 75acd00..8ec5e9b 100644 --- a/src/data/node.cpp +++ b/src/data/node.cpp @@ -23,15 +23,11 @@ Node::Node(QObject *parent) : QObject(parent), _tikzLine(-1) { - _data = new GraphElementData(); + _data = new GraphElementData(this); _style = noneStyle; _data->setProperty("style", "none"); } -Node::~Node() -{ - delete _data; -} Node *Node::copy() { Node *n1 = new Node(); @@ -81,8 +77,9 @@ GraphElementData *Node::data() const void Node::setData(GraphElementData *data) { - delete _data; + GraphElementData *oldData = _data; _data = data; + oldData->deleteLater(); } QString Node::styleName() const diff --git a/src/data/node.h b/src/data/node.h index 490393d..c40627b 100644 --- a/src/data/node.h +++ b/src/data/node.h @@ -31,7 +31,6 @@ class Node : public QObject Q_OBJECT public: explicit Node(QObject *parent = 0); - ~Node(); Node *copy(); diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp index 24a793b..863f1fd 100644 --- a/src/data/tikzdocument.cpp +++ b/src/data/tikzdocument.cpp @@ -34,16 +34,10 @@ TikzDocument::TikzDocument(QObject *parent) : QObject(parent) _parseSuccess = true; _fileName = ""; _shortName = ""; - _undoStack = new QUndoStack(); + _undoStack = new QUndoStack(this); _undoStack->setClean(); } -TikzDocument::~TikzDocument() -{ - delete _graph; - delete _undoStack; -} - QUndoStack *TikzDocument::undoStack() const { return _undoStack; @@ -79,11 +73,12 @@ void TikzDocument::open(QString fileName) _tikz = in.readAll(); file.close(); + Graph *oldGraph = _graph; Graph *newGraph = new Graph(this); TikzAssembler ass(newGraph); if (ass.parse(_tikz)) { - delete _graph; _graph = newGraph; + oldGraph->deleteLater(); foreach (Node *n, _graph->nodes()) n->attachStyle(); foreach (Edge *e, _graph->edges()) { e->attachStyle(); @@ -93,7 +88,7 @@ void TikzDocument::open(QString fileName) refreshTikz(); setClean(); } else { - delete newGraph; + newGraph->deleteLater(); _parseSuccess = false; } } diff --git a/src/data/tikzdocument.h b/src/data/tikzdocument.h index fca5434..a5f3534 100644 --- a/src/data/tikzdocument.h +++ b/src/data/tikzdocument.h @@ -34,7 +34,6 @@ class TikzDocument : public QObject Q_OBJECT public: explicit TikzDocument(QObject *parent = 0); - ~TikzDocument(); Graph *graph() const; void setGraph(Graph *graph); -- cgit v1.2.3 From a991943e59bc4341ceef55313642b85565454d86 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 16 Dec 2018 16:04:02 +0100 Subject: added dummy preview window, linked to poppler --- CMakeLists.txt | 12 ++++++++- src/gui/previewwindow.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++ src/gui/previewwindow.h | 7 ++++++ src/gui/previewwindow.ui | 63 +++++++++++++++++++++++++++++++++++++++++++++-- src/tikzit.cpp | 4 +++ 5 files changed, 144 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba0eee5..311dac4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,11 @@ find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Network) find_package(BISON) find_package(FLEX) +# use extra-cmake-modules to find poppler library +find_package(ECM REQUIRED NO_MODULE) +set(CMAKE_MODULE_PATH ${ECM_FIND_MODULE_DIR}) +find_package(Poppler REQUIRED COMPONENTS Core Qt5) + include_directories( ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src @@ -38,6 +43,7 @@ set(SOURCES src/gui/mainmenu.cpp src/gui/mainwindow.cpp src/gui/nodeitem.cpp + src/gui/previewwindow.cpp src/gui/propertypalette.cpp src/gui/styleeditor.cpp src/gui/stylepalette.cpp @@ -67,6 +73,7 @@ set(HEADERS src/gui/mainmenu.h src/gui/mainwindow.h src/gui/nodeitem.h + src/gui/previewwindow.h src/gui/propertypalette.h src/gui/styleeditor.h src/gui/stylepalette.h @@ -81,6 +88,7 @@ set(HEADERS set(FORMS src/gui/mainmenu.ui src/gui/mainwindow.ui + src/gui/previewwindow.ui src/gui/propertypalette.ui src/gui/styleeditor.ui src/gui/stylepalette.ui @@ -99,4 +107,6 @@ add_executable(tikzit ${BISON_PARSER_OUTPUTS} ${QT_RESOURCES}) -target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network) +target_link_libraries(${PROJECT_NAME} + Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network + ${Poppler_LIBRARIES}) diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 945c77e..bca28e3 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -1,14 +1,75 @@ #include "previewwindow.h" #include "ui_previewwindow.h" +#include +#include +#include +#include +#include +#include +#include + PreviewWindow::PreviewWindow(QWidget *parent) : QDialog(parent), ui(new Ui::PreviewWindow) { + QSettings settings("tikzit", "tikzit"); ui->setupUi(this); + + QVariant geom = settings.value("geometry-preview"); + + if (geom.isValid()) { + restoreGeometry(geom.toByteArray()); + } + + _doc = Poppler::Document::load("/home/aleks/ak-algebras.pdf"); + _doc->setRenderHint(Poppler::Document::Antialiasing); + _doc->setRenderHint(Poppler::Document::TextAntialiasing); + _doc->setRenderHint(Poppler::Document::TextHinting ); + _page = _doc->page(0); + + render(); } PreviewWindow::~PreviewWindow() { delete ui; } + +void PreviewWindow::closeEvent(QCloseEvent *e) { + QSettings settings("tikzit", "tikzit"); + settings.setValue("geometry-preview", saveGeometry()); +} + +void PreviewWindow::resizeEvent(QResizeEvent *e) { + render(); + QDialog::resizeEvent(e); +} + +void PreviewWindow::showEvent(QShowEvent *e) { + render(); + QDialog::showEvent(e); +} + +void PreviewWindow::render() { + QSizeF size = _page->pageSizeF(); + + QRect rect = ui->scrollArea->visibleRegion().boundingRect(); + int w = rect.width(); + int h = rect.height(); + qreal scale = fmin(static_cast(w) / size.width(), + static_cast(h) / size.height()); + int dpi = static_cast(scale * 72.0); + int w1 = static_cast(scale * size.width()); + int h1 = static_cast(scale * size.height()); + + // qDebug() << "visible width:" << w; + // qDebug() << "visible height:" << h; + // qDebug() << "doc width:" << size.width(); + // qDebug() << "doc height:" << size.height(); + // qDebug() << "scale:" << scale; + // qDebug() << "dpi:" << dpi; + + QImage img = _page->renderToImage(dpi,dpi, (w1 - w)/2, (h1 - h)/2, w, h); + ui->pdf->setPixmap(QPixmap::fromImage(img)); +} diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h index 5c4a384..f2366d6 100644 --- a/src/gui/previewwindow.h +++ b/src/gui/previewwindow.h @@ -2,6 +2,7 @@ #define PREVIEWWINDOW_H #include +#include namespace Ui { class PreviewWindow; @@ -14,9 +15,15 @@ class PreviewWindow : public QDialog public: explicit PreviewWindow(QWidget *parent = nullptr); ~PreviewWindow(); + void resizeEvent(QResizeEvent *e); + void showEvent(QShowEvent *e); + void closeEvent(QCloseEvent *e); private: Ui::PreviewWindow *ui; + void render(); + Poppler::Document *_doc; + Poppler::Page *_page; }; #endif // PREVIEWWINDOW_H diff --git a/src/gui/previewwindow.ui b/src/gui/previewwindow.ui index 59224aa..6bb993a 100644 --- a/src/gui/previewwindow.ui +++ b/src/gui/previewwindow.ui @@ -1,6 +1,7 @@ + PreviewWindow - + 0 @@ -10,8 +11,66 @@ - Dialog + Preview + + + + + 0 + + + + PDF + + + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + true + + + + + 0 + 0 + 358 + 233 + + + + + + + + + + + + + + + + + + + Output + + + + + + + + + + diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 1c3ba23..d69f4a8 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -19,6 +19,7 @@ #include "tikzit.h" #include "tikzassembler.h" #include "tikzstyles.h" +#include "previewwindow.h" #include #include @@ -126,6 +127,9 @@ void Tikzit::init() if (check.toBool()) { checkForUpdates(); } + + PreviewWindow *preview = new PreviewWindow(); + preview->show(); } //QMenuBar *Tikzit::mainMenu() const -- cgit v1.2.3 From 2802488b5928ed1d9886e393d06938db0e825a32 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 16 Dec 2018 16:39:03 +0100 Subject: added lib --- .appveyor.yml | 2 +- tikzit.pro | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index c8c4424..c2f27c4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -13,7 +13,7 @@ configuration: install: - cmd: choco install winflexbison - - cmd: 'C:\Qt\5.11.1\msvc2015_64\bin\qtenv2.bat' + - cmd: 'C:\Qt\5.11.2\msvc2015_64\bin\qtenv2.bat' - cmd: call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 - cmd: cd C:\projects\tikzit - sh: sudo apt-get update diff --git a/tikzit.pro b/tikzit.pro index 7de0bd4..e1e07b4 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -110,6 +110,8 @@ FORMS += src/gui/mainwindow.ui \ INCLUDEPATH += src src/gui src/data +LIBS += -lpoppler-qt5 + DISTFILES += RESOURCES += tikzit.qrc -- cgit v1.2.3 From fc24b3787a82a3b467fde9f52e1a5559160b7fe0 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 16 Dec 2018 16:39:21 +0100 Subject: incr Qt version --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index c8c4424..c2f27c4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -13,7 +13,7 @@ configuration: install: - cmd: choco install winflexbison - - cmd: 'C:\Qt\5.11.1\msvc2015_64\bin\qtenv2.bat' + - cmd: 'C:\Qt\5.11.2\msvc2015_64\bin\qtenv2.bat' - cmd: call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 - cmd: cd C:\projects\tikzit - sh: sudo apt-get update -- cgit v1.2.3 From 6121b486e168334db70cbbe7a67afe56c0272748 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 17 Dec 2018 12:37:15 +0100 Subject: preview almost works --- src/gui/latexprocess.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++ src/gui/latexprocess.h | 33 ++++++++++++++++ src/gui/mainmenu.cpp | 5 +++ src/gui/mainmenu.h | 1 + src/gui/mainmenu.ui | 9 +++++ src/gui/previewwindow.cpp | 37 +++++++++++++++--- src/gui/previewwindow.h | 6 +++ src/gui/previewwindow.ui | 8 ++-- src/tikzit.cpp | 33 +++++++++++++++- src/tikzit.h | 6 +++ tex/sample/tikzit.sty | 2 +- tikzit.pro | 6 ++- tikzit.qrc | 1 + 13 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 src/gui/latexprocess.cpp create mode 100644 src/gui/latexprocess.h diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp new file mode 100644 index 0000000..f81e883 --- /dev/null +++ b/src/gui/latexprocess.cpp @@ -0,0 +1,98 @@ +#include "latexprocess.h" +#include "tikzit.h" + +#include +#include +#include + +LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(parent) +{ + _preview = preview; + _output = preview->outputTextEdit(); + + _proc = new QProcess(this); + _proc->setProcessChannelMode(QProcess::MergedChannels); + _proc->setWorkingDirectory(_workingDir.path()); + + connect(_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput())); + connect(_proc, SIGNAL(finished(int)), this, SLOT(finished(int))); + + // for debug purposes + _workingDir.setAutoRemove(false); +} + +void LatexProcess::makePreview(QString tikz) +{ + _output->clear(); + + if (!_workingDir.isValid()) { + _output->appendPlainText("COULD NOT WRITE TO TEMP DIR: " + _workingDir.path() + "\n"); + return; + } + + _output->appendPlainText("USING TEMP DIR: " + _workingDir.path() + "\n"); + _output->appendPlainText("SEARCHING FOR pdflatex IN:"); + _output->appendPlainText(qgetenv("PATH")); + _output->appendPlainText("\n"); + + + QString pdflatex = QStandardPaths::findExecutable("pdflatex"); + if (pdflatex.isEmpty()) { + _output->appendPlainText("pdflatex NOT FOUND, ABORTING.\n"); + return; + } + + _output->appendPlainText("FOUND: " + pdflatex + "\n"); + + // copy active *.tikzstyles file to preview dir + if (!tikzit->styleFile().isEmpty() && QFile::exists(tikzit->styleFilePath())) { + QFile::copy(tikzit->styleFilePath(), _workingDir.path() + "/" + tikzit->styleFile()); + } + + // copy tikzit.sty to preview dir + QFile::copy(":/tex/sample/tikzit.sty", _workingDir.path() + "/tikzit.sty"); + + // write out the file containing the tikz picture + QFile f(_workingDir.path() + "/preview.tex"); + f.open(QIODevice::WriteOnly); + QTextStream tex(&f); + tex << "\\documentclass{article}\n"; + tex << "\\usepackage[active,tightpage]{preview}\n"; + tex << "\\PreviewEnvironment{tikzpicture}\n"; + tex << "\\usepackage{tikzit}\n"; + tex << "\\input{" + tikzit->styleFile() + "}\n"; + tex << "\\begin{document}\n\n"; + tex << tikz; + tex << "\n\n\\end{document}\n"; + + f.close(); + _proc->start(pdflatex, QStringList() << "preview.tex"); + +} + +void LatexProcess::kill() +{ + if (_proc->state() == QProcess::Running) _proc->kill(); +} + +void LatexProcess::readyReadStandardOutput() +{ + QByteArray s = _proc->readAllStandardOutput(); + _output->appendPlainText(s); +} + +void LatexProcess::finished(int exitCode) +{ + QByteArray s = _proc->readAllStandardOutput(); + _output->appendPlainText(s); + + if (exitCode == 0) { + QString pdf = _workingDir.path() + "/preview.pdf"; + _output->appendPlainText("\n\nSUCCESSFULLY GENERATED: " + pdf + "\n"); + //_preview->setPdf(pdf); + emit previewFinished(); + } else { + _output->appendPlainText("\n\npdflatex RETURNED AN ERROR\n"); + emit previewFinished(); + } +} diff --git a/src/gui/latexprocess.h b/src/gui/latexprocess.h new file mode 100644 index 0000000..dc815f2 --- /dev/null +++ b/src/gui/latexprocess.h @@ -0,0 +1,33 @@ +#ifndef LATEXPROCESS_H +#define LATEXPROCESS_H + +#include "previewwindow.h" + +#include +#include +#include +#include + +class LatexProcess : public QObject +{ + Q_OBJECT +public: + explicit LatexProcess(PreviewWindow *preview, QObject *parent = nullptr); + void makePreview(QString tikz); + void kill(); + +private: + QTemporaryDir _workingDir; + PreviewWindow *_preview; + QPlainTextEdit *_output; + QProcess *_proc; + +public slots: + void readyReadStandardOutput(); + void finished(int exitCode); + +signals: + void previewFinished(); +}; + +#endif // LATEXPROCESS_H diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 8166c59..ab1b898 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -228,6 +228,11 @@ void MainMenu::on_actionJump_to_Selection_triggered() } } +void MainMenu::on_actionRun_LaTeX_triggered() +{ + tikzit->makePreview(); +} + // View void MainMenu::on_actionZoom_In_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index c14a284..e1477b4 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -67,6 +67,7 @@ public slots: void on_actionParse_triggered(); void on_actionRevert_triggered(); void on_actionJump_to_Selection_triggered(); + void on_actionRun_LaTeX_triggered(); // View void on_actionZoom_In_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 0481c1d..58a2ff0 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -74,6 +74,7 @@ + @@ -335,6 +336,14 @@ About + + + Run LaTeX + + + Ctrl+R + + diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index bca28e3..0a37e1b 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -1,12 +1,18 @@ #include "previewwindow.h" #include "ui_previewwindow.h" +#include "tikzit.h" +#include "latexprocess.h" + #include #include #include #include -#include #include +#include +#include +#include +#include #include PreviewWindow::PreviewWindow(QWidget *parent) : @@ -22,23 +28,42 @@ PreviewWindow::PreviewWindow(QWidget *parent) : restoreGeometry(geom.toByteArray()); } - _doc = Poppler::Document::load("/home/aleks/ak-algebras.pdf"); + _doc = nullptr; + _page = nullptr; + //setPdf("/home/aleks/ak-algebras.pdf"); + + //qDebug() << "preview dir:" << preparePreview("foo"); + + render(); +} + +PreviewWindow::~PreviewWindow() +{ + delete ui; +} + +void PreviewWindow::setPdf(QString file) +{ + Poppler::Document *oldDoc = _doc; + _doc = Poppler::Document::load(file); _doc->setRenderHint(Poppler::Document::Antialiasing); _doc->setRenderHint(Poppler::Document::TextAntialiasing); _doc->setRenderHint(Poppler::Document::TextHinting ); _page = _doc->page(0); - render(); + + if (oldDoc != nullptr) delete oldDoc; } -PreviewWindow::~PreviewWindow() +QPlainTextEdit *PreviewWindow::outputTextEdit() { - delete ui; + return ui->output; } void PreviewWindow::closeEvent(QCloseEvent *e) { QSettings settings("tikzit", "tikzit"); settings.setValue("geometry-preview", saveGeometry()); + QDialog::closeEvent(e); } void PreviewWindow::resizeEvent(QResizeEvent *e) { @@ -52,6 +77,8 @@ void PreviewWindow::showEvent(QShowEvent *e) { } void PreviewWindow::render() { + if (_page == nullptr) return; + QSizeF size = _page->pageSizeF(); QRect rect = ui->scrollArea->visibleRegion().boundingRect(); diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h index f2366d6..c850ce9 100644 --- a/src/gui/previewwindow.h +++ b/src/gui/previewwindow.h @@ -2,6 +2,7 @@ #define PREVIEWWINDOW_H #include +#include #include namespace Ui { @@ -15,6 +16,11 @@ class PreviewWindow : public QDialog public: explicit PreviewWindow(QWidget *parent = nullptr); ~PreviewWindow(); + void setPdf(QString file); + QString preparePreview(QString tikz); + QPlainTextEdit *outputTextEdit(); + +protected: void resizeEvent(QResizeEvent *e); void showEvent(QShowEvent *e); void closeEvent(QCloseEvent *e); diff --git a/src/gui/previewwindow.ui b/src/gui/previewwindow.ui index 6bb993a..394fc41 100644 --- a/src/gui/previewwindow.ui +++ b/src/gui/previewwindow.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 603 + 480 @@ -40,8 +40,8 @@ 0 0 - 358 - 233 + 561 + 413 diff --git a/src/tikzit.cpp b/src/tikzit.cpp index d69f4a8..5f74d0b 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -20,6 +20,7 @@ #include "tikzassembler.h" #include "tikzstyles.h" #include "previewwindow.h" +#include "latexprocess.h" #include #include @@ -30,6 +31,7 @@ #include #include + // application-level instance of Tikzit Tikzit *tikzit; @@ -107,6 +109,8 @@ void Tikzit::init() _windows << new MainWindow(); _windows[0]->show(); + _styleFile = ""; + _styleFilePath = ""; QString styleFile = settings.value("previous-tikzstyles-file").toString(); if (!styleFile.isEmpty()) loadStyles(styleFile); @@ -128,8 +132,8 @@ void Tikzit::init() checkForUpdates(); } - PreviewWindow *preview = new PreviewWindow(); - preview->show(); + _preview = new PreviewWindow(); + _latex = nullptr; } //QMenuBar *Tikzit::mainMenu() const @@ -415,6 +419,31 @@ void Tikzit::updateReply(QNetworkReply *reply) } } +void Tikzit::makePreview() +{ + if (activeWindow()) { + LatexProcess *oldProc = _latex; + _latex = new LatexProcess(_preview, this); + if (oldProc != nullptr) { + oldProc->kill(); + oldProc->deleteLater(); + } + + connect(_latex, SIGNAL(previewFinished()), this, SLOT(cleanupLatex())); + _latex->makePreview(activeWindow()->tikzSource()); + _preview->show(); + } +} + +void Tikzit::cleanupLatex() +{ + LatexProcess *oldProc = _latex; + _latex = nullptr; + if (oldProc != nullptr) { + oldProc->deleteLater(); + } +} + //StylePalette *Tikzit::stylePalette() const //{ // return _stylePalette; diff --git a/src/tikzit.h b/src/tikzit.h index 5fed22c..3d4847d 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -60,6 +60,8 @@ #include "propertypalette.h" #include "stylepalette.h" #include "tikzstyles.h" +#include "latexprocess.h" +#include "previewwindow.h" #include #include @@ -137,6 +139,8 @@ public slots: void setCheckForUpdates(bool check); void checkForUpdates(); void updateReply(QNetworkReply *reply); + void makePreview(); + void cleanupLatex(); private: // void createMenu(); @@ -153,6 +157,8 @@ private: StyleEditor *_styleEditor; QStringList _colNames; QVector _cols; + LatexProcess *_latex; + PreviewWindow *_preview; }; extern Tikzit *tikzit; diff --git a/tex/sample/tikzit.sty b/tex/sample/tikzit.sty index b893a4a..9c51148 100644 --- a/tex/sample/tikzit.sty +++ b/tex/sample/tikzit.sty @@ -29,4 +29,4 @@ \pgfsetlayers{background,edgelayer,nodelayer,main} \tikzstyle{none}=[inner sep=0mm] \tikzstyle{every loop}=[] -\tikzstyle{mark coordinate}=[inner sep=0pt,outer sep=0pt,minimum size=3pt,fill=black,circle] \ No newline at end of file +\tikzstyle{mark coordinate}=[inner sep=0pt,outer sep=0pt,minimum size=3pt,fill=black,circle] diff --git a/tikzit.pro b/tikzit.pro index e1e07b4..82b4032 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -72,7 +72,8 @@ SOURCES += src/gui/mainwindow.cpp \ src/data/style.cpp \ src/gui/styleeditor.cpp \ src/data/stylelist.cpp \ - src/gui/previewwindow.cpp + src/gui/previewwindow.cpp \ + src/gui/latexprocess.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -99,7 +100,8 @@ HEADERS += src/gui/mainwindow.h \ src/data/style.h \ src/gui/styleeditor.h \ src/data/stylelist.h \ - src/gui/previewwindow.h + src/gui/previewwindow.h \ + src/gui/latexprocess.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ diff --git a/tikzit.qrc b/tikzit.qrc index 0484c2d..32bdfc8 100644 --- a/tikzit.qrc +++ b/tikzit.qrc @@ -8,6 +8,7 @@ images/refresh.svg images/tikzit.png images/text-x-generic_with_pencil.svg + tex/sample/tikzit.sty qt.conf -- cgit v1.2.3 From 2332239082db6a33ee66bb08491c1e9cf099f9b6 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 18 Dec 2018 09:53:00 +0100 Subject: preview works --- src/gui/latexprocess.cpp | 8 ++++---- src/gui/previewwindow.cpp | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index f81e883..20b22a4 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -18,7 +18,7 @@ LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(pa connect(_proc, SIGNAL(finished(int)), this, SLOT(finished(int))); // for debug purposes - _workingDir.setAutoRemove(false); + // _workingDir.setAutoRemove(false); } void LatexProcess::makePreview(QString tikz) @@ -57,9 +57,9 @@ void LatexProcess::makePreview(QString tikz) f.open(QIODevice::WriteOnly); QTextStream tex(&f); tex << "\\documentclass{article}\n"; - tex << "\\usepackage[active,tightpage]{preview}\n"; - tex << "\\PreviewEnvironment{tikzpicture}\n"; tex << "\\usepackage{tikzit}\n"; + tex << "\\usepackage[graphics,active,tightpage]{preview}\n"; + tex << "\\PreviewEnvironment{tikzpicture}\n"; tex << "\\input{" + tikzit->styleFile() + "}\n"; tex << "\\begin{document}\n\n"; tex << tikz; @@ -89,7 +89,7 @@ void LatexProcess::finished(int exitCode) if (exitCode == 0) { QString pdf = _workingDir.path() + "/preview.pdf"; _output->appendPlainText("\n\nSUCCESSFULLY GENERATED: " + pdf + "\n"); - //_preview->setPdf(pdf); + _preview->setPdf(pdf); emit previewFinished(); } else { _output->appendPlainText("\n\npdflatex RETURNED AN ERROR\n"); diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 0a37e1b..8625045 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include PreviewWindow::PreviewWindow(QWidget *parent) : @@ -45,7 +46,15 @@ PreviewWindow::~PreviewWindow() void PreviewWindow::setPdf(QString file) { Poppler::Document *oldDoc = _doc; - _doc = Poppler::Document::load(file); + Poppler::Document *newDoc = Poppler::Document::load(file); + if (!newDoc) { + QMessageBox::warning(nullptr, + "Could not read PDF", + "Could not read: '" + file + "'."); + return; + } + + _doc = newDoc; _doc->setRenderHint(Poppler::Document::Antialiasing); _doc->setRenderHint(Poppler::Document::TextAntialiasing); _doc->setRenderHint(Poppler::Document::TextHinting ); @@ -82,8 +91,8 @@ void PreviewWindow::render() { QSizeF size = _page->pageSizeF(); QRect rect = ui->scrollArea->visibleRegion().boundingRect(); - int w = rect.width(); - int h = rect.height(); + int w = rect.width() - 20; + int h = rect.height() - 20; qreal scale = fmin(static_cast(w) / size.width(), static_cast(h) / size.height()); int dpi = static_cast(scale * 72.0); -- cgit v1.2.3 From a923245a1151ffc36da25702a50a508d43094cd0 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 19 Dec 2018 14:11:06 +0000 Subject: build in windows works --- src/gui/mainmenu.cpp | 2 +- src/gui/previewwindow.cpp | 2 +- src/tikzit.cpp | 33 ++++++++++++++++++++++++++------- src/tikzit.h | 6 ++++-- tikzit.pro | 4 ++-- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index ab1b898..6f6ab00 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -265,5 +265,5 @@ void MainMenu::on_actionCheck_for_updates_automatically_triggered() void MainMenu::on_actionCheck_now_triggered() { - tikzit->checkForUpdates(); + tikzit->checkForUpdates(true); } diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 8625045..5452a7e 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -106,6 +106,6 @@ void PreviewWindow::render() { // qDebug() << "scale:" << scale; // qDebug() << "dpi:" << dpi; - QImage img = _page->renderToImage(dpi,dpi, (w1 - w)/2, (h1 - h)/2, w, h); + QImage img = _page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h); ui->pdf->setPixmap(QPixmap::fromImage(img)); } diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 5f74d0b..39a2924 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -129,7 +129,7 @@ void Tikzit::init() setCheckForUpdates(check.toBool()); if (check.toBool()) { - checkForUpdates(); + checkForUpdates(false); } _preview = new PreviewWindow(); @@ -365,16 +365,32 @@ void Tikzit::setCheckForUpdates(bool check) } } -void Tikzit::checkForUpdates() +void Tikzit::checkForUpdates(bool manual) { QNetworkAccessManager *manager = new QNetworkAccessManager(this); - connect(manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(updateReply(QNetworkReply*))); + + if (manual) { + connect(manager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(updateManual(QNetworkReply*))); + } else { + connect(manager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(updateAuto(QNetworkReply*))); + } manager->get(QNetworkRequest(QUrl("https://tikzit.github.io/latest-version.txt"))); } -void Tikzit::updateReply(QNetworkReply *reply) +void Tikzit::updateAuto(QNetworkReply *reply) +{ + updateReply(reply, false); +} + +void Tikzit::updateManual(QNetworkReply *reply) +{ + updateReply(reply, true); +} + +void Tikzit::updateReply(QNetworkReply *reply, bool manual) { if (!reply->isReadable()) return; @@ -403,7 +419,7 @@ void Tikzit::updateReply(QNetworkReply *reply) QString::number(latest.minorVersion()) + "." + QString::number(latest.microVersion()); if (rcLatest != 1000) strLatest += "-rc" + QString::number(rcLatest); - QMessageBox::information(0, + QMessageBox::information(nullptr, tr("Update available"), "

A new version of TikZiT is available!

" "

current version: " TIKZIT_VERSION "
" @@ -412,10 +428,13 @@ void Tikzit::updateReply(QNetworkReply *reply) "tikzit.github.io.

"); } } else { - QMessageBox::warning(0, + // don't complain of invalid response for auto update check + if (manual) { + QMessageBox::warning(nullptr, tr("Invalid response"), "

Got invalid version response from " "tikzit.github.io.

"); + } } } diff --git a/src/tikzit.h b/src/tikzit.h index 3d4847d..9011cc3 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -137,8 +137,10 @@ public: public slots: void setCheckForUpdates(bool check); - void checkForUpdates(); - void updateReply(QNetworkReply *reply); + void checkForUpdates(bool manual); + void updateAuto(QNetworkReply *reply); + void updateManual(QNetworkReply *reply); + void updateReply(QNetworkReply *reply, bool manual); void makePreview(); void cleanupLatex(); diff --git a/tikzit.pro b/tikzit.pro index 82b4032..b026511 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -110,9 +110,9 @@ FORMS += src/gui/mainwindow.ui \ src/gui/styleeditor.ui \ src/gui/previewwindow.ui -INCLUDEPATH += src src/gui src/data +INCLUDEPATH += src src/gui src/data extra -LIBS += -lpoppler-qt5 +LIBS += -L"$$PWD/extra" -lpoppler-qt5 DISTFILES += -- cgit v1.2.3 From 5c44437a879e37dfb311354603756f9436d1bfb8 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 19 Dec 2018 22:54:51 +0100 Subject: hidpi support --- src/gui/previewwindow.cpp | 21 ++++++++++++++++----- tikzit.pro | 8 ++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 5452a7e..724a951 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -46,7 +46,14 @@ PreviewWindow::~PreviewWindow() void PreviewWindow::setPdf(QString file) { Poppler::Document *oldDoc = _doc; - Poppler::Document *newDoc = Poppler::Document::load(file); + + // use loadFromData to avoid holding a lock on the PDF file in windows + QFile f(file); + f.open(QFile::ReadOnly); + QByteArray data = f.readAll(); + f.close(); + Poppler::Document *newDoc = Poppler::Document::loadFromData(data); + if (!newDoc) { QMessageBox::warning(nullptr, "Could not read PDF", @@ -90,11 +97,14 @@ void PreviewWindow::render() { QSizeF size = _page->pageSizeF(); + qreal ratio = devicePixelRatioF(); QRect rect = ui->scrollArea->visibleRegion().boundingRect(); - int w = rect.width() - 20; - int h = rect.height() - 20; + int w = static_cast(ratio * (rect.width() - 20)); + int h = static_cast(ratio * (rect.height() - 20)); qreal scale = fmin(static_cast(w) / size.width(), static_cast(h) / size.height()); + + int dpi = static_cast(scale * 72.0); int w1 = static_cast(scale * size.width()); int h1 = static_cast(scale * size.height()); @@ -106,6 +116,7 @@ void PreviewWindow::render() { // qDebug() << "scale:" << scale; // qDebug() << "dpi:" << dpi; - QImage img = _page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h); - ui->pdf->setPixmap(QPixmap::fromImage(img)); + QPixmap pm = QPixmap::fromImage(_page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h)); + pm.setDevicePixelRatio(ratio); + ui->pdf->setPixmap(pm); } diff --git a/tikzit.pro b/tikzit.pro index b026511..3fa4d5a 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -110,9 +110,13 @@ FORMS += src/gui/mainwindow.ui \ src/gui/styleeditor.ui \ src/gui/previewwindow.ui -INCLUDEPATH += src src/gui src/data extra +INCLUDEPATH += src src/gui src/data -LIBS += -L"$$PWD/extra" -lpoppler-qt5 +# link to pre-compiled poppler libs on windows +win32:INCLUDEPATH += win32-deps/include +win32:LIBS += -L"$$PWD/win32-deps/bin" + +LIBS += -lpoppler-qt5 DISTFILES += -- cgit v1.2.3 From 3a981911858553daab4af26af7e46e5b62b0034b Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 20 Dec 2018 22:28:41 +0100 Subject: updated CI scripts --- .appveyor.yml | 7 +++++-- deploy-win.bat | 9 ++++----- tikzit.pro | 6 ++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index c2f27c4..117c722 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -13,12 +13,15 @@ configuration: install: - cmd: choco install winflexbison - - cmd: 'C:\Qt\5.11.2\msvc2015_64\bin\qtenv2.bat' - - cmd: call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 + - cmd: 'C:\Qt\5.11.2\mingw53_32\bin\qtenv2.bat' - cmd: cd C:\projects\tikzit - sh: sudo apt-get update - sh: sudo apt-get -y install flex bison qt5-default +before_build: + - ps: (new-object net.webclient).DownloadFile('http://tikzit.github.io/download/win32-deps.zip', 'c:\projects\tikzit\win32-deps.zip') + - cmd: 7z x win32-deps.zip + build_script: - qmake -v - qmake diff --git a/deploy-win.bat b/deploy-win.bat index 1c19f40..20f85f6 100755 --- a/deploy-win.bat +++ b/deploy-win.bat @@ -7,12 +7,11 @@ mkdir icons copy ..\..\tikzfiles.reg . copy ..\..\release\tikzit.exe . copy ..\..\images\tikzdoc.ico icons\ -copy C:\Windows\System32\msvcp140.dll . -copy C:\Windows\System32\vcruntime140.dll . -copy C:\OpenSSL-Win64\bin\libeay32.dll . -copy C:\OpenSSL-Win64\bin\ssleay32.dll . +copy ..\..\win32-dist\*.dll . +copy C:\OpenSSL-Win32\bin\libeay32.dll . +copy C:\OpenSSL-Win32\bin\ssleay32.dll . -windeployqt.exe --no-compiler-runtime --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe +windeployqt.exe --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe cd .. 7z a -tzip tikzit.zip tikzit diff --git a/tikzit.pro b/tikzit.pro index 3fa4d5a..43fd1a0 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -113,8 +113,10 @@ FORMS += src/gui/mainwindow.ui \ INCLUDEPATH += src src/gui src/data # link to pre-compiled poppler libs on windows -win32:INCLUDEPATH += win32-deps/include -win32:LIBS += -L"$$PWD/win32-deps/bin" +win32 { + INCLUDEPATH += win32-deps/include + LIBS += -L"$$PWD/win32-deps/bin" +} LIBS += -lpoppler-qt5 -- cgit v1.2.3 From 52b50ae84813951e5cbc457153bd981e5a96bc2d Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 20 Dec 2018 22:36:02 +0100 Subject: ... --- .appveyor.yml | 2 +- .travis.yml | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 117c722..8f32415 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,7 +16,7 @@ install: - cmd: 'C:\Qt\5.11.2\mingw53_32\bin\qtenv2.bat' - cmd: cd C:\projects\tikzit - sh: sudo apt-get update - - sh: sudo apt-get -y install flex bison qt5-default + - sh: sudo apt-get -y install flex bison qt5-default poppler before_build: - ps: (new-object net.webclient).DownloadFile('http://tikzit.github.io/download/win32-deps.zip', 'c:\projects\tikzit\win32-deps.zip') diff --git a/.travis.yml b/.travis.yml index 1c814d1..45b5146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,27 +18,19 @@ matrix: - FILE=tikzit-osx-mountain.dmg - QTVER=56 - DEPLOY_TIKZIT=1 - # - os: linux - # dist: trusty - # env: - # - FILE=tikzit-linux.tar.gz - # - PPA=beineri/opt-qt-5.10.1-trusty before_install: - # - '[[ "$TRAVIS_OS_NAME" != linux || -z "$PPA" ]] || sudo add-apt-repository -y ppa:$PPA' - # - '[[ "$TRAVIS_OS_NAME" != linux ]] || sudo apt-get -qy update' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || curl https://raw.githubusercontent.com/GiovanniBussi/macports-ci/master/macports-ci > macports-ci' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || source macports-ci install' + # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || curl https://raw.githubusercontent.com/GiovanniBussi/macports-ci/master/macports-ci > macports-ci' + # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || source macports-ci install' install: - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install qt5' + - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install poppler --with-qt' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force qt5' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || sudo port -N -k install qt56' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || export PATH=/opt/local/libexec/qt5/bin:$PATH' - # - '[[ "$TRAVIS_OS_NAME" != linux ]] || sudo apt-get -qy install qt510base qt510xmlpatterns' - # - '[[ "$TRAVIS_OS_NAME" != linux ]] || . /opt/qt510/bin/qt510-env.sh' + # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || sudo port -N -k install qt56' + # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || export PATH=/opt/local/libexec/qt5/bin:$PATH' script: - qmake -v -- cgit v1.2.3 From 9e2724e96872d1dc320a00565152de227c836285 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 20 Dec 2018 22:43:18 +0100 Subject: various fixes to build scripts --- .appveyor.yml | 4 ++-- .travis.yml | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 8f32415..dc81831 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,7 +16,7 @@ install: - cmd: 'C:\Qt\5.11.2\mingw53_32\bin\qtenv2.bat' - cmd: cd C:\projects\tikzit - sh: sudo apt-get update - - sh: sudo apt-get -y install flex bison qt5-default poppler + - sh: sudo apt-get -y install flex bison qt5-default libpoppler-dev libpoppler-qt5-1 before_build: - ps: (new-object net.webclient).DownloadFile('http://tikzit.github.io/download/win32-deps.zip', 'c:\projects\tikzit\win32-deps.zip') @@ -25,7 +25,7 @@ before_build: build_script: - qmake -v - qmake - - cmd: nmake.exe + - cmd: mingw32-make - sh: make after_build: diff --git a/.travis.yml b/.travis.yml index 45b5146..722688d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,12 @@ matrix: - FILE=tikzit-osx.dmg - QTVER=511 - DEPLOY_TIKZIT=1 - - os: osx - compiler: clang - env: - - FILE=tikzit-osx-mountain.dmg - - QTVER=56 - - DEPLOY_TIKZIT=1 + # - os: osx + # compiler: clang + # env: + # - FILE=tikzit-osx-mountain.dmg + # - QTVER=56 + # - DEPLOY_TIKZIT=1 before_install: # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || curl https://raw.githubusercontent.com/GiovanniBussi/macports-ci/master/macports-ci > macports-ci' -- cgit v1.2.3 From 51c4e402f86296cc84dbb462ac9cbd25b0dcd3f9 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 20 Dec 2018 22:59:00 +0100 Subject: fixed path in deploy file --- deploy-win.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy-win.bat b/deploy-win.bat index 20f85f6..0890d64 100755 --- a/deploy-win.bat +++ b/deploy-win.bat @@ -7,7 +7,7 @@ mkdir icons copy ..\..\tikzfiles.reg . copy ..\..\release\tikzit.exe . copy ..\..\images\tikzdoc.ico icons\ -copy ..\..\win32-dist\*.dll . +copy ..\..\win32-deps\bin\*.dll . copy C:\OpenSSL-Win32\bin\libeay32.dll . copy C:\OpenSSL-Win32\bin\ssleay32.dll . -- cgit v1.2.3 From 7b31401ae764f4e5c86774affbb96db7b51b42f7 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 20 Dec 2018 23:10:34 +0100 Subject: added -dev --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index dc81831..f54801e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,7 +16,7 @@ install: - cmd: 'C:\Qt\5.11.2\mingw53_32\bin\qtenv2.bat' - cmd: cd C:\projects\tikzit - sh: sudo apt-get update - - sh: sudo apt-get -y install flex bison qt5-default libpoppler-dev libpoppler-qt5-1 + - sh: sudo apt-get -y install flex bison qt5-default libpoppler-dev libpoppler-qt5-dev before_build: - ps: (new-object net.webclient).DownloadFile('http://tikzit.github.io/download/win32-deps.zip', 'c:\projects\tikzit\win32-deps.zip') -- cgit v1.2.3 From bc705a2f28f930b1f3ba5400c6bfabf7804ff230 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 20 Dec 2018 23:14:06 +0100 Subject: brew link poppler --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 722688d..d6fc65a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,9 @@ before_install: install: - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install qt5' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install poppler --with-qt' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force qt5' + - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install poppler --with-qt' + - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force poppler' # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || sudo port -N -k install qt56' # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || export PATH=/opt/local/libexec/qt5/bin:$PATH' -- cgit v1.2.3 From 0e570aa2ef1018d66f3922f71266b0edde855e95 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 21 Dec 2018 14:20:11 +0100 Subject: added include path for brew --- .travis.yml | 1 - tikzit.pro | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6fc65a..07a6a6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,6 @@ install: - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install qt5' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force qt5' - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew install poppler --with-qt' - - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 511 ]] || brew link --force poppler' # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || sudo port -N -k install qt56' # - '[[ "$TRAVIS_OS_NAME" != osx || "$QTVER" != 56 ]] || export PATH=/opt/local/libexec/qt5/bin:$PATH' diff --git a/tikzit.pro b/tikzit.pro index 43fd1a0..3d3b12d 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -116,7 +116,12 @@ INCLUDEPATH += src src/gui src/data win32 { INCLUDEPATH += win32-deps/include LIBS += -L"$$PWD/win32-deps/bin" -} +} + +macx { + INCLUDEPATH += /usr/local/opt/poppler/include + LIBS += -L/usr/local/opt/poppler/lib +} LIBS += -lpoppler-qt5 -- cgit v1.2.3 From 871f080501b883b64f8d7c38c725cfa006b13981 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 21 Dec 2018 19:23:26 +0100 Subject: broke dmg into 2 steps --- deploy-osx.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deploy-osx.sh b/deploy-osx.sh index 15d69f7..5efe08e 100755 --- a/deploy-osx.sh +++ b/deploy-osx.sh @@ -1,5 +1,7 @@ # deploy the Mac app bundle. Note the bin/ directory # of Qt should be in your PATH -macdeployqt tikzit.app -dmg +macdeployqt tikzit.app +hdiutil create -volname TikZiT -srcfolder tikzit.app -ov -format UDZO tikzit.dmg + -- cgit v1.2.3 From 873316d120e185fcbc59b468961faebf33adf9af Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 21 Dec 2018 10:43:12 -0800 Subject: fixed paths in deploy script --- deploy-osx.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deploy-osx.sh b/deploy-osx.sh index 5efe08e..98043c0 100755 --- a/deploy-osx.sh +++ b/deploy-osx.sh @@ -1,7 +1,16 @@ # deploy the Mac app bundle. Note the bin/ directory # of Qt should be in your PATH +# copy in libraries and set (most) library paths macdeployqt tikzit.app + +# macdeployqt misses this path for some reason, so fix it +cd tikzit.app/Contents/Frameworks +install_name_tool -id "@executable_path/../Frameworks/libpoppler.83.dylib" libpoppler.83.dylib +install_name_tool -change /usr/local/Cellar/poppler/0.72.0/lib/libpoppler.83.dylib "@executable_path/../Frameworks/libpoppler.83.dylib" libpoppler-qt5.1.dylib +cd ../../.. + +# create DMG hdiutil create -volname TikZiT -srcfolder tikzit.app -ov -format UDZO tikzit.dmg -- cgit v1.2.3 From c93f003ce683fca7896cbbadb6375b929d22fe6d Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 22 Dec 2018 18:06:26 +0100 Subject: latex running feedback and better search for pdflatex --- images/dialog-accept.svg | 63 +++++++++ images/dialog-error.svg | 316 ++++++++++++++++++++++++++++++++++++++++++++++ images/loader.gif | Bin 0 -> 1456 bytes images/loader@2x.gif | Bin 0 -> 1456 bytes src/gui/latexprocess.cpp | 30 ++++- src/gui/previewwindow.cpp | 41 +++++- src/gui/previewwindow.h | 11 +- src/gui/previewwindow.ui | 34 ++++- src/tikzit.cpp | 18 +-- tikzit.qrc | 4 + 10 files changed, 500 insertions(+), 17 deletions(-) create mode 100644 images/dialog-accept.svg create mode 100644 images/dialog-error.svg create mode 100644 images/loader.gif create mode 100644 images/loader@2x.gif diff --git a/images/dialog-accept.svg b/images/dialog-accept.svg new file mode 100644 index 0000000..287b11e --- /dev/null +++ b/images/dialog-accept.svg @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Rodney Dawes + + + + + Jakub Steiner, Garrett LeSage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/dialog-error.svg b/images/dialog-error.svg new file mode 100644 index 0000000..9071b53 --- /dev/null +++ b/images/dialog-error.svg @@ -0,0 +1,316 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Rodney Dawes + + + + + Jakub Steiner, Garrett LeSage + + + + Dialog Error + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/loader.gif b/images/loader.gif new file mode 100644 index 0000000..078b55f Binary files /dev/null and b/images/loader.gif differ diff --git a/images/loader@2x.gif b/images/loader@2x.gif new file mode 100644 index 0000000..078b55f Binary files /dev/null and b/images/loader@2x.gif differ diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 20b22a4..82c1c5b 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -4,6 +4,7 @@ #include #include #include +#include LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(parent) { @@ -23,6 +24,7 @@ LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(pa void LatexProcess::makePreview(QString tikz) { + _preview->setStatus(PreviewWindow::Running); _output->clear(); if (!_workingDir.isValid()) { @@ -38,8 +40,28 @@ void LatexProcess::makePreview(QString tikz) QString pdflatex = QStandardPaths::findExecutable("pdflatex"); if (pdflatex.isEmpty()) { - _output->appendPlainText("pdflatex NOT FOUND, ABORTING.\n"); - return; + // if pdflatex is not in PATH, we are probably on mac or windows, so try common + // install directories. + _output->appendPlainText("NOT FOUND IN PATH, TRYING:"); + + QStringList texDirs; + // common macOS tex directories: + texDirs << "/Library/TeX/texbin"; + texDirs << "/usr/texbin"; + texDirs << "/usr/local/bin"; + texDirs << "/sw/bin"; + + // common windows tex directories + texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin"; + texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64"; + + _output->appendPlainText(texDirs.join(":")); + pdflatex = QStandardPaths::findExecutable("pdflatex", texDirs); + + if (pdflatex.isEmpty()) { + _output->appendPlainText("pdflatex NOT FOUND, ABORTING.\n"); + return; + } } _output->appendPlainText("FOUND: " + pdflatex + "\n"); @@ -66,7 +88,7 @@ void LatexProcess::makePreview(QString tikz) tex << "\n\n\\end{document}\n"; f.close(); - _proc->start(pdflatex, QStringList() << "preview.tex"); + _proc->start(pdflatex, QStringList() << "-interaction=nonstopmode" << "preview.tex"); } @@ -90,9 +112,11 @@ void LatexProcess::finished(int exitCode) QString pdf = _workingDir.path() + "/preview.pdf"; _output->appendPlainText("\n\nSUCCESSFULLY GENERATED: " + pdf + "\n"); _preview->setPdf(pdf); + _preview->setStatus(PreviewWindow::Success); emit previewFinished(); } else { _output->appendPlainText("\n\npdflatex RETURNED AN ERROR\n"); + _preview->setStatus(PreviewWindow::Failed); emit previewFinished(); } } diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 724a951..726ec8a 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -15,6 +15,7 @@ #include #include #include +#include PreviewWindow::PreviewWindow(QWidget *parent) : QDialog(parent), @@ -31,10 +32,15 @@ PreviewWindow::PreviewWindow(QWidget *parent) : _doc = nullptr; _page = nullptr; - //setPdf("/home/aleks/ak-algebras.pdf"); - //qDebug() << "preview dir:" << preparePreview("foo"); + _loader = new QLabel(this); + _loader->setMinimumSize(QSize(16,16)); + _loader->setMaximumSize(QSize(16,16)); + ui->tabWidget->tabBar()->setTabButton(1, QTabBar::RightSide, _loader); + connect(ui->tabWidget, SIGNAL(currentChanged(int)), + this, SLOT(render())); + render(); } @@ -76,6 +82,37 @@ QPlainTextEdit *PreviewWindow::outputTextEdit() return ui->output; } +void PreviewWindow::setStatus(PreviewWindow::Status status) +{ + QMovie *oldMovie = _loader->movie(); + if (status == PreviewWindow::Running) { + // loader.gif and loader@2x.gif derived from: + // https://commons.wikimedia.org/wiki/Throbbers#/media/File:Linux_Ubuntu_Loader.gif + // licensed GNU Free Documentation License v1.2 + QMovie *movie = new QMovie( + (devicePixelRatioF() > 1.0) ? ":images/loader@2x.gif" : ":images/loader.gif", + QByteArray(), _loader); + _loader->setPixmap(QPixmap()); + _loader->setMovie(movie); + movie->start(); + } else if (status == PreviewWindow::Success) { + _loader->setMovie(nullptr); + QPixmap accept(":images/dialog-accept.svg"); + accept.setDevicePixelRatio(devicePixelRatio()); + _loader->setPixmap(accept); + } else if (status == PreviewWindow::Failed) { + _loader->setMovie(nullptr); + QPixmap error(":images/dialog-error.svg"); + error.setDevicePixelRatio(devicePixelRatio()); + _loader->setPixmap(error); + } + + if (oldMovie != nullptr) oldMovie->deleteLater(); + + + _loader->repaint(); +} + void PreviewWindow::closeEvent(QCloseEvent *e) { QSettings settings("tikzit", "tikzit"); settings.setValue("geometry-preview", saveGeometry()); diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h index c850ce9..a937263 100644 --- a/src/gui/previewwindow.h +++ b/src/gui/previewwindow.h @@ -1,7 +1,9 @@ #ifndef PREVIEWWINDOW_H #define PREVIEWWINDOW_H + #include +#include #include #include @@ -14,11 +16,18 @@ class PreviewWindow : public QDialog Q_OBJECT public: + enum Status { + Running, Success, Failed + }; explicit PreviewWindow(QWidget *parent = nullptr); ~PreviewWindow(); void setPdf(QString file); QString preparePreview(QString tikz); QPlainTextEdit *outputTextEdit(); + void setStatus(Status status); + +public slots: + void render(); protected: void resizeEvent(QResizeEvent *e); @@ -27,9 +36,9 @@ protected: private: Ui::PreviewWindow *ui; - void render(); Poppler::Document *_doc; Poppler::Page *_page; + QLabel *_loader; }; #endif // PREVIEWWINDOW_H diff --git a/src/gui/previewwindow.ui b/src/gui/previewwindow.ui index 394fc41..7da886a 100644 --- a/src/gui/previewwindow.ui +++ b/src/gui/previewwindow.ui @@ -14,16 +14,46 @@ Preview + + 3 + + + 3 + + + 3 + + + 3 + 0 + + false + + + false + PDF + + 0 + + + 0 + + + 0 + + + 0 + @@ -40,8 +70,8 @@ 0 0 - 561 - 413 + 591 + 448 diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 39a2924..e12053b 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -31,14 +31,13 @@ #include #include - // application-level instance of Tikzit Tikzit *tikzit; // font to use for node labels QFont Tikzit::LABEL_FONT("Courrier", 9); -Tikzit::Tikzit() : _styleFile("[no styles]"), _activeWindow(0) +Tikzit::Tikzit() : _styleFile("[no styles]"), _activeWindow(nullptr) { } @@ -116,7 +115,7 @@ void Tikzit::init() QVariant check = settings.value("check-for-updates"); if (check.isNull()) { - int resp = QMessageBox::question(0, + int resp = QMessageBox::question(nullptr, tr("Check for updates"), tr("Would you like TikZiT to check for updates automatically?" " (You can always change this later in the Help menu.)"), @@ -213,7 +212,7 @@ void Tikzit::newTikzStyles() w->tikzScene()->reloadStyles(); } } else { - QMessageBox::warning(0, + QMessageBox::warning(nullptr, "Could not write to style file.", "Could not write to: '" + fileName + "'. Check file permissions or choose a new location."); } @@ -252,7 +251,7 @@ void Tikzit::removeWindow(MainWindow *w) _windows.removeAll(w); if (_activeWindow == w) { if (_windows.isEmpty()) { - _activeWindow = 0; + _activeWindow = nullptr; // TODO: check if we should quit when last window closed quit(); } else _activeWindow = _windows[0]; @@ -262,7 +261,7 @@ void Tikzit::removeWindow(MainWindow *w) void Tikzit::open() { QSettings settings("tikzit", "tikzit"); - QString fileName = QFileDialog::getOpenFileName(0, + QString fileName = QFileDialog::getOpenFileName(nullptr, tr("Open File"), settings.value("previous-file-path").toString(), tr("TiKZ Files (*.tikz)"), @@ -293,7 +292,7 @@ void Tikzit::open(QString fileName) void Tikzit::openTikzStyles() { QSettings settings("tikzit", "tikzit"); - QString fileName = QFileDialog::getOpenFileName(0, + QString fileName = QFileDialog::getOpenFileName(nullptr, tr("Open File"), settings.value("previous-tikzstyles-path").toString(), tr("TiKZ Style Files (*.tikzstyles)"), @@ -326,7 +325,7 @@ bool Tikzit::loadStyles(QString fileName) } return true; } else { - QMessageBox::warning(0, + QMessageBox::warning(nullptr, "Bad style file.", "Bad style file: '" + fileName + "'. Check the file is properly formatted and try to load it again."); return false; @@ -334,7 +333,8 @@ bool Tikzit::loadStyles(QString fileName) } else { //settings.setValue("previous-tikzstyles-file", ""); - QMessageBox::warning(0, "Style file not found.", "Could not open style file: '" + fileName + "'."); + QMessageBox::warning(nullptr, + "Style file not found.", "Could not open style file: '" + fileName + "'."); return false; } } diff --git a/tikzit.qrc b/tikzit.qrc index 32bdfc8..4b4defb 100644 --- a/tikzit.qrc +++ b/tikzit.qrc @@ -9,6 +9,10 @@ images/tikzit.png images/text-x-generic_with_pencil.svg tex/sample/tikzit.sty + images/loader.gif + images/loader@2x.gif + images/dialog-accept.svg + images/dialog-error.svg
qt.conf -- cgit v1.2.3 From c938446680685856ad4451a07c67372d52efc4d0 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 22 Dec 2018 19:25:03 +0100 Subject: called deploy-osx in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 07a6a6e..52de1f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ script: - qmake -v - qmake -r - make - - '[[ "$TRAVIS_OS_NAME" != osx ]] || (macdeployqt tikzit.app -dmg && mv tikzit.dmg $FILE)' + - '[[ "$TRAVIS_OS_NAME" != osx ]] || (chmod +x deploy-osx.sh && ./deploy-osx.sh && mv tikzit.dmg $FILE)' - '[[ "$DEPLOY_TIKZIT" != 1 ]] || curl --upload-file $FILE https://transfer.sh/$FILE' notifications: -- cgit v1.2.3 From 52147f458485df3a28453ca217e94f4e2e142d61 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 22 Dec 2018 22:27:59 +0100 Subject: set failed status on pdflatex not found --- src/gui/latexprocess.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 82c1c5b..39a7a51 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -60,6 +60,7 @@ void LatexProcess::makePreview(QString tikz) if (pdflatex.isEmpty()) { _output->appendPlainText("pdflatex NOT FOUND, ABORTING.\n"); + _preview->setStatus(PreviewWindow::Failed); return; } } -- cgit v1.2.3 From 2f0d6d4a7df7c8508a4f831818e41c11cffdd513 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 24 Dec 2018 23:35:08 +0100 Subject: added Open Recent (closes #40) --- src/data/tikzdocument.cpp | 44 ++++++++++++++++++++++++++++++++------------ src/data/tikzdocument.h | 3 +++ src/gui/mainmenu.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/gui/mainmenu.h | 3 +++ src/gui/mainmenu.ui | 11 +++++++++++ src/tikzit.cpp | 42 ++++++++++++++++++++++++++++++++++-------- src/tikzit.h | 2 ++ 7 files changed, 122 insertions(+), 20 deletions(-) diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp index 863f1fd..b89da10 100644 --- a/src/data/tikzdocument.cpp +++ b/src/data/tikzdocument.cpp @@ -69,6 +69,8 @@ void TikzDocument::open(QString fileName) return; } + addToRecentFiles(); + QTextStream in(&file); _tikz = in.readAll(); file.close(); @@ -98,10 +100,10 @@ bool TikzDocument::save() { return saveAs(); } else { MainWindow *win = tikzit->activeWindow(); - if (win != 0 && !win->tikzScene()->enabled()) { + if (win != nullptr && !win->tikzScene()->enabled()) { win->tikzScene()->parseTikz(win->tikzSource()); if (!win->tikzScene()->enabled()) { - auto resp = QMessageBox::question(0, + auto resp = QMessageBox::question(nullptr, tr("Tikz failed to parse"), tr("Cannot save file with invalid TiKZ source. Revert changes and save?")); if (resp == QMessageBox::Yes) win->tikzScene()->setEnabled(true); @@ -123,7 +125,8 @@ bool TikzDocument::save() { setClean(); return true; } else { - QMessageBox::warning(0, "Save Failed", "Could not open file: '" + _fileName + "' for writing."); + QMessageBox::warning(nullptr, + "Save Failed", "Could not open file: '" + _fileName + "' for writing."); } } @@ -140,6 +143,29 @@ void TikzDocument::setClean() _undoStack->setClean(); } +QString TikzDocument::fileName() const +{ + return _fileName; +} + +void TikzDocument::addToRecentFiles() +{ + QSettings settings("tikzit", "tikzit"); + if (!_fileName.isEmpty()) { + QStringList recentFiles = settings.value("recent-files").toStringList(); + + // if the file is in the list already, shift it to the top. Otherwise, add it. + recentFiles.removeAll(_fileName); + recentFiles.prepend(_fileName); + + // keep max 10 files + while (recentFiles.size() > 10) recentFiles.removeLast(); + + settings.setValue("recent-files", recentFiles); + tikzit->updateRecentFiles(); + } +} + void TikzDocument::setGraph(Graph *graph) { _graph = graph; @@ -148,10 +174,10 @@ void TikzDocument::setGraph(Graph *graph) bool TikzDocument::saveAs() { MainWindow *win = tikzit->activeWindow(); - if (win != 0 && !win->tikzScene()->enabled()) { + if (win != nullptr && !win->tikzScene()->enabled()) { win->tikzScene()->parseTikz(win->tikzSource()); if (!win->tikzScene()->enabled()) { - auto resp = QMessageBox::question(0, + auto resp = QMessageBox::question(nullptr, tr("Tikz failed to parse"), tr("Cannot save file with invalid TiKZ source. Revert changes and save?")); if (resp == QMessageBox::Yes) win->tikzScene()->setEnabled(true); @@ -170,19 +196,13 @@ bool TikzDocument::saveAs() { dialog.setDirectory(settings.value("previous-file-path").toString()); dialog.setOption(QFileDialog::DontUseNativeDialog); -// QString fileName = QFileDialog::getSaveFileName(tikzit->activeWindow(), -// tr("Save File As"), -// settings.value("previous-file-path").toString(), -// tr("TiKZ Files (*.tikz)"), -// nullptr, -// QFileDialog::DontUseNativeDialog); - if (dialog.exec() && !dialog.selectedFiles().isEmpty()) { QString fileName = dialog.selectedFiles()[0]; _fileName = fileName; if (save()) { // clean state might not change, so update title bar manually tikzit->activeWindow()->updateFileName(); + addToRecentFiles(); return true; } } diff --git a/src/data/tikzdocument.h b/src/data/tikzdocument.h index a5f3534..3b5990a 100644 --- a/src/data/tikzdocument.h +++ b/src/data/tikzdocument.h @@ -52,6 +52,8 @@ public: bool isClean() const; void setClean(); + QString fileName() const; + private: Graph *_graph; QString _tikz; @@ -59,6 +61,7 @@ private: QString _shortName; QUndoStack *_undoStack; bool _parseSuccess; + void addToRecentFiles(); signals: diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 6f6ab00..d4372ed 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -33,6 +33,8 @@ MainMenu::MainMenu() ui.actionCheck_for_updates_automatically->setChecked(settings.value("check-for-updates").toBool()); ui.actionCheck_for_updates_automatically->blockSignals(false); } + + updateRecentFiles(); } void MainMenu::addDocks(QMenu *m) @@ -48,6 +50,32 @@ QAction *MainMenu::updatesAction() return ui.actionCheck_for_updates_automatically; } +void MainMenu::updateRecentFiles() +{ + QSettings settings("tikzit", "tikzit"); + ui.menuOpen_Recent->clear(); + + QStringList recentFiles = settings.value("recent-files").toStringList(); + //qDebug() << "update:" << recentFiles; + + QAction *action; + foreach (QString f, recentFiles) { + QFileInfo fi(f); + action = new QAction(fi.fileName(), ui.menuOpen_Recent); + action->setData(f); + ui.menuOpen_Recent->addAction(action); + connect(action, SIGNAL(triggered()), + this, SLOT(openRecent())); + } + + ui.menuOpen_Recent->addSeparator(); + action = new QAction("Clear List", ui.menuOpen_Recent); + connect(action, SIGNAL(triggered()), + tikzit, SLOT(clearRecentFiles())); + ui.menuOpen_Recent->addAction(action); + ui.menuOpen_Recent->repaint(); +} + // File void MainMenu::on_actionNew_triggered() { @@ -82,6 +110,15 @@ void MainMenu::on_actionExit_triggered() tikzit->quit(); } +void MainMenu::openRecent() +{ + if (sender() != nullptr) { + if (QAction *action = dynamic_cast(sender())) { + tikzit->open(action->data().toString()); + } + } +} + // Edit void MainMenu::on_actionUndo_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index e1477b4..8acef49 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -30,6 +30,7 @@ public: MainMenu(); void addDocks(QMenu *m); QAction *updatesAction(); + void updateRecentFiles(); private: Ui::MainMenu ui; @@ -43,6 +44,8 @@ public slots: void on_actionSave_As_triggered(); void on_actionExit_triggered(); + void openRecent(); + // Edit void on_actionUndo_triggered(); void on_actionRedo_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 58a2ff0..097430c 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -14,8 +14,14 @@ File + + + Open Recent + + + @@ -344,6 +350,11 @@ Ctrl+R + + + Clear Menu + + diff --git a/src/tikzit.cpp b/src/tikzit.cpp index e12053b..e81706c 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -276,16 +276,28 @@ void Tikzit::open(QString fileName) if (!fileName.isEmpty()) { if (_windows.size() == 1 && _windows[0]->tikzDocument()->isClean() && - _windows[0]->tikzDocument()->shortName().isEmpty()) - { + _windows[0]->tikzDocument()->shortName().isEmpty()) + { _windows[0]->open(fileName); _windows[0]->show(); - } - else { - MainWindow *w = new MainWindow(); - w->show(); - w->open(fileName); - _windows << w; + } + else + { + bool found = false; + foreach (MainWindow *w, _windows) { + if (w->tikzDocument()->fileName() == fileName) { + w->raise(); + w->activateWindow(); + found = true; + } + } + + if (!found) { + MainWindow *w = new MainWindow(); + _windows << w; + w->show(); + w->open(fileName); + } } } } @@ -354,6 +366,20 @@ QString Tikzit::styleFilePath() const return _styleFilePath; } +void Tikzit::updateRecentFiles() +{ + foreach (MainWindow *w, _windows) { + w->menu()->updateRecentFiles(); + } +} + +void Tikzit::clearRecentFiles() +{ + QSettings settings("tikzit", "tikzit"); + settings.setValue("recent-files", QStringList()); + updateRecentFiles(); +} + void Tikzit::setCheckForUpdates(bool check) { QSettings settings("tikzit", "tikzit"); diff --git a/src/tikzit.h b/src/tikzit.h index 9011cc3..24bf56b 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -134,8 +134,10 @@ public: //StylePalette *stylePalette() const; QString styleFilePath() const; + void updateRecentFiles(); public slots: + void clearRecentFiles(); void setCheckForUpdates(bool check); void checkForUpdates(bool manual); void updateAuto(QNetworkReply *reply); -- cgit v1.2.3 From 131339ea8af42f0f53c1eb5d446034205123cac2 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 26 Dec 2018 11:21:43 +0100 Subject: don't repaint --- src/gui/mainmenu.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index d4372ed..3b8b92b 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -73,7 +73,6 @@ void MainMenu::updateRecentFiles() connect(action, SIGNAL(triggered()), tikzit, SLOT(clearRecentFiles())); ui.menuOpen_Recent->addAction(action); - ui.menuOpen_Recent->repaint(); } // File -- cgit v1.2.3 From 6878cc46739323b852a97af53eff963f7b0de0b4 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 28 Dec 2018 14:51:43 +0100 Subject: fixed dev pixel ratio at 3 for status icons --- src/gui/previewwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 726ec8a..938ed4e 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -98,12 +98,12 @@ void PreviewWindow::setStatus(PreviewWindow::Status status) } else if (status == PreviewWindow::Success) { _loader->setMovie(nullptr); QPixmap accept(":images/dialog-accept.svg"); - accept.setDevicePixelRatio(devicePixelRatio()); + accept.setDevicePixelRatio(3.0); _loader->setPixmap(accept); } else if (status == PreviewWindow::Failed) { _loader->setMovie(nullptr); QPixmap error(":images/dialog-error.svg"); - error.setDevicePixelRatio(devicePixelRatio()); + error.setDevicePixelRatio(3.0); _loader->setPixmap(error); } -- cgit v1.2.3 From 38123f92edf500acddf6de90b24c1e45a63b0d5b Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 28 Dec 2018 14:52:52 +0100 Subject: added missing libraries --- deploy-linux.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deploy-linux.sh b/deploy-linux.sh index 3a30f3b..373092a 100755 --- a/deploy-linux.sh +++ b/deploy-linux.sh @@ -65,16 +65,25 @@ cp --no-dereference $LIBDIR/libQt5Svg.so* lib cp --no-dereference $LIBDIR/libQt5Network.so* lib cp --no-dereference $LIBDIR/libQt5Gui.so* lib cp --no-dereference $LIBDIR/libQt5XcbQpa.so* lib +cp --no-dereference $LIBDIR/libQt5Xml.so* lib # add libicu, which is required by Qt5 for unicode support cp --no-dereference $LIBDIR/libicuuc.so* lib cp --no-dereference $LIBDIR/libicui18n.so* lib cp --no-dereference $LIBDIR/libicudata.so* lib +# add a couple of libraries which are not installed by default on Ubuntu +cp --no-dereference $LIBDIR/libdouble-conversion.so* lib +cp --no-dereference $LIBDIR/libxcb-xinerama.so* lib + # add openssl from the build system, as this seems to create some problems if the wrong version cp --no-dereference $LIBDIR/libssl.so* lib cp --no-dereference $LIBDIR/libcrypto.so* lib +# add poppler libs +cp --no-dereference $LIBDIR/libpoppler.so* lib +cp --no-dereference $LIBDIR/libpoppler-qt5.so* lib + # add Qt plugins used by TikZiT cp -R $PLUGINDIR/platforms plugins cp -R $PLUGINDIR/imageformats plugins -- cgit v1.2.3 From 09bd349657cd131b5382024814cca34068f2f8cd Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 28 Dec 2018 15:07:40 +0100 Subject: icon size --- src/gui/previewwindow.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 938ed4e..9dfce1d 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -97,14 +97,14 @@ void PreviewWindow::setStatus(PreviewWindow::Status status) movie->start(); } else if (status == PreviewWindow::Success) { _loader->setMovie(nullptr); - QPixmap accept(":images/dialog-accept.svg"); - accept.setDevicePixelRatio(3.0); - _loader->setPixmap(accept); + QIcon accept(":images/dialog-accept.svg"); + //accept.setDevicePixelRatio(devicePixelRatio()); + _loader->setPixmap(accept.pixmap(QSize(16,16))); } else if (status == PreviewWindow::Failed) { _loader->setMovie(nullptr); - QPixmap error(":images/dialog-error.svg"); - error.setDevicePixelRatio(3.0); - _loader->setPixmap(error); + QIcon error(":images/dialog-error.svg"); + //error.setDevicePixelRatio(devicePixelRatio()); + _loader->setPixmap(error.pixmap(QSize(16,16))); } if (oldMovie != nullptr) oldMovie->deleteLater(); -- cgit v1.2.3 From dcb0b7122a99f065c43ec609d5116c04fd15735a Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 28 Dec 2018 16:48:33 +0100 Subject: ... --- src/gui/previewwindow.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/previewwindow.ui b/src/gui/previewwindow.ui index 7da886a..aa49980 100644 --- a/src/gui/previewwindow.ui +++ b/src/gui/previewwindow.ui @@ -32,7 +32,7 @@ 0 - false + true false @@ -70,8 +70,8 @@ 0 0 - 591 - 448 + 595 + 451 -- cgit v1.2.3 From 281efdc81ddfbd8a94775e96d7076860af1ae2e3 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 28 Dec 2018 17:22:34 +0100 Subject: ... --- src/gui/previewwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 9dfce1d..7fd6376 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -33,7 +33,7 @@ PreviewWindow::PreviewWindow(QWidget *parent) : _doc = nullptr; _page = nullptr; - _loader = new QLabel(this); + _loader = new QLabel(ui->tabWidget->tabBar()); _loader->setMinimumSize(QSize(16,16)); _loader->setMaximumSize(QSize(16,16)); ui->tabWidget->tabBar()->setTabButton(1, QTabBar::RightSide, _loader); -- cgit v1.2.3 From c5fedfb1ec79b97edec4a82b70f082fba93a5b5d Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 31 Dec 2018 12:56:32 +0100 Subject: image export in progress --- src/data/pdfdocument.cpp | 132 +++++++++++++++++++++++++++++++++++++ src/data/pdfdocument.h | 28 ++++++++ src/gui/exportdialog.cpp | 80 +++++++++++++++++++++++ src/gui/exportdialog.h | 34 ++++++++++ src/gui/exportdialog.ui | 162 ++++++++++++++++++++++++++++++++++++++++++++++ src/gui/latexprocess.cpp | 2 +- src/gui/previewwindow.cpp | 100 ++++++++++++++++------------ src/gui/previewwindow.h | 19 ++++-- src/tikzit.cpp | 5 ++ src/tikzit.h | 2 + tikzit.pro | 13 ++-- 11 files changed, 522 insertions(+), 55 deletions(-) create mode 100644 src/data/pdfdocument.cpp create mode 100644 src/data/pdfdocument.h create mode 100644 src/gui/exportdialog.cpp create mode 100644 src/gui/exportdialog.h create mode 100644 src/gui/exportdialog.ui diff --git a/src/data/pdfdocument.cpp b/src/data/pdfdocument.cpp new file mode 100644 index 0000000..bfedeca --- /dev/null +++ b/src/data/pdfdocument.cpp @@ -0,0 +1,132 @@ +#include "pdfdocument.h" + +#include +#include +#include +#include +#include +#include +#include + +PdfDocument::PdfDocument(QString file, QObject *parent) : QObject(parent) +{ + // use loadFromData to avoid holding a lock on the PDF file in windows + QFile f(file); + if (f.open(QFile::ReadOnly)) { + QByteArray data = f.readAll(); + f.close(); + _doc = Poppler::Document::loadFromData(data); + } else { + _doc = nullptr; + } + + if (!_doc) { + _doc = nullptr; + _page = nullptr; + } else { + _doc->setRenderHint(Poppler::Document::Antialiasing); + _doc->setRenderHint(Poppler::Document::TextAntialiasing); + _doc->setRenderHint(Poppler::Document::TextHinting); + _page = _doc->page(0); + } +} + +void PdfDocument::renderTo(QLabel *label, QRect rect) +{ + if (!isValid()) return; + + QSizeF pageSize = _page->pageSizeF(); + + qreal ratio = label->devicePixelRatioF(); + //QRect rect = ui->scrollArea->visibleRegion().boundingRect(); + int w = static_cast(ratio * (rect.width() - 20)); + int h = static_cast(ratio * (rect.height() - 20)); + qreal scale = fmin(static_cast(w) / pageSize.width(), + static_cast(h) / pageSize.height()); + + + int dpi = static_cast(scale * 72.0); + int w1 = static_cast(scale * pageSize.width()); + int h1 = static_cast(scale * pageSize.height()); + + //qDebug() << "hidpi ratio:" << ratio; + //qDebug() << "visible width:" << w; + //qDebug() << "visible height:" << h; + //qDebug() << "doc width:" << pageSize.width(); + //qDebug() << "doc height:" << pageSize.height(); + //qDebug() << "scale:" << scale; + //qDebug() << "dpi:" << dpi; + + QPixmap pm = QPixmap::fromImage(_page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h)); + pm.setDevicePixelRatio(ratio); + label->setPixmap(pm); +} + +bool PdfDocument::isValid() +{ + return (_page != nullptr); +} + +bool PdfDocument::exportImage(QString file, const char *format, QSize outputSize) +{ + QImage img = asImage(outputSize); + if (!img.isNull()) return img.save(file, format); + else return false; +} + +bool PdfDocument::exportPdf(QString file) +{ + if (!isValid()) return false; + Poppler::PDFConverter *conv = _doc->pdfConverter(); + conv->setOutputFileName(file); + bool success = conv->convert(); + delete conv; + return success; +} + +void PdfDocument::copyImageToClipboard(QSize outputSize) +{ + QImage img = asImage(outputSize); + if (!img.isNull()) { + QApplication::clipboard()->setImage(img, QClipboard::Clipboard); + } +} + +QImage PdfDocument::asImage(QSize outputSize) +{ + if (!isValid()) return QImage(); + if (outputSize.isNull()) outputSize = size(); + QSize pageSize = _page->pageSize(); + int dpix = (72 * outputSize.width()) / pageSize.width(); + int dpiy = (72 * outputSize.width()) / pageSize.width(); + QImage img = _page->renderToImage(dpix, dpiy, 0, 0, + outputSize.width(), outputSize.height()); + return img; +} + +// CRASHES TikZiT when figures contain text, due to limitations of Arthur backend +//void PdfDocument::exportToSvg(QString file, QSize size) { +// QSvgGenerator gen; +// gen.setFileName(file); +// gen.setSize(size); +// gen.setViewBox(QRect(0,0,size.width(),size.height())); +// gen.setDescription("SVG generated from PDF by TikZiT"); +// QPainter painter; + +// // set the backend to Qt for renderToPainter() support +// Poppler::Document::RenderBackend backend = _doc->renderBackend(); +// _doc->setRenderBackend(Poppler::Document::ArthurBackend); +// painter.begin(&gen); +// _page->renderToPainter(&painter); +// painter.end(); +// _doc->setRenderBackend(backend); +//} + +QSize PdfDocument::size() +{ + if (isValid()) { + return _page->pageSize(); + } +} + + diff --git a/src/data/pdfdocument.h b/src/data/pdfdocument.h new file mode 100644 index 0000000..ebd33e9 --- /dev/null +++ b/src/data/pdfdocument.h @@ -0,0 +1,28 @@ +#ifndef PDFDOCUMENT_H +#define PDFDOCUMENT_H + +#include +#include +#include + +#include + +class PdfDocument : public QObject +{ + Q_OBJECT +public: + explicit PdfDocument(QString file, QObject *parent = nullptr); + void renderTo(QLabel *label, QRect rect); + bool isValid(); +// void exportToSvg(QString file, QSize size); + bool exportImage(QString file, const char *format, QSize outputSize=QSize()); + bool exportPdf(QString file); + void copyImageToClipboard(QSize outputSize=QSize()); + QImage asImage(QSize outputSize=QSize()); + QSize size(); +private: + Poppler::Document *_doc; + Poppler::Page *_page; +}; + +#endif // PDFDOCUMENT_H diff --git a/src/gui/exportdialog.cpp b/src/gui/exportdialog.cpp new file mode 100644 index 0000000..2d0d8a0 --- /dev/null +++ b/src/gui/exportdialog.cpp @@ -0,0 +1,80 @@ +#include "exportdialog.h" +#include "ui_exportdialog.h" + +#include "tikzit.h" + +ExportDialog::ExportDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ExportDialog) +{ + ui->setupUi(this); + + QIntValidator *v = new QIntValidator(this); + v->setBottom(1); + ui->width->setValidator(v); + ui->height->setValidator(v); + connect(ui->width, SIGNAL(editingFinished()), + this, SLOT(setHeightFromWidth())); + connect(ui->height, SIGNAL(editingFinished()), + this, SLOT(setWidthFromHeight())); + + PdfDocument *doc = tikzit->previewWindow()->doc(); + if (doc) { + QSize size = doc->size() * 4; + ui->width->blockSignals(true); + ui->height->blockSignals(true); + ui->width->setText(QString::number(size.width())); + ui->height->setText(QString::number(size.height())); + ui->width->blockSignals(false); + ui->height->blockSignals(false); + } +} + +ExportDialog::~ExportDialog() +{ + delete ui; +} + +void ExportDialog::setHeightFromWidth() +{ + if (ui->keepAspect->isChecked()) { + PdfDocument *doc = tikzit->previewWindow()->doc(); + if (doc == nullptr || doc->size().width() == 0 || doc->size().height() == 0) return; + int w = ui->width->text().toInt(); + int h = (w * doc->size().height()) / doc->size().width(); + + ui->height->blockSignals(true); + ui->height->setText(QString::number(h)); + ui->height->blockSignals(false); + } +} + +void ExportDialog::setWidthFromHeight() +{ + if (ui->keepAspect->isChecked()) { + PdfDocument *doc = tikzit->previewWindow()->doc(); + if (doc == nullptr || doc->size().width() == 0 || doc->size().height() == 0) return; + int h = ui->height->text().toInt(); + int w = (h * doc->size().width()) / doc->size().height(); + + ui->width->blockSignals(true); + ui->width->setText(QString::number(w)); + ui->width->blockSignals(false); + } +} + +void ExportDialog::on_keepAspect_stateChanged(int state) +{ + if (state == Qt::Checked) setHeightFromWidth(); +} + +void ExportDialog::on_browseButton_clicked() +{ + +} + +void ExportDialog::on_fileFormat_currentIndexChanged(int f) +{ + ui->width->setEnabled(f != PDF); + ui->height->setEnabled(f != PDF); +} diff --git a/src/gui/exportdialog.h b/src/gui/exportdialog.h new file mode 100644 index 0000000..064c968 --- /dev/null +++ b/src/gui/exportdialog.h @@ -0,0 +1,34 @@ +#ifndef EXPORTDIALOG_H +#define EXPORTDIALOG_H + +#include + +namespace Ui { +class ExportDialog; +} + +class ExportDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ExportDialog(QWidget *parent = nullptr); + ~ExportDialog(); + enum Format { + PNG = 0, + JPG = 1, + PDF = 2 + }; + +protected slots: + void setHeightFromWidth(); + void setWidthFromHeight(); + void on_keepAspect_stateChanged(int state); + void on_browseButton_clicked(); + void on_fileFormat_currentIndexChanged(int f); + +private: + Ui::ExportDialog *ui; +}; + +#endif // EXPORTDIALOG_H diff --git a/src/gui/exportdialog.ui b/src/gui/exportdialog.ui new file mode 100644 index 0000000..69e2a22 --- /dev/null +++ b/src/gui/exportdialog.ui @@ -0,0 +1,162 @@ + + + ExportDialog + + + + 0 + 0 + 394 + 119 + + + + + 0 + 0 + + + + Dialog + + + + + + + + File + + + + + + + Format + + + + + + + + + + + + ... + + + + + + + + + + Portable Network Graphics (PNG) + + + + + Jpeg Image (JPG) + + + + + Original (PDF) + + + + + + + + Dimensions + + + + + + + + + + + + X + + + + + + + + + + + + + + + + + + + Keep aspect ratio + + + true + + + + + + + + + Qt::Vertical + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + + buttonBox + accepted() + ExportDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ExportDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 39a7a51..0e2185a 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -19,7 +19,7 @@ LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(pa connect(_proc, SIGNAL(finished(int)), this, SLOT(finished(int))); // for debug purposes - // _workingDir.setAutoRemove(false); + _workingDir.setAutoRemove(false); } void LatexProcess::makePreview(QString tikz) diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 7fd6376..d9d22c2 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -3,6 +3,7 @@ #include "tikzit.h" #include "latexprocess.h" +#include "exportdialog.h" #include #include @@ -16,6 +17,7 @@ #include #include #include +#include PreviewWindow::PreviewWindow(QWidget *parent) : QDialog(parent), @@ -31,7 +33,6 @@ PreviewWindow::PreviewWindow(QWidget *parent) : } _doc = nullptr; - _page = nullptr; _loader = new QLabel(ui->tabWidget->tabBar()); _loader->setMinimumSize(QSize(16,16)); @@ -44,6 +45,27 @@ PreviewWindow::PreviewWindow(QWidget *parent) : render(); } +void PreviewWindow::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu menu(this); + QAction *act; + + act = new QAction("Export Image..."); + connect(act, SIGNAL(triggered()), this, SLOT(exportImage())); + menu.addAction(act); + + act = new QAction("Copy to Clipboard"); + connect(act, SIGNAL(triggered()), this, SLOT(copyImageToClipboard())); + menu.addAction(act); + + menu.exec(event->globalPos()); +} + +PdfDocument *PreviewWindow::doc() const +{ + return _doc; +} + PreviewWindow::~PreviewWindow() { delete ui; @@ -51,30 +73,24 @@ PreviewWindow::~PreviewWindow() void PreviewWindow::setPdf(QString file) { - Poppler::Document *oldDoc = _doc; - // use loadFromData to avoid holding a lock on the PDF file in windows - QFile f(file); - f.open(QFile::ReadOnly); - QByteArray data = f.readAll(); - f.close(); - Poppler::Document *newDoc = Poppler::Document::loadFromData(data); - - if (!newDoc) { + //QFile f(file); + //f.open(QFile::ReadOnly); + //QByteArray data = f.readAll(); + //f.close(); + PdfDocument *newDoc = new PdfDocument(file, this); + + if (newDoc->isValid()) { + PdfDocument *oldDoc = _doc; + _doc = newDoc; + if (oldDoc != nullptr) delete oldDoc; + render(); + } else { QMessageBox::warning(nullptr, "Could not read PDF", "Could not read: '" + file + "'."); - return; + delete newDoc; } - - _doc = newDoc; - _doc->setRenderHint(Poppler::Document::Antialiasing); - _doc->setRenderHint(Poppler::Document::TextAntialiasing); - _doc->setRenderHint(Poppler::Document::TextHinting ); - _page = _doc->page(0); - render(); - - if (oldDoc != nullptr) delete oldDoc; } QPlainTextEdit *PreviewWindow::outputTextEdit() @@ -130,30 +146,28 @@ void PreviewWindow::showEvent(QShowEvent *e) { } void PreviewWindow::render() { - if (_page == nullptr) return; - - QSizeF size = _page->pageSizeF(); - - qreal ratio = devicePixelRatioF(); - QRect rect = ui->scrollArea->visibleRegion().boundingRect(); - int w = static_cast(ratio * (rect.width() - 20)); - int h = static_cast(ratio * (rect.height() - 20)); - qreal scale = fmin(static_cast(w) / size.width(), - static_cast(h) / size.height()); + if (_doc != nullptr) { + _doc->renderTo(ui->pdf, + ui->scrollArea->visibleRegion().boundingRect()); + ui->pdf->repaint(); + } +} +void PreviewWindow::exportImage() +{ + if (_doc == nullptr) return; + ExportDialog *d = new ExportDialog(this); + int ret = d->exec(); + if (ret == QDialog::Accepted) { + qDebug() << "save accepted"; + } +} - int dpi = static_cast(scale * 72.0); - int w1 = static_cast(scale * size.width()); - int h1 = static_cast(scale * size.height()); +void PreviewWindow::copyImageToClipboard() +{ + if (_doc != nullptr) { + _doc->copyImageToClipboard(_doc->size() * 4); + } +} - // qDebug() << "visible width:" << w; - // qDebug() << "visible height:" << h; - // qDebug() << "doc width:" << size.width(); - // qDebug() << "doc height:" << size.height(); - // qDebug() << "scale:" << scale; - // qDebug() << "dpi:" << dpi; - QPixmap pm = QPixmap::fromImage(_page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h)); - pm.setDevicePixelRatio(ratio); - ui->pdf->setPixmap(pm); -} diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h index a937263..20dd042 100644 --- a/src/gui/previewwindow.h +++ b/src/gui/previewwindow.h @@ -1,10 +1,12 @@ #ifndef PREVIEWWINDOW_H #define PREVIEWWINDOW_H +#include "pdfdocument.h" #include #include #include +#include #include namespace Ui { @@ -20,24 +22,27 @@ public: Running, Success, Failed }; explicit PreviewWindow(QWidget *parent = nullptr); - ~PreviewWindow(); + ~PreviewWindow() override; void setPdf(QString file); QString preparePreview(QString tikz); QPlainTextEdit *outputTextEdit(); void setStatus(Status status); + PdfDocument *doc() const; + public slots: void render(); + void exportImage(); + void copyImageToClipboard(); protected: - void resizeEvent(QResizeEvent *e); - void showEvent(QShowEvent *e); - void closeEvent(QCloseEvent *e); - + void resizeEvent(QResizeEvent *e) override; + void showEvent(QShowEvent *e) override; + void closeEvent(QCloseEvent *e) override; + void contextMenuEvent(QContextMenuEvent *event) override; private: Ui::PreviewWindow *ui; - Poppler::Document *_doc; - Poppler::Page *_page; + PdfDocument *_doc; QLabel *_loader; }; diff --git a/src/tikzit.cpp b/src/tikzit.cpp index e81706c..2e36b21 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -489,6 +489,11 @@ void Tikzit::cleanupLatex() } } +PreviewWindow *Tikzit::previewWindow() const +{ + return _preview; +} + //StylePalette *Tikzit::stylePalette() const //{ // return _stylePalette; diff --git a/src/tikzit.h b/src/tikzit.h index 24bf56b..15f0b46 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -136,6 +136,8 @@ public: QString styleFilePath() const; void updateRecentFiles(); + PreviewWindow *previewWindow() const; + public slots: void clearRecentFiles(); void setCheckForUpdates(bool check); diff --git a/tikzit.pro b/tikzit.pro index 3d3b12d..d8abd30 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -1,6 +1,6 @@ # CONFIG += debug -QT += core gui widgets network +QT += core gui widgets network svg test { CONFIG += testcase @@ -73,7 +73,9 @@ SOURCES += src/gui/mainwindow.cpp \ src/gui/styleeditor.cpp \ src/data/stylelist.cpp \ src/gui/previewwindow.cpp \ - src/gui/latexprocess.cpp + src/gui/latexprocess.cpp \ + src/data/pdfdocument.cpp \ + src/gui/exportdialog.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -101,14 +103,17 @@ HEADERS += src/gui/mainwindow.h \ src/gui/styleeditor.h \ src/data/stylelist.h \ src/gui/previewwindow.h \ - src/gui/latexprocess.h + src/gui/latexprocess.h \ + src/data/pdfdocument.h \ + src/gui/exportdialog.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ src/gui/mainmenu.ui \ src/gui/stylepalette.ui \ src/gui/styleeditor.ui \ - src/gui/previewwindow.ui + src/gui/previewwindow.ui \ + src/gui/exportdialog.ui INCLUDEPATH += src src/gui src/data -- cgit v1.2.3 From d27a6bf59d5a9d0cd2c21820d5d94bd4131100c8 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 31 Dec 2018 19:51:04 +0100 Subject: added export dialog --- src/gui/exportdialog.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/gui/exportdialog.ui | 8 ++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/gui/exportdialog.cpp b/src/gui/exportdialog.cpp index 2d0d8a0..b176c71 100644 --- a/src/gui/exportdialog.cpp +++ b/src/gui/exportdialog.cpp @@ -3,6 +3,9 @@ #include "tikzit.h" +#include +#include + ExportDialog::ExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ExportDialog) @@ -70,11 +73,44 @@ void ExportDialog::on_keepAspect_stateChanged(int state) void ExportDialog::on_browseButton_clicked() { + QSettings settings("tikzit", "tikzit"); + + QString suffix; + switch (ui->fileFormat->currentIndex()) { + case PNG: suffix = "png"; break; + case JPG: suffix = "jpg"; break; + case PDF: suffix = "pdf"; break; + } + + QFileDialog dialog; + dialog.setDefaultSuffix(suffix); + dialog.setWindowTitle(tr("Export File Path")); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setNameFilter(ui->fileFormat->currentText()); + dialog.setFileMode(QFileDialog::AnyFile); + if (!settings.value("previous-export-file-path").isNull()) + dialog.setDirectory(settings.value("previous-export-file-path").toString()); + dialog.setOption(QFileDialog::DontUseNativeDialog); + if (dialog.exec()) { + ui->filePath->setText(QDir::toNativeSeparators(dialog.selectedFiles()[0])); + } } void ExportDialog::on_fileFormat_currentIndexChanged(int f) { ui->width->setEnabled(f != PDF); ui->height->setEnabled(f != PDF); + + QString path = ui->filePath->text(); + if (!path.isEmpty()) { + QRegularExpression re("\\.[^.]*$"); + switch (f) { + case PNG: path.replace(re, ".png"); break; + case JPG: path.replace(re, ".jpg"); break; + case PDF: path.replace(re, ".pdf"); break; + } + + ui->filePath->setText(path); + } } diff --git a/src/gui/exportdialog.ui b/src/gui/exportdialog.ui index 69e2a22..82cefdc 100644 --- a/src/gui/exportdialog.ui +++ b/src/gui/exportdialog.ui @@ -17,7 +17,7 @@ - Dialog + Export Image @@ -54,17 +54,17 @@ - Portable Network Graphics (PNG) + Portable Network Graphics (*.png) - Jpeg Image (JPG) + Jpeg Image (*.jpg) - Original (PDF) + Original (*.pdf) -- cgit v1.2.3 From f68cf0d4ae6837b5cd95a43ab482b1f63c1ca54e Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 1 Jan 2019 08:27:51 -0800 Subject: added Info.plist (fixes #47) --- Info.plist | 26 ++++++++++++++++++++++++++ src/gui/previewwindow.cpp | 1 + tikzit.pro | 4 ++++ 3 files changed, 31 insertions(+) create mode 100644 Info.plist diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..829cd67 --- /dev/null +++ b/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleExecutable + tikzit + CFBundleIconFile + tikzit.icns + CFBundleIdentifier + io.github.tikzit + CFBundlePackageType + APPL + CFBundleSignature + ???? + LSMinimumSystemVersion + 10.12 + NSPrincipalClass + NSApplication + NSSupportsAutomaticGraphicsSwitching + + CFBundleVersion + @FULL_VERSION@ + CFBundleShortVersionString + @FULL_VERSION@ + + diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index d9d22c2..c27c1be 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -37,6 +37,7 @@ PreviewWindow::PreviewWindow(QWidget *parent) : _loader = new QLabel(ui->tabWidget->tabBar()); _loader->setMinimumSize(QSize(16,16)); _loader->setMaximumSize(QSize(16,16)); + _loader->setAutoFillBackground(false); ui->tabWidget->tabBar()->setTabButton(1, QTabBar::RightSide, _loader); connect(ui->tabWidget, SIGNAL(currentChanged(int)), diff --git a/tikzit.pro b/tikzit.pro index d8abd30..8b15534 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -2,6 +2,8 @@ QT += core gui widgets network svg +VERSION = 2.1 + test { CONFIG += testcase } @@ -25,6 +27,8 @@ win32:RC_ICONS += images/tikzdoc.ico macx:ICON = images/tikzit.icns # linux-g++:QMAKE_CXXFLAGS += -Wsuggest-override +QMAKE_INFO_PLIST = Info.plist + # Qt 5.8 and above drop support for Mountain Lion contains(QT_VERSION, ^5\\.[5-7].*) { macx:QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8 -- cgit v1.2.3 From 0615dcb854da736e11665ad3387ecba0adbd8cd8 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 11:42:37 +0100 Subject: finished export dialog (closes #49) --- src/gui/exportdialog.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++-- src/gui/exportdialog.h | 7 +++++- src/gui/previewwindow.cpp | 18 ++++++++++++- 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/gui/exportdialog.cpp b/src/gui/exportdialog.cpp index b176c71..cc0be7b 100644 --- a/src/gui/exportdialog.cpp +++ b/src/gui/exportdialog.cpp @@ -5,11 +5,13 @@ #include #include +#include ExportDialog::ExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ExportDialog) { + QSettings settings("tikzit", "tikzit"); ui->setupUi(this); QIntValidator *v = new QIntValidator(this); @@ -31,6 +33,32 @@ ExportDialog::ExportDialog(QWidget *parent) : ui->width->blockSignals(false); ui->height->blockSignals(false); } + + if (!settings.value("previous-export-file-format").isNull()) { + ui->fileFormat->setCurrentIndex(settings.value("previous-export-file-format").toInt()); + } + + // set a default export file + QString path = (!settings.value("previous-export-file-path").isNull()) ? + settings.value("previous-export-file-path").toString() : + QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + + QString suffix; + switch (ui->fileFormat->currentIndex()) { + case PNG: suffix = ".png"; break; + case JPG: suffix = ".jpg"; break; + case PDF: suffix = ".pdf"; break; + } + + QString fileName; + int i = 0; + bool exists = true; + while (exists) { + fileName = path + "/tikzit_image" + QString::number(i) + suffix; + exists = QFileInfo::exists(fileName); + ++i; + } + ui->filePath->setText(QDir::toNativeSeparators(fileName)); } ExportDialog::~ExportDialog() @@ -38,6 +66,31 @@ ExportDialog::~ExportDialog() delete ui; } +QString ExportDialog::filePath() +{ + return ui->filePath->text(); +} + +QSize ExportDialog::size() +{ + return QSize(ui->width->text().toInt(), + ui->height->text().toInt()); +} + +ExportDialog::Format ExportDialog::fileFormat() +{ + return static_cast(ui->fileFormat->currentIndex()); +} + +void ExportDialog::accept() +{ + QSettings settings("tikzit", "tikzit"); + QFileInfo fi(filePath()); + settings.setValue("previous-export-file-path", fi.absolutePath()); + settings.setValue("previous-export-file-format", fileFormat()); + QDialog::accept(); +} + void ExportDialog::setHeightFromWidth() { if (ui->keepAspect->isChecked()) { @@ -88,8 +141,14 @@ void ExportDialog::on_browseButton_clicked() dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setNameFilter(ui->fileFormat->currentText()); dialog.setFileMode(QFileDialog::AnyFile); - if (!settings.value("previous-export-file-path").isNull()) - dialog.setDirectory(settings.value("previous-export-file-path").toString()); + dialog.setLabelText(QFileDialog::Accept, "Select"); + + QFileInfo fi(ui->filePath->text()); + if (!fi.absolutePath().isEmpty()) { + dialog.setDirectory(fi.absolutePath()); + dialog.selectFile(fi.baseName()); + } + dialog.setOption(QFileDialog::DontUseNativeDialog); if (dialog.exec()) { @@ -101,6 +160,7 @@ void ExportDialog::on_fileFormat_currentIndexChanged(int f) { ui->width->setEnabled(f != PDF); ui->height->setEnabled(f != PDF); + ui->keepAspect->setEnabled(f != PDF); QString path = ui->filePath->text(); if (!path.isEmpty()) { diff --git a/src/gui/exportdialog.h b/src/gui/exportdialog.h index 064c968..6788560 100644 --- a/src/gui/exportdialog.h +++ b/src/gui/exportdialog.h @@ -13,12 +13,17 @@ class ExportDialog : public QDialog public: explicit ExportDialog(QWidget *parent = nullptr); - ~ExportDialog(); + ~ExportDialog() override; enum Format { PNG = 0, JPG = 1, PDF = 2 }; + QString filePath(); + QSize size(); + Format fileFormat(); +public slots: + void accept() override; protected slots: void setHeightFromWidth(); diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index c27c1be..ec66f81 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -156,11 +156,27 @@ void PreviewWindow::render() { void PreviewWindow::exportImage() { + QSettings settings("tikzit", "tikzit"); if (_doc == nullptr) return; ExportDialog *d = new ExportDialog(this); int ret = d->exec(); if (ret == QDialog::Accepted) { - qDebug() << "save accepted"; + bool success; + if (d->fileFormat() == ExportDialog::PDF) { + success = _doc->exportPdf(d->filePath()); + } else { + success = _doc->exportImage( + d->filePath(), + (d->fileFormat() == ExportDialog::PNG) ? "PNG" : "JPG", + d->size()); + } + + if (!success) { + QMessageBox::warning(this, + "Error", + "Could not write to: '" + d->filePath() + + "'. Check file permissions or choose a new location."); + } } } -- cgit v1.2.3 From b703296cf7b671ca8049438804e612fc7a4e055a Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 12:10:40 +0100 Subject: updated tikzit.sty to only apply scaling if included by \tikzfig or passed the [tikzfig] style --- tex/sample/sample.tex | 21 +++++++++++++++++++++ tex/sample/tikzit.sty | 24 +++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/tex/sample/sample.tex b/tex/sample/sample.tex index 57ba88c..bbb20e0 100644 --- a/tex/sample/sample.tex +++ b/tex/sample/sample.tex @@ -5,6 +5,8 @@ \begin{document} +This is a demonstration of \texttt{tikzit.sty}, which provides some convenience macros for including \texttt{.tikz} files generated by TikZiT. Note this file is optional, however if you choose to omit it from your \LaTeX{} source, you should at least declare the layers, dummy properties, and \texttt{none} style from \texttt{tikzit.sty} for TikZiT figures to build correctly. + A centered tikz picture: \ctikzfig{fig} @@ -14,5 +16,24 @@ A tikz picture as part of mathematics: \tikzfig{fig} \end{equation} +It is also possible to paste a \texttt{tikzpicture} directly from TikZiT, without using the \texttt{$\backslash$tikzfig} macro. In that case, the \texttt{tikzfig} option should be given to the \texttt{tikzpicture} environment to get the same baseline and scaling as the other figures: +\[ +\begin{tikzpicture}[tikzfig] + \begin{pgfonlayer}{nodelayer} + \node [style=red node] (0) at (0, 1) {}; + \node [style=blue node 2] (1) at (1, 0) {}; + \node [style=blue node] (2) at (-1, 0) {}; + \node [style=yellow square] (3) at (0, -1) {foo}; + \end{pgfonlayer} + \begin{pgfonlayer}{edgelayer} + \draw [in=-90, out=0] (3.center) to (1.center); + \draw [bend right=45, looseness=1.25] (3.center) to (2.center); + \draw (2.center) to (0.center); + \draw (0.center) to (1.center); + \end{pgfonlayer} +\end{tikzpicture} +\] + + \end{document} diff --git a/tex/sample/tikzit.sty b/tex/sample/tikzit.sty index 9c51148..5ca1b46 100644 --- a/tex/sample/tikzit.sty +++ b/tex/sample/tikzit.sty @@ -3,30 +3,40 @@ \usetikzlibrary{arrows} \usetikzlibrary{shapes,shapes.geometric,shapes.misc} -\tikzstyle{every picture}=[baseline=-0.25em,scale=0.5] +% this style is applied by default to any tikzpicture included via \tikzfig +\tikzstyle{tikzfig}=[baseline=-0.25em,scale=0.5] +% these are dummy properties used by TikZiT, but ignored by LaTex \pgfkeys{/tikz/tikzit fill/.initial=0} \pgfkeys{/tikz/tikzit draw/.initial=0} \pgfkeys{/tikz/tikzit shape/.initial=0} \pgfkeys{/tikz/tikzit category/.initial=0} +% standard layers used in .tikz files +\pgfdeclarelayer{edgelayer} +\pgfdeclarelayer{nodelayer} +\pgfsetlayers{background,edgelayer,nodelayer,main} + +% style for blank nodes +\tikzstyle{none}=[inner sep=0mm] + +% include a .tikz file \newcommand{\tikzfig}[1]{% +{\tikzstyle{every picture}=[tikzfig] \IfFileExists{#1.tikz} {\input{#1.tikz}} {% \IfFileExists{./figures/#1.tikz} {\input{./figures/#1.tikz}} {\tikz[baseline=-0.5em]{\node[draw=red,font=\color{red},fill=red!10!white] {\textit{#1}};}}% - }% + }}% } + +% the same as \tikzfig, but in a {center} environment \newcommand{\ctikzfig}[1]{% \begin{center}\rm \tikzfig{#1} \end{center}} -\pgfdeclarelayer{edgelayer} -\pgfdeclarelayer{nodelayer} -\pgfsetlayers{background,edgelayer,nodelayer,main} -\tikzstyle{none}=[inner sep=0mm] +% fix strange self-loops, which are PGF/TikZ default \tikzstyle{every loop}=[] -\tikzstyle{mark coordinate}=[inner sep=0pt,outer sep=0pt,minimum size=3pt,fill=black,circle] -- cgit v1.2.3 From 317d5120c71ff0b68807b397b711a0f853657f43 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 12:31:22 +0100 Subject: copy added [tikzfig] style by default --- src/data/graph.cpp | 1 + tex/sample/figures/fig.tikz | 10 +++++----- tex/sample/sample.tex | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/data/graph.cpp b/src/data/graph.cpp index da7b345..1dd5574 100644 --- a/src/data/graph.cpp +++ b/src/data/graph.cpp @@ -279,6 +279,7 @@ Graph *Graph::copyOfSubgraphWithNodes(QSet nds) { Graph *g = new Graph(); g->setData(_data->copy()); + g->data()->setAtom("tikzfig"); QMap nodeTable; foreach (Node *n, nodes()) { if (nds.contains(n)) { diff --git a/tex/sample/figures/fig.tikz b/tex/sample/figures/fig.tikz index e485d9f..b7074a8 100644 --- a/tex/sample/figures/fig.tikz +++ b/tex/sample/figures/fig.tikz @@ -1,4 +1,4 @@ -\begin{tikzpicture} +\begin{tikzpicture}[tikzfig] \begin{pgfonlayer}{nodelayer} \node [style=red node] (0) at (0, 1) {}; \node [style=blue node 2] (1) at (1, 0) {}; @@ -6,9 +6,9 @@ \node [style=yellow square] (3) at (0, -1) {foo}; \end{pgfonlayer} \begin{pgfonlayer}{edgelayer} - \draw [in=-90, out=0] (3.center) to (1.center); - \draw [bend right=45, looseness=1.25] (3.center) to (2.center); - \draw (2.center) to (0.center); - \draw (0.center) to (1.center); + \draw [in=-90, out=0] (3) to (1); + \draw [bend right] (3) to (2); + \draw (2) to (0); + \draw (0) to (1); \end{pgfonlayer} \end{tikzpicture} diff --git a/tex/sample/sample.tex b/tex/sample/sample.tex index bbb20e0..1b10cf6 100644 --- a/tex/sample/sample.tex +++ b/tex/sample/sample.tex @@ -26,10 +26,10 @@ It is also possible to paste a \texttt{tikzpicture} directly from TikZiT, withou \node [style=yellow square] (3) at (0, -1) {foo}; \end{pgfonlayer} \begin{pgfonlayer}{edgelayer} - \draw [in=-90, out=0] (3.center) to (1.center); - \draw [bend right=45, looseness=1.25] (3.center) to (2.center); - \draw (2.center) to (0.center); - \draw (0.center) to (1.center); + \draw [in=-90, out=0] (3) to (1); + \draw [bend right] (3) to (2); + \draw (2) to (0); + \draw (0) to (1); \end{pgfonlayer} \end{tikzpicture} \] -- cgit v1.2.3 From 21b62e2ea5b1b04838878732a60d4692f20d51d3 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 12:51:32 +0100 Subject: allow custom tex code via .tikzdefs --- src/gui/latexprocess.cpp | 22 ++++++++++++++++------ tex/sample/figures/fig.tikz | 2 +- tex/sample/sample.tex | 2 +- tex/sample/sample.tikzdefs | 6 ++++++ tex/sample/sample.tikzstyles | 6 +++--- 5 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 tex/sample/sample.tikzdefs diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 0e2185a..992886e 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -67,11 +67,6 @@ void LatexProcess::makePreview(QString tikz) _output->appendPlainText("FOUND: " + pdflatex + "\n"); - // copy active *.tikzstyles file to preview dir - if (!tikzit->styleFile().isEmpty() && QFile::exists(tikzit->styleFilePath())) { - QFile::copy(tikzit->styleFilePath(), _workingDir.path() + "/" + tikzit->styleFile()); - } - // copy tikzit.sty to preview dir QFile::copy(":/tex/sample/tikzit.sty", _workingDir.path() + "/tikzit.sty"); @@ -83,7 +78,22 @@ void LatexProcess::makePreview(QString tikz) tex << "\\usepackage{tikzit}\n"; tex << "\\usepackage[graphics,active,tightpage]{preview}\n"; tex << "\\PreviewEnvironment{tikzpicture}\n"; - tex << "\\input{" + tikzit->styleFile() + "}\n"; + + // copy active *.tikzstyles file to preview dir + if (!tikzit->styleFile().isEmpty() && QFile::exists(tikzit->styleFilePath())) { + QFile::copy(tikzit->styleFilePath(), _workingDir.path() + "/" + tikzit->styleFile()); + tex << "\\input{" + tikzit->styleFile() + "}\n"; + + // if there is a *.tikzdefs file with the same basename, copy and include it as well + QFileInfo fi(tikzit->styleFilePath()); + QString defFile = fi.baseName() + ".tikzdefs"; + QString defFilePath = fi.absolutePath() + "/" + defFile; + if (QFile::exists(defFilePath)) { + QFile::copy(defFilePath, _workingDir.path() + "/" + defFile); + tex << "\\input{" + defFile + "}\n"; + } + } + tex << "\\begin{document}\n\n"; tex << tikz; tex << "\n\n\\end{document}\n"; diff --git a/tex/sample/figures/fig.tikz b/tex/sample/figures/fig.tikz index b7074a8..f454de2 100644 --- a/tex/sample/figures/fig.tikz +++ b/tex/sample/figures/fig.tikz @@ -3,7 +3,7 @@ \node [style=red node] (0) at (0, 1) {}; \node [style=blue node 2] (1) at (1, 0) {}; \node [style=blue node] (2) at (-1, 0) {}; - \node [style=yellow square] (3) at (0, -1) {foo}; + \node [style=yellow square] (3) at (0, -1) {\anglevec{\alpha}}; \end{pgfonlayer} \begin{pgfonlayer}{edgelayer} \draw [in=-90, out=0] (3) to (1); diff --git a/tex/sample/sample.tex b/tex/sample/sample.tex index 1b10cf6..c6fb3ca 100644 --- a/tex/sample/sample.tex +++ b/tex/sample/sample.tex @@ -1,7 +1,7 @@ \documentclass{article} \usepackage{tikzit} \input{sample.tikzstyles} - +\input{sample.tikzdefs} \begin{document} diff --git a/tex/sample/sample.tikzdefs b/tex/sample/sample.tikzdefs new file mode 100644 index 0000000..ac25b5a --- /dev/null +++ b/tex/sample/sample.tikzdefs @@ -0,0 +1,6 @@ +% Optional: use this file for definitions that should be used by TikZiT to generate +% LaTeX preview. It can also be included in the paper. + +\usepackage{bm} + +\newcommand{\anglevec}[1]{\ensuremath{\vec{\bm{#1}}}} diff --git a/tex/sample/sample.tikzstyles b/tex/sample/sample.tikzstyles index df70248..5790de1 100644 --- a/tex/sample/sample.tikzstyles +++ b/tex/sample/sample.tikzstyles @@ -4,9 +4,9 @@ % \tikzstyle{NAME}=[PROPERTY LIST] % Node styles -\tikzstyle{red node}=[fill=red, tikzit category=nodes] -\tikzstyle{blue node}=[fill=blue] -\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue] +\tikzstyle{red node}=[fill=red, tikzit category=nodes, shape=circle, draw=black] +\tikzstyle{blue node}=[fill=blue, shape=circle, draw=black] +\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue, shape=circle, draw=black] \tikzstyle{yellow square}=[draw=black, fill=yellow, shape=rectangle] % Edge styles -- cgit v1.2.3 From 50f56c81fcd68a54819302927fb93a54609107c0 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 12:54:05 +0100 Subject: pass -halt-on-error to pdflatex --- src/gui/latexprocess.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 992886e..cad8575 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -99,7 +99,11 @@ void LatexProcess::makePreview(QString tikz) tex << "\n\n\\end{document}\n"; f.close(); - _proc->start(pdflatex, QStringList() << "-interaction=nonstopmode" << "preview.tex"); + _proc->start(pdflatex, + QStringList() + << "-interaction=nonstopmode" + << "-halt-on-error" + << "preview.tex"); } -- cgit v1.2.3 From 0f68de6dcc601cfef295f2b0cb5245b631f75e37 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 17:12:37 +0100 Subject: created delimited string validator --- src/data/delimitedstringvalidator.cpp | 58 +++++++++++++++++++++++++++++++++++ src/data/delimitedstringvalidator.h | 42 +++++++++++++++++++++++++ src/gui/styleeditor.cpp | 4 +++ tikzit.pro | 6 ++-- 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/data/delimitedstringvalidator.cpp create mode 100644 src/data/delimitedstringvalidator.h diff --git a/src/data/delimitedstringvalidator.cpp b/src/data/delimitedstringvalidator.cpp new file mode 100644 index 0000000..9f1057e --- /dev/null +++ b/src/data/delimitedstringvalidator.cpp @@ -0,0 +1,58 @@ +/* + 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 "delimitedstringvalidator.h" + +DelimitedStringValidator::DelimitedStringValidator(QObject *parent) : QValidator(parent) +{ +} + +QValidator::State DelimitedStringValidator::validate(QString &input, int &/*pos*/) const +{ + int depth = braceDepth(input); + if (depth == 0) return Acceptable; + else if (depth > 0) return Intermediate; + else return Invalid; +} + +void DelimitedStringValidator::fixup(QString &input) const +{ + int depth = braceDepth(input); + if (depth > 0) input.append(QString("}").repeated(depth)); +} + +int DelimitedStringValidator::braceDepth(QString input) const +{ + int depth = 0; + bool escape = false; + for (int i = 0; i < input.length(); ++i) { + QCharRef c = input[i]; + if (escape) { + escape = false; + } else if (c == '\\') { + escape = true; + } else if (c == '{') { + depth++; + } else if (c == '}') { + depth--; + if (depth < 0) return -1; + } + } + + return depth; +} diff --git a/src/data/delimitedstringvalidator.h b/src/data/delimitedstringvalidator.h new file mode 100644 index 0000000..654e4ab --- /dev/null +++ b/src/data/delimitedstringvalidator.h @@ -0,0 +1,42 @@ +/* + 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 . +*/ + +/*! + * A string validator which keeps curly braces matched. Used in various places + * to ensure the user doesn't make non-parseable .tikz or .tikzstyles files. + */ + +#ifndef DELIMITEDSTRINGVALIDATOR_H +#define DELIMITEDSTRINGVALIDATOR_H + + +#include +#include + + +class DelimitedStringValidator : public QValidator +{ +public: + DelimitedStringValidator(QObject *parent); + QValidator::State validate(QString &input, int &/*pos*/) const override; + void fixup(QString &input) const override; +private: + int braceDepth(QString input) const; +}; + +#endif // DELIMITEDSTRINGVALIDATOR_H diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp index 29192d6..804a12b 100644 --- a/src/gui/styleeditor.cpp +++ b/src/gui/styleeditor.cpp @@ -4,6 +4,7 @@ #include "tikzit.h" #include "styleeditor.h" +#include "delimitedstringvalidator.h" #include "ui_styleeditor.h" StyleEditor::StyleEditor(QWidget *parent) : @@ -18,6 +19,9 @@ StyleEditor::StyleEditor(QWidget *parent) : ui->leftArrow << ui->rightArrow << ui->properties; + DelimitedStringValidator *v = new DelimitedStringValidator(this); + ui->name->setValidator(v); + setWindowIcon(QIcon(":/images/tikzit.png")); _styles = nullptr; _activeStyle = nullptr; diff --git a/tikzit.pro b/tikzit.pro index 8b15534..ce6a99a 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -79,7 +79,8 @@ SOURCES += src/gui/mainwindow.cpp \ src/gui/previewwindow.cpp \ src/gui/latexprocess.cpp \ src/data/pdfdocument.cpp \ - src/gui/exportdialog.cpp + src/gui/exportdialog.cpp \ + src/data/delimitedstringvalidator.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -109,7 +110,8 @@ HEADERS += src/gui/mainwindow.h \ src/gui/previewwindow.h \ src/gui/latexprocess.h \ src/data/pdfdocument.h \ - src/gui/exportdialog.h + src/gui/exportdialog.h \ + src/data/delimitedstringvalidator.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ -- cgit v1.2.3 From e090751ebb8e4c7c6a9075587e1017d4ac95cd05 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 17:14:58 +0100 Subject: added GPL to some files where it was missing --- src/gui/exportdialog.cpp | 18 ++++++++++++++++++ src/gui/exportdialog.h | 18 ++++++++++++++++++ src/gui/latexprocess.cpp | 18 ++++++++++++++++++ src/gui/latexprocess.h | 18 ++++++++++++++++++ src/gui/previewwindow.cpp | 18 ++++++++++++++++++ src/gui/previewwindow.h | 18 ++++++++++++++++++ src/gui/styleeditor.cpp | 18 ++++++++++++++++++ src/gui/styleeditor.h | 18 ++++++++++++++++++ 8 files changed, 144 insertions(+) diff --git a/src/gui/exportdialog.cpp b/src/gui/exportdialog.cpp index cc0be7b..bd1ef53 100644 --- a/src/gui/exportdialog.cpp +++ b/src/gui/exportdialog.cpp @@ -1,3 +1,21 @@ +/* + 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 "exportdialog.h" #include "ui_exportdialog.h" diff --git a/src/gui/exportdialog.h b/src/gui/exportdialog.h index 6788560..0f6940b 100644 --- a/src/gui/exportdialog.h +++ b/src/gui/exportdialog.h @@ -1,3 +1,21 @@ +/* + 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 . +*/ + #ifndef EXPORTDIALOG_H #define EXPORTDIALOG_H diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index cad8575..0bda54f 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -1,3 +1,21 @@ +/* + 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 "latexprocess.h" #include "tikzit.h" diff --git a/src/gui/latexprocess.h b/src/gui/latexprocess.h index dc815f2..4fe9987 100644 --- a/src/gui/latexprocess.h +++ b/src/gui/latexprocess.h @@ -1,3 +1,21 @@ +/* + 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 . +*/ + #ifndef LATEXPROCESS_H #define LATEXPROCESS_H diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index ec66f81..2f47efd 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -1,3 +1,21 @@ +/* + 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 "previewwindow.h" #include "ui_previewwindow.h" diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h index 20dd042..cf2ffd8 100644 --- a/src/gui/previewwindow.h +++ b/src/gui/previewwindow.h @@ -1,3 +1,21 @@ +/* + 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 . +*/ + #ifndef PREVIEWWINDOW_H #define PREVIEWWINDOW_H diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp index 804a12b..17929da 100644 --- a/src/gui/styleeditor.cpp +++ b/src/gui/styleeditor.cpp @@ -1,3 +1,21 @@ +/* + 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 #include #include diff --git a/src/gui/styleeditor.h b/src/gui/styleeditor.h index 4bae7db..e9a8a89 100644 --- a/src/gui/styleeditor.h +++ b/src/gui/styleeditor.h @@ -1,3 +1,21 @@ +/* + 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 . +*/ + #ifndef STYLEEDITOR_H #define STYLEEDITOR_H -- cgit v1.2.3 From 904e73cbfa571377ab1860ba7d5a54119ab909e0 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 2 Jan 2019 17:38:38 +0100 Subject: added some documentation to the source code --- src/data/delimitedstringvalidator.h | 14 ++++++++++++++ src/data/edge.h | 8 ++++++-- src/data/graphelementdata.h | 6 ++++++ src/data/graphelementproperty.h | 37 ++++++++++++++++++++++++++++++++++--- src/gui/exportdialog.h | 4 ++++ src/gui/latexprocess.h | 5 +++++ src/gui/previewwindow.h | 5 +++++ src/gui/styleeditor.h | 8 ++++++-- 8 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/data/delimitedstringvalidator.h b/src/data/delimitedstringvalidator.h index 654e4ab..b4ed3bd 100644 --- a/src/data/delimitedstringvalidator.h +++ b/src/data/delimitedstringvalidator.h @@ -19,6 +19,10 @@ /*! * A string validator which keeps curly braces matched. Used in various places * to ensure the user doesn't make non-parseable .tikz or .tikzstyles files. + * + * Its validation function will return Acceptable if all curly braces are matched + * properly, Intermediate if all braces are matched except for possibly some opening + * curly braces, and Invalid if there are unmatched closing curly braces. */ #ifndef DELIMITEDSTRINGVALIDATOR_H @@ -34,8 +38,18 @@ class DelimitedStringValidator : public QValidator public: DelimitedStringValidator(QObject *parent); QValidator::State validate(QString &input, int &/*pos*/) const override; + + /*! + * \brief fixup adds curly braces until all braces are matched (if possible) + * \param input + */ void fixup(QString &input) const override; private: + /*! + * \brief braceDepth computes the final (non-escaped) curly-brace depth of a given string + * \param input a string + * \return the final brace depth, or -1 if the depth *ever* drops below 0 + */ int braceDepth(QString input) const; }; diff --git a/src/data/edge.h b/src/data/edge.h index 5d26b3e..27d5bef 100644 --- a/src/data/edge.h +++ b/src/data/edge.h @@ -16,6 +16,10 @@ along with this program. If not, see . */ +/*! + * Class representing an edge in a Graph. + */ + #ifndef EDGE_H #define EDGE_H @@ -30,8 +34,8 @@ class Edge : public QObject { Q_OBJECT public: - explicit Edge(Node *s, Node *t, QObject *parent = 0); - Edge *copy(QMap *nodeTable = 0); + explicit Edge(Node *s, Node *t, QObject *parent = nullptr); + Edge *copy(QMap *nodeTable = nullptr); Node *source() const; Node *target() const; diff --git a/src/data/graphelementdata.h b/src/data/graphelementdata.h index b1311d7..dce0d46 100644 --- a/src/data/graphelementdata.h +++ b/src/data/graphelementdata.h @@ -16,6 +16,12 @@ along with this program. If not, see . */ +/*! + * A list of GraphElementProperty objects, which convenience methods + * for lookup, deletion, re-ordering, etc. It inherits QAbstractItemModel + * so it can be used as the model for a QTreeView in the StyleEditor. + */ + #ifndef GRAPHELEMENTDATA_H #define GRAPHELEMENTDATA_H diff --git a/src/data/graphelementproperty.h b/src/data/graphelementproperty.h index 4ebe104..5777c18 100644 --- a/src/data/graphelementproperty.h +++ b/src/data/graphelementproperty.h @@ -16,6 +16,11 @@ along with this program. If not, see . */ +/*! + * A class which holds either a single key/value pair (i.e. a proper property) + * or simply a key with no value (i.e. an atom). + */ + #ifndef GRAPHELEMENTPROPERTY_H #define GRAPHELEMENTPROPERTY_H @@ -26,13 +31,19 @@ class GraphElementProperty public: GraphElementProperty(); - // full constructor GraphElementProperty(QString key, QString value, bool atom); - // construct a proper property + /*! + * \brief GraphElementProperty constructs a proper property with the given key/value + * \param key + * \param value + */ GraphElementProperty(QString key, QString value); - // construct an atom + /*! + * \brief GraphElementProperty constructs an atom with the given key + * \param key + */ GraphElementProperty(QString key); QString key() const; @@ -40,9 +51,29 @@ public: QString value() const; void setValue(const QString &value); bool atom() const; + + /*! + * \brief operator == returns true for atoms if the keys match and for properties + * if the keys and values match. Note a property is never equal to an atom. + * \param p + * \return + */ bool operator==(const GraphElementProperty &p); + /*! + * \brief tikzEscape prepares a property key or value for export to tikz code. If + * the property only contains numbers, letters, whitespace, or the characters (<,>,-) + * this method does nothing. Otherwise, wrap the property in curly braces. + * \param str + * \return + */ static QString tikzEscape(QString str); + + /*! + * \brief tikz escapes the key/value of a propery or atom and outputs it as "key=value" + * for properties and "key" for atoms. + * \return + */ QString tikz(); signals: diff --git a/src/gui/exportdialog.h b/src/gui/exportdialog.h index 0f6940b..bcb6879 100644 --- a/src/gui/exportdialog.h +++ b/src/gui/exportdialog.h @@ -16,6 +16,10 @@ along with this program. If not, see . */ +/*! + * A dialog for exporting a LaTeX-generated preview to PNG, JPG, or PDF. + */ + #ifndef EXPORTDIALOG_H #define EXPORTDIALOG_H diff --git a/src/gui/latexprocess.h b/src/gui/latexprocess.h index 4fe9987..9853883 100644 --- a/src/gui/latexprocess.h +++ b/src/gui/latexprocess.h @@ -16,6 +16,11 @@ along with this program. If not, see . */ +/*! + * Run pdflatex and dump its output to the appropriate tab of + * the PreviewWindow. + */ + #ifndef LATEXPROCESS_H #define LATEXPROCESS_H diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h index cf2ffd8..a14303b 100644 --- a/src/gui/previewwindow.h +++ b/src/gui/previewwindow.h @@ -16,6 +16,11 @@ along with this program. If not, see . */ +/*! + * Displays a LaTeX-generated PDF preview using Poppler. The right-click + * menu has options for exporting to file or clipboard. + */ + #ifndef PREVIEWWINDOW_H #define PREVIEWWINDOW_H diff --git a/src/gui/styleeditor.h b/src/gui/styleeditor.h index e9a8a89..2c35d56 100644 --- a/src/gui/styleeditor.h +++ b/src/gui/styleeditor.h @@ -16,6 +16,10 @@ along with this program. If not, see . */ +/*! + * A GUI editor for .tikzstyles files. + */ + #ifndef STYLEEDITOR_H #define STYLEEDITOR_H @@ -35,8 +39,8 @@ class StyleEditor : public QMainWindow Q_OBJECT public: - explicit StyleEditor(QWidget *parent = 0); - ~StyleEditor(); + explicit StyleEditor(QWidget *parent = nullptr); + ~StyleEditor() override; void open(); void save(); -- cgit v1.2.3 From 5bcacbe0d3f9f943de0bae7c1b3906dbaa1f0ba1 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 3 Jan 2019 11:36:29 +0100 Subject: removed svg from qt modules --- src/data/pdfdocument.cpp | 4 ++-- tikzit.pro | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data/pdfdocument.cpp b/src/data/pdfdocument.cpp index bfedeca..9b213b2 100644 --- a/src/data/pdfdocument.cpp +++ b/src/data/pdfdocument.cpp @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include @@ -126,6 +124,8 @@ QSize PdfDocument::size() { if (isValid()) { return _page->pageSize(); + } else { + return QSize(); } } diff --git a/tikzit.pro b/tikzit.pro index ce6a99a..4f7585c 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -1,6 +1,6 @@ # CONFIG += debug -QT += core gui widgets network svg +QT += core gui widgets network VERSION = 2.1 -- cgit v1.2.3 From cbe3074cedac1cc509282a1a0df80cac998355a6 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 3 Jan 2019 12:31:18 +0100 Subject: string validation for the styleeditor (closes #44) --- src/data/delimitedstringvalidator.h | 1 + src/gui/delimitedstringitemdelegate.cpp | 44 +++++++++++++++++++++++++++++++++ src/gui/delimitedstringitemdelegate.h | 42 +++++++++++++++++++++++++++++++ src/gui/styleeditor.cpp | 6 +++++ tex/sample/sample.tikzstyles | 4 +-- tikzit.pro | 6 +++-- 6 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 src/gui/delimitedstringitemdelegate.cpp create mode 100644 src/gui/delimitedstringitemdelegate.h diff --git a/src/data/delimitedstringvalidator.h b/src/data/delimitedstringvalidator.h index b4ed3bd..60c2513 100644 --- a/src/data/delimitedstringvalidator.h +++ b/src/data/delimitedstringvalidator.h @@ -35,6 +35,7 @@ class DelimitedStringValidator : public QValidator { + Q_OBJECT public: DelimitedStringValidator(QObject *parent); QValidator::State validate(QString &input, int &/*pos*/) const override; diff --git a/src/gui/delimitedstringitemdelegate.cpp b/src/gui/delimitedstringitemdelegate.cpp new file mode 100644 index 0000000..7b6c58e --- /dev/null +++ b/src/gui/delimitedstringitemdelegate.cpp @@ -0,0 +1,44 @@ +/* + 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 "delimitedstringitemdelegate.h" + +#include + +DelimitedStringItemDelegate::DelimitedStringItemDelegate(QObject *parent) : QItemDelegate (parent) +{ + _validator = new DelimitedStringValidator(this); +} + +DelimitedStringItemDelegate::~DelimitedStringItemDelegate() +{ +} + +QWidget *DelimitedStringItemDelegate::createEditor( + QWidget *parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + QWidget *editor = QItemDelegate::createEditor(parent, option, index); + + if (QLineEdit *lineEdit = dynamic_cast(editor)) { + lineEdit->setValidator(_validator); + } + + return editor; +} diff --git a/src/gui/delimitedstringitemdelegate.h b/src/gui/delimitedstringitemdelegate.h new file mode 100644 index 0000000..bd1a856 --- /dev/null +++ b/src/gui/delimitedstringitemdelegate.h @@ -0,0 +1,42 @@ +/* + 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 . +*/ + +/*! + * A QItemDelete that attaches a DelimitedStringValidator to any QLineEdit + */ + +#ifndef DELIMITEDSTRINGITEMDELEGATE_H +#define DELIMITEDSTRINGITEMDELEGATE_H + +#include "delimitedstringvalidator.h" + +#include +#include + +class DelimitedStringItemDelegate : public QItemDelegate +{ + Q_OBJECT +public: + DelimitedStringItemDelegate(QObject *parent=nullptr); + virtual ~DelimitedStringItemDelegate() override; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; +private: + DelimitedStringValidator *_validator; +}; + +#endif // DELIMITEDSTRINGITEMDELEGATE_H diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp index 17929da..7817731 100644 --- a/src/gui/styleeditor.cpp +++ b/src/gui/styleeditor.cpp @@ -24,6 +24,7 @@ #include "styleeditor.h" #include "delimitedstringvalidator.h" #include "ui_styleeditor.h" +#include "delimitedstringitemdelegate.h" StyleEditor::StyleEditor(QWidget *parent) : QMainWindow(parent), @@ -39,6 +40,11 @@ StyleEditor::StyleEditor(QWidget *parent) : DelimitedStringValidator *v = new DelimitedStringValidator(this); ui->name->setValidator(v); + ui->category->lineEdit()->setValidator(v); + ui->shape->lineEdit()->setValidator(v); + + DelimitedStringItemDelegate *delegate = new DelimitedStringItemDelegate(ui->properties); + ui->properties->setItemDelegate(delegate); setWindowIcon(QIcon(":/images/tikzit.png")); _styles = nullptr; diff --git a/tex/sample/sample.tikzstyles b/tex/sample/sample.tikzstyles index 5790de1..20a2bbc 100644 --- a/tex/sample/sample.tikzstyles +++ b/tex/sample/sample.tikzstyles @@ -5,8 +5,8 @@ % Node styles \tikzstyle{red node}=[fill=red, tikzit category=nodes, shape=circle, draw=black] -\tikzstyle{blue node}=[fill=blue, shape=circle, draw=black] -\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue, shape=circle, draw=black] +\tikzstyle{blue node}=[fill=blue, shape=circle, draw=black, tikzit category=nodes] +\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue, shape=circle, draw=black, tikzit category=nodes] \tikzstyle{yellow square}=[draw=black, fill=yellow, shape=rectangle] % Edge styles diff --git a/tikzit.pro b/tikzit.pro index 4f7585c..ed1fca6 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -80,7 +80,8 @@ SOURCES += src/gui/mainwindow.cpp \ src/gui/latexprocess.cpp \ src/data/pdfdocument.cpp \ src/gui/exportdialog.cpp \ - src/data/delimitedstringvalidator.cpp + src/data/delimitedstringvalidator.cpp \ + src/gui/delimitedstringitemdelegate.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -111,7 +112,8 @@ HEADERS += src/gui/mainwindow.h \ src/gui/latexprocess.h \ src/data/pdfdocument.h \ src/gui/exportdialog.h \ - src/data/delimitedstringvalidator.h + src/data/delimitedstringvalidator.h \ + src/gui/delimitedstringitemdelegate.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ -- cgit v1.2.3 From 99bc4eedae99fc813db3a852139758bca75bddd7 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 3 Jan 2019 14:01:00 +0100 Subject: fixed many warnings in TikzScene and related files (mostly floating point) --- src/data/edge.cpp | 76 ++++++++++++++++++++++----------------------- src/data/edge.h | 12 +++---- src/gui/tikzscene.cpp | 81 ++++++++++++++++++++++++------------------------ src/gui/tikzscene.h | 4 +-- src/gui/undocommands.cpp | 6 ++-- src/gui/undocommands.h | 36 ++++++++++----------- src/tikzit.h | 4 +-- src/util.cpp | 34 ++++++++++++-------- src/util.h | 16 +++++----- 9 files changed, 139 insertions(+), 130 deletions(-) diff --git a/src/data/edge.cpp b/src/data/edge.cpp index a9acd85..afb1e57 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -27,7 +27,7 @@ Edge::Edge(Node *s, Node *t, QObject *parent) : QObject(parent), _source(s), _target(t) { _data = new GraphElementData(this); - _edgeNode = 0; + _edgeNode = nullptr; _dirty = true; if (s != t) { @@ -35,13 +35,13 @@ Edge::Edge(Node *s, Node *t, QObject *parent) : _bend = 0; _inAngle = 0; _outAngle = 0; - _weight = 0.4f; + _weight = 0.4; } else { _basicBendMode = false; _bend = 0; _inAngle = 135; _outAngle = 45; - _weight = 1.0f; + _weight = 1.0; } _style = noneEdgeStyle; updateControls(); @@ -57,7 +57,7 @@ Edge::Edge(Node *s, Node *t, QObject *parent) : Edge *Edge::copy(QMap *nodeTable) { Edge *e; - if (nodeTable == 0) e = new Edge(_source, _target); + if (nodeTable == nullptr) e = new Edge(_source, _target); else e = new Edge(nodeTable->value(_source), nodeTable->value(_target)); e->setData(_data->copy()); e->setBasicBendMode(_basicBendMode); @@ -145,12 +145,12 @@ void Edge::setEdgeNode(Node *edgeNode) { Node *oldEdgeNode = _edgeNode; _edgeNode = edgeNode; - if (oldEdgeNode != 0) oldEdgeNode->deleteLater(); + if (oldEdgeNode != nullptr) oldEdgeNode->deleteLater(); } bool Edge::hasEdgeNode() { - return _edgeNode != 0; + return _edgeNode != nullptr; } void Edge::updateControls() { @@ -158,22 +158,22 @@ void Edge::updateControls() { QPointF src = _source->point(); QPointF targ = _target->point(); - float dx = (targ.x() - src.x()); - float dy = (targ.y() - src.y()); + qreal dx = (targ.x() - src.x()); + qreal dy = (targ.y() - src.y()); - float outAngleR = 0.0f; - float inAngleR = 0.0f; + qreal outAngleR = 0.0; + qreal inAngleR = 0.0; if (_basicBendMode) { - float angle = std::atan2(dy, dx); - float bnd = (float)_bend * (M_PI / 180.0f); + qreal angle = std::atan2(dy, dx); + qreal bnd = static_cast(_bend) * (M_PI / 180.0); outAngleR = angle - bnd; inAngleR = M_PI + angle + bnd; - _outAngle = outAngleR * (180.f / M_PI); - _inAngle = inAngleR * (180.f / M_PI); + _outAngle = static_cast(round(outAngleR * (180.0 / M_PI))); + _inAngle = static_cast(round(inAngleR * (180.0 / M_PI))); } else { - outAngleR = (float)_outAngle * (M_PI / 180.0f); - inAngleR = (float)_inAngle * (M_PI / 180.0f); + outAngleR = static_cast(_outAngle) * (M_PI / 180.0); + inAngleR = static_cast(_inAngle) * (M_PI / 180.0); } // TODO: calculate head and tail properly, not just for circles @@ -192,7 +192,7 @@ void Edge::updateControls() { } // give a default distance for self-loops - _cpDist = (dx==0.0f && dy==0.0f) ? _weight : std::sqrt(dx*dx + dy*dy) * _weight; + _cpDist = (almostZero(dx) && almostZero(dy)) ? _weight : std::sqrt(dx*dx + dy*dy) * _weight; _cp1 = QPointF(src.x() + (_cpDist * std::cos(outAngleR)), src.y() + (_cpDist * std::sin(outAngleR))); @@ -200,9 +200,9 @@ void Edge::updateControls() { _cp2 = QPointF(targ.x() + (_cpDist * std::cos(inAngleR)), targ.y() + (_cpDist * std::sin(inAngleR))); - _mid = bezierInterpolateFull (0.5f, _tail, _cp1, _cp2, _head); - _tailTangent = bezierTangent(0.0f, 0.1f); - _headTangent = bezierTangent(1.0f, 0.9f); + _mid = bezierInterpolateFull (0.5, _tail, _cp1, _cp2, _head); + _tailTangent = bezierTangent(0.0, 0.1); + _headTangent = bezierTangent(1.0, 0.9); } void Edge::setAttributesFromData() @@ -214,16 +214,16 @@ void Edge::setAttributesFromData() _bend = -30; } else if (_data->atom("bend right")) { _bend = 30; - } else if (_data->property("bend left") != 0) { + } else if (_data->property("bend left") != nullptr) { _bend = -_data->property("bend left").toInt(&ok); if (!ok) _bend = -30; - } else if (_data->property("bend right") != 0) { + } else if (_data->property("bend right") != nullptr) { _bend = _data->property("bend right").toInt(&ok); if (!ok) _bend = 30; } else { _bend = 0; - if (_data->property("in") != 0 && _data->property("out") != 0) { + if (_data->property("in") != nullptr && _data->property("out") != nullptr) { _basicBendMode = false; _inAngle = _data->property("in").toInt(&ok); if (!ok) _inAngle = 0; @@ -233,10 +233,10 @@ void Edge::setAttributesFromData() } if (!_data->property("looseness").isNull()) { - _weight = _data->property("looseness").toFloat(&ok) / 2.5f; - if (!ok) _weight = 0.4f; + _weight = _data->property("looseness").toDouble(&ok) / 2.5; + if (!ok) _weight = 0.4; } else { - _weight = (isSelfLoop()) ? 1.0f : 0.4f; + _weight = (isSelfLoop()) ? 1.0 : 0.4; } //qDebug() << "bend: " << _bend << " in: " << _inAngle << " out: " << _outAngle; @@ -280,8 +280,8 @@ void Edge::updateData() } if (_source == _target) _data->setAtom("loop"); - if (!isSelfLoop() && !isStraight() && _weight != 0.4f) - _data->setProperty("looseness", QString::number(_weight*2.5f, 'f', 2)); + if (!isSelfLoop() && !isStraight() && almostEqual(_weight, 0.4)) + _data->setProperty("looseness", QString::number(_weight*2.5, 'f', 2)); if (_source->isBlankNode()) _sourceAnchor = "center"; else _sourceAnchor = ""; if (_target->isBlankNode()) _targetAnchor = "center"; @@ -325,7 +325,7 @@ int Edge::outAngle() const return _outAngle; } -float Edge::weight() const +qreal Edge::weight() const { return _weight; } @@ -335,7 +335,7 @@ bool Edge::basicBendMode() const return _basicBendMode; } -float Edge::cpDist() const +qreal Edge::cpDist() const { return _cpDist; } @@ -360,7 +360,7 @@ void Edge::setOutAngle(int outAngle) _outAngle = outAngle; } -void Edge::setWeight(float weight) +void Edge::setWeight(qreal weight) { _weight = weight; } @@ -402,18 +402,18 @@ Style *Edge::style() const return _style; } -QPointF Edge::bezierTangent(float start, float end) const +QPointF Edge::bezierTangent(qreal start, qreal end) const { - float dx = bezierInterpolate(end, _tail.x(), _cp1.x(), _cp2.x(), _head.x()) - + qreal dx = bezierInterpolate(end, _tail.x(), _cp1.x(), _cp2.x(), _head.x()) - bezierInterpolate(start, _tail.x(), _cp1.x(), _cp2.x(), _head.x()); - float dy = bezierInterpolate(end, _tail.y(), _cp1.y(), _cp2.y(), _head.y()) - + qreal dy = bezierInterpolate(end, _tail.y(), _cp1.y(), _cp2.y(), _head.y()) - bezierInterpolate(start, _tail.y(), _cp1.y(), _cp2.y(), _head.y()); // normalise - float len = sqrt(dx*dx + dy * dy); - if (len != 0) { - dx = (dx / len) * 0.1f; - dy = (dy / len) * 0.1f; + qreal len = sqrt(dx*dx + dy*dy); + if (almostZero(len)) { + dx = (dx / len) * 0.1; + dy = (dy / len) * 0.1; } return QPointF(dx, dy); diff --git a/src/data/edge.h b/src/data/edge.h index 27d5bef..909824b 100644 --- a/src/data/edge.h +++ b/src/data/edge.h @@ -71,15 +71,15 @@ public: int bend() const; int inAngle() const; int outAngle() const; - float weight() const; + qreal weight() const; bool basicBendMode() const; - float cpDist() const; + qreal cpDist() const; void setBasicBendMode(bool mode); void setBend(int bend); void setInAngle(int inAngle); void setOutAngle(int outAngle); - void setWeight(float weight); + void setWeight(qreal weight); int tikzLine() const; void setTikzLine(int tikzLine); @@ -95,7 +95,7 @@ signals: public slots: private: - QPointF bezierTangent(float start, float end) const; + QPointF bezierTangent(qreal start, qreal end) const; QString _sourceAnchor; QString _targetAnchor; @@ -115,8 +115,8 @@ private: int _bend; int _inAngle; int _outAngle; - float _weight; - float _cpDist; + qreal _weight; + qreal _cpDist; QPointF _head; QPointF _tail; diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index c061221..950bd59 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -34,8 +34,8 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, StylePalette *styles, QObject *parent) : QGraphicsScene(parent), _tikzDocument(tikzDocument), _tools(tools), _styles(styles) { - _modifyEdgeItem = 0; - _edgeStartNodeItem = 0; + _modifyEdgeItem = nullptr; + _edgeStartNodeItem = nullptr; _drawEdgeItem = new QGraphicsLineItem(); _rubberBandItem = new QGraphicsRectItem(); _enabled = true; @@ -43,7 +43,7 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, setSceneRect(-1000,-1000,2000,2000); QPen pen; - pen.setColor(QColor::fromRgbF(0.5f, 0.0f, 0.5f)); + pen.setColor(QColor::fromRgbF(0.5, 0.0, 0.5)); //pen.setWidth(3.0f); pen.setCosmetic(true); _drawEdgeItem->setPen(pen); @@ -51,7 +51,7 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, _drawEdgeItem->setVisible(false); addItem(_drawEdgeItem); - pen.setColor(QColor::fromRgbF(0.6f, 0.6f, 0.8f)); + pen.setColor(QColor::fromRgbF(0.6, 0.6, 0.8)); //pen.setWidth(3.0f); //QVector dash; //dash << 4.0 << 4.0; @@ -110,7 +110,7 @@ void TikzScene::graphReplaced() void TikzScene::extendSelectionUp() { bool found = false; - float m = 0.0f; + qreal m = 0.0; foreach (Node *n, getSelectedNodes()) { if (!found) { m = n->point().y(); @@ -128,7 +128,7 @@ void TikzScene::extendSelectionUp() void TikzScene::extendSelectionDown() { bool found = false; - float m = 0.0f; + qreal m = 0.0; foreach (Node *n, getSelectedNodes()) { if (!found) { m = n->point().y(); @@ -146,7 +146,7 @@ void TikzScene::extendSelectionDown() void TikzScene::extendSelectionLeft() { bool found = false; - float m = 0.0f; + qreal m = 0.0; foreach (Node *n, getSelectedNodes()) { if (!found) { m = n->point().x(); @@ -164,7 +164,7 @@ void TikzScene::extendSelectionLeft() void TikzScene::extendSelectionRight() { bool found = false; - float m = 0.0f; + qreal m = 0.0; foreach (Node *n, getSelectedNodes()) { if (!found) { m = n->point().x(); @@ -266,7 +266,7 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) } } - if (_modifyEdgeItem != 0) { + if (_modifyEdgeItem != nullptr) { // store for undo purposes Edge *e = _modifyEdgeItem->edge(); _oldBend = e->bend(); @@ -337,15 +337,15 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) switch (_tools->currentTool()) { case ToolPalette::SELECT: - if (_modifyEdgeItem != 0) { + if (_modifyEdgeItem != nullptr) { Edge *e = _modifyEdgeItem->edge(); // dragging a control point QPointF src = toScreen(e->source()->point()); QPointF targ = toScreen(e->target()->point()); - float dx1 = targ.x() - src.x(); - float dy1 = targ.y() - src.y(); - float dx2, dy2; + qreal dx1 = targ.x() - src.x(); + qreal dy1 = targ.y() - src.y(); + qreal dx2, dy2; if (_firstControlPoint) { dx2 = mousePos.x() - src.x(); dy2 = mousePos.y() - src.y(); @@ -354,25 +354,26 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) dy2 = mousePos.y() - targ.y(); } - float baseDist = sqrt(dx1*dx1 + dy1*dy1); - float handleDist = sqrt(dx2*dx2 + dy2*dy2); - float wcoarseness = 0.1f; + qreal baseDist = sqrt(dx1*dx1 + dy1*dy1); + qreal handleDist = sqrt(dx2*dx2 + dy2*dy2); + qreal wcoarseness = 0.1; if (!e->isSelfLoop()) { - if (baseDist != 0) { + if (baseDist != 0.0) { e->setWeight(roundToNearest(wcoarseness, handleDist/baseDist)); } else { e->setWeight(roundToNearest(wcoarseness, handleDist/GLOBAL_SCALEF)); } } - float control_angle = atan2(-dy2, dx2); + qreal control_angle = atan2(-dy2, dx2); int bcoarseness = 15; + qreal bcoarsenessi = 1.0/15.0; if(e->basicBendMode()) { - float bnd; - float base_angle = atan2(-dy1, dx1); + qreal bnd; + qreal base_angle = atan2(-dy1, dx1); if (_firstControlPoint) { bnd = base_angle - control_angle; } else { @@ -380,12 +381,10 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (bnd > M_PI) bnd -= 2*M_PI; } - e->setBend(round(bnd * (180.0f / M_PI) * (1.0f / (float)bcoarseness)) * bcoarseness); + e->setBend(static_cast(round(bnd * (180.0 / M_PI) * bcoarsenessi)) * bcoarseness); } else { - int bnd = round(control_angle * (180.0f / M_PI) * - (1.0f / (float)bcoarseness)) * - bcoarseness; + int bnd = static_cast(round(control_angle * (180.0 / M_PI) * bcoarsenessi)) * bcoarseness; if (_firstControlPoint) { // TODO: enable moving both control points // if ([theEvent modifierFlags] & NSAlternateKeyMask) { @@ -428,7 +427,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) NodeItem *ni = _nodeItems[n]; // in (rare) cases, the graph can change while we are dragging - if (ni != 0) { + if (ni != nullptr) { ni->setPos(toScreen(_oldNodePositions[n]) + shift); ni->writePos(); } @@ -454,7 +453,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) break; case ToolPalette::EDGE: if (_drawEdgeItem->isVisible()) { - _edgeEndNodeItem = 0; + _edgeEndNodeItem = nullptr; foreach (QGraphicsItem *gi, items(mousePos)) { if (NodeItem *ni = dynamic_cast(gi)){ _edgeEndNodeItem = ni; @@ -462,7 +461,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } QPointF p1 = _drawEdgeItem->line().p1(); - QPointF p2 = (_edgeEndNodeItem != 0) ? toScreen(_edgeEndNodeItem->node()->point()) : mousePos; + QPointF p2 = (_edgeEndNodeItem != nullptr) ? toScreen(_edgeEndNodeItem->node()->point()) : mousePos; QLineF line(p1, p2); _drawEdgeItem->setLine(line); @@ -482,11 +481,11 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) switch (_tools->currentTool()) { case ToolPalette::SELECT: - if (_modifyEdgeItem != 0) { + if (_modifyEdgeItem != nullptr) { // finished dragging a control point Edge *e = _modifyEdgeItem->edge(); - if (_oldWeight != e->weight() || + if (!almostEqual(_oldWeight, e->weight()) || _oldBend != e->bend() || _oldInAngle != e->inAngle() || _oldOutAngle != e->outAngle()) @@ -495,7 +494,7 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) _tikzDocument->undoStack()->push(cmd); } - _modifyEdgeItem = 0; + _modifyEdgeItem = nullptr; } else { // otherwise, process mouse move normally QGraphicsScene::mouseReleaseEvent(event); @@ -517,7 +516,7 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) QPointF shift = mousePos - _mouseDownPos; shift = QPointF(round(shift.x()/GRID_SEP)*GRID_SEP, round(shift.y()/GRID_SEP)*GRID_SEP); - if (shift.x() != 0 || shift.y() != 0) { + if (shift.x() != 0.0 || shift.y() != 0.0) { QMap newNodePositions; foreach (QGraphicsItem *gi, selectedItems()) { @@ -557,14 +556,14 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) break; case ToolPalette::EDGE: // add an edge - if (_edgeStartNodeItem != 0 && _edgeEndNodeItem != 0) { + if (_edgeStartNodeItem != nullptr && _edgeEndNodeItem != nullptr) { Edge *e = new Edge(_edgeStartNodeItem->node(), _edgeEndNodeItem->node(), _tikzDocument); e->setStyleName(_styles->activeEdgeStyleName()); AddEdgeCommand *cmd = new AddEdgeCommand(this, e); _tikzDocument->undoStack()->push(cmd); } - _edgeStartNodeItem = 0; - _edgeEndNodeItem = 0; + _edgeStartNodeItem = nullptr; + _edgeEndNodeItem = nullptr; _drawEdgeItem->setVisible(false); break; case ToolPalette::CROP: @@ -613,19 +612,19 @@ void TikzScene::keyPressEvent(QKeyEvent *event) if (event->modifiers() & Qt::ControlModifier) { QPointF delta(0,0); - float shift = (event->modifiers() & Qt::ShiftModifier) ? 1.0f : 10.0f; + qreal shift = (event->modifiers() & Qt::ShiftModifier) ? 1.0 : 10.0; switch(event->key()) { case Qt::Key_Left: - delta.setX(-0.025f * shift); + delta.setX(-0.025 * shift); break; case Qt::Key_Right: - delta.setX(0.025f * shift); + delta.setX(0.025 * shift); break; case Qt::Key_Up: - delta.setY(0.025f * shift); + delta.setY(0.025 * shift); break; case Qt::Key_Down: - delta.setY(-0.025f * shift); + delta.setY(-0.025 * shift); break; } @@ -767,7 +766,7 @@ void TikzScene::pasteFromClipboard() QRectF srcRect = g->realBbox(); QRectF tgtRect = graph()->realBbox(); - QPointF shift(tgtRect.right() - srcRect.left(), 0.0f); + QPointF shift(tgtRect.right() - srcRect.left(), 0.0); if (shift.x() > 0) { foreach (Node *n, g->nodes()) { @@ -890,7 +889,7 @@ void TikzScene::refreshAdjacentEdges(QList nodes) EdgeItem *ei = _edgeItems[e]; // the list "nodes" can be out of date, e.g. if the graph changes while dragging - if (ei != 0) { + if (ei != nullptr) { if (nodes.contains(ei->edge()->source()) || nodes.contains(ei->edge()->target())) { ei->edge()->updateControls(); ei->readPos(); diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 2a3e988..e8ea2c6 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -44,7 +44,7 @@ class TikzScene : public QGraphicsScene Q_OBJECT public: TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, StylePalette *styles, QObject *parent); - ~TikzScene(); + ~TikzScene() override; Graph *graph(); QMap &nodeItems(); QMap &edgeItems(); @@ -108,7 +108,7 @@ private: bool _draggingNodes; QMap _oldNodePositions; - float _oldWeight; + qreal _oldWeight; int _oldBend; int _oldInAngle; int _oldOutAngle; diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index f713582..8a00536 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -80,7 +80,7 @@ void MoveCommand::redo() } EdgeBendCommand::EdgeBendCommand(TikzScene *scene, Edge *edge, - float oldWeight, int oldBend, + qreal oldWeight, int oldBend, int oldInAngle, int oldOutAngle, QUndoCommand *parent) : GraphUpdateCommand(scene, parent), _edge(edge), @@ -405,7 +405,7 @@ void ChangeLabelCommand::undo() foreach (Node *n, _oldLabels.keys()) { n->setLabel(_oldLabels[n]); NodeItem *ni = _scene->nodeItems()[n]; - if (ni != 0) ni->updateBounds(); + if (ni != nullptr) ni->updateBounds(); } GraphUpdateCommand::undo(); @@ -416,7 +416,7 @@ void ChangeLabelCommand::redo() foreach (Node *n, _oldLabels.keys()) { n->setLabel(_newLabel); NodeItem *ni = _scene->nodeItems()[n]; - if (ni != 0) ni->updateBounds(); + if (ni != nullptr) ni->updateBounds(); } GraphUpdateCommand::redo(); diff --git a/src/gui/undocommands.h b/src/gui/undocommands.h index dc60549..ff51c90 100644 --- a/src/gui/undocommands.h +++ b/src/gui/undocommands.h @@ -36,7 +36,7 @@ class GraphUpdateCommand : public QUndoCommand { public: explicit GraphUpdateCommand(TikzScene *scene, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; protected: @@ -49,7 +49,7 @@ public: explicit MoveCommand(TikzScene *scene, QMap oldNodePositions, QMap newNodePositions, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -61,18 +61,18 @@ class EdgeBendCommand : public GraphUpdateCommand { public: explicit EdgeBendCommand(TikzScene *scene, Edge *edge, - float oldWeight, int oldBend, + qreal oldWeight, int oldBend, int oldInAngle, int oldOutAngle, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: Edge *_edge; - float _oldWeight; + qreal _oldWeight; int _oldBend; int _oldInAngle; int _oldOutAngle; - float _newWeight; + qreal _newWeight; int _newBend; int _newInAngle; int _newOutAngle; @@ -85,7 +85,7 @@ public: QMap deleteNodes, QMap deleteEdges, QSet selEdges, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -98,7 +98,7 @@ class AddNodeCommand : public GraphUpdateCommand { public: explicit AddNodeCommand(TikzScene *scene, Node *node, QRectF newBounds, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -110,7 +110,7 @@ private: class AddEdgeCommand : public GraphUpdateCommand { public: - explicit AddEdgeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = 0); + explicit AddEdgeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -120,7 +120,7 @@ private: class ChangeEdgeModeCommand : public GraphUpdateCommand { public: - explicit ChangeEdgeModeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = 0); + explicit ChangeEdgeModeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -130,7 +130,7 @@ private: class ApplyStyleToNodesCommand : public GraphUpdateCommand { public: - explicit ApplyStyleToNodesCommand(TikzScene *scene, QString style, QUndoCommand *parent = 0); + explicit ApplyStyleToNodesCommand(TikzScene *scene, QString style, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -141,7 +141,7 @@ private: class ApplyStyleToEdgesCommand : public GraphUpdateCommand { public: - explicit ApplyStyleToEdgesCommand(TikzScene *scene, QString style, QUndoCommand *parent = 0); + explicit ApplyStyleToEdgesCommand(TikzScene *scene, QString style, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -152,7 +152,7 @@ private: class PasteCommand : public GraphUpdateCommand { public: - explicit PasteCommand(TikzScene *scene, Graph *graph, QUndoCommand *parent = 0); + explicit PasteCommand(TikzScene *scene, Graph *graph, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -167,7 +167,7 @@ public: explicit ChangeLabelCommand(TikzScene *scene, QMap oldLabels, QString newLabel, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -181,7 +181,7 @@ public: explicit ReplaceGraphCommand(TikzScene *scene, Graph *oldGraph, Graph *newGraph, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -195,7 +195,7 @@ public: explicit ReflectNodesCommand(TikzScene *scene, QSet nodes, bool horizontal, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -209,7 +209,7 @@ public: explicit RotateNodesCommand(TikzScene *scene, QSet nodes, bool clockwise, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: @@ -225,7 +225,7 @@ public: const QVector &newNodeOrder, const QVector &oldEdgeOrder, const QVector &newEdgeOrder, - QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: diff --git a/src/tikzit.h b/src/tikzit.h index 15f0b46..6249b9e 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -76,8 +76,8 @@ // 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 GLOBAL_SCALEF 40.0 +#define GLOBAL_SCALEF_INV 0.025 #define GRID_N 4 #define GRID_SEP 10 #define GRID_SEPF 10.0f diff --git a/src/util.cpp b/src/util.cpp index d5e2b96..72b94eb 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -19,31 +19,31 @@ #include "util.h" -float bezierInterpolate(float dist, float c0, float c1, float c2, float c3) { - float distp = 1 - dist; +qreal bezierInterpolate(qreal dist, qreal c0, qreal c1, qreal c2, qreal c3) { + qreal 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) { +QPointF bezierInterpolateFull (qreal 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; +qreal roundToNearest(qreal stepSize, qreal val) { + if (stepSize==0.0) return val; else return round(val/stepSize)*stepSize; } -float radiansToDegrees (float radians) { - return (radians * 180.0f) / M_PI; +qreal radiansToDegrees (qreal radians) { + return (radians * 180.0) / M_PI; } -float degreesToRadians(float degrees) { - return (degrees * M_PI) / 180.0f; +qreal degreesToRadians(qreal degrees) { + return (degrees * M_PI) / 180.0; } int normaliseAngleDeg (int degrees) { @@ -56,7 +56,7 @@ int normaliseAngleDeg (int degrees) { return degrees; } -float normaliseAngleRad (float rads) { +qreal normaliseAngleRad (qreal rads) { while (rads > M_PI) { rads -= 2 * M_PI; } @@ -66,8 +66,16 @@ float normaliseAngleRad (float rads) { 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"; +bool almostZero(qreal f) { + return (f >= -0.000001 && f <= 0.000001); +} + +bool almostEqual(qreal f1, qreal f2) { + return almostZero(f1 - f2); +} + +// convert qreal to string, squashing very small qreals to zero +QString floatToString(qreal f) { + if (almostZero(f)) return "0"; else return QString::number(f); } diff --git a/src/util.h b/src/util.h index 89d0c5b..5d1073a 100644 --- a/src/util.h +++ b/src/util.h @@ -33,17 +33,19 @@ #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); +qreal bezierInterpolate(qreal dist, qreal c0, qreal c1, qreal c2, qreal c3); +QPointF bezierInterpolateFull (qreal dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3); // rounding -float roundToNearest(float stepSize, float val); -float radiansToDegrees (float radians); -QString floatToString(float f); +qreal roundToNearest(qreal stepSize, qreal val); +qreal radiansToDegrees (qreal radians); +bool almostZero(qreal f); +bool almostEqual(qreal f1, qreal f2); +QString floatToString(qreal f); // angles -float degreesToRadians(float degrees); +qreal degreesToRadians(qreal degrees); int normaliseAngleDeg (int degrees); -float normaliseAngleRad (float rads); +qreal normaliseAngleRad (qreal rads); #endif // UTIL_H -- cgit v1.2.3 From af55e1aac22126f72f738a666db01c8a146d99dc Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 3 Jan 2019 14:09:21 +0100 Subject: removed dep on fmin() --- src/data/pdfdocument.cpp | 6 ++++-- src/util.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/data/pdfdocument.cpp b/src/data/pdfdocument.cpp index 9b213b2..c9574b8 100644 --- a/src/data/pdfdocument.cpp +++ b/src/data/pdfdocument.cpp @@ -39,9 +39,11 @@ void PdfDocument::renderTo(QLabel *label, QRect rect) //QRect rect = ui->scrollArea->visibleRegion().boundingRect(); int w = static_cast(ratio * (rect.width() - 20)); int h = static_cast(ratio * (rect.height() - 20)); - qreal scale = fmin(static_cast(w) / pageSize.width(), - static_cast(h) / pageSize.height()); + // not all platforms have fmin, compute the min by hand + qreal hscale = static_cast(w) / pageSize.width(); + qreal vscale = static_cast(h) / pageSize.height(); + qreal scale = (hscale < vscale) ? hscale : vscale; int dpi = static_cast(scale * 72.0); int w1 = static_cast(scale * pageSize.width()); diff --git a/src/util.cpp b/src/util.cpp index 72b94eb..304f9e7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -79,3 +79,4 @@ QString floatToString(qreal f) { if (almostZero(f)) return "0"; else return QString::number(f); } + -- cgit v1.2.3 From 6760247a5ca6143779699cbd5de5022e7477bd80 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 3 Jan 2019 16:28:16 +0100 Subject: validate node label text --- src/gui/tikzscene.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 950bd59..31d5bf6 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -28,6 +28,7 @@ #include #include #include +#include TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, @@ -664,16 +665,23 @@ void TikzScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) } break; } else if (NodeItem *ni = dynamic_cast(it)) { - bool ok; - QString newLabel = QInputDialog::getText(views()[0], tr("Node label"), - tr("Label:"), QLineEdit::Normal, - ni->node()->label(), &ok); - if (ok) { + QInputDialog *d = new QInputDialog(views()[0]); + d->setLabelText(tr("Label:")); + d->setTextValue(ni->node()->label()); + d->setWindowTitle(tr("Node label")); + + if (QLineEdit *le = d->findChild()) { + le->setValidator(new DelimitedStringValidator(le)); + } + + if (d->exec()) { QMap oldLabels; oldLabels.insert(ni->node(), ni->node()->label()); - ChangeLabelCommand *cmd = new ChangeLabelCommand(this, oldLabels, newLabel); + ChangeLabelCommand *cmd = new ChangeLabelCommand(this, oldLabels, d->textValue()); _tikzDocument->undoStack()->push(cmd); } + + d->deleteLater(); break; } } -- cgit v1.2.3 From 7d9ca91c2922ede0d21a856abf61c14d9ce7898a Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 5 Jan 2019 21:13:04 +0100 Subject: preference dialog done (closes #50) --- src/gui/latexprocess.cpp | 57 +++++---- src/gui/mainmenu.cpp | 8 ++ src/gui/mainmenu.h | 3 +- src/gui/mainmenu.ui | 16 ++- src/gui/preferencedialog.cpp | 111 ++++++++++++++++++ src/gui/preferencedialog.h | 31 +++++ src/gui/preferencedialog.ui | 272 +++++++++++++++++++++++++++++++++++++++++++ src/gui/styleeditor.cpp | 34 ------ src/gui/tikzview.cpp | 8 +- src/tikzit.cpp | 134 +++++++++++++-------- src/tikzit.h | 6 +- tikzit.pro | 9 +- 12 files changed, 572 insertions(+), 117 deletions(-) create mode 100644 src/gui/preferencedialog.cpp create mode 100644 src/gui/preferencedialog.h create mode 100644 src/gui/preferencedialog.ui diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 0bda54f..d267bf5 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -23,6 +23,7 @@ #include #include #include +#include LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(parent) { @@ -42,6 +43,7 @@ LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(pa void LatexProcess::makePreview(QString tikz) { + QSettings settings("tikzit", "tikzit"); _preview->setStatus(PreviewWindow::Running); _output->clear(); @@ -51,40 +53,47 @@ void LatexProcess::makePreview(QString tikz) } _output->appendPlainText("USING TEMP DIR: " + _workingDir.path() + "\n"); - _output->appendPlainText("SEARCHING FOR pdflatex IN:"); - _output->appendPlainText(qgetenv("PATH")); - _output->appendPlainText("\n"); + QString pdflatex; - QString pdflatex = QStandardPaths::findExecutable("pdflatex"); - if (pdflatex.isEmpty()) { - // if pdflatex is not in PATH, we are probably on mac or windows, so try common - // install directories. - _output->appendPlainText("NOT FOUND IN PATH, TRYING:"); - - QStringList texDirs; - // common macOS tex directories: - texDirs << "/Library/TeX/texbin"; - texDirs << "/usr/texbin"; - texDirs << "/usr/local/bin"; - texDirs << "/sw/bin"; - - // common windows tex directories - texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin"; - texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64"; - - _output->appendPlainText(texDirs.join(":")); - pdflatex = QStandardPaths::findExecutable("pdflatex", texDirs); + if (settings.value("auto-detect-pdflatex", true).toBool()) { + _output->appendPlainText("SEARCHING FOR pdflatex IN:"); + _output->appendPlainText(qgetenv("PATH")); + _output->appendPlainText("\n"); + pdflatex = QStandardPaths::findExecutable("pdflatex"); + if (pdflatex.isEmpty()) { + // if pdflatex is not in PATH, we are probably on mac or windows, so try common + // install directories. + _output->appendPlainText("NOT FOUND IN PATH, TRYING:"); + + QStringList texDirs; + // common macOS tex directories: + texDirs << "/Library/TeX/texbin"; + texDirs << "/usr/texbin"; + texDirs << "/usr/local/bin"; + texDirs << "/sw/bin"; + + // common windows tex directories + texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin"; + texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64"; + + _output->appendPlainText(texDirs.join(":")); + pdflatex = QStandardPaths::findExecutable("pdflatex", texDirs); + } if (pdflatex.isEmpty()) { _output->appendPlainText("pdflatex NOT FOUND, ABORTING.\n"); _preview->setStatus(PreviewWindow::Failed); return; + } else { + _output->appendPlainText("FOUND: " + pdflatex + "\n"); } + } else { + _output->appendPlainText("USING pdflatex:\n"); + pdflatex = settings.value("pdflatex-path", "/usr/bin/pdflatex").toString(); + _output->appendPlainText(pdflatex + "\n"); } - _output->appendPlainText("FOUND: " + pdflatex + "\n"); - // copy tikzit.sty to preview dir QFile::copy(":/tex/sample/tikzit.sty", _workingDir.path() + "/tikzit.sty"); diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 3b8b92b..6f4f8db 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -17,6 +17,7 @@ */ #include "mainmenu.h" +#include "preferencedialog.h" #include "tikzit.h" #include @@ -269,6 +270,13 @@ void MainMenu::on_actionRun_LaTeX_triggered() tikzit->makePreview(); } +void MainMenu::on_actionPreferences_triggered() +{ + PreferenceDialog *d = new PreferenceDialog(this); + d->exec(); + d->deleteLater(); +} + // View void MainMenu::on_actionZoom_In_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index 8acef49..4d672cd 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -66,11 +66,12 @@ public slots: void on_actionExtendLeft_triggered(); void on_actionExtendRight_triggered(); - // Tikz + // Tools void on_actionParse_triggered(); void on_actionRevert_triggered(); void on_actionJump_to_Selection_triggered(); void on_actionRun_LaTeX_triggered(); + void on_actionPreferences_triggered(); // View void on_actionZoom_In_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 097430c..54b02f8 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -75,12 +75,14 @@
- Tikz + Tools + + @@ -204,7 +206,7 @@ - Parse Tikz + Parse TikZ Ctrl+T @@ -233,7 +235,10 @@ - Revert Tikz + Revert TikZ + + + Ctrl+Alt+T @@ -355,6 +360,11 @@ Clear Menu + + + Preferences... + + diff --git a/src/gui/preferencedialog.cpp b/src/gui/preferencedialog.cpp new file mode 100644 index 0000000..06159af --- /dev/null +++ b/src/gui/preferencedialog.cpp @@ -0,0 +1,111 @@ +#include "preferencedialog.h" +#include "ui_preferencedialog.h" + +#include +#include +#include + +PreferenceDialog::PreferenceDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::PreferenceDialog) +{ + ui->setupUi(this); + QSettings settings("tikzit", "tikzit"); + ui->autoPdflatex->setChecked(true); + + if (!settings.value("auto-detect-pdflatex").isNull()) + ui->autoPdflatex->setChecked(settings.value("auto-detect-pdflatex").toBool()); + if (!settings.value("pdflatex-path").isNull()) + ui->pdflatexPath->setText(settings.value("pdflatex-path").toString()); + + + setColor(ui->axesColor, settings.value("grid-color-axes", + QColor(220,220,240)).value()); + setColor(ui->majorColor, settings.value("grid-color-major", + QColor(240,240,250)).value()); + setColor(ui->minorColor, settings.value("grid-color-minor", + QColor(250,250,255)).value()); + + + connect(ui->axesColor, SIGNAL(clicked()), this, SLOT(colorClick())); + connect(ui->majorColor, SIGNAL(clicked()), this, SLOT(colorClick())); + connect(ui->minorColor, SIGNAL(clicked()), this, SLOT(colorClick())); +} + +PreferenceDialog::~PreferenceDialog() +{ + delete ui; +} + +void PreferenceDialog::accept() +{ + QSettings settings("tikzit", "tikzit"); + settings.setValue("auto-detect-pdflatex", ui->autoPdflatex->isChecked()); + settings.setValue("pdflatex-path", ui->pdflatexPath->text()); + settings.setValue("grid-color-axes", color(ui->axesColor)); + settings.setValue("grid-color-major", color(ui->majorColor)); + settings.setValue("grid-color-minor", color(ui->minorColor)); + QDialog::accept(); +} + +void PreferenceDialog::on_resetColors_clicked() +{ + setColor(ui->axesColor, QColor(220,220,240)); + setColor(ui->majorColor, QColor(240,240,250)); + setColor(ui->minorColor, QColor(250,250,255)); +} + +void PreferenceDialog::colorClick() +{ + if (QPushButton *btn = dynamic_cast(sender())) { + QColor col = QColorDialog::getColor( + color(btn), + this, + "Set color", + QColorDialog::DontUseNativeDialog); + if (col.isValid()) setColor(btn, col); + } +} + +void PreferenceDialog::on_autoPdflatex_stateChanged(int state) +{ + ui->pdflatexPath->setEnabled(state != Qt::Checked); + ui->browsePdflatex->setEnabled(state != Qt::Checked); +} + +void PreferenceDialog::on_browsePdflatex_clicked() +{ + QSettings settings("tikzit", "tikzit"); + + QFileDialog dialog; + dialog.setWindowTitle(tr("pdflatex Path")); + dialog.setAcceptMode(QFileDialog::AcceptOpen); + dialog.setFileMode(QFileDialog::ExistingFile); + dialog.setLabelText(QFileDialog::Accept, "Select"); + + QFileInfo fi(ui->pdflatexPath->text()); + if (!fi.absolutePath().isEmpty()) { + dialog.setDirectory(fi.absolutePath()); + dialog.selectFile(fi.baseName()); + } + + dialog.setOption(QFileDialog::DontUseNativeDialog); + + if (dialog.exec()) { + ui->pdflatexPath->setText(QDir::toNativeSeparators(dialog.selectedFiles()[0])); + } +} + +void PreferenceDialog::setColor(QPushButton *btn, QColor col) +{ + QPalette pal = btn->palette(); + pal.setColor(QPalette::Button, col); + btn->setPalette(pal); + btn->update(); +} + +QColor PreferenceDialog::color(QPushButton *btn) +{ + QPalette pal = btn->palette(); + return pal.color(QPalette::Button); +} diff --git a/src/gui/preferencedialog.h b/src/gui/preferencedialog.h new file mode 100644 index 0000000..9da8ae6 --- /dev/null +++ b/src/gui/preferencedialog.h @@ -0,0 +1,31 @@ +#ifndef PREFERENCEDIALOG_H +#define PREFERENCEDIALOG_H + +#include + +namespace Ui { +class PreferenceDialog; +} + +class PreferenceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit PreferenceDialog(QWidget *parent = nullptr); + ~PreferenceDialog() override; + +protected slots: + void accept() override; + void colorClick(); + void on_resetColors_clicked(); + void on_autoPdflatex_stateChanged(int state); + void on_browsePdflatex_clicked(); + +private: + Ui::PreferenceDialog *ui; + QColor color(QPushButton *btn); + void setColor(QPushButton *btn, QColor col); +}; + +#endif // PREFERENCEDIALOG_H diff --git a/src/gui/preferencedialog.ui b/src/gui/preferencedialog.ui new file mode 100644 index 0000000..9a32e7d --- /dev/null +++ b/src/gui/preferencedialog.ui @@ -0,0 +1,272 @@ + + + PreferenceDialog + + + + 0 + 0 + 345 + 176 + + + + Dialog + + + + + + + + pdflatex Location + + + + + + + + + + + + ... + + + + + + + + + Automatically detect pdflatex + + + + + + + Grid colors + + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + true + + + + + + + + + + Axes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + true + + + + + + + + + + Major + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + true + + + + + + + + + + Minor + + + + + + + + + Reset colors + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PreferenceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PreferenceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp index 7817731..e2ade45 100644 --- a/src/gui/styleeditor.cpp +++ b/src/gui/styleeditor.cpp @@ -72,40 +72,6 @@ StyleEditor::StyleEditor(QWidget *parent) : SIGNAL(currentIndexChanged(int)), this, SLOT(shapeChanged())); - // setup the color dialog to display only the named colors that tikzit/xcolor knows - // about as "standard colors". - for (int i = 0; i < 48; ++i) { - QColorDialog::setStandardColor(i, QColor(Qt::white)); - } - - // grayscale in column 1 - int pos = 0; - for (int i=0; i < 5; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - - // rainbow in column 2 - pos = 6; - for (int i=5; i < 11; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - - // brown/green/teal spectrum in column 3 - pos = 12; - for (int i=11; i < 16; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - - // pinks in column 4 - pos = 18; - for (int i=16; i < 19; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - refreshDisplay(); } diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp index 52a32cf..5b0f09c 100644 --- a/src/gui/tikzview.cpp +++ b/src/gui/tikzview.cpp @@ -21,6 +21,7 @@ #include #include +#include TikzView::TikzView(QWidget *parent) : QGraphicsView(parent) { @@ -53,6 +54,7 @@ void TikzView::setScene(QGraphicsScene *scene) void TikzView::drawBackground(QPainter *painter, const QRectF &rect) { + QSettings settings("tikzit", "tikzit"); QGraphicsView::drawBackground(painter, rect); // draw a gray background if disabled TikzScene *sc = static_cast(scene()); @@ -63,13 +65,13 @@ void TikzView::drawBackground(QPainter *painter, const QRectF &rect) QPen pen1; //pen1.setWidthF(0.5); pen1.setCosmetic(true); - pen1.setColor(QColor(250,250,255)); + pen1.setColor(settings.value("grid-color-minor", QColor(250,250,255)).value()); QPen pen2 = pen1; - pen2.setColor(QColor(240,240,250)); + pen2.setColor(settings.value("grid-color-major", QColor(240,240,250)).value()); QPen pen3 = pen1; - pen3.setColor(QColor(220,220,240)); + pen3.setColor(settings.value("grid-color-axes", QColor(220,220,240)).value()); painter->setPen(pen1); diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 2e36b21..2a7c00a 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -30,6 +30,7 @@ #include #include #include +#include // application-level instance of Tikzit Tikzit *tikzit; @@ -45,54 +46,7 @@ void Tikzit::init() { QSettings settings("tikzit", "tikzit"); - // 19 standard xcolor colours - _colNames << - "black" << - "darkgray" << - "gray" << - "lightgray" << - "white" << - - "red" << - "orange" << - "yellow" << - "green" << - "blue" << - "purple" << - - "brown" << - "olive" << - "lime" << - "cyan" << - "teal" << - - "magenta" << - "violet" << - "pink"; - - _cols << - QColor::fromRgbF(0,0,0) << - QColor::fromRgbF(0.25,0.25,0.25) << - QColor::fromRgbF(0.5,0.5,0.5) << - QColor::fromRgbF(0.75,0.75,0.75) << - QColor::fromRgbF(1,1,1) << - - QColor::fromRgbF(1,0,0) << - QColor::fromRgbF(1,0.5,0) << - QColor::fromRgbF(1,1,0) << - QColor::fromRgbF(0,1,0) << - QColor::fromRgbF(0,0,1) << - QColor::fromRgbF(0.75,0,0.25) << - - QColor::fromRgbF(0.75,0.5,0.25) << - QColor::fromRgbF(0.5,0.5,0) << - QColor::fromRgbF(0.75,1,0) << - QColor::fromRgbF(0,1,1) << - QColor::fromRgbF(0,0.5,0.5) << - - QColor::fromRgbF(1,0,1) << - QColor::fromRgbF(0.5,0,0.5) << - QColor::fromRgbF(1,0.75,0.75); + initColors(); _mainMenu = new MainMenu(); QMainWindow *dummy = new QMainWindow(); @@ -489,6 +443,90 @@ void Tikzit::cleanupLatex() } } +void Tikzit::initColors() +{ + // 19 standard xcolor colours + _colNames << + "black" << + "darkgray" << + "gray" << + "lightgray" << + "white" << + + "red" << + "orange" << + "yellow" << + "green" << + "blue" << + "purple" << + + "brown" << + "olive" << + "lime" << + "cyan" << + "teal" << + + "magenta" << + "violet" << + "pink"; + + _cols << + QColor::fromRgbF(0,0,0) << + QColor::fromRgbF(0.25,0.25,0.25) << + QColor::fromRgbF(0.5,0.5,0.5) << + QColor::fromRgbF(0.75,0.75,0.75) << + QColor::fromRgbF(1,1,1) << + + QColor::fromRgbF(1,0,0) << + QColor::fromRgbF(1,0.5,0) << + QColor::fromRgbF(1,1,0) << + QColor::fromRgbF(0,1,0) << + QColor::fromRgbF(0,0,1) << + QColor::fromRgbF(0.75,0,0.25) << + + QColor::fromRgbF(0.75,0.5,0.25) << + QColor::fromRgbF(0.5,0.5,0) << + QColor::fromRgbF(0.75,1,0) << + QColor::fromRgbF(0,1,1) << + QColor::fromRgbF(0,0.5,0.5) << + + QColor::fromRgbF(1,0,1) << + QColor::fromRgbF(0.5,0,0.5) << + QColor::fromRgbF(1,0.75,0.75); + + for (int i = 0; i < 48; ++i) { + QColorDialog::setStandardColor(i, QColor(Qt::white)); + } + + // grayscale in column 1 + int pos = 0; + for (int i=0; i < 5; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } + + // rainbow in column 2 + pos = 6; + for (int i=5; i < 11; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } + + // brown/green/teal spectrum in column 3 + pos = 12; + for (int i=11; i < 16; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } + + // pinks in column 4 + pos = 18; + for (int i=16; i < 19; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } +} + PreviewWindow *Tikzit::previewWindow() const { return _preview; diff --git a/src/tikzit.h b/src/tikzit.h index 6249b9e..4797f48 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -149,7 +149,11 @@ public slots: void cleanupLatex(); private: - // void createMenu(); + /*! + * \brief initColors initialises a table of xcolor named colors and their associated + * QColor values, and adds them as standard colors to the Qt color dialog. + */ + void initColors(); MainMenu *_mainMenu; ToolPalette *_toolPalette; diff --git a/tikzit.pro b/tikzit.pro index ed1fca6..692433d 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -81,7 +81,8 @@ SOURCES += src/gui/mainwindow.cpp \ src/data/pdfdocument.cpp \ src/gui/exportdialog.cpp \ src/data/delimitedstringvalidator.cpp \ - src/gui/delimitedstringitemdelegate.cpp + src/gui/delimitedstringitemdelegate.cpp \ + src/gui/preferencedialog.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -113,7 +114,8 @@ HEADERS += src/gui/mainwindow.h \ src/data/pdfdocument.h \ src/gui/exportdialog.h \ src/data/delimitedstringvalidator.h \ - src/gui/delimitedstringitemdelegate.h + src/gui/delimitedstringitemdelegate.h \ + src/gui/preferencedialog.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ @@ -121,7 +123,8 @@ FORMS += src/gui/mainwindow.ui \ src/gui/stylepalette.ui \ src/gui/styleeditor.ui \ src/gui/previewwindow.ui \ - src/gui/exportdialog.ui + src/gui/exportdialog.ui \ + src/gui/preferencedialog.ui INCLUDEPATH += src src/gui src/data -- cgit v1.2.3 From 6cc196eaf2e0af11290c275e8d0c012f06c30147 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 5 Jan 2019 22:31:13 +0100 Subject: added XML to windows deploy script --- deploy-win.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy-win.bat b/deploy-win.bat index 0890d64..ba4d7b8 100755 --- a/deploy-win.bat +++ b/deploy-win.bat @@ -11,7 +11,7 @@ copy ..\..\win32-deps\bin\*.dll . copy C:\OpenSSL-Win32\bin\libeay32.dll . copy C:\OpenSSL-Win32\bin\ssleay32.dll . -windeployqt.exe --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe +windeployqt.exe --xml --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe cd .. 7z a -tzip tikzit.zip tikzit -- cgit v1.2.3 From 6fd94bf97d9f6f6263262d7dd23f8f2c2e33d796 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 6 Jan 2019 15:15:50 +0100 Subject: add a blank node when previewing empty graph --- src/data/tikzdocument.cpp | 5 +++++ src/data/tikzdocument.h | 2 ++ src/gui/latexprocess.cpp | 6 +++++- src/tikzit.cpp | 9 ++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp index b89da10..1099779 100644 --- a/src/data/tikzdocument.cpp +++ b/src/data/tikzdocument.cpp @@ -148,6 +148,11 @@ QString TikzDocument::fileName() const return _fileName; } +bool TikzDocument::isEmpty() +{ + return _graph->nodes().isEmpty(); +} + void TikzDocument::addToRecentFiles() { QSettings settings("tikzit", "tikzit"); diff --git a/src/data/tikzdocument.h b/src/data/tikzdocument.h index 3b5990a..ad5499f 100644 --- a/src/data/tikzdocument.h +++ b/src/data/tikzdocument.h @@ -54,6 +54,8 @@ public: QString fileName() const; + bool isEmpty(); + private: Graph *_graph; QString _tikz; diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index d267bf5..8d720d5 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -38,7 +38,7 @@ LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(pa connect(_proc, SIGNAL(finished(int)), this, SLOT(finished(int))); // for debug purposes - _workingDir.setAutoRemove(false); + //_workingDir.setAutoRemove(false); } void LatexProcess::makePreview(QString tikz) @@ -76,6 +76,10 @@ void LatexProcess::makePreview(QString tikz) // common windows tex directories texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin"; texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64"; + texDirs << "C:\\Program Files\\MiKTeX 2.8\\miktex\\bin"; + texDirs << "C:\\Program Files\\MiKTeX 2.8\\miktex\\bin\\x64"; + texDirs << "C:\\Program Files\\MiKTeX 2.7\\miktex\\bin"; + texDirs << "C:\\Program Files\\MiKTeX 2.7\\miktex\\bin\\x64"; _output->appendPlainText(texDirs.join(":")); pdflatex = QStandardPaths::findExecutable("pdflatex", texDirs); diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 2a7c00a..06777d1 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -429,7 +429,14 @@ void Tikzit::makePreview() } connect(_latex, SIGNAL(previewFinished()), this, SLOT(cleanupLatex())); - _latex->makePreview(activeWindow()->tikzSource()); + + if (activeWindow()->tikzDocument()->isEmpty()) { + _latex->makePreview("\\begin{tikzpicture}\n" + " \\node [style=none] (0) at (0,0) {};\n" + "\\end{tikzpicture}\n"); + } else { + _latex->makePreview(activeWindow()->tikzSource()); + } _preview->show(); } } -- cgit v1.2.3 From 561cc8b7ed11cbd9bb15d35491548acac57e1a70 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 6 Jan 2019 16:20:47 +0100 Subject: include extra dll in windows dist --- deploy-win.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy-win.bat b/deploy-win.bat index ba4d7b8..c40dd1d 100755 --- a/deploy-win.bat +++ b/deploy-win.bat @@ -10,6 +10,7 @@ copy ..\..\images\tikzdoc.ico icons\ copy ..\..\win32-deps\bin\*.dll . copy C:\OpenSSL-Win32\bin\libeay32.dll . copy C:\OpenSSL-Win32\bin\ssleay32.dll . +copy C:\Windows\System32\msvcr120.dll . windeployqt.exe --xml --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe -- cgit v1.2.3 From ad519c0f0dfab503d41a59d7129fb9a6c9682860 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 6 Jan 2019 16:59:44 +0100 Subject: revert previous --- deploy-win.bat | 1 - 1 file changed, 1 deletion(-) diff --git a/deploy-win.bat b/deploy-win.bat index c40dd1d..ba4d7b8 100755 --- a/deploy-win.bat +++ b/deploy-win.bat @@ -10,7 +10,6 @@ copy ..\..\images\tikzdoc.ico icons\ copy ..\..\win32-deps\bin\*.dll . copy C:\OpenSSL-Win32\bin\libeay32.dll . copy C:\OpenSSL-Win32\bin\ssleay32.dll . -copy C:\Windows\System32\msvcr120.dll . windeployqt.exe --xml --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe -- cgit v1.2.3 From 6fe55641057153e1a8f4da2e377150acd8a8cbd3 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 6 Jan 2019 18:02:17 +0100 Subject: fixed looseness/bend bug --- src/data/edge.cpp | 4 +--- src/data/graphelementdata.cpp | 3 ++- src/gui/latexprocess.cpp | 1 + tex/sample/sample.tikzstyles | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data/edge.cpp b/src/data/edge.cpp index afb1e57..864d5ed 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -254,8 +254,6 @@ void Edge::updateData() _data->unsetProperty("bend right"); _data->unsetProperty("looseness"); - // TODO: style handling? - if (_basicBendMode) { if (_bend != 0) { QString bendKey; @@ -280,7 +278,7 @@ void Edge::updateData() } if (_source == _target) _data->setAtom("loop"); - if (!isSelfLoop() && !isStraight() && almostEqual(_weight, 0.4)) + if (!isSelfLoop() && !isStraight() && !almostEqual(_weight, 0.4)) _data->setProperty("looseness", QString::number(_weight*2.5, 'f', 2)); if (_source->isBlankNode()) _sourceAnchor = "center"; else _sourceAnchor = ""; diff --git a/src/data/graphelementdata.cpp b/src/data/graphelementdata.cpp index f743bc5..cd09a6d 100644 --- a/src/data/graphelementdata.cpp +++ b/src/data/graphelementdata.cpp @@ -97,7 +97,8 @@ bool GraphElementData::hasProperty(QString key) bool GraphElementData::atom(QString atom) { - return (indexOfKey(atom) != -1); + int idx = indexOfKey(atom); + return (idx != -1 && _properties[idx].atom()); } int GraphElementData::indexOfKey(QString key) diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 8d720d5..426ea4a 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -107,6 +107,7 @@ void LatexProcess::makePreview(QString tikz) QTextStream tex(&f); tex << "\\documentclass{article}\n"; tex << "\\usepackage{tikzit}\n"; + tex << "\\tikzstyle{every picure}=[dotpic]\n"; tex << "\\usepackage[graphics,active,tightpage]{preview}\n"; tex << "\\PreviewEnvironment{tikzpicture}\n"; diff --git a/tex/sample/sample.tikzstyles b/tex/sample/sample.tikzstyles index 20a2bbc..f32728c 100644 --- a/tex/sample/sample.tikzstyles +++ b/tex/sample/sample.tikzstyles @@ -6,7 +6,7 @@ % Node styles \tikzstyle{red node}=[fill=red, tikzit category=nodes, shape=circle, draw=black] \tikzstyle{blue node}=[fill=blue, shape=circle, draw=black, tikzit category=nodes] -\tikzstyle{blue node 2}=[tikzit fill=green, fill=blue, shape=circle, draw=black, tikzit category=nodes] +\tikzstyle{green node}=[tikzit fill=green, fill=green, shape=circle, draw=black, tikzit category=nodes] \tikzstyle{yellow square}=[draw=black, fill=yellow, shape=rectangle] % Edge styles -- cgit v1.2.3 From 71199194c1eb77ccac750a4133e5c130d40fb680 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 6 Jan 2019 22:29:25 +0100 Subject: added [tikzfig] to preview and changed openssl DLLs in deploy script --- deploy-win.bat | 2 -- src/gui/latexprocess.cpp | 2 +- tex/sample/sample.tikzdefs | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/deploy-win.bat b/deploy-win.bat index ba4d7b8..b9871f2 100755 --- a/deploy-win.bat +++ b/deploy-win.bat @@ -8,8 +8,6 @@ copy ..\..\tikzfiles.reg . copy ..\..\release\tikzit.exe . copy ..\..\images\tikzdoc.ico icons\ copy ..\..\win32-deps\bin\*.dll . -copy C:\OpenSSL-Win32\bin\libeay32.dll . -copy C:\OpenSSL-Win32\bin\ssleay32.dll . windeployqt.exe --xml --no-webkit2 --no-angle --no-opengl-sw --no-system-d3d-compiler --no-translations --no-quick-import .\tikzit.exe diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 426ea4a..59db9ea 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -107,7 +107,7 @@ void LatexProcess::makePreview(QString tikz) QTextStream tex(&f); tex << "\\documentclass{article}\n"; tex << "\\usepackage{tikzit}\n"; - tex << "\\tikzstyle{every picure}=[dotpic]\n"; + tex << "\\tikzstyle{every picture}=[tikzfig]\n"; tex << "\\usepackage[graphics,active,tightpage]{preview}\n"; tex << "\\PreviewEnvironment{tikzpicture}\n"; diff --git a/tex/sample/sample.tikzdefs b/tex/sample/sample.tikzdefs index ac25b5a..4fd5bc9 100644 --- a/tex/sample/sample.tikzdefs +++ b/tex/sample/sample.tikzdefs @@ -2,5 +2,4 @@ % LaTeX preview. It can also be included in the paper. \usepackage{bm} - -\newcommand{\anglevec}[1]{\ensuremath{\vec{\bm{#1}}}} +\newcommand{\param}[1]{\ensuremath{\vec{\bm{#1}}}} -- cgit v1.2.3 From 10317d06974df2aca788d87814eca163b5878160 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 7 Jan 2019 17:32:31 +0100 Subject: updated build instructions --- README.md | 61 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 797b653..7b18ad5 100644 --- a/README.md +++ b/README.md @@ -5,23 +5,22 @@ TikZiT is a graphical tool for rapidly creating graphs and string diagrams using ## Building on Windows -TiKZiT can be built in Windows using Qt Creator (part of Qt for Windows) or Visual Studio with the Qt VS Tools extension. +TiKZiT can be built in Windows using Qt Creator (part of Qt for Windows) or from the command line. In either case, it is recommended you compile with mingw32, which is included in the official Qt distribution. There is no reason, in principle, that you couldn't use mingw64 or MSVC, but these haven't been tested. -To build with Qt Creator, simply click 'Open Project' and navigate to the `.pro` file in the TikZiT repo. +In addition to Qt itself, TikZiT needs flex/bison, Poppler (with Qt bindings), and OpenSSL. For flex/bison, the simplest way to install this is to download WinFlexBison, then make sure both are in your `%Path%` so the build tools can find them. Alternatively, you can install it via Chocolatey, via: -To install Qt VS Tools in Visual Studio 2017, go to `Tools > Extensions and Updates`, then click "Online" in the sidebar and search for Qt. Configure your Qt install under `Qt VS Tools > Qt Options`. If you installed Qt using the Windows package above, the path to Qt is probably something like `C:\Qt\5.XXX\msvc2017_64`. Once that is done, open the `.pro` file in the TikZiT repo via `Qt VS Tools > Open Qt Project File`. + > choco install winflexbison -The only dependency besides Qt itself is flex/bison, which is used to build the TikZ parser. The simplest way to install this is to download WinFlexBison, then make sure both are in your `%PATH%` so the build tools can find them. +For convenience, I have packaged up some headers and pre-built DLLs to take care of the Poppler and OpenSSL dependencies in a single shot. If you wish to use these, download win32-deps.zip and extract it into the source folder before building. At this point, you should be able to open `tikzit.pro` in Qt Creator and build the project. If you wish to build from the command line, make sure `mingw32-make.exe` is in your `%Path%`. For the version that comes with Qt, this is in `C:\Qt\Tools\mingw530_32\bin`. Then, from the command prompt, run: -You can alternatively build from the command line with mingw or Visual Studio, and install necessary dependencies via Chocolatey. This setup has been tested on Windows 10 with Visual Studio 2015 and Qt 5.11.1. After installing Qt 5.11 and Visual Studio, run the following commands in a `cmd` prompt: + > C:\Qt\5.XX.X\mingw53_32\bin\qtenv2.bat + > cd \path\to\tikzit + > qmake -r + > mingw32-make - - choco install winflexbison - C:\Qt\5.11.1\msvc2015_64\bin\qtenv2.bat - call "C:\ProgramFiles (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 - cd C:\path\to\tikzit - qmake - nmake +To get a portable directory, you can then (optionally) run: + + > deploy-win.bat @@ -29,48 +28,44 @@ You can alternatively build from the command line with mingw or Visual Studio, a This should be buildable in Linux using a "standard" dev setup (gcc, flex, bison, make) as well as Qt. It has been tested with Qt 5.9, which is packaged with Ubuntu 18.04 (Bionic Beaver). The setup on Ubuntu is: - $ sudo apt-get install flex bison qt5-default + $ sudo apt -y install flex bison qt5-default libpoppler-dev libpoppler-qt5-dev After that, building is: - $ qmake + $ qmake -r $ make +To get a portable directory, you can then (optionally) run: + + ./deploy-linux.sh + Building on other distributions should be similar. For Qt setup, you can find instructions for openSUSE and Arch Linux on the Qt wiki. ## Building on MacOS -You'll need developer tools and Qt5 installed. The latter can be installed using e.g. Homebrew, as follows: +You'll need developer tools, Qt5, and Poppler (with Qt bindings) installed. You can install these via Homebrew with the following commands: $ brew install qt5 + $ brew install poppler --with-qt -This doesn't add Qt binaries to the PATH by default, so you may wish to add this to your shell startup script: +This doesn't add Qt binaries to the `$PATH` by default, so you may wish either run: - export PATH="/usr/local/opt/qt/bin:$PATH" + $ brew link --force qt5 -Then, TikZiT is built just like a normal Qt project: +or add `/usr/local/opt/qt/bin` to your `$PATH`. Once this is done, TikZiT can be build from the command line via: - $ qmake + $ qmake -r $ make +To bundle the required libraries into `tikzit.app` and create a `.dmg` file, you can additionally run: + + $ ./deploy-osx.sh + On older systems (pre-10.11), you can build with Qt 5.6, which claims to support Mac OS as far back as Mountain Lion. It is installable via MacPorts: $ sudo port -N -k install qt56 $ export PATH=/opt/local/libexec/qt5/bin:$PATH -Then, you should be able to run `qmake && make`, as above. - - - - -## Building Poppler with Qt bindings - -Although TikZiT doesn't currently support PDF preview, it probably will in the near future via Poppler. Here's the instructions for building it as a developer. - -Poppler should be built from source to get the Qt5 bindings. If Qt is setup correctly, the configure script included with Poppler should enable these automatically. Also, note that clang needs to have C++11 features enabled to build successfully. TikZiT has been tested on MacOS with poppler-0.50.0 (available here), built with the following commands: - - $ CXXFLAGS="-std=c++11" ./configure - $ CXXFLAGS="-std=c++11" make - +I have only tested this with TikZiT 2.0, so to install Poppler (required by TikZiT >= 2.1), you are on your own. -- cgit v1.2.3 From 93598b62ba955fa80215315c750d8d6c76809c4d Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 7 Jan 2019 17:35:04 +0100 Subject: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b18ad5..fea1675 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ This doesn't add Qt binaries to the `$PATH` by default, so you may wish either r $ brew link --force qt5 -or add `/usr/local/opt/qt/bin` to your `$PATH`. Once this is done, TikZiT can be build from the command line via: +or add `/usr/local/opt/qt/bin` to your `$PATH`. Once this is done, TikZiT can be built from the command line via: $ qmake -r $ make -- cgit v1.2.3 From 3a179ba2230f7550a7a5a00899e326006d51c862 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 7 Jan 2019 17:37:13 +0100 Subject: typo2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fea1675..badcd22 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ You'll need developer tools, Qt5, and Poppler (with Qt bindings) installed. You $ brew install qt5 $ brew install poppler --with-qt -This doesn't add Qt binaries to the `$PATH` by default, so you may wish either run: +This doesn't add Qt binaries to the `$PATH` by default, so you may wish to either run: $ brew link --force qt5 -- cgit v1.2.3 From 7966858e937fe2018e57005c188468e99a3a0339 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 8 Jan 2019 10:45:55 +0100 Subject: changed menu entry --- src/gui/mainmenu.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 54b02f8..08067aa 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -349,7 +349,7 @@ - Run LaTeX + Make Preview Ctrl+R -- cgit v1.2.3 From 7807d9c60d2574fb58069eb3faf65cd478905ff7 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 8 Jan 2019 14:29:47 +0100 Subject: re-running preview brings it to front --- src/tikzit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 06777d1..8569817 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -438,6 +438,7 @@ void Tikzit::makePreview() _latex->makePreview(activeWindow()->tikzSource()); } _preview->show(); + _preview->raise(); } } -- cgit v1.2.3