Allow scrolling hand dragging for non interactive scenes.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-07-21 12:27:58 +03:00
parent 9f6bb49a22
commit 185e228853
4 changed files with 25 additions and 3 deletions

View File

@ -1116,7 +1116,8 @@ QList<QGraphicsScene *> MainWindowsNoGUI::CreateScenes(const QList<QGraphicsItem
QList<QGraphicsScene *> scenes; QList<QGraphicsScene *> scenes;
for (int i=0; i<papers.size(); ++i) for (int i=0; i<papers.size(); ++i)
{ {
QGraphicsScene *scene = new VMainGraphicsScene(); auto *scene = new VMainGraphicsScene();
scene->SetNonInteractive(true);
scene->setBackgroundBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern)); scene->setBackgroundBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern));
scene->addItem(shadows.at(i)); scene->addItem(shadows.at(i));
scene->addItem(papers.at(i)); scene->addItem(papers.at(i));

View File

@ -113,6 +113,18 @@ void VMainGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QGraphicsScene::mouseReleaseEvent(event); QGraphicsScene::mouseReleaseEvent(event);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VMainGraphicsScene::IsNonInteractive() const
{
return m_nonInteractive;
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsScene::SetNonInteractive(bool nonInteractive)
{
m_nonInteractive = nonInteractive;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsScene::InitOrigins() void VMainGraphicsScene::InitOrigins()
{ {

View File

@ -63,6 +63,10 @@ public:
QRectF VisibleItemsBoundingRect() const; QRectF VisibleItemsBoundingRect() const;
void InitOrigins(); void InitOrigins();
void SetOriginsVisible(bool visible); void SetOriginsVisible(bool visible);
bool IsNonInteractive() const;
void SetNonInteractive(bool nonInteractive);
public slots: public slots:
void ChoosedItem(quint32 id, const SceneObject &type); void ChoosedItem(quint32 id, const SceneObject &type);
void SelectedItem(bool selected, quint32 object, quint32 tool); void SelectedItem(bool selected, quint32 object, quint32 tool);
@ -145,6 +149,7 @@ signals:
void LanguageChanged(); void LanguageChanged();
private: private:
Q_DISABLE_COPY(VMainGraphicsScene)
/** @brief horScrollBar value horizontal scroll bar. */ /** @brief horScrollBar value horizontal scroll bar. */
qint32 horScrollBar; qint32 horScrollBar;
@ -155,6 +160,9 @@ private:
QTransform _transform; QTransform _transform;
QPointF scenePos; QPointF scenePos;
QVector<QGraphicsItem *> origins; QVector<QGraphicsItem *> origins;
/** @brief m_nonInteractive all item on scene in non interactive. */
bool m_nonInteractive{false};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -568,9 +568,10 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *event)
} }
case Qt::MiddleButton: case Qt::MiddleButton:
{ {
auto scene = qobject_cast<VMainGraphicsScene*>(this->scene());
const QList<QGraphicsItem *> list = items(event->pos()); const QList<QGraphicsItem *> list = items(event->pos());
if (list.size() == 0) if (list.isEmpty() || (scene && scene->IsNonInteractive()))
{// Only when the user clicks on the scene background {// Only when the user clicks on the scene background or non interactive scene
m_ptStartPos = event->pos(); m_ptStartPos = event->pos();
m_oldCursor = viewport()->cursor(); m_oldCursor = viewport()->cursor();
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);