summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/mainwindow.cpp33
-rw-r--r--src/gui/mainwindow.h1
-rw-r--r--src/gui/nodeitem.cpp9
-rw-r--r--src/gui/preferencedialog.cpp2
-rw-r--r--src/gui/preferencedialog.ui17
-rw-r--r--src/gui/previewwindow.cpp23
-rw-r--r--src/gui/previewwindow.h2
-rw-r--r--src/gui/tikzview.cpp10
-rw-r--r--src/tikzit.cpp10
-rw-r--r--src/tikzit.h2
-rw-r--r--src/util.cpp84
-rw-r--r--src/util.h4
12 files changed, 165 insertions, 32 deletions
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index 71fea63..71b9070 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -46,19 +46,7 @@ MainWindow::MainWindow(QWidget *parent) :
_menu->setParent(this);
setMenuBar(_menu);
- QVariant geom = settings.value(QString("geometry-main-qt") + qVersion());
- QVariant state = settings.value(QString("windowState-main-qt") + qVersion());
-
- if (geom.isValid()) {
- restoreGeometry(geom.toByteArray());
- }
- if (state.isValid()) {
- restoreState(state.toByteArray(), 2);
- } else {
- addDockWidget(Qt::RightDockWidgetArea, _stylePalette);
- resizeDocks({_stylePalette}, {130}, Qt::Horizontal);
- }
// initially, the source view should be collapsed
QList<int> sz = ui->splitter->sizes();
@@ -76,6 +64,15 @@ MainWindow::MainWindow(QWidget *parent) :
#else
ui->tikzSource->setTabStopWidth(20);
#endif
+
+
+ QVariant state = settings.value(QString("windowState-main-qt") + qVersion());
+ if (state.isValid()) {
+ restoreState(state.toByteArray(), 2);
+ } else {
+ addDockWidget(Qt::RightDockWidgetArea, _stylePalette);
+ resizeDocks({_stylePalette}, {130}, Qt::Horizontal);
+ }
}
MainWindow::~MainWindow()
@@ -84,6 +81,18 @@ MainWindow::~MainWindow()
delete ui;
}
+void MainWindow::restorePosition()
+{
+ QSettings settings("tikzit", "tikzit");
+ QVariant geom = settings.value(QString("geometry-main-qt") + qVersion());
+
+ if (geom.isValid()) {
+ restoreGeometry(geom.toByteArray());
+ }
+
+
+}
+
void MainWindow::open(QString fileName)
{
_tikzDocument->open(fileName);
diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h
index 21fbd5a..48a88dd 100644
--- a/src/gui/mainwindow.h
+++ b/src/gui/mainwindow.h
@@ -29,6 +29,7 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
+ void restorePosition();
void open(QString fileName);
int windowId() const;
TikzView *tikzView() const;
diff --git a/src/gui/nodeitem.cpp b/src/gui/nodeitem.cpp
index 78fe66e..82692f2 100644
--- a/src/gui/nodeitem.cpp
+++ b/src/gui/nodeitem.cpp
@@ -19,6 +19,7 @@
#include "tikzit.h"
#include "nodeitem.h"
#include "tikzscene.h"
+#include "util.h"
#include <cmath>
#include <QPen>
@@ -50,7 +51,7 @@ void NodeItem::writePos()
}
QRectF NodeItem::labelRect() const {
- QString label = _node->label();
+ QString label = replaceTexConstants(_node->label());
QFontMetrics fm(Tikzit::LABEL_FONT);
QRectF rect = fm.boundingRect(label);
rect.moveCenter(QPointF(0,0));
@@ -58,7 +59,7 @@ QRectF NodeItem::labelRect() const {
}
QRectF NodeItem::outerLabelRect() const {
- QString label = _node->data()->property("label");
+ QString label = replaceTexConstants(_node->data()->property("label"));
label.replace(QRegularExpression("^[^:]*:"), "");
QFontMetrics fm(Tikzit::LABEL_FONT);
QRectF rect = fm.boundingRect(label);
@@ -102,11 +103,11 @@ void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
painter->setPen(QPen(Qt::black));
painter->setFont(Tikzit::LABEL_FONT);
- painter->drawText(rect, Qt::AlignCenter, _node->label());
+ painter->drawText(rect, Qt::AlignCenter, replaceTexConstants(_node->label()));
}
if (_node->data()->hasProperty("label")) {
- QString label = _node->data()->property("label");
+ QString label = replaceTexConstants(_node->data()->property("label"));
label.replace(QRegularExpression("^[^:]*:"), "");
QRectF rect = outerLabelRect();
diff --git a/src/gui/preferencedialog.cpp b/src/gui/preferencedialog.cpp
index 14cacf0..0fdd5c3 100644
--- a/src/gui/preferencedialog.cpp
+++ b/src/gui/preferencedialog.cpp
@@ -31,6 +31,7 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) :
connect(ui->minorColor, SIGNAL(clicked()), this, SLOT(colorClick()));
ui->selectNewEdges->setChecked(settings.value("select-new-edges", false).toBool());
+ ui->shiftToScroll->setChecked(settings.value("shift-to-scroll", false).toBool());
}
PreferenceDialog::~PreferenceDialog()
@@ -47,6 +48,7 @@ void PreferenceDialog::accept()
settings.setValue("grid-color-major", color(ui->majorColor));
settings.setValue("grid-color-minor", color(ui->minorColor));
settings.setValue("select-new-edges", ui->selectNewEdges->isChecked());
+ settings.setValue("shift-to-scroll", ui->shiftToScroll->isChecked());
QDialog::accept();
}
diff --git a/src/gui/preferencedialog.ui b/src/gui/preferencedialog.ui
index 80bdc57..894d356 100644
--- a/src/gui/preferencedialog.ui
+++ b/src/gui/preferencedialog.ui
@@ -47,7 +47,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
- <string>Grid colors</string>
+ <string>Grid Colors</string>
</property>
</widget>
</item>
@@ -220,17 +220,24 @@
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
- <string>Auto-select new edges</string>
+ <string>UI Options</string>
</property>
</widget>
</item>
- <item row="4" column="1">
+ <item row="5" column="1">
<widget class="QCheckBox" name="selectNewEdges">
<property name="text">
- <string/>
+ <string>Auto-select new edges</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QCheckBox" name="shiftToScroll">
+ <property name="text">
+ <string>Hold shift to scroll with wheel or touchpad</string>
</property>
</widget>
</item>
diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp
index acce1a1..4906484 100644
--- a/src/gui/previewwindow.cpp
+++ b/src/gui/previewwindow.cpp
@@ -41,15 +41,10 @@ PreviewWindow::PreviewWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::PreviewWindow)
{
- QSettings settings("tikzit", "tikzit");
- ui->setupUi(this);
- QVariant geom = settings.value(QString("geometry-preview-qt") + qVersion());
-
- if (geom.isValid()) {
- restoreGeometry(geom.toByteArray());
- }
+ ui->setupUi(this);
+ _positionRestored = false;
_doc = nullptr;
_loader = new QLabel(ui->tabWidget->tabBar());
@@ -90,6 +85,20 @@ PreviewWindow::~PreviewWindow()
delete ui;
}
+void PreviewWindow::restorePosition()
+{
+ // only restore position 1 time
+ if (_positionRestored) return;
+
+ QSettings settings("tikzit", "tikzit");
+ QVariant geom = settings.value(QString("geometry-preview-qt") + qVersion());
+
+ if (geom.isValid()) {
+ restoreGeometry(geom.toByteArray());
+ }
+ _positionRestored = true;
+}
+
void PreviewWindow::setPdf(QString file)
{
// use loadFromData to avoid holding a lock on the PDF file in windows
diff --git a/src/gui/previewwindow.h b/src/gui/previewwindow.h
index a14303b..0cb10aa 100644
--- a/src/gui/previewwindow.h
+++ b/src/gui/previewwindow.h
@@ -46,6 +46,7 @@ public:
};
explicit PreviewWindow(QWidget *parent = nullptr);
~PreviewWindow() override;
+ void restorePosition();
void setPdf(QString file);
QString preparePreview(QString tikz);
QPlainTextEdit *outputTextEdit();
@@ -67,6 +68,7 @@ private:
Ui::PreviewWindow *ui;
PdfDocument *_doc;
QLabel *_loader;
+ bool _positionRestored;
};
#endif // PREVIEWWINDOW_H
diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp
index ddbc404..3615685 100644
--- a/src/gui/tikzview.cpp
+++ b/src/gui/tikzview.cpp
@@ -134,10 +134,16 @@ void TikzView::drawBackground(QPainter *painter, const QRectF &rect)
void TikzView::wheelEvent(QWheelEvent *event)
{
- if (event->modifiers() & Qt::ShiftModifier) {
+ QSettings settings("tikzit", "tikzit");
+ bool shiftScroll = settings.value("shift-to-scroll", false).toBool();
+ if ((!shiftScroll && event->modifiers() == Qt::NoModifier) ||
+ (shiftScroll && (event->modifiers() == Qt::ShiftModifier)))
+ {
event->setModifiers(Qt::NoModifier);
QGraphicsView::wheelEvent(event);
- } else if (event->modifiers() & Qt::ControlModifier) {
+ }
+
+ if (event->modifiers() & Qt::ControlModifier) {
if (event->angleDelta().y() > 0) {
zoomIn();
} else if (event->angleDelta().y() < 0) {
diff --git a/src/tikzit.cpp b/src/tikzit.cpp
index 8569817..a286630 100644
--- a/src/tikzit.cpp
+++ b/src/tikzit.cpp
@@ -21,6 +21,7 @@
#include "tikzstyles.h"
#include "previewwindow.h"
#include "latexprocess.h"
+#include "util.h"
#include <QFile>
#include <QFileDialog>
@@ -47,6 +48,7 @@ void Tikzit::init()
QSettings settings("tikzit", "tikzit");
initColors();
+ initTexConstants();
_mainMenu = new MainMenu();
QMainWindow *dummy = new QMainWindow();
@@ -61,6 +63,7 @@ void Tikzit::init()
//_stylePalette->show();
_windows << new MainWindow();
_windows[0]->show();
+ _windows[0]->restorePosition();
_styleFile = "";
_styleFilePath = "";
@@ -187,6 +190,7 @@ void Tikzit::newDoc()
{
MainWindow *w = new MainWindow();
w->show();
+ w->restorePosition();
_windows << w;
}
@@ -250,6 +254,7 @@ void Tikzit::open(QString fileName)
MainWindow *w = new MainWindow();
_windows << w;
w->show();
+ w->restorePosition();
w->open(fileName);
}
}
@@ -437,7 +442,12 @@ void Tikzit::makePreview()
} else {
_latex->makePreview(activeWindow()->tikzSource());
}
+
_preview->show();
+
+ // restores position from settings the first time this is called, otherwise
+ // do nothing.
+ _preview->restorePosition();
_preview->raise();
}
}
diff --git a/src/tikzit.h b/src/tikzit.h
index 4b99062..94aba9d 100644
--- a/src/tikzit.h
+++ b/src/tikzit.h
@@ -49,7 +49,7 @@
#ifndef TIKZIT_H
#define TIKZIT_H
-#define TIKZIT_VERSION "2.1.3"
+#define TIKZIT_VERSION "2.1.4"
#include "mainwindow.h"
#include "mainmenu.h"
diff --git a/src/util.cpp b/src/util.cpp
index 304f9e7..75cfa76 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -21,7 +21,7 @@
qreal bezierInterpolate(qreal dist, qreal c0, qreal c1, qreal c2, qreal c3) {
qreal distp = 1 - dist;
- return (distp*distp*distp) * c0 +
+ return (distp*distp*distp) * c0 +
3 * (distp*distp) * dist * c1 +
3 * (dist*dist) * distp * c2 +
(dist*dist*dist) * c3;
@@ -80,3 +80,85 @@ QString floatToString(qreal f) {
else return QString::number(f);
}
+
+static QList<QString> texConstantNames;
+static QList<QString> texConstantCodes;
+static QList<QString> texModifierNames;
+
+
+void initTexConstants() {
+ texConstantNames
+ << "\\alpha" << "\\beta" << "\\gamma" << "\\delta" << "\\epsilon"
+ << "\\zeta" << "\\eta" << "\\theta" << "\\iota" << "\\kappa"
+ << "\\lambda" << "\\mu" << "\\nu" << "\\xi" << "\\pi"
+ << "\\rho" << "\\sigma" << "\\tau" << "\\upsilon" << "\\phi"
+ << "\\chi" << "\\psi" << "\\omega"
+
+ << "\\Gamma" << "\\Delta" << "\\Theta" << "\\Lambda" << "\\Xi"
+ << "\\Pi" << "\\Sigma" << "\\Upsilon" << "\\Phi" << "\\Psi"
+ << "\\Omega"
+
+ << "\\pm" << "\\to" << "\\Rightarrow" << "\\Leftrightarrow" << "\\forall"
+ << "\\partial" << "\\exists" << "\\emptyset" << "\\nabla" << "\\in"
+ << "\\notin" << "\\prod" << "\\sum" << "\\surd" << "\\infty"
+ << "\\wedge" << "\\vee" << "\\cap" << "\\cup" << "\\int"
+ << "\\approx" << "\\neq" << "\\equiv" << "\\leq" << "\\geq"
+ << "\\subset" << "\\supset"
+
+ << "\\ldots" << "\\vdots" << "\\cdots" << "\\ddots" << "\\iddots"
+ << "\\cdot";
+
+ texConstantCodes
+ << "\u03b1" << "\u03b2" << "\u03b3" << "\u03b4" << "\u03b5"
+ << "\u03b6" << "\u03b7" << "\u03b8" << "\u03b9" << "\u03ba"
+ << "\u03bb" << "\u03bc" << "\u03bd" << "\u03be" << "\u03c0"
+ << "\u03c1" << "\u03c3" << "\u03c4" << "\u03c5" << "\u03c6"
+ << "\u03c7" << "\u03c8" << "\u03c9"
+
+ << "\u0393" << "\u0394" << "\u0398" << "\u039b" << "\u039e"
+ << "\u03a0" << "\u03a3" << "\u03a5" << "\u03a6" << "\u03a8"
+ << "\u03a9"
+
+ << "\u00b1" << "\u2192" << "\u21d2" << "\u21d4" << "\u2200"
+ << "\u2202" << "\u2203" << "\u2205" << "\u2207" << "\u2208"
+ << "\u2209" << "\u220f" << "\u2211" << "\u221a" << "\u221e"
+ << "\u2227" << "\u2228" << "\u2229" << "\u222a" << "\u222b"
+ << "\u2248" << "\u2260" << "\u2261" << "\u2264" << "\u2265"
+ << "\u2282" << "\u2283"
+
+ << "\u2026" << "\u22ee" << "\u22ef" << "\u22f1" << "\u22f0"
+ << "\u22c5";
+
+ texModifierNames
+ << "\\tiny"
+ << "\\scriptsize"
+ << "\\footnotesize"
+ << "\\small"
+ << "\\normalsize"
+ << "\\large"
+ << "\\Large"
+ << "\\LARGE"
+ << "\\huge"
+ << "\\Huge";
+}
+
+QString replaceTexConstants(QString s) {
+ QString s1 = s;
+ for (int i = 0; i < texConstantNames.length(); ++i) {
+ s1 = s1.replace(texConstantNames[i], texConstantCodes[i]);
+ }
+
+ for (int i = 0; i < texModifierNames.length(); ++i) {
+ s1 = s1.replace(texModifierNames[i], "");
+ }
+
+ if (s1.startsWith('$') && s1.endsWith('$')) {
+ s1 = s1.mid(1, s1.length()-2);
+ }
+
+ return s1;
+}
+
+
+
+
diff --git a/src/util.h b/src/util.h
index 5d1073a..3ddaf17 100644
--- a/src/util.h
+++ b/src/util.h
@@ -48,4 +48,8 @@ qreal degreesToRadians(qreal degrees);
int normaliseAngleDeg (int degrees);
qreal normaliseAngleRad (qreal rads);
+// strings
+void initTexConstants();
+QString replaceTexConstants(QString s);
+
#endif // UTIL_H