tikzit.h 5.07 KB
Newer Older
Aleks Kissinger's avatar
Aleks Kissinger committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
    TikZiT - a GUI diagram editor for TikZ
    Copyright (C) 2018 Aleks Kissinger

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/


/*!
 *
 * \mainpage TikZiT Documentation
 *
 * This is the source code documentation for TikZiT. The global entry point
 * for the TikZiT executable is in main.cpp, whereas the class Tikzit maintains
 * the global application state.
 *
 * The TikZ parser is implemented in flex/bison in the files tikzlexer.l and tikzparser.y.
 *
 * Most of the interesting code for handling user input is in the class TikzScene. Anything
 * that makes a change to the tikz file should be implemented as a QUndoCommand. Currently,
 * these are all in undocommands.h.
 *
 * I've basically been adding documentation as I go. Other bits and pieces can be accessed
 * by searching, or via the class list/class hierarchy links in the menu above.
 *
 */

/*!
 *
 * \class Tikzit
 *
 * Tikzit is the top-level class which maintains the global application state. For convenience,
 * it also holds an instance of the main menu for macOS (or Ubuntu unity) style GUIs which only
 * have one, application-level menu.
 *
 */

#ifndef TIKZIT_H
#define TIKZIT_H

Aleks Kissinger's avatar
Aleks Kissinger committed
52
#define TIKZIT_VERSION "2.1.5"
Aleks Kissinger's avatar
Aleks Kissinger committed
53

Aleks Kissinger's avatar
Aleks Kissinger committed
54 55 56 57
#include "mainwindow.h"
#include "mainmenu.h"
#include "ui_mainmenu.h"

Aleks Kissinger's avatar
Aleks Kissinger committed
58
#include "styleeditor.h"
Aleks Kissinger's avatar
Aleks Kissinger committed
59 60 61 62
#include "toolpalette.h"
#include "propertypalette.h"
#include "stylepalette.h"
#include "tikzstyles.h"
Aleks Kissinger's avatar
Aleks Kissinger committed
63 64
#include "latexprocess.h"
#include "previewwindow.h"
Aleks Kissinger's avatar
Aleks Kissinger committed
65 66 67

#include <QObject>
#include <QVector>
68
#include <QStringList>
Aleks Kissinger's avatar
Aleks Kissinger committed
69 70 71 72
#include <QPointF>
#include <QMenuBar>
#include <QMainWindow>
#include <QFont>
73
#include <QColor>
74
#include <QNetworkReply>
Aleks Kissinger's avatar
Aleks Kissinger committed
75 76 77 78

// 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
79 80
#define GLOBAL_SCALEF 40.0
#define GLOBAL_SCALEF_INV 0.025
Aleks Kissinger's avatar
Aleks Kissinger committed
81 82 83 84
#define GRID_N 4
#define GRID_SEP 10
#define GRID_SEPF 10.0f

Aleks Kissinger's avatar
Aleks Kissinger committed
85

Aleks Kissinger's avatar
Aleks Kissinger committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
inline QPointF toScreen(QPointF src)
{ src.setY(-src.y()); src *= GLOBAL_SCALEF; return src; }

inline QPointF fromScreen(QPointF src)
{ src.setY(-src.y()); src *= GLOBAL_SCALEF_INV; return src; }

inline QRectF rectToScreen(QRectF src)
{ return QRectF(src.x()                 * GLOBAL_SCALEF,
                -(src.y()+src.height()) * GLOBAL_SCALEF,
                src.width()             * GLOBAL_SCALEF,
                src.height()            * GLOBAL_SCALEF); }

inline QRectF rectFromScreen(QRectF src)
{ return QRectF(src.x()                 * GLOBAL_SCALEF_INV,
                -(src.y()+src.height()) * GLOBAL_SCALEF_INV,
                src.width()             * GLOBAL_SCALEF_INV,
                src.height()            * GLOBAL_SCALEF_INV); }

class Tikzit : public QObject {
    Q_OBJECT
public:
    Tikzit();
    ToolPalette *toolPalette() const;
    PropertyPalette *propertyPalette() const;

    MainWindow *activeWindow() const;
    void setActiveWindow(MainWindow *activeWindow);
    void removeWindow(MainWindow *w);

    static QFont LABEL_FONT;

    void newDoc();
    void open();
	void open(QString fileName);
    void quit();
Aleks Kissinger's avatar
Aleks Kissinger committed
121
    void init();
Aleks Kissinger's avatar
Aleks Kissinger committed
122

123 124 125 126 127
    // convenience functions for named colors
    QColor colorByIndex(int i);
    QColor colorByName(QString name);
    QString nameForColor(QColor col);

128
    void newTikzStyles();
Aleks Kissinger's avatar
Aleks Kissinger committed
129
    void openTikzStyles();
130
    bool loadStyles(QString fileName);
Aleks Kissinger's avatar
Aleks Kissinger committed
131
    void showStyleEditor();
Aleks Kissinger's avatar
Aleks Kissinger committed
132 133 134 135
    TikzStyles *styles() const;
    QString styleFile() const;
    //StylePalette *stylePalette() const;

136
    QString styleFilePath() const;
137
    void updateRecentFiles();
138

139 140
    PreviewWindow *previewWindow() const;

Aleks Kissinger's avatar
Aleks Kissinger committed
141
public slots:
142
    void clearRecentFiles();
Aleks Kissinger's avatar
Aleks Kissinger committed
143
    void setCheckForUpdates(bool check);
Aleks Kissinger's avatar
Aleks Kissinger committed
144 145 146 147
    void checkForUpdates(bool manual);
    void updateAuto(QNetworkReply *reply);
    void updateManual(QNetworkReply *reply);
    void updateReply(QNetworkReply *reply, bool manual);
Aleks Kissinger's avatar
Aleks Kissinger committed
148 149
    void makePreview();
    void cleanupLatex();
Aleks Kissinger's avatar
Aleks Kissinger committed
150

Aleks Kissinger's avatar
Aleks Kissinger committed
151
private:
152 153 154 155 156
    /*!
     * \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();
Aleks Kissinger's avatar
Aleks Kissinger committed
157 158 159 160 161 162 163

    MainMenu *_mainMenu;
    ToolPalette *_toolPalette;
    PropertyPalette *_propertyPalette;
    //StylePalette *_stylePalette;
    TikzStyles *_styles;
    QString _styleFile;
164
    QString _styleFilePath;
Aleks Kissinger's avatar
Aleks Kissinger committed
165 166
    QVector<MainWindow*> _windows;
    MainWindow *_activeWindow;
Aleks Kissinger's avatar
Aleks Kissinger committed
167
    StyleEditor *_styleEditor;
168 169
    QStringList _colNames;
    QVector<QColor> _cols;
Aleks Kissinger's avatar
Aleks Kissinger committed
170 171
    LatexProcess *_latex;
    PreviewWindow *_preview;
Aleks Kissinger's avatar
Aleks Kissinger committed
172 173 174 175 176
};

extern Tikzit *tikzit;

#endif // TIKZIT_H