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"
28 #include <QChildEvent>
29 #include <QApplication>
31 class QcScrollWidgetFactory
: public QcWidgetFactory
<QcScrollWidget
>
34 virtual void initialize( QWidgetProxy
*p
, QcScrollWidget
*w
, QList
<QVariant
> & args
)
37 QObject::connect( w
, SIGNAL(painting(QPainter
*)),
38 p
, SLOT(customPaint(QPainter
*)) );
42 static QcScrollWidgetFactory scrollWidgetFactory
;
44 QcScrollWidget::QcScrollWidget( QWidget
*parent
) : QcCanvas( parent
)
46 setSizePolicy( QSizePolicy::Minimum
, QSizePolicy::Minimum
);
49 QSize
QcScrollWidget::sizeHint() const
51 QRect r
= childrenRect();
52 QSize
sz( r
.x() + r
.width(), r
.y() + r
.height() );
56 bool QcScrollWidget::event ( QEvent
* e
) {
58 if( t
== QEvent::ChildAdded
) {
59 QChildEvent
*ce
= static_cast<QChildEvent
*>(e
);
60 ce
->child()->installEventFilter( this );
62 else if( t
== QEvent::ChildRemoved
) {
66 return QWidget::event( e
);
69 bool QcScrollWidget::eventFilter ( QObject
* watched
, QEvent
* event
) {
72 switch( event
->type() ) {
88 static QcWidgetFactory
<QcScrollArea
> scrollAreaFactory
;
90 QcScrollArea::QcScrollArea()
95 void QcScrollArea::setWidget( QObjectProxy
*proxy
)
97 QWidget
*w
= qobject_cast
<QWidget
*>( proxy
->object() );
99 qcErrorMsg( "QcScrollArea::setCanvas: given proxy does not contain a valid widget." );
102 QScrollArea::setWidget( w
);
103 setWidgetResizable( true );
106 void QcScrollArea::addChild( QWidget
* w
)
109 w
->setParent( widget() );
114 QRectF
QcScrollArea::innerBounds() const {
115 QSize vs
= viewport()->size();
116 if( !widget() ) return QRectF(0,0,vs
.width(),vs
.height());
117 QSize cs
= widget()->size();
119 qMax( vs
.width(), cs
.width() ),
120 qMax( vs
.height(), cs
.height() ) );
123 void QcScrollArea::setHasBorder( bool b
) {
125 QFrame::setFrameShape( QFrame::StyledPanel
);
127 QFrame::setFrameShape( QFrame::NoFrame
);
130 QPointF
QcScrollArea::visibleOrigin() const
132 QWidget
*w
= widget();
133 return ( w
!= 0 ? widget()->mapFromParent( QPoint(0,0) ) : QPoint(0,0) );
136 void QcScrollArea::setVisibleOrigin( const QPointF
&pt
)
138 horizontalScrollBar()->setValue( pt
.x() );
139 verticalScrollBar()->setValue( pt
.y() );