summaryrefslogtreecommitdiff
path: root/src/gui/tikzview.cpp
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-01-04 16:00:52 +0100
committerAleks Kissinger <aleks0@gmail.com>2018-01-04 16:00:52 +0100
commit738ecbd5fad2b46836bfd6a94aeebf165ae2bbca (patch)
treedf04709807cc9ec8481a3ebc7d80ac25e5b2f457 /src/gui/tikzview.cpp
parent0421a96749743868554d44585050b1b3d04864d2 (diff)
relocated source code to the root
Diffstat (limited to 'src/gui/tikzview.cpp')
-rw-r--r--src/gui/tikzview.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp
new file mode 100644
index 0000000..fe6c401
--- /dev/null
+++ b/src/gui/tikzview.cpp
@@ -0,0 +1,84 @@
+#include "tikzview.h"
+#include "tikzit.h"
+
+#include <QDebug>
+
+TikzView::TikzView(QWidget *parent) : QGraphicsView(parent)
+{
+ setRenderHint(QPainter::Antialiasing);
+ setDragMode(QGraphicsView::RubberBandDrag);
+
+ _scale = 1.0f;
+}
+
+void TikzView::zoomIn()
+{
+ _scale *= 1.6f;
+ scale(1.6,1.6);
+}
+
+void TikzView::zoomOut()
+{
+ _scale *= 0.625f;
+ scale(0.625,0.625);
+}
+
+void TikzView::drawBackground(QPainter *painter, const QRectF &rect)
+{
+ // draw the grid
+ int step = GLOBAL_SCALE / 8;
+
+ QPen pen1;
+ pen1.setWidth(1);
+ pen1.setCosmetic(true);
+ pen1.setColor(QColor(230,230,230));
+
+ QPen pen2 = pen1;
+ pen2.setColor(QColor(200,200,200));
+
+ QPen pen3 = pen1;
+ pen3.setColor(QColor(160,160,160));
+
+ painter->setPen(pen1);
+
+ if (_scale > 0.2f) {
+ for (int x = -step; x > rect.left(); x -= step) {
+ if (x % (step * 8) != 0) painter->drawLine(x, rect.top(), x, rect.bottom());
+ }
+
+ for (int x = step; x < rect.right(); x += step) {
+ if (x % (step * 8) != 0) painter->drawLine(x, rect.top(), x, rect.bottom());
+ }
+
+ for (int y = -step; y > rect.top(); y -= step) {
+ if (y % (step * 8) != 0) painter->drawLine(rect.left(), y, rect.right(), y);
+ }
+
+ for (int y = step; y < rect.bottom(); y += step) {
+ if (y % (step * 8) != 0) painter->drawLine(rect.left(), y, rect.right(), y);
+ }
+ }
+
+ painter->setPen(pen2);
+
+ for (int x = -step*8; x > rect.left(); x -= step*8) {
+ painter->drawLine(x, rect.top(), x, rect.bottom());
+ }
+
+ for (int x = step*8; x < rect.right(); x += step*8) {
+ painter->drawLine(x, rect.top(), x, rect.bottom());
+ }
+
+ for (int y = -step*8; y > rect.top(); y -= step*8) {
+ painter->drawLine(rect.left(), y, rect.right(), y);
+ }
+
+ for (int y = step*8; y < rect.bottom(); y += step*8) {
+ painter->drawLine(rect.left(), y, rect.right(), y);
+ }
+
+ painter->setPen(pen3);
+ painter->drawLine(rect.left(), 0, rect.right(), 0);
+ painter->drawLine(0, rect.top(), 0, rect.bottom());
+}
+