Synchronize with upstream release 0.3 from https://monav.googlecode.com/svn/tags...
[monav:monav.git] / client / scrollarea.cpp
1 /*
2 Copyright 2010  Christian Vetter veaac.fdirct@gmail.com
3
4 This file is part of MoNav.
5
6 MoNav is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MoNav is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with MoNav.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "scrollarea.h"
21 #include <QApplication>
22 #include <QStyle>
23 #include <QResizeEvent>
24 #include <QMouseEvent>
25 #include <QtDebug>
26
27 ScrollArea::ScrollArea( QWidget* parent ) :
28         QScrollArea( parent )
29 {
30         m_orientation = Qt::Vertical;
31 }
32
33 Qt::Orientation ScrollArea::orientation()
34 {
35         return m_orientation;
36 }
37
38 void ScrollArea::setOrientation( Qt::Orientation orientation )
39 {
40         m_orientation = orientation;
41 }
42
43 void ScrollArea::mousePressEvent( QMouseEvent* event )
44 {
45         event->accept();
46 }
47
48 void ScrollArea::mouseMoveEvent( QMouseEvent* event )
49 {
50         event->accept();
51 }
52
53 void ScrollArea::resizeEvent( QResizeEvent* event )
54 {
55         QScrollArea::resizeEvent( event );
56
57         if ( widget() == NULL )
58                 return;
59
60         int widgetWidth = widget()->sizeHint().width() + 2 * frameWidth();
61         int widgetHeight = widget()->sizeHint().height() + 2 * frameWidth();
62
63         if ( m_orientation == Qt::Vertical ) {
64                 if ( widgetHeight > height() ) {
65                         widgetWidth += QApplication::style()->pixelMetric( QStyle::PM_ScrollBarExtent );
66                         widgetWidth += QApplication::style()->pixelMetric( QStyle::PM_ScrollView_ScrollBarSpacing );
67                 }
68                 setFixedWidth( widgetWidth );
69                 setMaximumHeight( widgetHeight );
70         } else {
71                 if ( widgetWidth > width() ) {
72                         widgetHeight += QApplication::style()->pixelMetric( QStyle::PM_ScrollBarExtent );
73                         widgetHeight += QApplication::style()->pixelMetric( QStyle::PM_ScrollView_ScrollBarSpacing );
74                 }
75                 setFixedHeight( widgetHeight );
76                 setMaximumWidth( widgetWidth );
77         }
78 }