MIRA
ScrollView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_SCROLLVIEW_H_
48 #define _MIRA_SCROLLVIEW_H_
49 
50 #include <QAbstractScrollArea>
51 
52 namespace mira {
53 
55 
66 class ScrollView : public QAbstractScrollArea
67 {
68  Q_OBJECT
69 public:
70 
71  ScrollView(QWidget* parent);
72 
74  int contentsX() const { return mContentsRect.x(); }
76  int contentsY() const { return mContentsRect.y(); }
78  int contentsHeight() const { return mContentsRect.height(); }
80  int contentsWidth() const { return mContentsRect.width(); }
81 
83  void setContentsPos(int x, int y);
85  void resizeContents(int width, int height);
86 
93  void ensureVisible(int x, int y, int marginX = 50, int marginY = 50);
94 
96  QPoint viewportToContents(const QPoint& pos) const;
98  QPoint contentsToViewport(const QPoint& pos) const;
99 
100 signals:
101 
103  void contentsMoving(int x, int y);
104 
105 protected:
106 
107  void updateScrollBars();
108  virtual void scrollContentsBy(int dX, int dY);
109 
110  virtual void resizeEvent(QResizeEvent* resizeEvent);
111  virtual void paintEvent(QPaintEvent* paintEvent);
112  virtual void wheelEvent(QWheelEvent* wheelEvent);
113 
118  virtual void drawContents(QPainter* painter, const QRect& rect) = 0;
119 
125  virtual void updateContents(const QRect& rect);
130  virtual void updateContents();
131 
133 };
134 
136 
137 }
138 
139 #endif
QPoint viewportToContents(const QPoint &pos) const
Converts viewport coordinates to content area coordinates.
virtual void resizeEvent(QResizeEvent *resizeEvent)
int contentsX() const
The x coordinate of the content area.
Definition: ScrollView.h:74
void setContentsPos(int x, int y)
Set the position of the content area.
virtual void scrollContentsBy(int dX, int dY)
int contentsWidth() const
The width of the content area.
Definition: ScrollView.h:80
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void ensureVisible(int x, int y, int marginX=50, int marginY=50)
Ensures that the position given by x and y with the specified margins is within the content area by s...
int contentsHeight() const
The height of the content area.
Definition: ScrollView.h:78
void resizeContents(int width, int height)
Resize the content area.
int contentsY() const
The y coordinate of the content area.
Definition: ScrollView.h:76
void contentsMoving(int x, int y)
Signal emitted when the position of the content area changed.
ScrollView(QWidget *parent)
void updateScrollBars()
virtual void wheelEvent(QWheelEvent *wheelEvent)
virtual void drawContents(QPainter *painter, const QRect &rect)=0
Overload this method in derived classes to draw the content of the content area.
virtual void paintEvent(QPaintEvent *paintEvent)
virtual void updateContents()
Call this method to schedule an update of the content area.
ScrollView extends the QAbstractScrollArea by features like automatic scaling of scrollbars, signals when the visible are was moved and so on.
Definition: ScrollView.h:66
QRect mContentsRect
Definition: ScrollView.h:132
QPoint contentsToViewport(const QPoint &pos) const
Converts content area coordinates to viewport coordinates.