From b4f6b3997ba1d1355a42e6d2cd90e7715a9f9114 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 20 Jan 2017 11:25:28 +0100 Subject: directory structure --- tikzit/src/data/edge.cpp | 19 +++ tikzit/src/data/edge.h | 26 ++++ tikzit/src/data/graph.cpp | 30 ++++ tikzit/src/data/graph.h | 32 +++++ tikzit/src/data/graphelementdata.cpp | 135 ++++++++++++++++++ tikzit/src/data/graphelementdata.h | 61 +++++++++ tikzit/src/data/graphelementproperty.cpp | 45 ++++++ tikzit/src/data/graphelementproperty.h | 38 ++++++ tikzit/src/data/node.cpp | 43 ++++++ tikzit/src/data/node.h | 34 +++++ tikzit/src/data/tikzgraphassembler.cpp | 9 ++ tikzit/src/data/tikzgraphassembler.h | 25 ++++ tikzit/src/data/tikzlexer.lpp | 171 +++++++++++++++++++++++ tikzit/src/data/tikzparser.ypp | 228 +++++++++++++++++++++++++++++++ tikzit/src/data/tikzparserdefs.h | 2 + tikzit/src/gui/mainwindow.cpp | 23 ++++ tikzit/src/gui/mainwindow.h | 25 ++++ tikzit/src/gui/mainwindow.ui | 76 +++++++++++ tikzit/src/gui/propertypalette.cpp | 26 ++++ tikzit/src/gui/propertypalette.h | 22 +++ tikzit/src/gui/propertypalette.ui | 30 ++++ tikzit/src/gui/tikzscene.cpp | 6 + tikzit/src/gui/tikzscene.h | 13 ++ tikzit/src/gui/toolpalette.cpp | 39 ++++++ tikzit/src/gui/toolpalette.h | 22 +++ tikzit/src/main.cpp | 23 ++++ 26 files changed, 1203 insertions(+) create mode 100644 tikzit/src/data/edge.cpp create mode 100644 tikzit/src/data/edge.h create mode 100644 tikzit/src/data/graph.cpp create mode 100644 tikzit/src/data/graph.h create mode 100644 tikzit/src/data/graphelementdata.cpp create mode 100644 tikzit/src/data/graphelementdata.h create mode 100644 tikzit/src/data/graphelementproperty.cpp create mode 100644 tikzit/src/data/graphelementproperty.h create mode 100644 tikzit/src/data/node.cpp create mode 100644 tikzit/src/data/node.h create mode 100644 tikzit/src/data/tikzgraphassembler.cpp create mode 100644 tikzit/src/data/tikzgraphassembler.h create mode 100644 tikzit/src/data/tikzlexer.lpp create mode 100644 tikzit/src/data/tikzparser.ypp create mode 100644 tikzit/src/data/tikzparserdefs.h create mode 100644 tikzit/src/gui/mainwindow.cpp create mode 100644 tikzit/src/gui/mainwindow.h create mode 100644 tikzit/src/gui/mainwindow.ui create mode 100644 tikzit/src/gui/propertypalette.cpp create mode 100644 tikzit/src/gui/propertypalette.h create mode 100644 tikzit/src/gui/propertypalette.ui create mode 100644 tikzit/src/gui/tikzscene.cpp create mode 100644 tikzit/src/gui/tikzscene.h create mode 100644 tikzit/src/gui/toolpalette.cpp create mode 100644 tikzit/src/gui/toolpalette.h create mode 100644 tikzit/src/main.cpp (limited to 'tikzit/src') diff --git a/tikzit/src/data/edge.cpp b/tikzit/src/data/edge.cpp new file mode 100644 index 0000000..bea96b8 --- /dev/null +++ b/tikzit/src/data/edge.cpp @@ -0,0 +1,19 @@ +#include "edge.h" + +Edge::Edge(Node *s, Node *t, QObject *parent) : + QObject(parent), _source(s), _target(t) +{ + +} + +Node *Edge::source() const +{ + return _source; +} + +Node *Edge::target() const +{ + return _target; +} + + diff --git a/tikzit/src/data/edge.h b/tikzit/src/data/edge.h new file mode 100644 index 0000000..2153f30 --- /dev/null +++ b/tikzit/src/data/edge.h @@ -0,0 +1,26 @@ +#ifndef EDGE_H +#define EDGE_H + +#include + +class Node; + +class Edge : public QObject +{ + Q_OBJECT +public: + explicit Edge(Node *s, Node *t, QObject *parent = 0); + + Node *source() const; + Node *target() const; + +signals: + +public slots: + +private: + Node *_source; + Node *_target; +}; + +#endif // EDGE_H diff --git a/tikzit/src/data/graph.cpp b/tikzit/src/data/graph.cpp new file mode 100644 index 0000000..0db20e1 --- /dev/null +++ b/tikzit/src/data/graph.cpp @@ -0,0 +1,30 @@ +#include "graph.h" + +Graph::Graph(QObject *parent) : QObject(parent) +{ + +} + +void Graph::removeNode(Node *n) { + nodes.removeAll(n); + inEdges.remove(n); + outEdges.remove(n); +} + +Edge *Graph::addEdge(Node *s, Node *t) +{ + +} + +void Graph::removeEdge(Edge *e) +{ + +} + +Node *Graph::addNode() { + Node *n = new Node(this); + nodes << n; + return n; +} + + diff --git a/tikzit/src/data/graph.h b/tikzit/src/data/graph.h new file mode 100644 index 0000000..f55b3c9 --- /dev/null +++ b/tikzit/src/data/graph.h @@ -0,0 +1,32 @@ +#ifndef GRAPH_H +#define GRAPH_H + +#include "node.h" +#include "edge.h" + +#include +#include +#include + +class Graph : public QObject +{ + Q_OBJECT +public: + explicit Graph(QObject *parent = 0); + Node *addNode(); + void removeNode(Node *n); + Edge *addEdge(Node *s, Node*t); + void removeEdge(Edge *e); + +signals: + +public slots: + +private: + QVector nodes; + QVector edges; + QMultiHash inEdges; + QMultiHash outEdges; +}; + +#endif // GRAPH_H diff --git a/tikzit/src/data/graphelementdata.cpp b/tikzit/src/data/graphelementdata.cpp new file mode 100644 index 0000000..04c7760 --- /dev/null +++ b/tikzit/src/data/graphelementdata.cpp @@ -0,0 +1,135 @@ +#include "graphelementdata.h" + +#include + +GraphElementData::GraphElementData(QObject *parent) : QAbstractItemModel(parent) +{ + root = new GraphElementProperty(); +} + +GraphElementData::~GraphElementData() +{ + delete root; +} + +void GraphElementData::setProperty(QString key, QString value) +{ + GraphElementProperty m(key, true); + int i = _properties.indexOf(m); + if (i != -1) { + _properties[i].setValue(value); + } else { + GraphElementProperty p(key, value); + _properties << p; + } +} + +void GraphElementData::unsetProperty(QString key) +{ + GraphElementProperty m(key, true); + int i = _properties.indexOf(m); + if (i != -1) + _properties.remove(i); +} + +void GraphElementData::setAtom(QString atom) +{ + GraphElementProperty a(atom); + int i = _properties.indexOf(a); + if (i == -1) + _properties << a; +} + +void GraphElementData::unsetAtom(QString atom) +{ + GraphElementProperty a(atom); + int i = _properties.indexOf(a); + if (i != -1) + _properties.remove(i); +} + +QString GraphElementData::property(QString key) +{ + GraphElementProperty m(key, true); + int i = _properties.indexOf(m); + if (i != -1) { + return _properties[i].value(); + } else { + return 0; + } +} + +bool GraphElementData::atom(QString atom) +{ + GraphElementProperty a(atom); + return (_properties.indexOf(a) != -1); +} + +QVariant GraphElementData::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (index.row() >= 0 && index.row() < _properties.length()) { + const GraphElementProperty &p = _properties[index.row()]; + QString s = (index.column() == 0) ? p.key() : p.value(); + return QVariant(s); + } +} + +QVariant GraphElementData::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + if (section == 0) return QVariant("Key/Atom"); + else return QVariant("Value"); + } + + return QVariant(); +} + +QModelIndex GraphElementData::index(int row, int column, const QModelIndex &parent) const +{ + return createIndex(row, column, (void*)0); +} + +QModelIndex GraphElementData::parent(const QModelIndex &index) const +{ + GraphElementProperty *p = static_cast(index.internalPointer()); + if (p == root) return QModelIndex(); + else return createIndex(0,0,static_cast(root)); +} + +int GraphElementData::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } else { + return _properties.size(); + } +} + +int GraphElementData::columnCount(const QModelIndex &parent) const +{ + return 2; +} + +Qt::ItemFlags GraphElementData::flags(const QModelIndex &index) const +{ + return QAbstractItemModel::flags(index); +} + +//bool GraphElementData::setData(const QModelIndex &index, const QVariant &value, int role) +//{ + +//} + +//bool GraphElementData::insertRows(int position, int rows, const QModelIndex &parent) +//{ + +//} + +//bool GraphElementData::removeRows(int position, int rows, const QModelIndex &parent) +//{ + +//} + diff --git a/tikzit/src/data/graphelementdata.h b/tikzit/src/data/graphelementdata.h new file mode 100644 index 0000000..fee65e7 --- /dev/null +++ b/tikzit/src/data/graphelementdata.h @@ -0,0 +1,61 @@ +#ifndef GRAPHELEMENTDATA_H +#define GRAPHELEMENTDATA_H + +#include "graphelementproperty.h" + +#include +#include +#include +#include +#include + +class GraphElementData : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit GraphElementData(QObject *parent = 0); + ~GraphElementData(); + void setProperty(QString key, QString value); + void unsetProperty(QString key); + void setAtom(QString atom); + void unsetAtom(QString atom); + QString property(QString key); + bool atom(QString atom); + + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; + + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; + +// bool setData(const QModelIndex &index, const QVariant &value, +// int role = Qt::EditRole) Q_DECL_OVERRIDE; +// bool setHeaderData(int section, Qt::Orientation orientation, +// const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; + +// bool insertColumns(int position, int columns, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; +// bool removeColumns(int position, int columns, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; +// bool insertRows(int position, int rows, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; +// bool removeRows(int position, int rows, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + +signals: + +public slots: + +private: + QVector _properties; + GraphElementProperty *root; +}; + +#endif // GRAPHELEMENTDATA_H diff --git a/tikzit/src/data/graphelementproperty.cpp b/tikzit/src/data/graphelementproperty.cpp new file mode 100644 index 0000000..9cc6b00 --- /dev/null +++ b/tikzit/src/data/graphelementproperty.cpp @@ -0,0 +1,45 @@ +#include "graphelementproperty.h" + +GraphElementProperty::GraphElementProperty (): + _key(""), _value(""), _atom(false), _keyMatch(false) +{} + +GraphElementProperty::GraphElementProperty(QString key, QString value, bool atom, bool keyMatch) : + _key(key), _value(value), _atom(atom), _keyMatch(keyMatch) +{} + +GraphElementProperty::GraphElementProperty(QString key, QString value) : + _key(key), _value(value), _atom(false), _keyMatch(false) +{} + +GraphElementProperty::GraphElementProperty(QString key, bool keyMatch) : + _key(key), _value(""), _atom(!keyMatch), _keyMatch(keyMatch) +{} + +QString GraphElementProperty::key() const +{ return _key; } + +QString GraphElementProperty::value() const +{ return _value; } + +void GraphElementProperty::setValue(const QString &value) +{ _value = value; } + +bool GraphElementProperty::atom() const +{ return _atom; } + +bool GraphElementProperty::keyMatch() const +{ return _keyMatch; } + +bool GraphElementProperty::matches(const GraphElementProperty &p) +{ + if (p.atom()) return _atom && _key == p.key(); + if (p.keyMatch()) return !_atom && _key == p.key(); + if (_keyMatch) return !p.atom() && _key == p.key(); + return !_atom && _key == p.key() && _value == p.value(); +} + +bool GraphElementProperty::operator==(const GraphElementProperty &p) +{ + return matches(p); +} diff --git a/tikzit/src/data/graphelementproperty.h b/tikzit/src/data/graphelementproperty.h new file mode 100644 index 0000000..4e8bbd1 --- /dev/null +++ b/tikzit/src/data/graphelementproperty.h @@ -0,0 +1,38 @@ +#ifndef GRAPHELEMENTPROPERTY_H +#define GRAPHELEMENTPROPERTY_H + +#include + +class GraphElementProperty +{ +public: + GraphElementProperty(); + GraphElementProperty(QString key, QString value, bool atom, bool keyMatch); + + // construct a property + GraphElementProperty(QString key, QString value); + + // construct an atom or keymatch + GraphElementProperty(QString key, bool keyMatch = false); + + QString key() const; + QString value() const; + void setValue(const QString &value); + bool atom() const; + bool keyMatch() const; + + bool matches(const GraphElementProperty &p); + bool operator==(const GraphElementProperty &p); + +signals: + +public slots: + +private: + QString _key; + QString _value; + bool _atom; + bool _keyMatch; +}; + +#endif // GRAPHELEMENTPROPERTY_H diff --git a/tikzit/src/data/node.cpp b/tikzit/src/data/node.cpp new file mode 100644 index 0000000..2c1c7ee --- /dev/null +++ b/tikzit/src/data/node.cpp @@ -0,0 +1,43 @@ +#include "node.h" + +#include + +Node::Node(QObject *parent) : QObject(parent) +{ + qDebug() << "Node()"; +} + +Node::~Node() +{ + qDebug() << "~Node()"; +} + +QPointF Node::pos() const +{ + return _pos; +} + +void Node::setPos(const QPointF &pos) +{ + _pos = pos; +} + +QString Node::name() const +{ + return _name; +} + +void Node::setName(const QString &name) +{ + _name = name; +} + +QString Node::label() const +{ + return _label; +} + +void Node::setLabel(const QString &label) +{ + _label = label; +} diff --git a/tikzit/src/data/node.h b/tikzit/src/data/node.h new file mode 100644 index 0000000..8eae520 --- /dev/null +++ b/tikzit/src/data/node.h @@ -0,0 +1,34 @@ +#ifndef NODE_H +#define NODE_H + +#include +#include +#include + +class Node : public QObject +{ + Q_OBJECT +public: + explicit Node(QObject *parent = 0); + ~Node(); + + QPointF pos() const; + void setPos(const QPointF &pos); + + QString name() const; + void setName(const QString &name); + + QString label() const; + void setLabel(const QString &label); + +signals: + +public slots: + +private: + QPointF _pos; + QString _name; + QString _label; +}; + +#endif // NODE_H diff --git a/tikzit/src/data/tikzgraphassembler.cpp b/tikzit/src/data/tikzgraphassembler.cpp new file mode 100644 index 0000000..a785d85 --- /dev/null +++ b/tikzit/src/data/tikzgraphassembler.cpp @@ -0,0 +1,9 @@ +#include "tikzgraphassembler.h" + +TikzGraphAssembler::TikzGraphAssembler(QObject *parent) : QObject(parent) +{ + +} + +void TikzGraphAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); } +Node *TikzGraphAssembler::nodeWithName(QString name) { return _nodeMap[name]; } diff --git a/tikzit/src/data/tikzgraphassembler.h b/tikzit/src/data/tikzgraphassembler.h new file mode 100644 index 0000000..5869d95 --- /dev/null +++ b/tikzit/src/data/tikzgraphassembler.h @@ -0,0 +1,25 @@ +#ifndef TIKZGRAPHASSEMBLER_H +#define TIKZGRAPHASSEMBLER_H + +#include "node.h" + +#include +#include + +class TikzGraphAssembler : public QObject +{ + Q_OBJECT +public: + explicit TikzGraphAssembler(QObject *parent = 0); + void addNodeToMap(Node *n); + Node *nodeWithName(QString name); + +signals: + +public slots: + +private: + QHash _nodeMap; +}; + +#endif // TIKZGRAPHASSEMBLER_H diff --git a/tikzit/src/data/tikzlexer.lpp b/tikzit/src/data/tikzlexer.lpp new file mode 100644 index 0000000..19c4d85 --- /dev/null +++ b/tikzit/src/data/tikzlexer.lpp @@ -0,0 +1,171 @@ +%{ +/* + * Copyright 2010 Chris Heunen + * Copyright 2010-2013 Aleks Kissinger + * Copyright 2013 K. Johan Paulsson + * Copyright 2013 Alex Merry + * + * 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 2 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 "tikzparserdefs.h" +#include "tikzparser.h" + +#include + +#define YY_USER_ACTION \ + yylloc->first_line = yylloc->last_line; \ + yylloc->first_column = yylloc->last_column + 1; \ + yylloc->last_column = yylloc->first_column + yyleng - 1; + +%} + +%option reentrant bison-bridge bison-locations 8bit +%option nounput +%option yylineno +%option noyywrap +%option header-file="common/tikzlexer.h" +%option extra-type="TikzGraphAssembler *" + + +%s props +%s xcoord +%s ycoord +%s noderef + +FLOAT \-?[0-9]*(\.[0-9]+)? + +%% + + /* whitespace is ignored, except for position counting; we don't + count formfeed and vtab as whitespace, because it's not obvious + how they should be dealt with and no-one actually uses them */ + + /* lex will take the longest-matching string */ +\r\n|\r|\n { + yylloc->first_line += 1; + yylloc->last_line = yylloc->first_line; + yylloc->first_column = yylloc->last_column = 0; +} +[\t ]+ { } + +\\begin\{tikzpicture\} { return BEGIN_TIKZPICTURE_CMD; } +\\end\{tikzpicture\} { return END_TIKZPICTURE_CMD; } +\\begin\{pgfonlayer\} { return BEGIN_PGFONLAYER_CMD; } +\\end\{pgfonlayer\} { return END_PGFONLAYER_CMD; } +\\draw { return DRAW_CMD; } +\\node { return NODE_CMD; } +\\path { return PATH_CMD; } +rectangle { return RECTANGLE; } +node { return NODE; } +at { return AT; } +to { return TO; } +; { return SEMICOLON; } + +\([ ]*{FLOAT}[ ]*,[ ]*{FLOAT}[ ]*\) { + yylloc->last_column = yylloc->first_column + 1; + yyless(1); + BEGIN(xcoord); +} +{FLOAT} { + yylval->pt.x=(float)strtod(yytext,NULL); + BEGIN(ycoord); +} +, { } +{FLOAT} { + yylval->pt.y=(float)strtod(yytext,NULL); +} +\) { + BEGIN(INITIAL); + return COORD; +} + + /* when we see "[", change parsing mode */ +\[ /*syntaxhlfix]*/ { + BEGIN(props); + return LEFTBRACKET; +} += { return EQUALS; } +, { return COMMA; } + /* technically, it is possible to have newlines in the middle of + property names or values, but in practice this is unlikely and + screws up our line counting */ +[^=,\{\] \t\n]([^=,\{\]\n]*[^=,\{\] \t\n])? { + yylval->nsstr=[NSString stringWithUTF8String:yytext]; + return PROPSTRING; +} +\] { + BEGIN(INITIAL); + return RIGHTBRACKET; +} + +\( { + BEGIN(noderef); + return LEFTPARENTHESIS; +} +\. { + return FULLSTOP; +} + /* we assume node names (and anchor names) never contain + newlines */ +[^\.\{\)\n]+ { + yylval->nsstr=[NSString stringWithUTF8String:yytext]; + return REFSTRING; +} +\) { + BEGIN(INITIAL); + return RIGHTPARENTHESIS; +} + +\{ { + NSMutableString *buf = [NSMutableString string]; + unsigned int brace_depth = 1; + unsigned int escape = 0; + while (1) { + char c = input(yyscanner); + // eof reached before closing brace + if (c == '\0' || c == EOF) { + return UNCLOSED_DELIM_STR; + } + + yylloc->last_column += 1; + yyleng += 1; + if (escape) { + escape = 0; + } else if (c == '\\') { + escape = 1; + } else if (c == '{') { + brace_depth++; + } else if (c == '}') { + brace_depth--; + if (brace_depth == 0) break; + } else if (c == '\n') { + yylloc->last_line += 1; + yylloc->last_column = 0; + } + [buf appendFormat:@"%c", c]; + } + + yylval->nsstr = buf; + return DELIMITEDSTRING; +} + +\\begin { return UNKNOWN_BEGIN_CMD; } +\\end { return UNKNOWN_END_CMD; } +\\[a-zA-Z0-9]+ { return UNKNOWN_CMD; } +[a-zA-Z0-9]+ { return UNKNOWN_STR; } +. { return UNKNOWN_STR; } + + /* vi:ft=lex:noet:ts=4:sts=4:sw=4: + */ diff --git a/tikzit/src/data/tikzparser.ypp b/tikzit/src/data/tikzparser.ypp new file mode 100644 index 0000000..e97b1c7 --- /dev/null +++ b/tikzit/src/data/tikzparser.ypp @@ -0,0 +1,228 @@ +%{ +/* + * Copyright 2010 Chris Heunen + * Copyright 2010-2013 Aleks Kissinger + * Copyright 2013 K. Johan Paulsson + * Copyright 2013 Alex Merry + * + * 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 2 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 "tikzparserdefs.h" +%} + +/* we use features added to bison 2.4 */ +%require "2.3" + +%error-verbose +/* enable maintaining locations for better error messages */ +%locations +/* the name of the header file */ +/*%defines "common/tikzparser.h"*/ +/* make it re-entrant (no global variables) */ +%pure-parser +/* We use a pure (re-entrant) lexer. This means yylex + will take a void* (opaque) type to maintain its state */ +%lex-param {void *scanner} +/* Since this parser is also pure, yyparse needs to take + that lexer state as an argument */ +%parse-param {void *scanner} + +/* possible data types for semantic values */ +%union { + QString qstr; + GraphElementProperty *prop; + GraphElementData *data; + Node *node; + QPointF pt; + struct noderef noderef; +} + +%{ +#include "node.h" +#include "edge.h" + #include "graphelementdata.h" +#include "graphelementproperty.h" + +#include "tikzlexer.h" +#import "tikzgraphassembler.h" +/* the assembler (used by this parser) is stored in the lexer + state as "extra" data */ +#define assembler yyget_extra(scanner) + +/* pass errors off to the assembler */ +void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { + // TODO: implement reportError() + //assembler->reportError(str, yylloc); +} +%} + +/* yyloc is set up with first_column = last_column = 1 by default; + however, it makes more sense to think of us being "before the + start of the line" before we parse anything */ +%initial-action { + yylloc.first_column = yylloc.last_column = 0; +} + + +%token BEGIN_TIKZPICTURE_CMD "\\begin{tikzpicture}" +%token END_TIKZPICTURE_CMD "\\end{tikzpicture}" +%token BEGIN_PGFONLAYER_CMD "\\begin{pgfonlayer}" +%token END_PGFONLAYER_CMD "\\end{pgfonlayer}" +%token DRAW_CMD "\\draw" +%token NODE_CMD "\\node" +%token PATH_CMD "\\path" +%token RECTANGLE "rectangle" +%token NODE "node" +%token AT "at" +%token TO "to" +%token SEMICOLON ";" +%token COMMA "," + +%token LEFTPARENTHESIS "(" +%token RIGHTPARENTHESIS ")" +%token LEFTBRACKET "[" +%token RIGHTBRACKET "]" +%token FULLSTOP "." +%token EQUALS "=" +%token COORD "co-ordinate" +%token PROPSTRING "key/value string" +%token REFSTRING "string" +%token DELIMITEDSTRING "{-delimited string" + +%token UNKNOWN_BEGIN_CMD "unknown \\begin command" +%token UNKNOWN_END_CMD "unknown \\end command" +%token UNKNOWN_CMD "unknown latex command" +%token UNKNOWN_STR "unknown string" +%token UNCLOSED_DELIM_STR "unclosed {-delimited string" + +%type nodename +%type optanchor +%type val +%type property +%type extraproperties +%type properties +%type optproperties +%type optedgenode +%type noderef +%type optnoderef + +%% + +tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}" + { + if ($2) { + assembler->graph()->setData($2); + } + }; +tikzcmds: tikzcmds tikzcmd | ; +tikzcmd: node | edge | boundingbox | ignore; + +ignore: "\\begin{pgfonlayer}" DELIMITEDSTRING | "\\end{pgfonlayer}"; + +optproperties: + "[" "]" + { $$ = 0; } + | "[" properties "]" + { $$ = $2; } + | { $$ = 0; }; +properties: extraproperties property + { + [$1 addObject:$2]; + $$ = $1; + }; +extraproperties: + extraproperties property "," + { + [$1 addObject:$2]; + $$ = $1; + } + | { $$ = [GraphElementData data]; }; +property: + val "=" val + { $$ = [GraphElementProperty property:$1 withValue:$3]; } + | val + { $$ = [GraphElementProperty atom:$1]; }; +val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; + +nodename: "(" REFSTRING ")" { $$ = $2; }; +node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";" + { + Node *node = assembler->graph()->addNode(); + if ($2) + node->setData($2); + node->setName($3); + node->setPoint($5); + node->setLabel($6); + assembler->addNodeToMap(node); + }; + +optanchor: { $$ = 0; } | "." REFSTRING { $$ = $2; }; +noderef: "(" REFSTRING optanchor ")" + { + $$.node = assembler->nodeWithName($2); + $$.anchor = $3; + }; +optnoderef: + noderef { $$ = $1; } + | "(" ")" { $$.node = 0; $$.anchor = 0; } +optedgenode: + { $$ = 0; } + | "node" optproperties DELIMITEDSTRING + { + // TODO: implement edge-nodes + // $$ = [Node node]; + // if ($2) + // [$$ setData:$2]; + // [$$ setLabel:$3]; + } +edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";" + { + Node *s; + Node *t; + Node *en; + + // TODO: anchors and edge nodes + + s = $3.node; + if ($6.node) { + t = $6.node; + //[edge setTargetAnchor:$6.anchor]; + } else { + t = $3.node; + //[edge setTargetAnchor:$3.anchor]; + } + + Edge *edge = assembler->graph()->addEdge(s, t); + if ($2) + edge->setData($2); + + // [edge setSourceAnchor:$3.anchor]; + // [edge setEdgeNode:$5]; + + // [edge setAttributesFromData]; + }; + +ignoreprop: val | val "=" val; +ignoreprops: ignoreprop ignoreprops | ; +optignoreprops: "[" ignoreprops "]"; +boundingbox: + "\\path" optignoreprops COORD "rectangle" COORD ";" + { + // TODO: bounding box + //[[assembler graph] setBoundingBox:NSRectAroundPoints($3, $5)]; + }; + +/* vi:ft=yacc:noet:ts=4:sts=4:sw=4 +*/ diff --git a/tikzit/src/data/tikzparserdefs.h b/tikzit/src/data/tikzparserdefs.h new file mode 100644 index 0000000..f721ba5 --- /dev/null +++ b/tikzit/src/data/tikzparserdefs.h @@ -0,0 +1,2 @@ +// nothing here + diff --git a/tikzit/src/gui/mainwindow.cpp b/tikzit/src/gui/mainwindow.cpp new file mode 100644 index 0000000..ef73a20 --- /dev/null +++ b/tikzit/src/gui/mainwindow.cpp @@ -0,0 +1,23 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + tikzScene = new TikzScene(this); + ui->tikzView->setScene(tikzScene); + //tikzView = new QGraphicsView(tikzScene); + //setCentralWidget(tikzView); + //resize(700, 500); + // badger? +} + +MainWindow::~MainWindow() +{ + qDebug() << "~MainWindow"; +} diff --git a/tikzit/src/gui/mainwindow.h b/tikzit/src/gui/mainwindow.h new file mode 100644 index 0000000..d33a89d --- /dev/null +++ b/tikzit/src/gui/mainwindow.h @@ -0,0 +1,25 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include "tikzscene.h" + +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); +private: + TikzScene *tikzScene; + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/tikzit/src/gui/mainwindow.ui b/tikzit/src/gui/mainwindow.ui new file mode 100644 index 0000000..6439ee8 --- /dev/null +++ b/tikzit/src/gui/mainwindow.ui @@ -0,0 +1,76 @@ + + + MainWindow + + + + 0 + 0 + 476 + 378 + + + + TikZiT + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Stuff written here</p></body></html> + + + + + + + + + + 0 + 0 + 476 + 22 + + + + + File + + + + + + + + + New... + + + + + + + diff --git a/tikzit/src/gui/propertypalette.cpp b/tikzit/src/gui/propertypalette.cpp new file mode 100644 index 0000000..6fc9ef9 --- /dev/null +++ b/tikzit/src/gui/propertypalette.cpp @@ -0,0 +1,26 @@ +#include "propertypalette.h" +#include "graphelementdata.h" +#include "ui_propertypalette.h" + +#include +#include + +PropertyPalette::PropertyPalette(QWidget *parent) : + QDockWidget(parent), + ui(new Ui::PropertyPalette) +{ + ui->setupUi(this); + GraphElementData *d = new GraphElementData(); + d->setProperty("key 1", "value 1"); + d->setAtom("atom 1"); + d->setProperty("key 2", "value 2"); + + QModelIndex i = d->index(0,0); + qDebug() << "data: " << i.data(); + ui->treeView->setModel(d); +} + +PropertyPalette::~PropertyPalette() +{ + delete ui; +} diff --git a/tikzit/src/gui/propertypalette.h b/tikzit/src/gui/propertypalette.h new file mode 100644 index 0000000..8e8e5b3 --- /dev/null +++ b/tikzit/src/gui/propertypalette.h @@ -0,0 +1,22 @@ +#ifndef PROPERTYPALETTE_H +#define PROPERTYPALETTE_H + +#include + +namespace Ui { +class PropertyPalette; +} + +class PropertyPalette : public QDockWidget +{ + Q_OBJECT + +public: + explicit PropertyPalette(QWidget *parent = 0); + ~PropertyPalette(); + +private: + Ui::PropertyPalette *ui; +}; + +#endif // PROPERTYPALETTE_H diff --git a/tikzit/src/gui/propertypalette.ui b/tikzit/src/gui/propertypalette.ui new file mode 100644 index 0000000..83d586e --- /dev/null +++ b/tikzit/src/gui/propertypalette.ui @@ -0,0 +1,30 @@ + + + PropertyPalette + + + + 0 + 0 + 194 + 341 + + + + Properties + + + + + + + 0 + + + + + + + + + diff --git a/tikzit/src/gui/tikzscene.cpp b/tikzit/src/gui/tikzscene.cpp new file mode 100644 index 0000000..60939dd --- /dev/null +++ b/tikzit/src/gui/tikzscene.cpp @@ -0,0 +1,6 @@ +#include "tikzscene.h" + +TikzScene::TikzScene(QObject *parent) : QGraphicsScene(parent) +{ + +} diff --git a/tikzit/src/gui/tikzscene.h b/tikzit/src/gui/tikzscene.h new file mode 100644 index 0000000..dd3cba7 --- /dev/null +++ b/tikzit/src/gui/tikzscene.h @@ -0,0 +1,13 @@ +#ifndef TIKZSCENE_H +#define TIKZSCENE_H + +#include +#include + +class TikzScene : public QGraphicsScene +{ +public: + TikzScene(QObject *parent); +}; + +#endif // TIKZSCENE_H diff --git a/tikzit/src/gui/toolpalette.cpp b/tikzit/src/gui/toolpalette.cpp new file mode 100644 index 0000000..fd06730 --- /dev/null +++ b/tikzit/src/gui/toolpalette.cpp @@ -0,0 +1,39 @@ +#include "toolpalette.h" + +#include +#include +#include + +ToolPalette::ToolPalette(QWidget *parent) : + QToolBar(parent) +{ + setWindowFlags(Qt::Window + | Qt::WindowStaysOnTopHint + | Qt::CustomizeWindowHint + | Qt::WindowDoesNotAcceptFocus); + setOrientation(Qt::Vertical); + setFocusPolicy(Qt::NoFocus); + + tools = new QActionGroup(this); + + select = new QAction(QIcon(":/images/select-rectangular.png"), "Select"); + vertex = new QAction(QIcon(":/images/draw-ellipse.png"), "Add Vertex"); + edge = new QAction(QIcon(":/images/draw-path.png"), "Add Edge"); + crop = new QAction(QIcon(":/images/transform-crop-and-resize.png"), "Bounding Box"); + + tools->addAction(select); + tools->addAction(vertex); + tools->addAction(edge); + tools->addAction(crop); + + select->setCheckable(true); + vertex->setCheckable(true); + edge->setCheckable(true); + crop->setCheckable(true); + select->setChecked(true); + + addAction(select); + addAction(vertex); + addAction(edge); + addAction(crop); +} diff --git a/tikzit/src/gui/toolpalette.h b/tikzit/src/gui/toolpalette.h new file mode 100644 index 0000000..05b2e12 --- /dev/null +++ b/tikzit/src/gui/toolpalette.h @@ -0,0 +1,22 @@ +#ifndef TOOLPALETTE_H +#define TOOLPALETTE_H + +#include +#include +#include +#include + +class ToolPalette : public QToolBar +{ + Q_OBJECT +public: + ToolPalette(QWidget *parent = 0); +private: + QActionGroup *tools; + QAction *select; + QAction *vertex; + QAction *edge; + QAction *crop; +}; + +#endif // TOOLPALETTE_H diff --git a/tikzit/src/main.cpp b/tikzit/src/main.cpp new file mode 100644 index 0000000..0de5fd8 --- /dev/null +++ b/tikzit/src/main.cpp @@ -0,0 +1,23 @@ + +#include "mainwindow.h" +#include "toolpalette.h" +#include "propertypalette.h" +#include "graph.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow *w = new MainWindow(); + w->show(); + + ToolPalette *tp = new ToolPalette(new QMainWindow()); + tp->show(); + //w->addToolBar(Qt::LeftToolBarArea, tp); + + PropertyPalette *pp = new PropertyPalette; + pp->show(); + + return a.exec(); +} -- cgit v1.2.3