COPASI API  4.16.103
CQGLViewport.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "CQGLViewport.h"
12 
13 #include <QtOpenGL/QtOpenGL>
14 #include <QtGui/QScrollBar>
15 #include <QtCore/QRect>
16 #include <QtGui/QHBoxLayout>
17 #include <QtGui/QLayout>
18 #include <QtGui/QResizeEvent>
19 #include <QtGui/QVBoxLayout>
20 #include <QtGui/QFrame>
21 
22 #include <iostream>
23 
24 #include "copasi/layout/CLBase.h"
25 #include "copasi/layout/CLayout.h"
26 #include "CQGLNetworkPainter.h"
27 
28 /**
29  * Constructor.
30  */
31 CQGLViewport::CQGLViewport(QWidget* pParent, Qt::WFlags f):
32  QFrame(pParent, f)
33  , mpVerticalScrollbar(new QScrollBar(Qt::Vertical, NULL))
34  , mpHorizontalScrollbar(new QScrollBar(Qt::Horizontal, NULL))
35  , mpNetworkPainter(NULL)
36 {
37  QVBoxLayout* pVBoxLayout = new QVBoxLayout();
38  this->setLayout(pVBoxLayout);
39  QFrame* pHBox = new QFrame(this);
40  pHBox->setLayout(new QHBoxLayout());
41  pVBoxLayout->addWidget(pHBox);
42  QGLFormat format;
43  format.setDoubleBuffer(TRUE);
44  this->mpNetworkPainter = new CQGLNetworkPainter(format, pHBox);
45  pHBox->layout()->addWidget(this->mpNetworkPainter);
46  pHBox->layout()->addWidget(this->mpVerticalScrollbar);
47  this->mpVerticalScrollbar->setSingleStep(1);
48  pVBoxLayout->addWidget(this->mpHorizontalScrollbar);
49  this->mpHorizontalScrollbar->setSingleStep(1);
50  connect(this->mpVerticalScrollbar, SIGNAL(valueChanged(int)), this, SLOT(slotVValueChanged(int)));
51  connect(this->mpHorizontalScrollbar, SIGNAL(valueChanged(int)), this, SLOT(slotHValueChanged(int)));
52 }
53 
54 /**
55  * Destructor.
56  */
58 {}
59 
60 void CQGLViewport::resizeEvent(QResizeEvent* e)
61 {
62  this->updateScrollbars();
63  QFrame::resizeEvent(e);
64 }
65 
67 {
68  return this->mpNetworkPainter;
69 }
70 
72 {
73  return this->mpNetworkPainter;
74 }
75 
77 {
78  this->mpNetworkPainter->createGraph(IP);
79  this->updateScrollbars();
80 }
81 
83 {
84  // TODO make sure the GL window is only redrawn once
85  this->mpNetworkPainter->setZoomFactor(zoom);
86  this->updateScrollbars();
87  this->mpNetworkPainter->update();
88 }
89 
91 {
92  // reset the scollbar range
93  // TODO check te setting for the scroll range since there seem to be some
94  // error messages
95  // disconnect the scrollbar listeners and handle the update so that the GL
96  // window is only redrawn once
97  double zoom = this->mpNetworkPainter->getZoomFactor();
100  double graphWidth = (max.getX() - min.getX()) * zoom;
101  double graphHeight = (max.getY() - min.getY()) * zoom;
102  double rectangleHeight = this->contentsRect().height();
103  double rectangleWidth = this->contentsRect().width();
104 
105  if (graphHeight < rectangleHeight)
106  {
107  this->mpVerticalScrollbar->hide();
108  this->mpVerticalScrollbar->setValue(0);
109  }
110  else
111  {
112  this->mpVerticalScrollbar->setPageStep(rectangleHeight);
113  this->mpVerticalScrollbar->setRange(0, (unsigned int)(graphHeight - rectangleHeight));
114  this->mpVerticalScrollbar->show();
115  this->mpNetworkPainter->update();
116  }
117 
118  if (graphWidth < rectangleWidth)
119  {
120  this->mpHorizontalScrollbar->hide();
121  this->mpHorizontalScrollbar->setValue(0);
122  }
123  else
124  {
125  this->mpHorizontalScrollbar->setPageStep(rectangleWidth);
126  this->mpHorizontalScrollbar->setRange(0, (unsigned int)(graphWidth - rectangleWidth));
127  this->mpHorizontalScrollbar->show();
128  this->mpNetworkPainter->update();
129  }
130 }
131 
133 {
134  CLPoint p = this->mpNetworkPainter->getGraphMin();
135  double zoom = this->mpNetworkPainter->getZoomFactor();
136  this->mpNetworkPainter->setCurrentPositionY((double)(p.getY() + value / zoom));
137 }
138 
140 {
141  CLPoint p = this->mpNetworkPainter->getGraphMin();
142  double zoom = this->mpNetworkPainter->getZoomFactor();
143  this->mpNetworkPainter->setCurrentPositionX((double)(p.getX() + value / zoom));
144 }
145 
147 {
148  // TODO disconnect the scrollbar listeners
149  // so that the display is only redrawn once
150  this->mpNetworkPainter->resetView();
151  this->updateScrollbars();
152 }
153 
154 /**
155  * Make the diagram fit the screen.
156  * Returns the new zoom value.
157  */
159 {
160  double zoom = this->mpNetworkPainter->fitToScreen();
161  this->updateScrollbars();
162  return zoom;
163 }
164 
166 {
167  this->mpNetworkPainter->update();
168 }
169 
171 {
172  return this->mpNetworkPainter->isCircleMode();
173 }
#define TRUE
Definition: CGA.h:25
void updateWidget()
double fitToScreen()
QScrollBar * mpVerticalScrollbar
Definition: CQGLViewport.h:27
void setZoomFactor(double zoom)
void setCurrentPositionY(C_FLOAT64 y)
const CQGLNetworkPainter * getPainter() const
virtual void resizeEvent(QResizeEvent *e)
CQGLViewport(QWidget *pParent=0, Qt::WFlags f=0)
void createGraph(CLayout *lP)
void updateScrollbars()
void createGraph(CLayout *lP)
void setCurrentPositionX(C_FLOAT64 x)
const C_FLOAT64 & getX() const
Definition: CLBase.h:83
Definition: CLBase.h:54
virtual ~CQGLViewport()
const C_FLOAT64 & getY() const
Definition: CLBase.h:84
#define C_FLOAT64
Definition: copasi.h:92
CQGLNetworkPainter * mpNetworkPainter
Definition: CQGLViewport.h:29
const CLPoint & getGraphMax()
void slotVValueChanged(int value)
C_FLOAT64 getZoomFactor() const
void setZoomFactor(C_FLOAT64)
bool isCircleMode() const
QScrollBar * mpHorizontalScrollbar
Definition: CQGLViewport.h:28
#define min(a, b)
Definition: f2c.h:175
const CLPoint & getGraphMin()
void slotHValueChanged(int value)
#define max(a, b)
Definition: f2c.h:176