libyui-qt-graph  2.44.6
YQGraph.cc
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: YQGraph.cc
18  * Author: Arvin Schnell <aschnell@suse.de>
19  */
20 
21 
22 #define YUILogComponent "qt-graph"
23 #include "YUILog.h"
24 
25 #include "YQGraph.h"
26 
27 #include "YQDialog.h"
28 #include "YQApplication.h"
29 #include "utf8.h"
30 #include "YQUI.h"
31 #include "YEvent.h"
32 #include "YQi18n.h"
33 
34 
35 YQGraph::YQGraph(YWidget* parent, const string& filename, const string& layoutAlgorithm)
36  : QY2Graph(filename, layoutAlgorithm, (QWidget*) parent->widgetRep()),
37  YGraph(parent, filename, layoutAlgorithm)
38 {
39  setWidgetRep(this);
40 
41  init();
42 }
43 
44 
45 YQGraph::YQGraph(YWidget* parent, /* graph_t */ void* graph)
46  : QY2Graph((graph_t*)graph, (QWidget*) parent->widgetRep()),
47  YGraph(parent, (graph_t*) graph)
48 {
49  setWidgetRep(this);
50 
51  init();
52 }
53 
54 
55 YQGraph::~YQGraph()
56 {
57 }
58 
59 
60 void
61 YQGraph::init()
62 {
63  connect(this, SIGNAL(backgroundContextMenuEvent(QContextMenuEvent*)),
64  this, SLOT(backgroundContextMenu(QContextMenuEvent*)));
65 
66  connect(this, SIGNAL(nodeContextMenuEvent(QContextMenuEvent*, const QString&)),
67  this, SLOT(nodeContextMenu(QContextMenuEvent*, const QString&)));
68 
69  connect(this, SIGNAL(nodeDoubleClickEvent(QMouseEvent*, const QString&)),
70  this, SLOT(nodeDoubleClick(QMouseEvent*, const QString&)));
71 }
72 
73 
74 void
75 YQGraph::renderGraph(const string& filename, const string& layoutAlgorithm)
76 {
77  QY2Graph::renderGraph(filename, layoutAlgorithm);
78 }
79 
80 
81 void
82 YQGraph::renderGraph(/* graph_t */ void* graph)
83 {
84  QY2Graph::renderGraph((graph_t*)graph);
85 }
86 
87 
88 int
90 {
91  return std::min(160, sizeHint().width());
92 }
93 
94 
95 int
97 {
98  return std::min(120, sizeHint().height());
99 }
100 
101 
102 void
103 YQGraph::setSize(int newWidth, int newHeight)
104 {
105  resize(newWidth, newHeight);
106 }
107 
108 
109 void
110 YQGraph::backgroundContextMenu(QContextMenuEvent* event)
111 {
112  if (notifyContextMenu())
113  {
114  lastActivatedNode.clear();
115  YQUI::yqApp()->setContextMenuPos(event->globalPos());
116  YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::ContextMenuActivated));
117  }
118 }
119 
120 
121 void
122 YQGraph::nodeContextMenu(QContextMenuEvent* event, const QString& name)
123 {
124  if (notifyContextMenu())
125  {
126  lastActivatedNode = name.toStdString();
127  YQUI::yqApp()->setContextMenuPos(event->globalPos());
128  YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::ContextMenuActivated));
129  }
130 }
131 
132 
133 void
134 YQGraph::nodeDoubleClick(QMouseEvent* event, const QString& name)
135 {
136  if (notify())
137  {
138  lastActivatedNode = name.toStdString();
139  YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::Activated));
140  }
141 }
142 
143 
144 #include "YQGraph.moc"
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQGraph.cc:89
The QY2Graph widget shows a graph layouted by graphviz in a QGraphicsView/QGraphicsScene.
Definition: QY2Graph.h:40
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQGraph.cc:103
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQGraph.cc:96