summaryrefslogtreecommitdiffstats
path: root/examples/animation/padnavigator-ng/roundrectitem.cpp
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-04-17 14:06:06 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-04-17 14:06:06 (GMT)
commitf15b8a83e2e51955776a3f07cb85ebfc342dd8ef (patch)
treec5dc684986051654898db11ce73e03b9fec8db99 /examples/animation/padnavigator-ng/roundrectitem.cpp
downloadQt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.zip
Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.gz
Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.bz2
Initial import of statemachine branch from the old kinetic repository
Diffstat (limited to 'examples/animation/padnavigator-ng/roundrectitem.cpp')
-rw-r--r--examples/animation/padnavigator-ng/roundrectitem.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/examples/animation/padnavigator-ng/roundrectitem.cpp b/examples/animation/padnavigator-ng/roundrectitem.cpp
new file mode 100644
index 0000000..e498538
--- /dev/null
+++ b/examples/animation/padnavigator-ng/roundrectitem.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $TROLLTECH_DUAL_LICENSE$
+**
+****************************************************************************/
+
+#include "roundrectitem.h"
+
+#include <QtGui/QtGui>
+
+RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget)
+ : QGraphicsWidget(),
+ brush(brush),
+ proxyWidget(0),
+ m_rect(rect)
+{
+ if (embeddedWidget) {
+ proxyWidget = new QGraphicsProxyWidget(this);
+ proxyWidget->setFocusPolicy(Qt::StrongFocus);
+ proxyWidget->setWidget(embeddedWidget);
+ }
+}
+
+void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ const bool widgetHidden = parentItem() == 0 || qAbs(static_cast<QGraphicsWidget*>(parentItem())->yRotation()) < 90;
+
+ if (proxyWidget) {
+ if (widgetHidden) {
+ proxyWidget->hide();
+ } else {
+ if (!proxyWidget->isVisible()) {
+ proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25));
+ proxyWidget->show();
+ proxyWidget->setFocus();
+ }
+ painter->setBrush(brush);
+ painter->setPen(QPen(Qt::black, 1));
+ painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+ painter->drawRoundRect(m_rect);
+ }
+ } else if (widgetHidden) {
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(0, 0, 0, 64));
+ painter->drawRoundRect(m_rect.translated(2, 2));
+
+ QLinearGradient gradient(m_rect.topLeft(), m_rect.bottomRight());
+ const QColor col = brush.color();
+ gradient.setColorAt(0, col);
+ gradient.setColorAt(1, col.dark(200));
+ painter->setBrush(gradient);
+ painter->setPen(QPen(Qt::black, 1));
+ painter->drawRoundRect(m_rect);
+ if (!pix.isNull()) {
+ painter->scale(qreal(1.95), qreal(1.95));
+ painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix);
+ }
+ }
+
+}
+
+QRectF RoundRectItem::boundingRect() const
+{
+ qreal penW = qreal(.5);
+ qreal shadowW = 2;
+ return m_rect.adjusted(-penW, -penW, penW + shadowW, penW + shadowW);
+}
+
+void RoundRectItem::setPixmap(const QPixmap &pixmap)
+{
+ pix = pixmap;
+ if (scene() && isVisible())
+ update();
+}
+
+void RoundRectItem::keyPressEvent(QKeyEvent *event)
+{
+ if (event->isAutoRepeat() || event->key() != Qt::Key_Return) {
+ QGraphicsWidget::keyPressEvent(event);
+ return;
+ }
+
+ if (!proxyWidget) {
+ setXScale(qreal(.9));
+ setYScale(qreal(.9));
+ }
+ emit activated();
+}
+
+void RoundRectItem::keyReleaseEvent(QKeyEvent *event)
+{
+ if (event->isAutoRepeat() || event->key() != Qt::Key_Return) {
+ QGraphicsWidget::keyReleaseEvent(event);
+ return;
+ }
+
+ if (!proxyWidget) {
+ setXScale(1);
+ setYScale(1);
+ }
+}