class library: PriorityQueue - implement removeValue, hide array
[supercollider.git] / QtCollider / widgets / QcScrollArea.cpp
blob53cdd2bd920530dd479954cab896fad6ea127a7b
1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #include "QcScrollArea.h"
23 #include "../QcWidgetFactory.h"
25 #include <QLayout>
26 #include <QScrollBar>
27 #include <QEvent>
28 #include <QChildEvent>
29 #include <QApplication>
31 class QcScrollWidgetFactory : public QcWidgetFactory<QcScrollWidget>
33 protected:
34 virtual void initialize( QWidgetProxy *p, QcScrollWidget *w )
36 QObject::connect( w, SIGNAL(painting(QPainter*)),
37 p, SLOT(customPaint(QPainter*)) );
41 static QcScrollWidgetFactory scrollWidgetFactory;
43 QcScrollWidget::QcScrollWidget( QWidget *parent ) : QcCanvas( parent )
45 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
48 QSize QcScrollWidget::sizeHint() const
50 QRect r = childrenRect();
51 QSize sz( r.x() + r.width(), r.y() + r.height() );
52 return sz;
55 bool QcScrollWidget::event ( QEvent * e ) {
56 int t = e->type();
57 if( t == QEvent::ChildAdded ) {
58 QChildEvent *ce = static_cast<QChildEvent*>(e);
59 ce->child()->installEventFilter( this );
61 else if( t == QEvent::ChildRemoved ) {
62 updateGeometry();
65 return QWidget::event( e );
68 bool QcScrollWidget::eventFilter ( QObject * watched, QEvent * event ) {
69 Q_UNUSED( watched );
71 switch( event->type() ) {
72 case QEvent::Resize:
73 case QEvent::Move:
74 case QEvent::Show:
75 case QEvent::Hide:
76 updateGeometry();
77 break;
78 default:
79 return false;
82 return false;
87 static QcWidgetFactory<QcScrollArea> scrollAreaFactory;
89 QcScrollArea::QcScrollArea()
94 void QcScrollArea::setWidget( QObjectProxy *proxy )
96 QWidget *w = qobject_cast<QWidget*>( proxy->object() );
97 if( !w ) {
98 qcErrorMsg( "QcScrollArea::setCanvas: given proxy does not contain a valid widget." );
99 return;
101 QScrollArea::setWidget( w );
102 setWidgetResizable( true );
105 void QcScrollArea::addChild( QWidget* w )
107 if( widget() ) {
108 w->setParent( widget() );
109 w->show();
113 QRectF QcScrollArea::innerBounds() const {
114 QSize vs = viewport()->size();
115 if( !widget() ) return QRectF(0,0,vs.width(),vs.height());
116 QSize cs = widget()->size();
117 return QRectF(0, 0,
118 qMax( vs.width(), cs.width() ),
119 qMax( vs.height(), cs.height() ) );
122 void QcScrollArea::setHasBorder( bool b ) {
123 if( b )
124 QFrame::setFrameShape( QFrame::StyledPanel );
125 else
126 QFrame::setFrameShape( QFrame::NoFrame );
129 QPointF QcScrollArea::visibleOrigin() const
131 QWidget *w = widget();
132 return ( w != 0 ? widget()->mapFromParent( QPoint(0,0) ) : QPoint(0,0) );
135 void QcScrollArea::setVisibleOrigin( const QPointF &pt )
137 horizontalScrollBar()->setValue( pt.x() );
138 verticalScrollBar()->setValue( pt.y() );