Back to index

texmacs  1.0.7.15
Public Member Functions | Protected Member Functions | Private Attributes | Friends
QTMScrollView Class Reference

#include <QTMScrollView.hpp>

Inheritance diagram for QTMScrollView:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 QTMScrollView (QWidget *_parent=NULL)
virtual ~QTMScrollView ()
void setOrigin (QPoint newOrigin)
void setExtents (QRect newExtents)
QRect extents ()
QWidget * surface ()
QPoint origin ()
void ensureVisible (int cx, int cy, int mx=50, int my=50)
QPoint viewportToContents (QPoint const &pos) const
QPoint contentsToViewport (QPoint const &pos) const

Protected Member Functions

void updateScrollBars ()
void scrollContentsBy (int dx, int dy)
virtual bool viewportEvent (QEvent *e)
virtual bool surfaceEvent (QEvent *e)
virtual bool event (QEvent *e)

Private Attributes

QRect p_extents
QPoint p_origin
QWidget * p_surface

Friends

class QTMSurface

Detailed Description

Definition at line 26 of file QTMScrollView.hpp.


Constructor & Destructor Documentation

QTMScrollView::QTMScrollView ( QWidget *  _parent = NULL)

Definition at line 57 of file QTMScrollView.cpp.

: QAbstractScrollArea (_parent), p_extents(QRect(0,0,0,0))  {

  QWidget *_viewport = QAbstractScrollArea::viewport();
  _viewport->setBackgroundRole(QPalette::Mid);
  _viewport->setAutoFillBackground(true);

  p_surface = new QTMSurface (_viewport);
  p_surface->setAttribute(Qt::WA_NoSystemBackground);
  p_surface->setAttribute(Qt::WA_StaticContents); 
  p_surface->setAttribute(Qt::WA_MacNoClickThrough);
  p_surface->setAutoFillBackground(false);
  p_surface->setBackgroundRole(QPalette::NoRole);
  p_surface->setAttribute(Qt::WA_OpaquePaintEvent);
  p_surface->setGeometry(_viewport->geometry());
  p_surface->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);

  QHBoxLayout *layout = new QHBoxLayout();
  layout->addWidget(p_surface, 0, Qt::AlignHCenter);
  layout->setContentsMargins(0,0,0,0);
  _viewport->setLayout(layout);
  
}
QTMScrollView::~QTMScrollView ( void  ) [virtual]

Definition at line 86 of file QTMScrollView.cpp.

{ }

Member Function Documentation

QPoint QTMScrollView::contentsToViewport ( QPoint const &  pos) const [inline]

Definition at line 49 of file QTMScrollView.hpp.

{ return pos - p_origin; };
void QTMScrollView::ensureVisible ( int  cx,
int  cy,
int  mx = 50,
int  my = 50 
)

Definition at line 109 of file QTMScrollView.cpp.

                                                              {
       QWidget *_viewport = QAbstractScrollArea::viewport();
       int w = _viewport->width();
       int h = _viewport->height();
  
       int dx = - p_origin.x();
       int dy = - p_origin.y();
       int cw = p_extents.width();
       int ch = p_extents.height();
  
       if (w < mx * 2) mx = w / 2;
       if (h < my * 2) my = h / 2;
  
       if (cw <= w) { mx = 0; dx = 0; }
  
       if (ch <= h) { my = 0; dy = 0; }
  
       if (cx < mx - dx) dx = mx - cx;
       else if (cx >= w - mx - dx) dx  = w - mx - cx;
  
       if (cy < my - dy) dy = my - cy;
       else if (cy >= h - my - dy) dy  = h - my - cy;
  
       if (dx > 0) dx = 0;
       else if (dx < w - cw && cw > w) dx = w - cw;
  
       if (dy > 0) dy = 0;
       else if (dy < h - ch && ch > h) dy = h - ch;
  
       setOrigin (QPoint(-dx, -dy));
}

Here is the call graph for this function:

bool QTMScrollView::event ( QEvent *  e) [protected, virtual]

Definition at line 264 of file QTMScrollView.cpp.

                                        {
  switch (event->type()) {
    case QEvent::Resize:
    {
      bool res = QAbstractScrollArea::event(event);
      updateScrollBars();
      return res;
    }
    default:
      break;
  }
  return QAbstractScrollArea::event(event);
}

Here is the call graph for this function:

Here is the caller graph for this function:

QRect QTMScrollView::extents ( ) [inline]

Definition at line 40 of file QTMScrollView.hpp.

{ return p_extents; }

Here is the caller graph for this function:

QPoint QTMScrollView::origin ( ) [inline]

Definition at line 42 of file QTMScrollView.hpp.

{ return p_origin; }

Here is the caller graph for this function:

void QTMScrollView::scrollContentsBy ( int  dx,
int  dy 
) [protected]

Reimplemented in QTMWidget.

Definition at line 186 of file QTMScrollView.cpp.

                                                 {
       if (dx) p_origin.setX(p_origin.x() - dx);
       if (dy) p_origin.setY(p_origin.y() - dy);
}
void QTMScrollView::setExtents ( QRect  newExtents)

Definition at line 99 of file QTMScrollView.cpp.

                                             {
  if (p_extents != newExtents) {
    p_extents = newExtents;
    if (p_extents.width() < 0) p_extents.setWidth(0);
    if (p_extents.height() < 0) p_extents.setHeight(0);
    updateScrollBars();
  }
}

Here is the call graph for this function:

void QTMScrollView::setOrigin ( QPoint  newOrigin)

Definition at line 89 of file QTMScrollView.cpp.

                                            {
  if (newOrigin.x() != p_origin.x()) {
    QAbstractScrollArea::horizontalScrollBar()->setSliderPosition(newOrigin.x());
  }
  if (newOrigin.y() != p_origin.y()) {
       QAbstractScrollArea::verticalScrollBar()->setSliderPosition(newOrigin.y());
  } 
}

Here is the caller graph for this function:

QWidget * QTMScrollView::surface ( )

Definition at line 82 of file QTMScrollView.cpp.

                                {
  return p_surface;
}

Here is the caller graph for this function:

bool QTMScrollView::surfaceEvent ( QEvent *  e) [protected, virtual]

Definition at line 229 of file QTMScrollView.cpp.

{
  switch (e->type()) {
    case QEvent::Resize:
    case QEvent::Paint:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick:
#if QT_VERSION >= 0x040600
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
#endif
    case QEvent::MouseMove:
    case QEvent::ContextMenu:
    case QEvent::Wheel:
    case QEvent::Drop:
    case QEvent::DragEnter:
    case QEvent::DragMove:
    case QEvent::DragLeave:
      return QFrame::event(e);
    case QEvent::LayoutRequest:
#if QT_VERSION >= 0x040600
#ifndef QT_NO_GESTURES
    case QEvent::Gesture:
    case QEvent::GestureOverride:
      return event(e);
#endif
#endif
    default:
      break;
  }
  return false; // let the surface widget handle the event
}

Here is the call graph for this function:

Here is the caller graph for this function:

void QTMScrollView::updateScrollBars ( void  ) [protected]

Definition at line 142 of file QTMScrollView.cpp.

                                     {
       QWidget *_viewport = QAbstractScrollArea::viewport();
       int w = _viewport->width()  ; // -2
       int h = _viewport->height() ; // -2
  
       QScrollBar *_hScrollBar = QAbstractScrollArea::horizontalScrollBar();
       int cw = (p_extents.width() > w ? p_extents.width() - w : 0);
       if (_hScrollBar->sliderPosition() > cw)
              _hScrollBar->setSliderPosition(cw);
       _hScrollBar->setRange(0, cw);
       _hScrollBar->setSingleStep((w >> 4) + 1);
       _hScrollBar->setPageStep(w);
  
  QRect r = (p_extents.width() > w) ? QRect(0,0,w,h) 
    : QRect ((w-p_extents.width())/2,0,p_extents.width(),h);
//  surface()->setGeometry(r);
  surface()->setMinimumWidth(r.width());
  
       QScrollBar *_vScrollBar = QAbstractScrollArea::verticalScrollBar();
       int ch = (p_extents.height() > h ? p_extents.height() - h : 0);
       if (_vScrollBar->sliderPosition() > ch)
              _vScrollBar->setSliderPosition(ch);
       _vScrollBar->setRange(0, ch);
       _vScrollBar->setSingleStep((h >> 4) + 1);
       _vScrollBar->setPageStep(h);
  
  
  // we may need a relayout if the surface width is changed
  updateGeometry();
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool QTMScrollView::viewportEvent ( QEvent *  e) [protected, virtual]

Definition at line 192 of file QTMScrollView.cpp.

{
  switch (e->type()) {
    case QEvent::Resize:
    case QEvent::Paint:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick:
#if QT_VERSION >= 0x040600
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
#endif
    case QEvent::MouseMove:
    case QEvent::ContextMenu:
    case QEvent::Wheel:
    case QEvent::Drop:
    case QEvent::DragEnter:
    case QEvent::DragMove:
    case QEvent::DragLeave:
//      return QFrame::event(e);
      return false; // let the viewport widget handle the event
    case QEvent::LayoutRequest:
#if QT_VERSION >= 0x040600
#ifndef QT_NO_GESTURES
    case QEvent::Gesture:
    case QEvent::GestureOverride:
      return event(e);
#endif
#endif
    default:
      break;
  }
  return false; // let the viewport widget handle the event
}

Here is the call graph for this function:

QPoint QTMScrollView::viewportToContents ( QPoint const &  pos) const [inline]

Definition at line 48 of file QTMScrollView.hpp.

{ return pos + p_origin; };

Friends And Related Function Documentation

friend class QTMSurface [friend]

Definition at line 63 of file QTMScrollView.hpp.


Member Data Documentation

QRect QTMScrollView::p_extents [private]

Definition at line 29 of file QTMScrollView.hpp.

QPoint QTMScrollView::p_origin [private]

Definition at line 30 of file QTMScrollView.hpp.

QWidget* QTMScrollView::p_surface [private]

Definition at line 31 of file QTMScrollView.hpp.


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