diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-05-22 10:17:59 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-05-22 10:17:59 (GMT) |
commit | 42fe40e777a35818dcb9f7cd00ddf93e44477e36 (patch) | |
tree | 2b4f675826d5d57cbece5ad9b4dc89d470453342 /examples | |
parent | d0ac49ec731f0781ba48f8f5d8ce04e19ce0010d (diff) | |
download | Qt-42fe40e777a35818dcb9f7cd00ddf93e44477e36.zip Qt-42fe40e777a35818dcb9f7cd00ddf93e44477e36.tar.gz Qt-42fe40e777a35818dcb9f7cd00ddf93e44477e36.tar.bz2 |
Revert "update the padnavigator example and suppress the padnavigator-ng"
This reverts commit 1cad8c56002a61a6240e6580cdbd784209821fa6.
Conflicts:
examples/graphicsview/padnavigator/roundrectitem.cpp
Diffstat (limited to 'examples')
-rw-r--r-- | examples/graphicsview/padnavigator/images/artsfftscope.png | bin | 1290 -> 1291 bytes | |||
-rw-r--r-- | examples/graphicsview/padnavigator/main.cpp | 4 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/panel.cpp | 168 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/panel.h | 29 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/roundrectitem.cpp | 109 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/roundrectitem.h | 16 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/splashitem.cpp | 25 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/splashitem.h | 6 |
8 files changed, 207 insertions, 150 deletions
diff --git a/examples/graphicsview/padnavigator/images/artsfftscope.png b/examples/graphicsview/padnavigator/images/artsfftscope.png Binary files differindex 756a1cf..4db003f 100644 --- a/examples/graphicsview/padnavigator/images/artsfftscope.png +++ b/examples/graphicsview/padnavigator/images/artsfftscope.png diff --git a/examples/graphicsview/padnavigator/main.cpp b/examples/graphicsview/padnavigator/main.cpp index f7d6f90..dc5ff0c 100644 --- a/examples/graphicsview/padnavigator/main.cpp +++ b/examples/graphicsview/padnavigator/main.cpp @@ -40,6 +40,10 @@ ****************************************************************************/ #include <QtGui> +#ifndef QT_NO_OPENGL +# include <QtOpenGL> +#endif + #include "panel.h" int main(int argc, char *argv[]) diff --git a/examples/graphicsview/padnavigator/panel.cpp b/examples/graphicsview/padnavigator/panel.cpp index c088fbc..28a3cb4 100644 --- a/examples/graphicsview/padnavigator/panel.cpp +++ b/examples/graphicsview/padnavigator/panel.cpp @@ -50,15 +50,15 @@ #endif #include <QtGui/QtGui> +#include <math.h> + Panel::Panel(int width, int height) - : selectedIndex(0), - grid(width*height), + : selectedX(0), + selectedY(0), width(width), height(height), flipped(false), - flippingGroup(0), - rotationXanim(0), - rotationYanim(0) + flipLeft(true) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -72,9 +72,12 @@ Panel::Panel(int width, int height) #endif setMinimumSize(50, 50); + selectionTimeLine = new QTimeLine(150, this); + flipTimeLine = new QTimeLine(500, this); + QRectF bounds((-width / 2.0) * 150, (-height / 2.0) * 150, width * 150, height * 150); - QGraphicsScene *scene = new QGraphicsScene(bounds, this); + scene = new QGraphicsScene(bounds, this); scene->setItemIndexMethod(QGraphicsScene::NoIndex); setScene(scene); @@ -87,24 +90,28 @@ Panel::Panel(int width, int height) ui->hostName->setFocus(); backItem = new RoundRectItem(bounds, embed->palette().window(), embed); - backItem->setYRotation(180); + backItem->setTransform(QTransform().rotate(180, Qt::YAxis)); backItem->setParentItem(baseItem); selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray); selectionItem->setParentItem(baseItem); selectionItem->setZValue(-1); - selectionItem->setPos(posForLocation(0)); + selectionItem->setPos(posForLocation(0, 0)); + startPos = selectionItem->pos(); - int currentIndex = 0; + grid = new QGraphicsItem **[height]; + for (int y = 0; y < height; ++y) { + grid[y] = new QGraphicsItem *[width]; + for (int x = 0; x < width; ++x) { RoundRectItem *item = new RoundRectItem(QRectF(-54, -54, 108, 108), QColor(214, 240, 110, 128)); - item->setPos(posForLocation(currentIndex)); + item->setPos(posForLocation(x, y)); item->setParentItem(baseItem); item->setFlag(QGraphicsItem::ItemIsFocusable); - grid[currentIndex++] = item; + grid[y][x] = item; switch (qrand() % 9) { case 0: item->setPixmap(QPixmap(":/images/kontact_contacts.png")); break; @@ -124,10 +131,14 @@ Panel::Panel(int width, int height) } } - grid.first()->setFocus(); + grid[0][0]->setFocus(); connect(backItem, SIGNAL(activated()), this, SLOT(flip())); + connect(selectionTimeLine, SIGNAL(valueChanged(qreal)), + this, SLOT(updateSelectionStep(qreal))); + connect(flipTimeLine, SIGNAL(valueChanged(qreal)), + this, SLOT(updateFlipStep(qreal))); splash = new SplashItem; splash->setZValue(5); @@ -136,15 +147,16 @@ Panel::Panel(int width, int height) splash->grabKeyboard(); - //initialize the position - baseItem->setYRotation(selectionItem->x()/6.); - baseItem->setXRotation(selectionItem->y()/6.); + updateSelectionStep(0); setWindowTitle(tr("Pad Navigator Example")); } Panel::~Panel() { + for (int y = 0; y < height; ++y) + delete [] grid[y]; + delete [] grid; } void Panel::keyPressEvent(QKeyEvent *event) @@ -154,93 +166,73 @@ void Panel::keyPressEvent(QKeyEvent *event) return; } - selectedIndex = (selectedIndex + grid.count() + (event->key() == Qt::Key_Right) - (event->key() == Qt::Key_Left) - + width * ((event->key() == Qt::Key_Down) - (event->key() == Qt::Key_Up))) % grid.count(); - grid[selectedIndex]->setFocus(); - - const QPointF pos = posForLocation(selectedIndex); - - const double angleY = pos.x() / 6., - angleX = pos.y() / 6.; - - QAnimationGroup *group = new QParallelAnimationGroup(); - - QVariantAnimation *anim = new QPropertyAnimation(baseItem, "xRotation"); - anim->setEndValue(angleX); - anim->setDuration(150); - anim->setEasingCurve(QEasingCurve::OutInSine); - group->addAnimation(anim); - - anim = new QPropertyAnimation(baseItem, "yRotation"); - anim->setEndValue(angleY); - anim->setDuration(150); - anim->setEasingCurve(QEasingCurve::OutInSine); - group->addAnimation(anim); - - anim = new QPropertyAnimation(selectionItem, "pos"); - anim->setEndValue(pos); - anim->setDuration(150); - anim->setEasingCurve(QEasingCurve::Linear); - group->addAnimation(anim); - - group->start(QAbstractAnimation::DeleteWhenStopped); + selectedX = (selectedX + width + (event->key() == Qt::Key_Right) - (event->key() == Qt::Key_Left)) % width; + selectedY = (selectedY + height + (event->key() == Qt::Key_Down) - (event->key() == Qt::Key_Up)) % height; + grid[selectedY][selectedX]->setFocus(); + + selectionTimeLine->stop(); + startPos = selectionItem->pos(); + endPos = posForLocation(selectedX, selectedY); + selectionTimeLine->start(); } void Panel::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); - fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); + fitInView(scene->sceneRect(), Qt::KeepAspectRatio); } -void Panel::flip() +void Panel::updateSelectionStep(qreal val) { - grid[selectedIndex]->setFocus(); - - if (flippingGroup == 0) { - flippingGroup = new QParallelAnimationGroup(this); - - const qreal zoomOut = qreal(.75); - - //slight scaling down while flipping - QVariantAnimation *anim = new QPropertyAnimation(baseItem, "yScale"); - anim->setKeyValueAt(qreal(.5), zoomOut); - anim->setEndValue(1); - anim->setEasingCurve(QEasingCurve::OutInSine); - anim->setDuration(500); - flippingGroup->addAnimation(anim); - - anim = new QPropertyAnimation(baseItem, "xScale"); - anim->setKeyValueAt(qreal(.5), zoomOut); - anim->setEndValue(1); - anim->setEasingCurve(QEasingCurve::OutInSine); - anim->setDuration(500); - flippingGroup->addAnimation(anim); - - rotationXanim = new QPropertyAnimation(baseItem, "xRotation"); - rotationXanim->setEndValue(0); - rotationXanim->setDuration(500); - flippingGroup->addAnimation(rotationXanim); - - rotationYanim = new QPropertyAnimation(baseItem, "yRotation"); - rotationYanim->setStartValue(0); - rotationYanim->setEndValue(180); - rotationYanim->setDuration(500); - flippingGroup->addAnimation(rotationYanim); - } + QPointF newPos(startPos.x() + (endPos - startPos).x() * val, + startPos.y() + (endPos - startPos).y() * val); + selectionItem->setPos(newPos); + + QTransform transform; + yrot = newPos.x() / 6.0; + xrot = newPos.y() / 6.0; + transform.rotate(newPos.x() / 6.0, Qt::YAxis); + transform.rotate(newPos.y() / 6.0, Qt::XAxis); + baseItem->setTransform(transform); +} - if (flippingGroup->currentTime() != 0 && flippingGroup->direction() == QAbstractAnimation::Forward) - flippingGroup->setDirection(QAbstractAnimation::Backward); +void Panel::updateFlipStep(qreal val) +{ + qreal finalxrot = xrot - xrot * val; + qreal finalyrot; + if (flipLeft) + finalyrot = yrot - yrot * val - 180 * val; else - flippingGroup->setDirection(QAbstractAnimation::Forward); + finalyrot = yrot - yrot * val + 180 * val; + QTransform transform; + transform.rotate(finalyrot, Qt::YAxis); + transform.rotate(finalxrot, Qt::XAxis); + qreal scale = 1 - sin(3.14 * val) * 0.3; + transform.scale(scale, scale); + baseItem->setTransform(transform); + if (val == 0) + grid[selectedY][selectedX]->setFocus(); +} - flippingGroup->start(); - flipped = !flipped; +void Panel::flip() +{ + if (flipTimeLine->state() == QTimeLine::Running) + return; + + if (flipTimeLine->currentValue() == 0) { + flipTimeLine->setDirection(QTimeLine::Forward); + flipTimeLine->start(); + flipped = true; + flipLeft = selectionItem->pos().x() < 0; + } else { + flipTimeLine->setDirection(QTimeLine::Backward); + flipTimeLine->start(); + flipped = false; + } } -QPointF Panel::posForLocation(int index) const +QPointF Panel::posForLocation(int x, int y) const { - const int x = index % width, - y = index / width; return QPointF(x * 150, y * 150) - QPointF((width - 1) * 75, (height - 1) * 75); } diff --git a/examples/graphicsview/padnavigator/panel.h b/examples/graphicsview/padnavigator/panel.h index cc03530..03876b7 100644 --- a/examples/graphicsview/padnavigator/panel.h +++ b/examples/graphicsview/padnavigator/panel.h @@ -40,12 +40,10 @@ ****************************************************************************/ #include <QtGui/qgraphicsview.h> -#include <QtGui/qgraphicswidget.h> QT_BEGIN_NAMESPACE +class QTimeLine; class Ui_BackSide; -class QAnimationGroup; -class QPropertyAnimation; QT_END_NAMESPACE; class RoundRectItem; @@ -62,24 +60,33 @@ protected: void resizeEvent(QResizeEvent *event); private Q_SLOTS: + void updateSelectionStep(qreal val); + void updateFlipStep(qreal val); void flip(); private: - QPointF posForLocation(int index) const; + QPointF posForLocation(int x, int y) const; - QGraphicsWidget *selectionItem; - QGraphicsWidget *baseItem; + QGraphicsScene *scene; + RoundRectItem *selectionItem; + RoundRectItem *baseItem; RoundRectItem *backItem; QGraphicsWidget *splash; - int selectedIndex; + QTimeLine *selectionTimeLine; + QTimeLine *flipTimeLine; + int selectedX, selectedY; - QVector<QGraphicsItem*> grid; + QGraphicsItem ***grid; + QPointF startPos; + QPointF endPos; + qreal xrot, yrot; + qreal xrot2, yrot2; + int width; int height; bool flipped; - Ui_BackSide *ui; + bool flipLeft; - QAnimationGroup *flippingGroup; - QPropertyAnimation *rotationXanim, *rotationYanim; + Ui_BackSide *ui; }; diff --git a/examples/graphicsview/padnavigator/roundrectitem.cpp b/examples/graphicsview/padnavigator/roundrectitem.cpp index 73d6d33..c5dc35d 100644 --- a/examples/graphicsview/padnavigator/roundrectitem.cpp +++ b/examples/graphicsview/padnavigator/roundrectitem.cpp @@ -44,61 +44,72 @@ #include <QtGui/QtGui> RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget) - : QGraphicsWidget(), - m_rect(rect), + : QGraphicsRectItem(rect), brush(brush), + timeLine(75), + lastVal(0), + opa(1), proxyWidget(0) { + connect(&timeLine, SIGNAL(valueChanged(qreal)), + this, SLOT(updateValue(qreal))); + if (embeddedWidget) { proxyWidget = new QGraphicsProxyWidget(this); proxyWidget->setFocusPolicy(Qt::StrongFocus); proxyWidget->setWidget(embeddedWidget); + proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25)); } } void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { - const bool widgetHidden = parentItem() == 0 || qAbs(static_cast<QGraphicsWidget*>(parentItem())->yRotation()) < 90; - - if (proxyWidget) { - if (widgetHidden) { + QTransform x = painter->worldTransform(); + + QLineF unit = x.map(QLineF(0, 0, 1, 1)); + if (unit.p1().x() > unit.p2().x() || unit.p1().y() > unit.p2().y()) { + if (proxyWidget && proxyWidget->isVisible()) { 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); + proxyWidget->setGeometry(rect()); } - } else if (widgetHidden) { - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0, 0, 0, 64)); - painter->drawRoundRect(m_rect.translated(2, 2)); + return; + } - QLinearGradient gradient(m_rect.topLeft(), m_rect.bottomRight()); + if (proxyWidget && !proxyWidget->isVisible()) { + proxyWidget->show(); + proxyWidget->setFocus(); + } + if (proxyWidget && proxyWidget->pos() != QPoint()) + proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25)); + + painter->setOpacity(opacity()); + painter->setPen(Qt::NoPen); + painter->setBrush(QColor(0, 0, 0, 64)); + painter->drawRoundRect(rect().translated(2, 2)); + + if (!proxyWidget) { + QLinearGradient gradient(rect().topLeft(), rect().bottomRight()); const QColor col = brush.color(); gradient.setColorAt(0, col); - gradient.setColorAt(1, col.dark(200)); + gradient.setColorAt(1, col.dark(int(200 + lastVal * 50))); 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); - } + } else { + painter->setBrush(brush); } + painter->setPen(QPen(Qt::black, 1)); + painter->drawRoundRect(rect()); + if (!pix.isNull()) { + painter->scale(1.95, 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); + qreal penW = 0.5; + qreal shadowW = 2.0; + return rect().adjusted(-penW, -penW, penW + shadowW, penW + shadowW); } void RoundRectItem::setPixmap(const QPixmap &pixmap) @@ -108,26 +119,46 @@ void RoundRectItem::setPixmap(const QPixmap &pixmap) update(); } +qreal RoundRectItem::opacity() const +{ + RoundRectItem *parent = parentItem() ? (RoundRectItem *)parentItem() : 0; + return opa + (parent ? parent->opacity() : 0); +} + +void RoundRectItem::setOpacity(qreal opacity) +{ + opa = opacity; + update(); +} + void RoundRectItem::keyPressEvent(QKeyEvent *event) { - if (event->isAutoRepeat() || event->key() != Qt::Key_Return) { - QGraphicsWidget::keyPressEvent(event); + if (event->isAutoRepeat() || event->key() != Qt::Key_Return + || (timeLine.state() == QTimeLine::Running && timeLine.direction() == QTimeLine::Forward)) { + QGraphicsRectItem::keyPressEvent(event); return; } - if (!proxyWidget) - setScale(qreal(.9), qreal(.9)); - + timeLine.stop(); + timeLine.setDirection(QTimeLine::Forward); + timeLine.start(); emit activated(); } void RoundRectItem::keyReleaseEvent(QKeyEvent *event) { - if (event->isAutoRepeat() || event->key() != Qt::Key_Return) { - QGraphicsWidget::keyReleaseEvent(event); + if (event->key() != Qt::Key_Return) { + QGraphicsRectItem::keyReleaseEvent(event); return; } + timeLine.stop(); + timeLine.setDirection(QTimeLine::Backward); + timeLine.start(); +} +void RoundRectItem::updateValue(qreal value) +{ + lastVal = value; if (!proxyWidget) - setScale(1, 1); + setTransform(QTransform().scale(1 - value / 10.0, 1 - value / 10.0)); } diff --git a/examples/graphicsview/padnavigator/roundrectitem.h b/examples/graphicsview/padnavigator/roundrectitem.h index b0d44dd..33e33d7 100644 --- a/examples/graphicsview/padnavigator/roundrectitem.h +++ b/examples/graphicsview/padnavigator/roundrectitem.h @@ -40,14 +40,15 @@ ****************************************************************************/ #include <QtCore/qobject.h> +#include <QtCore/qtimeline.h> +#include <QtGui/qgraphicsitem.h> #include <QtGui/qbrush.h> -#include <QtGui/qgraphicswidget.h> QT_BEGIN_NAMESPACE class QGraphicsProxyWidget; QT_END_NAMESPACE; -class RoundRectItem : public QGraphicsWidget +class RoundRectItem : public QObject, public QGraphicsRectItem { Q_OBJECT public: @@ -58,6 +59,9 @@ public: void setPixmap(const QPixmap &pixmap); + qreal opacity() const; + void setOpacity(qreal opacity); + Q_SIGNALS: void activated(); @@ -65,9 +69,15 @@ protected: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); +private slots: + void updateValue(qreal value); + private: - QRectF m_rect; QBrush brush; QPixmap pix; + QTimeLine timeLine; + qreal lastVal; + qreal opa; + QGraphicsProxyWidget *proxyWidget; }; diff --git a/examples/graphicsview/padnavigator/splashitem.cpp b/examples/graphicsview/padnavigator/splashitem.cpp index a83d4d5..2a374bf 100644 --- a/examples/graphicsview/padnavigator/splashitem.cpp +++ b/examples/graphicsview/padnavigator/splashitem.cpp @@ -46,6 +46,12 @@ SplashItem::SplashItem(QGraphicsItem *parent) : QGraphicsWidget(parent) { + opacity = 1.0; + + + timeLine = new QTimeLine(350); + timeLine->setCurveShape(QTimeLine::EaseInCurve); + connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(setValue(qreal))); text = tr("Welcome to the Pad Navigator Example. You can use the" " keyboard arrows to navigate the icons, and press enter" @@ -55,6 +61,7 @@ SplashItem::SplashItem(QGraphicsItem *parent) void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { + painter->setOpacity(opacity); painter->setPen(QPen(Qt::black, 2)); painter->setBrush(QColor(245, 245, 255, 220)); painter->setClipRect(rect()); @@ -72,14 +79,14 @@ void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWid void SplashItem::keyPressEvent(QKeyEvent * /* event */) { - QVariantAnimation *anim = new QPropertyAnimation(this, "pos"); - anim->setEndValue(QPointF(x(), scene()->sceneRect().top() - rect().height())); - anim->setDuration(350); - anim->start(QAbstractAnimation::DeleteWhenStopped); - - anim = new QPropertyAnimation(this, "opacity"); - anim->setEndValue(0); - anim->start(QAbstractAnimation::DeleteWhenStopped); + if (timeLine->state() == QTimeLine::NotRunning) + timeLine->start(); +} - connect(anim, SIGNAL(finished()), SLOT(close())); +void SplashItem::setValue(qreal value) +{ + opacity = 1 - value; + setPos(x(), scene()->sceneRect().top() - rect().height() * value); + if (value == 1) + hide(); } diff --git a/examples/graphicsview/padnavigator/splashitem.h b/examples/graphicsview/padnavigator/splashitem.h index e2655ec..982bbe2 100644 --- a/examples/graphicsview/padnavigator/splashitem.h +++ b/examples/graphicsview/padnavigator/splashitem.h @@ -40,6 +40,7 @@ ****************************************************************************/ #include <QtCore/qobject.h> +#include <QtCore/qtimeline.h> #include <QtGui/qgraphicswidget.h> class SplashItem : public QGraphicsWidget @@ -52,6 +53,11 @@ public: protected: void keyPressEvent(QKeyEvent *event); +private Q_SLOTS: + void setValue(qreal value); + private: + QTimeLine *timeLine; QString text; + qreal opacity; }; |