|
|
@ -1,4 +1,17 @@ |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 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 3 of the License, or |
|
|
|
|
|
|
|
* (at your option) any later version. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful, |
|
|
|
|
|
|
|
* 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <QtGui> |
|
|
|
#include <QtGui> |
|
|
|
#include "UBMagnifer.h" |
|
|
|
#include "UBMagnifer.h" |
|
|
@ -7,25 +20,15 @@ |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
|
|
|
|
|
|
|
|
// #include <QPainter>
|
|
|
|
|
|
|
|
// #include <QPixmap>
|
|
|
|
|
|
|
|
// #include <QDebug>
|
|
|
|
|
|
|
|
// #include <QWidget>
|
|
|
|
|
|
|
|
// #include <QGraphicsView>
|
|
|
|
|
|
|
|
// #include <QTimerEvent>
|
|
|
|
|
|
|
|
// #include <QBitmap>
|
|
|
|
|
|
|
|
// #include <QPen>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
|
|
|
|
UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
|
|
|
|
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) |
|
|
|
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) |
|
|
|
, gView(0) |
|
|
|
|
|
|
|
, mView(0) |
|
|
|
|
|
|
|
, inTimer(false) |
|
|
|
|
|
|
|
, borderPen(Qt::darkGray) |
|
|
|
|
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, mShouldResizeWidget(false) |
|
|
|
, mShouldResizeWidget(false) |
|
|
|
|
|
|
|
, inTimer(false) |
|
|
|
|
|
|
|
, borderPen(Qt::darkGray) |
|
|
|
|
|
|
|
, gView(0) |
|
|
|
|
|
|
|
, mView(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
setMouseTracking(true); |
|
|
|
setMouseTracking(true); |
|
|
@ -69,29 +72,29 @@ UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) |
|
|
|
|
|
|
|
|
|
|
|
UBMagnifier::~UBMagnifier() |
|
|
|
UBMagnifier::~UBMagnifier() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (timerUpdate != 0) |
|
|
|
if (timerUpdate != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
killTimer(timerUpdate); |
|
|
|
killTimer(timerUpdate); |
|
|
|
timerUpdate = 0; |
|
|
|
timerUpdate = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(sClosePixmap) |
|
|
|
if(sClosePixmap) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete sClosePixmap; |
|
|
|
delete sClosePixmap; |
|
|
|
sClosePixmap = NULL; |
|
|
|
sClosePixmap = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(sIncreasePixmap) |
|
|
|
if(sIncreasePixmap) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete sIncreasePixmap; |
|
|
|
delete sIncreasePixmap; |
|
|
|
sIncreasePixmap = NULL; |
|
|
|
sIncreasePixmap = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(sDecreasePixmap) |
|
|
|
if(sDecreasePixmap) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete sDecreasePixmap; |
|
|
|
delete sDecreasePixmap; |
|
|
|
sDecreasePixmap = NULL; |
|
|
|
sDecreasePixmap = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -114,9 +117,9 @@ void UBMagnifier::setSize(qreal percentFromScene) |
|
|
|
setGeometry(0, 0, size, size); |
|
|
|
setGeometry(0, 0, size, size); |
|
|
|
|
|
|
|
|
|
|
|
// prepare transparent bit mask
|
|
|
|
// prepare transparent bit mask
|
|
|
|
QImage mask_img(width(), height(), QImage::Format_Mono); |
|
|
|
QImage mask_img(width(), height(), QImage::Format_Mono); |
|
|
|
mask_img.fill(0xff); |
|
|
|
mask_img.fill(0xff); |
|
|
|
QPainter mask_ptr(&mask_img); |
|
|
|
QPainter mask_ptr(&mask_img); |
|
|
|
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); |
|
|
|
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); |
|
|
|
mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); |
|
|
|
mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); |
|
|
|
bmpMask = QBitmap::fromImage(mask_img); |
|
|
|
bmpMask = QBitmap::fromImage(mask_img); |
|
|
@ -134,10 +137,9 @@ void UBMagnifier::setZoom(qreal zoom) |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::paintEvent(QPaintEvent * event) |
|
|
|
void UBMagnifier::paintEvent(QPaintEvent * event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(event); |
|
|
|
QPainter painter(this); |
|
|
|
QPainter painter(this); |
|
|
|
|
|
|
|
|
|
|
|
// painter.drawRect(0,0,size().width()-1, size().height()-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
|
|
|
|
|
|
|
@ -205,8 +207,8 @@ void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
|
|
|
|
QWidget::mouseMoveEvent(event); |
|
|
|
QWidget::mouseMoveEvent(event); |
|
|
|
emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); |
|
|
|
emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) |
|
|
@ -218,7 +220,7 @@ void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; |
|
|
|
qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; |
|
|
|
qreal newPercentSize = newXSize * 100 / cvW; |
|
|
|
qreal newPercentSize = newXSize * 100 / cvW; |
|
|
|
|
|
|
|
|
|
|
|
emit magnifierResized_Signal(newPercentSize); |
|
|
|
emit magnifierResized_Signal(newPercentSize); |
|
|
|
|
|
|
|
|
|
|
|
event->ignore(); |
|
|
|
event->ignore(); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -236,8 +238,8 @@ void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
setCursor(mResizeCursor); |
|
|
|
setCursor(mResizeCursor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
event->ignore(); |
|
|
|
event->ignore(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -255,7 +257,7 @@ void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) |
|
|
|
event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
emit magnifierClose_Signal(); |
|
|
|
emit magnifierClose_Signal(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
|
|
|
|
if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
|
|
|
@ -264,7 +266,7 @@ void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) |
|
|
|
event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) |
|
|
|
{ |
|
|
|
{ |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
emit magnifierZoomIn_Signal(); |
|
|
|
emit magnifierZoomIn_Signal(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
|
|
|
|
if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
|
|
|
@ -273,7 +275,7 @@ void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) |
|
|
|
event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) |
|
|
|
{ |
|
|
|
{ |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
emit magnifierZoomOut_Signal(); |
|
|
|
emit magnifierZoomOut_Signal(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
|
|
|
|
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
|
|
|
@ -283,19 +285,19 @@ void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::timerEvent(QTimerEvent *e) |
|
|
|
void UBMagnifier::timerEvent(QTimerEvent *e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(inTimer) return; |
|
|
|
if(inTimer) return; |
|
|
|
if (e->timerId() == timerUpdate) |
|
|
|
if (e->timerId() == timerUpdate) |
|
|
|
{ |
|
|
|
{ |
|
|
|
inTimer = true; |
|
|
|
inTimer = true; |
|
|
|
if(!(updPointGrab.isNull()))
|
|
|
|
if(!(updPointGrab.isNull()))
|
|
|
|
grabPoint(updPointGrab); |
|
|
|
grabPoint(updPointGrab); |
|
|
|
|
|
|
|
|
|
|
|
if(isCusrsorAlreadyStored) |
|
|
|
if(isCusrsorAlreadyStored) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPoint globalCursorPos = QCursor::pos(); |
|
|
|
QPoint globalCursorPos = QCursor::pos(); |
|
|
|
QPoint cursorPos = mapFromGlobal(globalCursorPos); |
|
|
|
QPoint cursorPos = mapFromGlobal(globalCursorPos); |
|
|
|
if (cursorPos.x() < size().width() - mResizeItem->width() - 20 ||
|
|
|
|
if (cursorPos.x() < size().width() - mResizeItem->width() - 20 ||
|
|
|
|
cursorPos.x() > size().width() - 20 || |
|
|
|
cursorPos.x() > size().width() - 20 || |
|
|
|
cursorPos.y() < size().height() - mResizeItem->height() - 20 || |
|
|
|
cursorPos.y() < size().height() - mResizeItem->height() - 20 || |
|
|
@ -305,12 +307,12 @@ void UBMagnifier::timerEvent(QTimerEvent *e) |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
setCursor(mOldCursor); |
|
|
|
setCursor(mOldCursor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inTimer = false; |
|
|
|
inTimer = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::grabPoint() |
|
|
|
void UBMagnifier::grabPoint() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -326,8 +328,8 @@ void UBMagnifier::grabPoint() |
|
|
|
|
|
|
|
|
|
|
|
QPixmap newPixMap(QSize(zWidth,zHeight)); |
|
|
|
QPixmap newPixMap(QSize(zWidth,zHeight)); |
|
|
|
((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); |
|
|
|
((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); |
|
|
|
UBApplication::boardController->activeScene()->update(); |
|
|
|
UBApplication::boardController->activeScene()->update(); |
|
|
|
|
|
|
|
|
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
pMap = newPixMap.scaled(QSize(width(), height())); |
|
|
|
pMap = newPixMap.scaled(QSize(width(), height())); |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
pMap.setMask(bmpMask); |
|
|
@ -350,8 +352,8 @@ void UBMagnifier::grabPoint(const QPoint &pGrab) |
|
|
|
|
|
|
|
|
|
|
|
QPixmap newPixMap(QSize(zWidth,zHeight)); |
|
|
|
QPixmap newPixMap(QSize(zWidth,zHeight)); |
|
|
|
((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); |
|
|
|
((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); |
|
|
|
UBApplication::boardController->activeScene()->update(); |
|
|
|
UBApplication::boardController->activeScene()->update(); |
|
|
|
|
|
|
|
|
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
pMap = newPixMap.scaled(QSize(width(), height())); |
|
|
|
pMap = newPixMap.scaled(QSize(width(), height())); |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
pMap.setMask(bmpMask); |
|
|
@ -362,8 +364,8 @@ void UBMagnifier::grabPoint(const QPoint &pGrab) |
|
|
|
// from global
|
|
|
|
// from global
|
|
|
|
void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) |
|
|
|
void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) |
|
|
|
{ |
|
|
|
{ |
|
|
|
updPointGrab = pGrab; |
|
|
|
updPointGrab = pGrab; |
|
|
|
updPointMove = pMove; |
|
|
|
updPointMove = pMove; |
|
|
|
|
|
|
|
|
|
|
|
if(needGrab) |
|
|
|
if(needGrab) |
|
|
|
grabPoint(pGrab); |
|
|
|
grabPoint(pGrab); |
|
|
@ -376,11 +378,11 @@ void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needG |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::setGrabView(QWidget *view) |
|
|
|
void UBMagnifier::setGrabView(QWidget *view) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (timerUpdate != 0) |
|
|
|
if (timerUpdate != 0) |
|
|
|
killTimer(timerUpdate); |
|
|
|
killTimer(timerUpdate); |
|
|
|
gView = view; |
|
|
|
gView = view; |
|
|
|
timerUpdate = startTimer(200); |
|
|
|
timerUpdate = startTimer(200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|