COPASI API  4.16.103
Public Types | Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
ScrollZoomer Class Reference

#include <scrollzoomer.h>

Inheritance diagram for ScrollZoomer:
Inheritance graph
[legend]
Collaboration diagram for ScrollZoomer:
Collaboration graph
[legend]

Public Types

enum  ScrollBarPosition { AttachedToScale, OppositeToScale }
 

Public Member Functions

QWidget * cornerWidget () const
 
virtual bool eventFilter (QObject *, QEvent *)
 
ScrollBarhorizontalScrollBar () const
 
Q3ScrollView::ScrollBarMode hScrollBarMode () const
 
ScrollBarPosition hScrollBarPosition () const
 
virtual void rescale ()
 
 ScrollZoomer (QwtPlotCanvas *)
 
virtual void setCornerWidget (QWidget *)
 
void setHScrollBarMode (Q3ScrollView::ScrollBarMode)
 
void setHScrollBarPosition (ScrollBarPosition)
 
void setVScrollBarMode (Q3ScrollView::ScrollBarMode)
 
void setVScrollBarPosition (ScrollBarPosition)
 
ScrollBarverticalScrollBar () const
 
Q3ScrollView::ScrollBarMode vScrollBarMode () const
 
ScrollBarPosition vScrollBarPosition () const
 
virtual ~ScrollZoomer ()
 
- Public Member Functions inherited from LogPlotZoomer
 LogPlotZoomer (QwtPlotCanvas *canvas)
 

Protected Member Functions

virtual void layoutScrollBars (const QRect &)
 
virtual ScrollBarscrollBar (Qt::Orientation)
 
virtual void updateScrollBars ()
 
- Protected Member Functions inherited from LogPlotZoomer
virtual QwtText trackerText (const QwtDoublePoint &pos) const
 

Private Slots

void scrollBarMoved (Qt::Orientation o, double min, double max)
 

Private Member Functions

bool needScrollBar (Qt::Orientation) const
 
int oppositeAxis (int) const
 

Private Attributes

QWidget * d_cornerWidget
 
ScrollDatad_hScrollData
 
ScrollDatad_vScrollData
 

Additional Inherited Members

- Public Slots inherited from LogPlotZoomer
virtual void move (double x, double y)
 

Detailed Description

Definition at line 54 of file scrollzoomer.h.

Member Enumeration Documentation

Enumerator
AttachedToScale 
OppositeToScale 

Definition at line 58 of file scrollzoomer.h.

Constructor & Destructor Documentation

ScrollZoomer::ScrollZoomer ( QwtPlotCanvas *  canvas)

Definition at line 151 of file scrollzoomer.cpp.

References d_hScrollData, and d_vScrollData.

151  :
152  LogPlotZoomer(canvas),
153  d_cornerWidget(NULL),
154  d_hScrollData(NULL),
155  d_vScrollData(NULL)
156 {
157  if (!canvas)
158  return;
159 
162 }
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
LogPlotZoomer(QwtPlotCanvas *canvas)
ScrollZoomer::~ScrollZoomer ( )
virtual

Definition at line 164 of file scrollzoomer.cpp.

References d_cornerWidget, d_hScrollData, and d_vScrollData.

165 {
166  delete d_cornerWidget;
167  delete d_vScrollData;
168  delete d_hScrollData;
169 }
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111

Member Function Documentation

QWidget * ScrollZoomer::cornerWidget ( ) const

Definition at line 301 of file scrollzoomer.cpp.

References d_cornerWidget.

302 {
303  return d_cornerWidget;
304 }
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
bool ScrollZoomer::eventFilter ( QObject *  o,
QEvent *  e 
)
virtual

Definition at line 306 of file scrollzoomer.cpp.

References d_cornerWidget, d_hScrollData, d_vScrollData, layoutScrollBars(), and ScrollData::scrollBar.

307 {
308  if (o == canvas())
309  {
310  switch (e->type())
311  {
312  case QEvent::Resize:
313  {
314  const int fw = ((QwtPlotCanvas *)canvas())->frameWidth();
315 
316  QRect rect;
317  rect.setSize(((QResizeEvent *)e)->size());
318  rect.setRect(rect.x() + fw, rect.y() + fw,
319  rect.width() - 2 * fw, rect.height() - 2 * fw);
320 
321  layoutScrollBars(rect);
322  break;
323  }
324  case QEvent::ChildRemoved:
325  {
326  const QObject *child = ((QChildEvent *)e)->child();
327 
328  if (child == d_cornerWidget)
329  d_cornerWidget = NULL;
330  else if (child == d_hScrollData->scrollBar)
331  d_hScrollData->scrollBar = NULL;
332  else if (child == d_vScrollData->scrollBar)
333  d_vScrollData->scrollBar = NULL;
334 
335  break;
336  }
337  default:
338  break;
339  }
340  }
341 
342  return QwtPlotZoomer::eventFilter(o, e);
343 }
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
virtual void layoutScrollBars(const QRect &)
ScrollBar * scrollBar
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
ScrollBar * ScrollZoomer::horizontalScrollBar ( ) const

Definition at line 194 of file scrollzoomer.cpp.

References d_hScrollData, and ScrollData::scrollBar.

Referenced by layoutScrollBars(), and updateScrollBars().

195 {
196  return d_hScrollData->scrollBar;
197 }
ScrollBar * scrollBar
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
Q3ScrollView::ScrollBarMode ScrollZoomer::hScrollBarMode ( ) const

Definition at line 231 of file scrollzoomer.cpp.

236 {
237  return d_hScrollData->mode;
238 }
Q3ScrollView::ScrollBarMode mode
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
ScrollZoomer::ScrollBarPosition ScrollZoomer::hScrollBarPosition ( ) const

Definition at line 268 of file scrollzoomer.cpp.

References d_hScrollData, and ScrollData::position.

Referenced by layoutScrollBars(), and updateScrollBars().

269 {
270  return d_hScrollData->position;
271 }
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
ScrollZoomer::ScrollBarPosition position
void ScrollZoomer::layoutScrollBars ( const QRect &  rect)
protectedvirtual

Definition at line 504 of file scrollzoomer.cpp.

References d_cornerWidget, ScrollBar::extent(), horizontalScrollBar(), hScrollBarPosition(), oppositeAxis(), OppositeToScale, verticalScrollBar(), and vScrollBarPosition().

Referenced by eventFilter(), and updateScrollBars().

505 {
506  int hPos = xAxis();
507 
509  hPos = oppositeAxis(hPos);
510 
511  int vPos = yAxis();
512 
514  vPos = oppositeAxis(vPos);
515 
516  ScrollBar *hScrollBar = horizontalScrollBar();
517  ScrollBar *vScrollBar = verticalScrollBar();
518 
519  const int hdim = hScrollBar ? hScrollBar->extent() : 0;
520  const int vdim = vScrollBar ? vScrollBar->extent() : 0;
521 
522  if (hScrollBar && hScrollBar->isVisible())
523  {
524  int x = rect.x();
525  int y = (hPos == QwtPlot::xTop)
526  ? rect.top() : rect.bottom() - hdim + 1;
527  int w = rect.width();
528 
529  if (vScrollBar && vScrollBar->isVisible())
530  {
531  if (vPos == QwtPlot::yLeft)
532  x += vdim;
533 
534  w -= vdim;
535  }
536 
537  hScrollBar->setGeometry(x, y, w, hdim);
538  }
539 
540  if (vScrollBar && vScrollBar->isVisible())
541  {
542  int pos = yAxis();
543 
545  pos = oppositeAxis(pos);
546 
547  int x = (vPos == QwtPlot::yLeft)
548  ? rect.left() : rect.right() - vdim + 1;
549  int y = rect.y();
550 
551  int h = rect.height();
552 
553  if (hScrollBar && hScrollBar->isVisible())
554  {
555  if (hPos == QwtPlot::xTop)
556  y += hdim;
557 
558  h -= hdim;
559  }
560 
561  vScrollBar->setGeometry(x, y, vdim, h);
562  }
563 
564  if (hScrollBar && hScrollBar->isVisible() &&
565  vScrollBar && vScrollBar->isVisible())
566  {
567  if (d_cornerWidget)
568  {
569  QRect cornerRect(
570  vScrollBar->pos().x(), hScrollBar->pos().y(),
571  vdim, hdim);
572  d_cornerWidget->setGeometry(cornerRect);
573  }
574  }
575 }
ScrollBar * horizontalScrollBar() const
int extent() const
Definition: scrollbar.cpp:218
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
ScrollBarPosition hScrollBarPosition() const
ScrollBar * verticalScrollBar() const
ScrollBarPosition vScrollBarPosition() const
int oppositeAxis(int) const
bool ScrollZoomer::needScrollBar ( Qt::Orientation  o) const
private

Definition at line 345 of file scrollzoomer.cpp.

References d_hScrollData, d_vScrollData, and ScrollData::mode.

Referenced by updateScrollBars().

346 {
347 #if QT_VERSION < 0x040000
348  Q3ScrollView::ScrollBarMode mode;
349 #else
350  Qt::ScrollBarPolicy mode;
351 #endif
352  double zoomMin, zoomMax, baseMin, baseMax;
353 
354  if (o == Qt::Horizontal)
355  {
356  mode = d_hScrollData->mode;
357  baseMin = zoomBase().left();
358  baseMax = zoomBase().right();
359  zoomMin = zoomRect().left();
360  zoomMax = zoomRect().right();
361  }
362  else
363  {
364  mode = d_vScrollData->mode;
365  baseMin = zoomBase().top();
366  baseMax = zoomBase().bottom();
367  zoomMin = zoomRect().top();
368  zoomMax = zoomRect().bottom();
369  }
370 
371  bool needed = false;
372 
373  switch (mode)
374  {
375 #if QT_VERSION < 0x040000
376  case Q3ScrollView::AlwaysOn:
377 #else
378  case Qt::ScrollBarAlwaysOn:
379 #endif
380  needed = true;
381  break;
382 #if QT_VERSION < 0x040000
383  case Q3ScrollView::AlwaysOff:
384 #else
385  case Qt::ScrollBarAlwaysOff:
386 #endif
387  needed = false;
388  break;
389  default:
390  {
391  if (baseMin < zoomMin || baseMax > zoomMax)
392  needed = true;
393 
394  break;
395  }
396  }
397 
398  return needed;
399 }
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
Q3ScrollView::ScrollBarMode mode
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
int ScrollZoomer::oppositeAxis ( int  axis) const
private

Definition at line 587 of file scrollzoomer.cpp.

Referenced by layoutScrollBars(), and updateScrollBars().

588 {
589  switch (axis)
590  {
591  case QwtPlot::xBottom:
592  return QwtPlot::xTop;
593  case QwtPlot::xTop:
594  return QwtPlot::xBottom;
595  case QwtPlot::yLeft:
596  return QwtPlot::yRight;
597  case QwtPlot::yRight:
598  return QwtPlot::yLeft;
599  default:
600  break;
601  }
602 
603  return axis;
604 }
void ScrollZoomer::rescale ( )
virtual

Definition at line 171 of file scrollzoomer.cpp.

References updateScrollBars().

172 {
173  QwtPlotZoomer::rescale();
175 }
virtual void updateScrollBars()
ScrollBar * ScrollZoomer::scrollBar ( Qt::Orientation  o)
protectedvirtual

Definition at line 177 of file scrollzoomer.cpp.

References d_hScrollData, d_vScrollData, if(), ScrollData::scrollBar, and scrollBarMoved().

Referenced by updateScrollBars().

178 {
179  ScrollBar *&sb = (o == Qt::Vertical)
181 
182  if (sb == NULL)
183  {
184  sb = new ScrollBar(o, canvas());
185  sb->hide();
186  connect(sb,
187  SIGNAL(valueChanged(Qt::Orientation, double, double)),
188  SLOT(scrollBarMoved(Qt::Orientation, double, double)));
189  }
190 
191  return sb;
192 }
ScrollBar * scrollBar
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
if(!yymsg) yymsg
void scrollBarMoved(Qt::Orientation o, double min, double max)
void ScrollZoomer::scrollBarMoved ( Qt::Orientation  o,
double  min,
double  max 
)
privateslot

Definition at line 577 of file scrollzoomer.cpp.

References LogPlotZoomer::move().

Referenced by scrollBar().

578 {
579  if (o == Qt::Horizontal)
580  move(min, zoomRect().top());
581  else
582  move(zoomRect().left(), min);
583 
584  emit zoomed(zoomRect());
585 }
virtual void move(double x, double y)
#define min(a, b)
Definition: f2c.h:175
void ScrollZoomer::setCornerWidget ( QWidget *  w)
virtual

Definition at line 278 of file scrollzoomer.cpp.

References d_cornerWidget, and updateScrollBars().

279 {
280  if (w != d_cornerWidget)
281  {
282  if (canvas())
283  {
284  delete d_cornerWidget;
285  d_cornerWidget = w;
286 
287  if (d_cornerWidget->parent() != canvas())
288  {
289 #if QT_VERSION < 0x040000
290  d_cornerWidget->reparent(canvas(), QPoint(0, 0));
291 #else
292  d_cornerWidget->setParent(canvas());
293 #endif
294  }
295 
297  }
298  }
299 }
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
virtual void updateScrollBars()
void ScrollZoomer::setHScrollBarMode ( Q3ScrollView::ScrollBarMode  mode)

Definition at line 205 of file scrollzoomer.cpp.

209 {
210  if (hScrollBarMode() != mode)
211  {
212  d_hScrollData->mode = mode;
214  }
215 }
virtual void updateScrollBars()
Q3ScrollView::ScrollBarMode hScrollBarMode() const
Q3ScrollView::ScrollBarMode mode
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
void ScrollZoomer::setHScrollBarPosition ( ScrollBarPosition  pos)

Definition at line 250 of file scrollzoomer.cpp.

References d_hScrollData, ScrollData::position, and updateScrollBars().

251 {
252  if (d_hScrollData->position != pos)
253  {
254  d_hScrollData->position = pos;
256  }
257 }
virtual void updateScrollBars()
ScrollData * d_hScrollData
Definition: scrollzoomer.h:111
ScrollZoomer::ScrollBarPosition position
void ScrollZoomer::setVScrollBarMode ( Q3ScrollView::ScrollBarMode  mode)

Definition at line 218 of file scrollzoomer.cpp.

222 {
223  if (vScrollBarMode() != mode)
224  {
225  d_vScrollData->mode = mode;
227  }
228 }
virtual void updateScrollBars()
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
Q3ScrollView::ScrollBarMode mode
Q3ScrollView::ScrollBarMode vScrollBarMode() const
void ScrollZoomer::setVScrollBarPosition ( ScrollBarPosition  pos)

Definition at line 259 of file scrollzoomer.cpp.

References d_vScrollData, ScrollData::position, and updateScrollBars().

260 {
261  if (d_vScrollData->position != pos)
262  {
263  d_vScrollData->position = pos;
265  }
266 }
virtual void updateScrollBars()
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
ScrollZoomer::ScrollBarPosition position
void ScrollZoomer::updateScrollBars ( )
protectedvirtual

Definition at line 401 of file scrollzoomer.cpp.

References d_cornerWidget, ScrollBar::extent(), horizontalScrollBar(), hScrollBarPosition(), layoutScrollBars(), ScrollBar::moveSlider(), needScrollBar(), oppositeAxis(), OppositeToScale, scrollBar(), ScrollBar::setBase(), ScrollBar::setInverted(), ScrollBar::setLogScale(), verticalScrollBar(), and vScrollBarPosition().

Referenced by rescale(), setCornerWidget(), setHScrollBarPosition(), and setVScrollBarPosition().

402 {
403  if (!canvas())
404  return;
405 
406  const int xAxis = QwtPlotZoomer::xAxis();
407  const int yAxis = QwtPlotZoomer::yAxis();
408 
409  int xScrollBarAxis = xAxis;
410 
412  xScrollBarAxis = oppositeAxis(xScrollBarAxis);
413 
414  int yScrollBarAxis = yAxis;
415 
417  yScrollBarAxis = oppositeAxis(yScrollBarAxis);
418 
419  QwtPlotLayout *layout = plot()->plotLayout();
420 
421  bool showHScrollBar = needScrollBar(Qt::Horizontal);
422 
423  if (showHScrollBar)
424  {
425  ScrollBar *sb = scrollBar(Qt::Horizontal);
426 
427  sb->setPalette(plot()->palette());
428 
429  const QwtScaleEngine *se = plot()->axisScaleEngine(xAxis);
430  sb->setInverted(se->testAttribute(QwtScaleEngine::Inverted));
431  sb->setLogScale(dynamic_cast<const QwtLog10ScaleEngine*>(se));
432 
433  sb->setBase(zoomBase().left(), zoomBase().right());
434  sb->moveSlider(zoomRect().left(), zoomRect().right());
435 
436  if (!sb->isVisibleTo(canvas()))
437  {
438  sb->show();
439  layout->setCanvasMargin(layout->canvasMargin(xScrollBarAxis)
440  + sb->extent(), xScrollBarAxis);
441  }
442  }
443  else
444  {
445  if (horizontalScrollBar())
446  {
447  horizontalScrollBar()->hide();
448  layout->setCanvasMargin(layout->canvasMargin(xScrollBarAxis)
449  - horizontalScrollBar()->extent(), xScrollBarAxis);
450  }
451  }
452 
453  bool showVScrollBar = needScrollBar(Qt::Vertical);
454 
455  if (showVScrollBar)
456  {
457  ScrollBar *sb = scrollBar(Qt::Vertical);
458 
459  sb->setPalette(plot()->palette());
460 
461  const QwtScaleEngine *se = plot()->axisScaleEngine(yAxis);
462  sb->setInverted(!(se->testAttribute(QwtScaleEngine::Inverted)));
463  sb->setLogScale(dynamic_cast<const QwtLog10ScaleEngine*>(se));
464 
465  sb->setBase(zoomBase().top(), zoomBase().bottom());
466  sb->moveSlider(zoomRect().top(), zoomRect().bottom());
467 
468  if (!sb->isVisibleTo(canvas()))
469  {
470  sb->show();
471  layout->setCanvasMargin(layout->canvasMargin(yScrollBarAxis)
472  + sb->extent(), yScrollBarAxis);
473  }
474  }
475  else
476  {
477  if (verticalScrollBar())
478  {
479  verticalScrollBar()->hide();
480  layout->setCanvasMargin(layout->canvasMargin(yScrollBarAxis)
481  - verticalScrollBar()->extent(), yScrollBarAxis);
482  }
483  }
484 
485  if (showHScrollBar && showVScrollBar)
486  {
487  if (d_cornerWidget == NULL)
488  {
489  d_cornerWidget = new QWidget(canvas());
490  d_cornerWidget->setPalette(plot()->palette());
491  }
492 
493  d_cornerWidget->show();
494  }
495  else
496  {
497  if (d_cornerWidget)
498  d_cornerWidget->hide();
499  }
500 
501  layoutScrollBars(((QwtPlotCanvas *)canvas())->contentsRect());
502 }
ScrollBar * horizontalScrollBar() const
int extent() const
Definition: scrollbar.cpp:218
QWidget * d_cornerWidget
Definition: scrollzoomer.h:109
virtual void layoutScrollBars(const QRect &)
ScrollBarPosition hScrollBarPosition() const
ScrollBar * verticalScrollBar() const
void setInverted(bool)
Definition: scrollbar.cpp:68
bool needScrollBar(Qt::Orientation) const
ScrollBarPosition vScrollBarPosition() const
int oppositeAxis(int) const
void setLogScale(bool l)
Definition: scrollbar.cpp:243
virtual ScrollBar * scrollBar(Qt::Orientation)
virtual void moveSlider(double min, double max)
Definition: scrollbar.cpp:99
virtual void setBase(double min, double max)
Definition: scrollbar.cpp:82
ScrollBar * ScrollZoomer::verticalScrollBar ( ) const

Definition at line 199 of file scrollzoomer.cpp.

References d_vScrollData, and ScrollData::scrollBar.

Referenced by layoutScrollBars(), and updateScrollBars().

200 {
201  return d_vScrollData->scrollBar;
202 }
ScrollBar * scrollBar
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
Q3ScrollView::ScrollBarMode ScrollZoomer::vScrollBarMode ( ) const

Definition at line 241 of file scrollzoomer.cpp.

246 {
247  return d_vScrollData->mode;
248 }
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
Q3ScrollView::ScrollBarMode mode
ScrollZoomer::ScrollBarPosition ScrollZoomer::vScrollBarPosition ( ) const

Definition at line 273 of file scrollzoomer.cpp.

References d_vScrollData, and ScrollData::position.

Referenced by layoutScrollBars(), and updateScrollBars().

274 {
275  return d_vScrollData->position;
276 }
ScrollData * d_vScrollData
Definition: scrollzoomer.h:112
ScrollZoomer::ScrollBarPosition position

Member Data Documentation

QWidget* ScrollZoomer::d_cornerWidget
private
ScrollData* ScrollZoomer::d_hScrollData
private
ScrollData* ScrollZoomer::d_vScrollData
private

The documentation for this class was generated from the following files: