Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

customproxy.cpp Example File
demos/embeddeddialogs/customproxy.cpp

 /****************************************************************************
 **
 ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
 **
 ** This file is part of the demonstration applications of the Qt Toolkit.
 **
 ** This file may be used under the terms of the GNU General Public
 ** License version 2.0 as published by the Free Software Foundation
 ** and appearing in the file LICENSE.GPL included in the packaging of
 ** this file.  Please review the following information to ensure GNU
 ** General Public Licensing requirements will be met:
 ** http://trolltech.com/products/qt/licenses/licensing/opensource/
 **
 ** If you are unsure which license is appropriate for your use, please
 ** review the following information:
 ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
 ** or contact the sales department at sales@trolltech.com.
 **
 ** In addition, as a special exception, Trolltech gives you certain
 ** additional rights. These rights are described in the Trolltech GPL
 ** Exception version 1.0, which can be found at
 ** http://www.trolltech.com/products/qt/gplexception/ and in the file
 ** GPL_EXCEPTION.txt in this package.
 **
 ** In addition, as a special exception, Trolltech, as the sole copyright
 ** holder for Qt Designer, grants users of the Qt/Eclipse Integration
 ** plug-in the right for the Qt/Eclipse Integration to link to
 ** functionality provided by Qt Designer and its related libraries.
 **
 ** Trolltech reserves all rights not expressly granted herein.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/

 #include "customproxy.h"

 #include <QtGui>

 CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
     : QGraphicsProxyWidget(parent, wFlags)
 {
     timeLine = new QTimeLine(250, this);
     connect(timeLine, SIGNAL(valueChanged(qreal)),
             this, SLOT(updateStep(qreal)));
     connect(timeLine, SIGNAL(stateChanged(QTimeLine::State)),
             this, SLOT(stateChanged(QTimeLine::State)));
 }

 QRectF CustomProxy::boundingRect() const
 {
     return QGraphicsProxyWidget::boundingRect().adjusted(0, 0, 10, 10);
 }

 void CustomProxy::paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
                                    QWidget *widget)
 {
     QRectF br = boundingRect();
     painter->setPen(Qt::NoPen);
     painter->setBrush(QColor(0, 0, 0, 64));
     painter->drawPolygon(QPolygonF(br.adjusted(10, 10, 10, 10))
                          .intersected(br));
     QGraphicsProxyWidget::paintWindowFrame(painter, option, widget);
 }

 void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
     QGraphicsProxyWidget::hoverEnterEvent(event);
     scene()->setActiveWindow(this);
     if (timeLine->direction() != QTimeLine::Forward)
         timeLine->setDirection(QTimeLine::Forward);
     if (timeLine->state() == QTimeLine::NotRunning)
         timeLine->start();
 }

 void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
 {
     QGraphicsProxyWidget::hoverLeaveEvent(event);
     if (timeLine->direction() != QTimeLine::Backward)
         timeLine->setDirection(QTimeLine::Backward);
     if (timeLine->state() == QTimeLine::NotRunning)
         timeLine->start();
 }

 void CustomProxy::updateStep(qreal step)
 {
     QRectF r = boundingRect();
     setTransform(QTransform()
                  .translate(r.width() / 2, r.height() / 2)
                  .rotate(step * 30, Qt::XAxis)
                  .rotate(step * 10, Qt::YAxis)
                  .rotate(step * 5, Qt::ZAxis)
                  .scale(1 + 1.5 * step, 1 + 1.5 * step)
                  .translate(-r.width() / 2, -r.height() / 2));
 }

 void CustomProxy::stateChanged(QTimeLine::State state)
 {
     if (state == QTimeLine::Running) {
         if (timeLine->direction() == QTimeLine::Forward)
             setCacheMode(NoCache);
     } else if (state == QTimeLine::NotRunning) {
         if (timeLine->direction() == QTimeLine::Backward)
             setCacheMode(DeviceCoordinateCache);
     }
 }


Copyright © 2007 Trolltech Trademarks
Qt 4.4.0-tp1