libyui-qt-graph  2.42.7
 All Classes Functions
YQGraph.cc
1 /*
2  * Copyright (c) [2009-2012] Novell, Inc.
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 /*
23  * File: YQGraph.cc
24  * Author: Arvin Schnell <aschnell@suse.de>
25  */
26 
27 
28 #define YUILogComponent "qt-graph"
29 #include "YUILog.h"
30 
31 #include "YQGraph.h"
32 
33 #include "YQDialog.h"
34 #include "YQApplication.h"
35 #include "utf8.h"
36 #include "YQUI.h"
37 #include "YEvent.h"
38 #include "YQi18n.h"
39 
40 
41 YQGraph::YQGraph(YWidget* parent, const string& filename, const string& layoutAlgorithm)
42  : QY2Graph(filename, layoutAlgorithm, (QWidget*) parent->widgetRep()),
43  YGraph(parent, filename, layoutAlgorithm)
44 {
45  setWidgetRep(this);
46 
47  init();
48 }
49 
50 
51 YQGraph::YQGraph(YWidget* parent, /* graph_t */ void* graph)
52  : QY2Graph((graph_t*)graph, (QWidget*) parent->widgetRep()),
53  YGraph(parent, (graph_t*) graph)
54 {
55  setWidgetRep(this);
56 
57  init();
58 }
59 
60 
61 YQGraph::~YQGraph()
62 {
63 }
64 
65 
66 void
67 YQGraph::init()
68 {
69  connect(this, SIGNAL(backgroundContextMenuEvent(QContextMenuEvent*)),
70  this, SLOT(backgroundContextMenu(QContextMenuEvent*)));
71 
72  connect(this, SIGNAL(nodeContextMenuEvent(QContextMenuEvent*, const QString&)),
73  this, SLOT(nodeContextMenu(QContextMenuEvent*, const QString&)));
74 
75  connect(this, SIGNAL(nodeDoubleClickEvent(QMouseEvent*, const QString&)),
76  this, SLOT(nodeDoubleClick(QMouseEvent*, const QString&)));
77 }
78 
79 
80 void
81 YQGraph::renderGraph(const string& filename, const string& layoutAlgorithm)
82 {
83  QY2Graph::renderGraph(filename, layoutAlgorithm);
84 }
85 
86 
87 void
88 YQGraph::renderGraph(/* graph_t */ void* graph)
89 {
90  QY2Graph::renderGraph((graph_t*)graph);
91 }
92 
93 
94 int
96 {
97  return std::min(160, sizeHint().width());
98 }
99 
100 
101 int
103 {
104  return std::min(120, sizeHint().height());
105 }
106 
107 
108 void
109 YQGraph::setSize(int newWidth, int newHeight)
110 {
111  resize(newWidth, newHeight);
112 }
113 
114 
115 void
116 YQGraph::backgroundContextMenu(QContextMenuEvent* event)
117 {
118  if (notifyContextMenu())
119  {
120  lastActivatedNode.clear();
121  YQUI::yqApp()->setContextMenuPos(event->globalPos());
122  YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::ContextMenuActivated));
123  }
124 }
125 
126 
127 void
128 YQGraph::nodeContextMenu(QContextMenuEvent* event, const QString& name)
129 {
130  if (notifyContextMenu())
131  {
132  lastActivatedNode = name.toStdString();
133  YQUI::yqApp()->setContextMenuPos(event->globalPos());
134  YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::ContextMenuActivated));
135  }
136 }
137 
138 
139 void
140 YQGraph::nodeDoubleClick(QMouseEvent* event, const QString& name)
141 {
142  if (notify())
143  {
144  lastActivatedNode = name.toStdString();
145  YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::Activated));
146  }
147 }
148 
149 
150 #include "YQGraph.moc"
virtual int preferredWidth()
Definition: YQGraph.cc:95
virtual void setSize(int newWidth, int newHeight)
Definition: YQGraph.cc:109
virtual int preferredHeight()
Definition: YQGraph.cc:102