mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Improve the gesture event with a trackpad (better zoom behavior, and add the scroll with two fingers)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4266 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -244,7 +244,7 @@ void DiagramView::dragEnterEvent(QDragEnterEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere les dragleaveevent
|
Gere les dragleave
|
||||||
@param e le QDragEnterEvent correspondant au drag'n drop sortant
|
@param e le QDragEnterEvent correspondant au drag'n drop sortant
|
||||||
*/
|
*/
|
||||||
void DiagramView::dragLeaveEvent(QDragLeaveEvent *e) {
|
void DiagramView::dragLeaveEvent(QDragLeaveEvent *e) {
|
||||||
@@ -345,50 +345,23 @@ void DiagramView::setSelectionMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DiagramView::zoomIn
|
* @brief DiagramView::zoom
|
||||||
* Zoom in the current folio
|
* Zomm the view.
|
||||||
|
* A zoom_factor > 1 zoom in.
|
||||||
|
* A zoom_factor < 1 zoom out
|
||||||
|
* @param zoom_factor
|
||||||
*/
|
*/
|
||||||
void DiagramView::zoomIn() {
|
void DiagramView::zoom(const qreal zoom_factor)
|
||||||
scale(1.15, 1.15);
|
|
||||||
adjustGridToZoom();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DiagramView::zoomOut
|
|
||||||
* Zoom out the current folio.
|
|
||||||
* If zoom-out-beyond-of-folio is true in common setting, the zoom out is infinite
|
|
||||||
* else zoom out is stopped when the entire folio is visible.
|
|
||||||
*/
|
|
||||||
void DiagramView::zoomOut()
|
|
||||||
{
|
{
|
||||||
QSettings settings;
|
if (zoom_factor >= 1)
|
||||||
if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
|
scale(zoom_factor, zoom_factor);
|
||||||
(horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
|
else
|
||||||
scale(0.85, 0.85);
|
{
|
||||||
|
QSettings settings;
|
||||||
adjustGridToZoom();
|
if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
|
||||||
}
|
(horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
|
||||||
|
scale(zoom_factor, zoom_factor);
|
||||||
/**
|
}
|
||||||
* @brief DiagramView::zoomInSlowly
|
|
||||||
* Like zoomIn but more slowly
|
|
||||||
*/
|
|
||||||
void DiagramView::zoomInSlowly() {
|
|
||||||
scale(1.02, 1.02);
|
|
||||||
adjustGridToZoom();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DiagramView::zoomOutSlowly
|
|
||||||
* Like zoomOut but more slowly
|
|
||||||
*/
|
|
||||||
void DiagramView::zoomOutSlowly()
|
|
||||||
{
|
|
||||||
QSettings settings;
|
|
||||||
if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
|
|
||||||
(horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
|
|
||||||
scale(0.98, 0.98);
|
|
||||||
|
|
||||||
adjustGridToZoom();
|
adjustGridToZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,38 +520,50 @@ bool DiagramView::gestures() const
|
|||||||
Manage wheel event of mouse
|
Manage wheel event of mouse
|
||||||
@param e QWheelEvent
|
@param e QWheelEvent
|
||||||
*/
|
*/
|
||||||
void DiagramView::wheelEvent(QWheelEvent *e)
|
void DiagramView::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event_interface && m_event_interface->wheelEvent(e)) return;
|
if (m_event_interface && m_event_interface->wheelEvent(event)) return;
|
||||||
|
|
||||||
//Zoom and scrolling
|
//Zoom and scrolling
|
||||||
if (gestures() && (e->modifiers() & Qt::ControlModifier))
|
QPoint angle = event->angleDelta();
|
||||||
e -> delta() > 0 ? zoomInSlowly() : zoomOutSlowly();
|
|
||||||
else if (e->modifiers() == Qt::NoModifier)
|
if (gestures()) //When gesture mode is enable, we suppose the wheel event are made from a trackpad.
|
||||||
e -> delta() > 0 ? zoomIn(): zoomOut();
|
{
|
||||||
|
if (event->modifiers() == Qt::ControlModifier) //zoom
|
||||||
|
{
|
||||||
|
qreal value = angle.y();
|
||||||
|
zoom(1 + value/1000);
|
||||||
|
}
|
||||||
|
else //scroll
|
||||||
|
{
|
||||||
|
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - angle.x());
|
||||||
|
verticalScrollBar()->setValue(verticalScrollBar()->value() - angle.y());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (event->modifiers() == Qt::NoModifier) //Else we suppose the wheel event are made from a mouse.
|
||||||
|
{
|
||||||
|
qreal value = angle.y();
|
||||||
|
zoom(1 + value/1000);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
QGraphicsView::wheelEvent(e);
|
QGraphicsView::wheelEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilise le pincement du trackpad pour zoomer
|
|
||||||
* @brief DiagramView::gestureEvent
|
* @brief DiagramView::gestureEvent
|
||||||
|
* Use the pinch of the trackpad for zoom
|
||||||
* @param event
|
* @param event
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
bool DiagramView::gestureEvent(QGestureEvent *event)
|
||||||
|
{
|
||||||
bool DiagramView::gestureEvent(QGestureEvent *event){
|
if (QGesture *gesture = event->gesture(Qt::PinchGesture))
|
||||||
if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
|
{
|
||||||
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
|
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
|
||||||
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged){
|
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
|
||||||
|
{
|
||||||
qreal value = gesture->property("scaleFactor").toReal();
|
qreal value = gesture->property("scaleFactor").toReal();
|
||||||
if (value > 1){
|
value > 1 ? zoom(1.02) : zoom(0.98);
|
||||||
zoomInSlowly();
|
|
||||||
}else{
|
|
||||||
zoomOutSlowly();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -132,10 +132,7 @@ class DiagramView : public QGraphicsView
|
|||||||
void rotateTexts();
|
void rotateTexts();
|
||||||
void setVisualisationMode();
|
void setVisualisationMode();
|
||||||
void setSelectionMode();
|
void setSelectionMode();
|
||||||
void zoomIn();
|
void zoom(const qreal zoom_factor);
|
||||||
void zoomOut();
|
|
||||||
void zoomInSlowly();
|
|
||||||
void zoomOutSlowly();
|
|
||||||
void zoomFit();
|
void zoomFit();
|
||||||
void zoomContent();
|
void zoomContent();
|
||||||
void zoomReset();
|
void zoomReset();
|
||||||
|
|||||||
@@ -1098,9 +1098,9 @@ void QETDiagramEditor::zoomGroupTriggered(QAction *action)
|
|||||||
if (!dv || value.isEmpty()) return;
|
if (!dv || value.isEmpty()) return;
|
||||||
|
|
||||||
if (value == "zoom_in")
|
if (value == "zoom_in")
|
||||||
dv->zoomIn();
|
dv->zoom(1.15);
|
||||||
else if (value == "zoom_out")
|
else if (value == "zoom_out")
|
||||||
dv->zoomOut();
|
dv->zoom(0.85);
|
||||||
else if (value == "zoom_content")
|
else if (value == "zoom_content")
|
||||||
dv->zoomContent();
|
dv->zoomContent();
|
||||||
else if (value == "zoom_fit")
|
else if (value == "zoom_fit")
|
||||||
|
|||||||
Reference in New Issue
Block a user