libyui-qt-graph
 
Loading...
Searching...
No Matches
QY2Graph.h
1/*
2 * Copyright (C) 2009-2012 Novell, Inc
3 * This library is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU Lesser General Public License as
5 * published by the Free Software Foundation; either version 2.1 of the
6 * License, or (at your option) version 3.0 of the License. This library
7 * is distributed in the hope that it will be useful, but WITHOUT ANY
8 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 * License for more details. You should have received a copy of the GNU
11 * Lesser General Public License along with this library; if not, write
12 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 * Floor, Boston, MA 02110-1301 USA
14 */
15
16/*
17 * File: QY2Graph.h
18 * Author: Arvin Schnell <aschnell@suse.de>
19 */
20
21
22#ifndef QY2Graph_h
23#define QY2Graph_h
24
25#include <graphviz/gvc.h>
26#include <string>
27
28#include <QGraphicsView>
29#include <QGraphicsScene>
30#include <QGraphicsPathItem>
31#include <QPicture>
32#include <QContextMenuEvent>
33#include <QMouseEvent>
34
35
40class QY2Graph : public QGraphicsView
41{
42 Q_OBJECT
43
44public:
45
46 QY2Graph(const std::string& filename, const std::string& layoutAlgorithm, QWidget* parent = 0);
47
48 QY2Graph(graph_t* graph, QWidget* parent = 0);
49
50 virtual ~QY2Graph();
51
52 virtual void renderGraph(const std::string& filename, const std::string& layoutAlgorithm);
53 virtual void renderGraph(graph_t* graph);
54
55 void clearGraph();
56
57signals:
58
59 void backgroundContextMenuEvent(QContextMenuEvent* event);
60 void nodeContextMenuEvent(QContextMenuEvent* event, const QString& name);
61 void nodeDoubleClickEvent(QMouseEvent* event, const QString& name);
62
63protected:
64
65 void keyPressEvent(QKeyEvent* event);
66 void wheelEvent(QWheelEvent* event);
67 void contextMenuEvent(QContextMenuEvent* event);
68 void mouseDoubleClickEvent(QMouseEvent* event);
69
70private:
71
72 void init();
73
74 void scaleView(qreal scaleFactor);
75
76 QGraphicsScene* scene;
77
78 QRectF graphRect;
79
80 QPointF gToQ(const pointf& p, bool upside_down = true) const;
81
82 QString aggetToQString(void* obj, const char* name, const QString& fallback) const;
83 QColor aggetToQColor(void* obj, const char* name, const QColor& fallback) const;
84 Qt::PenStyle aggetToQPenStyle(void* obj, const char* name, const Qt::PenStyle fallback) const;
85
86 QPainterPath makeShape(node_t* node) const;
87 QPolygonF makeShapeHelper(node_t* node) const;
88
89 QPainterPath makeBezier(const bezier& bezier) const;
90
91 void drawLabel(const textlabel_t* textlabel, QPainter* painter) const;
92
93 void drawArrow(const QLineF& line, const QColor& color, QPainter* painter) const;
94
102 QString unescape(const std::string&) const;
103
104};
105
106
107class QY2Node : public QObject, public QGraphicsPathItem
108{
109 Q_OBJECT
110
111public:
112
113 QY2Node(const QPainterPath& path, const QPicture& picture, const QString& name);
114
115 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
116
117private:
118
119 QPicture picture;
120
121public:
122
123 QString name;
124
125};
126
127
128class QY2Edge : public QGraphicsPathItem
129{
130
131public:
132
133 QY2Edge(const QPainterPath& path, const QPicture& picture);
134
135 QRectF boundingRect() const;
136
137 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
138
139private:
140
141 QPicture picture;
142
143};
144
145
146#endif // QY2Graph_h