tuchulcha  0.10.1
Graphical Workflow Configuration Editor
FlowWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
25 #include "FlowWidget.h"
26 #include <QGraphicsView>
27 #include <QMessageBox>
28 #include <QFileInfo>
29 #include <QWheelEvent>
30 #include <QDir>
31 #include "TuchulchaWindow.h"
32 #include "GraphModel.h"
33 #include "NodeHandler.h"
34 
35 FlowWidget::FlowWidget(GraphModel* modelIn, QWidget* myParent) :
36  QMdiSubWindow(myParent) {
37  // init GUI
38  _viewer = new QGraphicsView(this);
39  _viewer->setRenderHints(QPainter::Antialiasing);
40  _viewer->setAcceptDrops(true);
41  _nodehandler = new NodeHandler(modelIn, _viewer);
42  _viewer->setScene(_nodehandler);
43 
44  setWidget(_viewer);
45  setAttribute(Qt::WA_DeleteOnClose, true);
46  connect(model(), SIGNAL(fileNameChanged (QString)),
47  SLOT(updateFileName(QString)));
48  connect(_nodehandler, SIGNAL(statusMessage(QString)),
49  SIGNAL(statusMessage(QString)));
50  connect(_nodehandler, SIGNAL(nodeTypeSelected(QString)),
51  SIGNAL(nodeTypeSelected(QString)));
52  connect(model(), SIGNAL(modified(bool)), SLOT(modify(bool)));
53  connect(model(), SIGNAL(commentChanged(QString)), _nodehandler,
54  SLOT(updateTooltip(QString)));
55  connect(this, SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates)),
56  SLOT(zoomFit(Qt::WindowStates, Qt::WindowStates)));
57  updateFileName(model()->fileName());
58 }
59 
60 void FlowWidget::updateFileName(const QString& fileName) {
61  if (fileName.isEmpty() || fileName == QDir::homePath()) {
62  setWindowTitle(tr("New file")+" [*]");
63  }
64  else {
65  QFileInfo info(fileName);
66  setWindowTitle(QString("%1 [*]").arg(info.baseName()));
67  }
68 }
69 
71  return _nodehandler->model();
72 }
73 
74 const GraphModel* FlowWidget::model() const {
75  return _nodehandler->model();
76 }
77 
80 }
81 
83  _viewer->scale(1.2, 1.2);
84 }
85 
87  _viewer->scale(0.8, 0.8);
88 }
89 
91  _viewer->fitInView(_viewer->sceneRect(), Qt::KeepAspectRatio);
92 }
93 
94 void FlowWidget::modify(bool val) {
95  setWindowModified(val);
96 }
97 
98 void FlowWidget::wheelEvent(QWheelEvent* ev) {
99  if(ev->modifiers() & Qt::ControlModifier) {
100  ev->accept();
101  if(ev->delta() > 0)
102  zoomIn();
103  else
104  zoomOut();
105  }
106  else
107  QMdiSubWindow::wheelEvent(ev);
108 }
109 
110 void FlowWidget::closeEvent(QCloseEvent* clEvent) {
111  if (isWindowModified() && !model()->fileName().isEmpty()
112  && QMessageBox::question(
113  this, tr("Save modified content?"),
114  tr("Content has been modified."
115  "Do you want to save to %1 before closing?")
116  .arg(model()->fileName()),
117  QMessageBox::Save|QMessageBox::Discard) == QMessageBox::Save)
118  model()->save();
119  QMdiSubWindow::closeEvent(clEvent);
120 }
121 
122 void FlowWidget::zoomFit(Qt::WindowStates oldStates, Qt::WindowStates newStates) {
123  // check if any flag except for Qt::WindowActive has changed
124  if ((oldStates ^ newStates) == Qt::WindowActive)
125  return;
126  zoomFit();
127 }
This model wraps a ParameterFile instance and provides access to the data interpreted as a (directed)...
Definition: GraphModel.h:32
NodeHandler * _nodehandler
graphics scene to display
Definition: FlowWidget.h:91
virtual void save(const QString &fileName="")
Save model content to a text file.
void zoomIn()
zoom in
Definition: FlowWidget.cpp:82
Declaration of class MainWindow.
GraphModel * model()
Get used model.
Definition: FlowWidget.cpp:70
QGraphicsView * _viewer
viewer
Definition: FlowWidget.h:89
virtual void wheelEvent(QWheelEvent *event)
zooms in and out on mousewheel event
Definition: FlowWidget.cpp:98
Declaration of class GraphModel.
void zoomFit()
fit in view
Definition: FlowWidget.cpp:90
void updateFileName(const QString &fileName)
update title and main window file information
Definition: FlowWidget.cpp:60
void statusMessage(QString msg) const
Send status message.
void saveFlowChart() const
Save flowchart diagram to graphics file.
Definition: FlowWidget.cpp:78
virtual void closeEvent(QCloseEvent *closeEvent)
check modification status and ask to save before closing
Definition: FlowWidget.cpp:110
GraphModel * model()
get the current GraphModel
void zoomOut()
zoom out
Definition: FlowWidget.cpp:86
void saveFlowchart()
save flowchart to file
void modify(bool val=true)
set modified flag
Definition: FlowWidget.cpp:94
Declaration of class FlowWidget.
FlowWidget(GraphModel *model, QWidget *parent=0)
Default constructor.
Definition: FlowWidget.cpp:35
Declaration of class NodeHandler.
QGraphicsScene that handles all drag&drop, node move and connect events.
Definition: NodeHandler.h:36
void nodeTypeSelected(QString type) const
Send type of currently selected node.