void Ut_VolumeBar::testMousePressesAndMovesUpdatePercentage() { volumeBar->setGeometry(QRectF(0, 0, 50, 30)); mWidgetIsOnDisplay = false; QGraphicsSceneMouseEvent event; event.setPos(QPointF(25, 10)); volumeBar->mousePressEvent(&event); QCOMPARE(event.isAccepted(), true); QCOMPARE(volumeBar->currentPercentage(), (volumeBar->geometry().height() - event.pos().y()) / volumeBar->geometry().height()); event.setPos(QPointF(35, 20)); volumeBar->mouseMoveEvent(&event); QCOMPARE(volumeBar->currentPercentage(), (volumeBar->geometry().height() - event.pos().y()) / volumeBar->geometry().height()); }
bool CustomEdit::startSelection(const QPointF &hitPoint) { QPointF startSelectionPoint = startPoint(hitPoint); //fake double click to activate selection on text edit QGraphicsSceneMouseEvent event; event.setPos(startSelectionPoint); event.setButton(Qt::LeftButton); mousePressEvent(&event); event.setPos(startSelectionPoint); mouseReleaseEvent(&event); event.setPos(startSelectionPoint); mousePressEvent(&event); event.setPos(startSelectionPoint); mouseReleaseEvent(&event); return hasSelectedText(); }
QGraphicsSceneMouseEvent* EventSender::createGraphicsSceneMouseEvent(QEvent::Type type, const QPoint& pos, const QPoint& screenPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) { QGraphicsSceneMouseEvent* event; event = new QGraphicsSceneMouseEvent(type); event->setPos(pos); event->setScreenPos(screenPos); event->setButton(button); event->setButtons(buttons); event->setModifiers(modifiers); return event; }
void Ut_LockScreenWithPadlockView::testDraggableIconMovement() { QFETCH(int, layoutDirection); QSKIP("This test method currently fails", SkipSingle); QSignalSpy unlockSpy(m_subject, SIGNAL(unlocked())); m_subject->lockScreenHeader->setLayoutDirection((Qt::LayoutDirection)layoutDirection); m_subject->lockScreenHeader->setPreferredSize(100, 10); // send three mouse events that ultimately will send the unlocked signal from the window. QGraphicsSceneMouseEvent *pressEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress); pressEvent->setPos(QPointF(layoutDirection == Qt::LeftToRight ? m_subject->lockScreenHeader->preferredWidth() : 0, m_subject->lockScreenHeader->pos().y())); QGraphicsSceneMouseEvent *moveEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove); moveEvent->setPos(QPointF(400, 240)); QGraphicsSceneMouseEvent *moveEventNotActive = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove); moveEventNotActive->setPos(QPointF(400, 0)); QGraphicsSceneMouseEvent *releaseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseRelease); // sending a press event the place where it should activate the draggable icon. m_subject->mousePressEvent(pressEvent); QTest::qWait(50); QCoreApplication::processEvents(); QCOMPARE(m_subject->dragAndDropState, (int)LockScreenWithPadlockView::STATE_MOVING); QVERIFY(nameOfLastFeedback == "start-dragndrop"); checkOverlayPos(pressEvent->pos()); QVERIFY(m_subject->dragAndDropIcon != 0); QCOMPARE(m_subject->dragAndDropOverlay.widget(), static_cast<MWidget*>(m_subject->dragAndDropIcon)); QCOMPARE(gAppearSceneWindowList.count(), 1); QCOMPARE(gAppearSceneWindowList.at(0), &m_subject->dragAndDropOverlay); QCOMPARE(m_subject->dragAndDropIcon->objectName(), QString("LockScreenDnDIcon")); QVERIFY(m_subject->dragAndDropOverlay.isVisible()); QCOMPARE(m_subject->lockScreenHeader->objectName(), QString("LockLiftArea")); QVERIFY(gUnlockAreaStub->stubLastCallTo("setEnabled").parameter<bool>(0)); // move the mouse right into the middle of the screen m_subject->mouseMoveEvent(moveEvent); QCOMPARE(m_subject->dragAndDropState, (int)LockScreenWithPadlockView::STATE_MOVING_ACTIVE); QVERIFY(nameOfLastFeedback == "enter-dragndrop-dropzone"); checkOverlayPos(moveEvent->pos()); QCOMPARE(m_subject->dragAndDropIcon->objectName(), QString("LockScreenDnDIconActive")); QVERIFY(gUnlockAreaStub->stubLastCallTo("setActive").parameter<bool>(0)); // move back to some non-active place m_subject->mouseMoveEvent(moveEventNotActive); QCOMPARE(m_subject->dragAndDropState, (int)LockScreenWithPadlockView::STATE_MOVING); QVERIFY(nameOfLastFeedback == "exit-dragndrop-dropzone"); QCOMPARE(m_subject->dragAndDropIcon->objectName(), QString("LockScreenDnDIcon")); QVERIFY(!gUnlockAreaStub->stubLastCallTo("setActive").parameter<bool>(0)); // again move to active area m_subject->mouseMoveEvent(moveEvent); QCOMPARE(m_subject->dragAndDropState, (int)LockScreenWithPadlockView::STATE_MOVING_ACTIVE); QVERIFY(nameOfLastFeedback == "enter-dragndrop-dropzone"); QVERIFY(gUnlockAreaStub->stubLastCallTo("setActive").parameter<bool>(0)); // when the mouse is released, the unlocked signal should be sent m_subject->mouseReleaseEvent(releaseEvent); QCOMPARE(unlockSpy.count(), 1); QVERIFY(nameOfLastFeedback == "release-inside-dragndrop-dropzone"); QCOMPARE(m_subject->dragAndDropIcon->objectName(), QString("LockScreenDnDIcon")); QVERIFY(!m_subject->dragAndDropOverlay.isVisible()); QCOMPARE(m_subject->lockScreenHeader->objectName(), QString("LockLiftAreaWithPadlock")); QVERIFY(!gUnlockAreaStub->stubLastCallTo("setEnabled").parameter<bool>(0)); }