2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vmaingraphicsview.h
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
#ifndef VMAINGRAPHICSVIEW_H
|
|
|
|
#define VMAINGRAPHICSVIEW_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <qcompilerdetection.h>
|
2013-08-13 18:48:36 +02:00
|
|
|
#include <QGraphicsView>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMetaObject>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QString>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
2014-08-19 14:46:52 +02:00
|
|
|
/*!
|
|
|
|
* This class adds ability to zoom QGraphicsView using mouse wheel. The point under cursor
|
|
|
|
* remains motionless while it's possible.
|
|
|
|
*
|
|
|
|
* When the user starts scrolling, this class remembers original scene position and
|
|
|
|
* keeps it until scrolling is completed. It's better than getting original scene position at
|
|
|
|
* each scrolling step because that approach leads to position errors due to before-mentioned
|
|
|
|
* positioning restrictions.
|
|
|
|
*
|
|
|
|
* When zommed using scroll, this class emits zoomed() signal.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* new Graphics_view_zoom(view);
|
|
|
|
*
|
|
|
|
* The object will be deleted automatically when the view is deleted.
|
|
|
|
*
|
|
|
|
* You can set keyboard modifiers used for zooming using set_modified(). Zooming will be
|
|
|
|
* performed only on exact match of modifiers combination. The default modifier is Ctrl.
|
|
|
|
*
|
|
|
|
* You can change zoom velocity by calling set_zoom_factor_base().
|
|
|
|
* Zoom coefficient is calculated as zoom_factor_base^angle_delta
|
|
|
|
* (see QWheelEvent::angleDelta).
|
|
|
|
* The default zoom factor base is 1.0015.
|
|
|
|
*/
|
2014-10-04 21:12:46 +02:00
|
|
|
|
|
|
|
class QTimeLine;
|
|
|
|
|
2014-08-19 14:46:52 +02:00
|
|
|
class GraphicsViewZoom : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-10-12 13:52:48 +02:00
|
|
|
explicit GraphicsViewZoom(QGraphicsView* view);
|
2014-08-19 14:46:52 +02:00
|
|
|
void gentle_zoom(double factor);
|
|
|
|
void set_modifiers(Qt::KeyboardModifiers modifiers);
|
|
|
|
void set_zoom_factor_base(double value);
|
|
|
|
signals:
|
|
|
|
void zoomed();
|
|
|
|
public slots:
|
2016-03-30 10:25:13 +02:00
|
|
|
void VerticalScrollingTime(qreal x);
|
|
|
|
void HorizontalScrollingTime(qreal x);
|
2014-08-19 14:46:52 +02:00
|
|
|
void animFinished();
|
2015-12-17 20:13:07 +01:00
|
|
|
protected:
|
|
|
|
virtual bool eventFilter(QObject* object, QEvent* event) Q_DECL_OVERRIDE;
|
2014-08-19 14:46:52 +02:00
|
|
|
private:
|
2015-12-02 19:39:25 +01:00
|
|
|
Q_DISABLE_COPY(GraphicsViewZoom)
|
2016-03-30 10:25:13 +02:00
|
|
|
QGraphicsView *_view;
|
2014-08-19 14:46:52 +02:00
|
|
|
Qt::KeyboardModifiers _modifiers;
|
|
|
|
double _zoom_factor_base;
|
2014-09-11 16:15:49 +02:00
|
|
|
QPointF target_scene_pos;
|
2014-08-19 14:46:52 +02:00
|
|
|
QPointF target_viewport_pos;
|
2016-03-30 10:25:13 +02:00
|
|
|
QTimeLine *verticalScrollAnim;
|
|
|
|
/** @brief _numScheduledVerticalScrollings keep number scheduled vertical scrollings. */
|
|
|
|
qint32 _numScheduledVerticalScrollings;
|
|
|
|
QTimeLine *horizontalScrollAnim;
|
|
|
|
/** @brief _numScheduledHorizontalScrollings keep number scheduled horizontal scrollings. */
|
|
|
|
qint32 _numScheduledHorizontalScrollings;
|
2016-01-25 14:49:37 +01:00
|
|
|
|
|
|
|
static const int duration;
|
|
|
|
static const int updateInterval;
|
2015-12-02 19:39:25 +01:00
|
|
|
|
|
|
|
void FictiveSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
2016-03-30 10:25:13 +02:00
|
|
|
|
|
|
|
bool StartVerticalScrollings(QWheelEvent* wheel_event);
|
|
|
|
bool StartHorizontalScrollings(QWheelEvent* wheel_event);
|
2014-08-19 14:46:52 +02:00
|
|
|
};
|
|
|
|
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-27 13:27:26 +01:00
|
|
|
* @brief The VMainGraphicsView class main scene view.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
class VMainGraphicsView : public QGraphicsView
|
|
|
|
{
|
2013-08-13 18:48:36 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-06-13 19:02:41 +02:00
|
|
|
|
2014-02-26 10:22:05 +01:00
|
|
|
explicit VMainGraphicsView(QWidget *parent = nullptr);
|
2014-08-30 21:58:31 +02:00
|
|
|
void setShowToolOptions(bool value);
|
2016-03-31 16:01:41 +02:00
|
|
|
void AllowRubberBand(bool value);
|
2014-08-30 21:58:31 +02:00
|
|
|
|
2017-10-27 08:13:51 +02:00
|
|
|
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item = nullptr);
|
2016-01-15 13:57:47 +01:00
|
|
|
static QRectF SceneVisibleArea(QGraphicsView *view);
|
2015-06-15 09:40:23 +02:00
|
|
|
|
2016-12-06 15:18:40 +01:00
|
|
|
static qreal MinScale();
|
|
|
|
static qreal MaxScale();
|
|
|
|
|
2017-10-02 15:25:18 +02:00
|
|
|
void EnsureVisibleWithDelay(const QRectF &rect, unsigned long msecs, int xmargin = 50, int ymargin = 50);
|
|
|
|
void EnsureVisibleWithDelay(const QGraphicsItem *item, unsigned long msecs, int xmargin = 50, int ymargin = 50);
|
|
|
|
|
|
|
|
static const unsigned long scrollDelay;
|
|
|
|
|
2018-01-01 15:16:50 +01:00
|
|
|
void setCurrentCursorShape();
|
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
signals:
|
2014-07-23 10:56:32 +02:00
|
|
|
/**
|
|
|
|
* @brief MouseRelease help catch mouse release event.
|
|
|
|
*
|
|
|
|
* Usefull when you need show dialog after working with tool visualization.
|
|
|
|
*/
|
2014-08-26 19:23:08 +02:00
|
|
|
void MouseRelease();
|
|
|
|
void itemClicked(QGraphicsItem *item);
|
2013-10-14 11:31:56 +02:00
|
|
|
public slots:
|
2014-06-02 20:42:46 +02:00
|
|
|
void ZoomIn();
|
|
|
|
void ZoomOut();
|
2014-07-11 15:10:54 +02:00
|
|
|
void ZoomOriginal();
|
|
|
|
void ZoomFitBest();
|
2013-08-13 18:48:36 +02:00
|
|
|
protected:
|
2017-04-14 07:22:28 +02:00
|
|
|
virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
2015-11-25 18:26:37 +01:00
|
|
|
virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
2013-10-14 10:40:01 +02:00
|
|
|
private:
|
2014-09-04 15:42:16 +02:00
|
|
|
Q_DISABLE_COPY(VMainGraphicsView)
|
2014-08-19 14:46:52 +02:00
|
|
|
GraphicsViewZoom* zoom;
|
2017-04-14 07:22:28 +02:00
|
|
|
bool showToolOptions;
|
|
|
|
bool isAllowRubberBand;
|
|
|
|
QPoint m_ptStartPos;
|
2017-10-30 10:08:25 +01:00
|
|
|
QCursor m_oldCursor;
|
2018-01-01 15:16:50 +01:00
|
|
|
Qt::CursorShape m_currentCursor;
|
2013-08-13 18:48:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VMAINGRAPHICSVIEW_H
|