forked from scribusproject/scribus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvasgesture_rectselect.cpp
More file actions
113 lines (93 loc) · 3.09 KB
/
canvasgesture_rectselect.cpp
File metadata and controls
113 lines (93 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QEvent>
#include <QInputMethodEvent>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QRubberBand>
#include "canvas.h"
#include "canvasgesture_rectselect.h"
#include "scribusview.h"
#include "selectionrubberband.h"
void RectSelect::enterEvent(QEvent * e){}
void RectSelect::leaveEvent(QEvent * e){}
void RectSelect::prepare(QPointF globalStartPos)
{
if (!m_selectionRubberBand)
m_selectionRubberBand = new SelectionRubberBand(QRubberBand::Rectangle, m_view);
setStart(globalStartPos);
//FIXME Move to new code like SelectionRubberBand
QPoint selectionPoint = m_view->mapFromGlobal(globalStartPos).toPoint();
m_selectionRubberBand->setWindowOpacity(0.5);
m_selectionRubberBand->setGeometry(QRect(selectionPoint, selectionPoint));
}
void RectSelect::clear()
{
m_selectionRubberBand->hide();
m_start = QPointF(0,0);
}
void RectSelect::activate(bool fromGesture)
{
CanvasGesture::activate(fromGesture);
prepare(m_start);
m_selectionRubberBand->show();
}
void RectSelect::deactivate(bool fromGesture)
{
m_selectionRubberBand->hide();
CanvasGesture::deactivate(fromGesture);
}
void RectSelect::setStart(QPointF globalPos)
{
m_start = globalPos;
}
void RectSelect::setEnd(QPointF globalPos)
{
QPointF startPoint = m_view->mapFromGlobal(m_start);
QPointF endPoint = m_view->mapFromGlobal(globalPos);
m_selectionRubberBand->setGeometry(QRect(startPoint.toPoint(), endPoint.toPoint()).normalized());
}
QRectF RectSelect::result() const
{
QRect geom = m_selectionRubberBand->geometry().normalized();
geom = QRect(m_view->mapToGlobal(geom.topLeft()), m_view->mapToGlobal(geom.bottomRight()));
return m_canvas->globalToCanvas(geom);
}
void RectSelect::mousePressEvent(QMouseEvent *m)
{
prepare(m->globalPosition());
m->accept();
}
void RectSelect::mouseReleaseEvent(QMouseEvent *m)
{
// qDebug() << "RectSelect::mouseRelease" << m->globalPosition();
setEnd(m->globalPosition());
m->accept();
m_view->stopGesture();
}
void RectSelect::mouseMoveEvent(QMouseEvent *m)
{
setEnd(m->globalPosition());
m->accept();
}
void RectSelect::drawControls(QPainter* p)
{
m_delegate->drawControls(p);
}