void KdeObservatory::switchViews(int delta) { if (m_views.count() > 0 && m_transitionTimer->state() == QTimeLine::NotRunning) { int previousView = m_currentView; int newView = m_currentView + delta; m_currentView = (newView >= 0) ? (newView % m_views.count()):(m_views.count() + newView); QGraphicsWidget *previousViewWidget = m_views.at(previousView); QGraphicsWidget *currentViewWidget = m_views.at(m_currentView); currentViewWidget->setPos(currentViewWidget->geometry().width(), 0); currentViewWidget->show(); m_transitionTimer->setFrameRange(0, 1); m_transitionTimer->setCurveShape(QTimeLine::EaseOutCurve); m_animationPrevious = new QGraphicsItemAnimation(this); m_animationPrevious->setItem(previousViewWidget); m_animationPrevious->setTimeLine(m_transitionTimer); m_animationPrevious->setPosAt(0, QPointF(0, 0)); m_animationPrevious->setPosAt(1, -delta*QPointF(previousViewWidget->geometry().width(), 0)); m_animationNew = new QGraphicsItemAnimation(this); m_animationNew->setItem(currentViewWidget); m_animationNew->setTimeLine(m_transitionTimer); m_animationNew->setPosAt(0, delta*QPointF(currentViewWidget->geometry().width(), 0)); m_animationNew->setPosAt(1, QPointF(0, 0)); m_transitionTimer->start(); } }
void graphics_maze_scene_private::fit_into_view() { //Log4Qt::Logger::logger("Process")->info("Maze drawned. Fitting into view."); QList<QGraphicsView*> lViews = public_->views (); QRectF rectF = main_item->geometry (); lViews.first ()->fitInView (rectF, Qt::KeepAspectRatio); }
void tst_QGraphicsLayout::invalidateAndMove() { // Check that if we set the position of an item and invalidate its layout at the same // time, the widget keeps its correct size QFETCH(bool, instantInvalidatePropagation); QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation); QGraphicsScene scene; QGraphicsWidget *widget = new QGraphicsWidget; new QGraphicsLinearLayout(widget); widget->setMinimumSize(1,1); widget->setPreferredSize(34,34); widget->setMaximumSize(100,100); widget->resize(widget->preferredSize()); scene.addItem(widget); qApp->processEvents(); /* Invalidate and reactivate. The size should not have changed */ widget->layout()->invalidate(); widget->layout()->activate(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setX(1); //Change just the position using setX QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setGeometry(1,1,34,34); //Change just the position using setGeometry QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setGeometry(1,1,60,60); //Change just the size using setGeometry QCOMPARE(widget->geometry().size(), QSizeF(60,60)); QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); qApp->processEvents(); QCOMPARE(widget->geometry().size(), QSizeF(60,60)); QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); widget->layout()->invalidate(); widget->setGeometry(0,0,34,34); //Change the size and position using setGeometry QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); QGraphicsLayout::setInstantInvalidatePropagation(false); }
SEXP qt_qgeometry_QGraphicsWidget(SEXP rself) { QGraphicsWidget *widget = unwrapQObject(rself, QGraphicsWidget); return asRRectF(widget->geometry()); }