Back to index

texmacs  1.0.7.15
QTMScrollView.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  * MODULE     : QTMScrollView.hpp
00004  * DESCRIPTION: QT Texmacs abstract scroll view widget
00005  * COPYRIGHT  : (C) 2009 Massimiliano Gubinelli
00006  *******************************************************************************
00007  * This software falls under the GNU general public license version 3 or later.
00008  * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009  * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010  ******************************************************************************/
00011 
00012 #ifndef QTMSCROLLVIEW_HPP
00013 #define QTMSCROLLVIEW_HPP
00014 
00015 #include <QAbstractScrollArea>
00016 #include <QRect>
00017 
00018 // Forward declarations.
00019 class QResizeEvent;
00020 class QPaintEvent;
00021 
00022 
00023 //----------------------------------------------------------------------------
00024 // QTMScrollView -- abstract scroll view widget.
00025 
00026 class QTMScrollView : public QAbstractScrollArea {
00027   Q_OBJECT
00028 
00029   QRect p_extents;
00030   QPoint p_origin;
00031   QWidget *p_surface;
00032   
00033 public:
00034   
00035   QTMScrollView (QWidget *_parent = NULL);
00036   virtual ~QTMScrollView();
00037   
00038   void setOrigin ( QPoint newOrigin ) ;
00039   void setExtents ( QRect newExtents ) ;
00040   QRect extents() { return p_extents; }
00041   QWidget* surface() ;
00042   QPoint origin() { return p_origin; }
00043   
00044   // Scrolls contents so that given point is visible.
00045   void ensureVisible (int cx, int cy, int mx = 50, int my = 50);
00046   
00047   // Viewport/contents position converters.
00048   QPoint viewportToContents ( QPoint const& pos) const { return pos + p_origin; };
00049   QPoint contentsToViewport ( QPoint const& pos) const { return pos - p_origin; };
00050   
00051 protected:
00052   
00053   // Scrollbar stabilization.
00054   void updateScrollBars();
00055   
00056   // Scroll area updater.
00057   void scrollContentsBy(int dx, int dy);
00058   
00059   virtual bool viewportEvent(QEvent *e);
00060   virtual bool surfaceEvent(QEvent *e);
00061   virtual bool event(QEvent *e);
00062 
00063   friend class QTMSurface;
00064 };
00065 
00066 #endif // QTMSCROLLVIEW_HPP