|
|
@ -1,388 +1,402 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
|
|
* 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 |
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
|
|
* (at your option) any later version. |
|
|
|
* (at your option) any later version. |
|
|
|
* |
|
|
|
* |
|
|
|
* This program is distributed in the hope that it will be useful, |
|
|
|
* This program is distributed in the hope that it will be useful, |
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
* GNU General Public License for more details. |
|
|
|
* GNU General Public License for more details. |
|
|
|
* |
|
|
|
* |
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <QtGui> |
|
|
|
#include <QtGui> |
|
|
|
#include "UBMagnifer.h" |
|
|
|
#include "UBMagnifer.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "core/UBApplication.h" |
|
|
|
#include "core/UBApplication.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
|
|
|
|
#include "board/UBBoardView.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
|
|
|
|
|
|
|
|
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) |
|
|
|
UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
|
|
|
|
, mShouldMoveWidget(false) |
|
|
|
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) |
|
|
|
, mShouldResizeWidget(false) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, inTimer(false) |
|
|
|
, mShouldResizeWidget(false) |
|
|
|
, borderPen(Qt::darkGray) |
|
|
|
, borderPen(Qt::darkGray) |
|
|
|
, gView(0) |
|
|
|
, gView(0) |
|
|
|
, mView(0) |
|
|
|
, mView(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
setMouseTracking(true); |
|
|
|
setMouseTracking(true); |
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------//
|
|
|
|
//--------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap pix(":/images/cursors/resize.png"); |
|
|
|
QPixmap pix(":/images/cursors/resize.png"); |
|
|
|
QTransform tr; |
|
|
|
QTransform tr; |
|
|
|
tr.rotate(45); |
|
|
|
tr.rotate(45); |
|
|
|
mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); |
|
|
|
mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); |
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------//
|
|
|
|
//--------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
params.sizePercentFromScene = 20; |
|
|
|
params.sizePercentFromScene = 20; |
|
|
|
m_isInteractive = isInteractive; |
|
|
|
m_isInteractive = isInteractive; |
|
|
|
sClosePixmap = new QPixmap(":/images/close.svg"); |
|
|
|
sClosePixmap = new QPixmap(":/images/close.svg"); |
|
|
|
sIncreasePixmap = new QPixmap(":/images/increase.svg"); |
|
|
|
sIncreasePixmap = new QPixmap(":/images/increase.svg"); |
|
|
|
sDecreasePixmap = new QPixmap(":/images/decrease.svg"); |
|
|
|
sDecreasePixmap = new QPixmap(":/images/decrease.svg"); |
|
|
|
mResizeItem = new QPixmap(":/images/resize.svg"); |
|
|
|
mResizeItem = new QPixmap(":/images/resize.svg"); |
|
|
|
|
|
|
|
|
|
|
|
if (parent) |
|
|
|
if (parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setAttribute(Qt::WA_NoMousePropagation); |
|
|
|
setAttribute(Qt::WA_NoMousePropagation); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
// standalone window
|
|
|
|
// standalone window
|
|
|
|
// !!!! Should be included into Windows after QT recompilation
|
|
|
|
// !!!! Should be included into Windows after QT recompilation
|
|
|
|
#ifndef Q_WS_WIN |
|
|
|
#ifndef Q_WS_WIN |
|
|
|
// setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
// setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow); |
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#ifdef Q_WS_MAC |
|
|
|
#ifdef Q_WS_MAC |
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow); |
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow); |
|
|
|
setAttribute(Qt::WA_MacNonActivatingToolWindow); |
|
|
|
setAttribute(Qt::WA_MacNonActivatingToolWindow); |
|
|
|
setAttribute(Qt::WA_MacNoShadow); |
|
|
|
setAttribute(Qt::WA_MacNoShadow); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh())); |
|
|
|
|
|
|
|
} |
|
|
|
UBMagnifier::~UBMagnifier() |
|
|
|
|
|
|
|
{ |
|
|
|
UBMagnifier::~UBMagnifier() |
|
|
|
if (timerUpdate != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(sClosePixmap) |
|
|
|
killTimer(timerUpdate); |
|
|
|
{ |
|
|
|
timerUpdate = 0; |
|
|
|
delete sClosePixmap; |
|
|
|
} |
|
|
|
sClosePixmap = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
if(sClosePixmap) |
|
|
|
|
|
|
|
{ |
|
|
|
if(sIncreasePixmap) |
|
|
|
delete sClosePixmap; |
|
|
|
{ |
|
|
|
sClosePixmap = NULL; |
|
|
|
delete sIncreasePixmap; |
|
|
|
} |
|
|
|
sIncreasePixmap = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
if(sIncreasePixmap) |
|
|
|
|
|
|
|
{ |
|
|
|
if(sDecreasePixmap) |
|
|
|
delete sIncreasePixmap; |
|
|
|
{ |
|
|
|
sIncreasePixmap = NULL; |
|
|
|
delete sDecreasePixmap; |
|
|
|
} |
|
|
|
sDecreasePixmap = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
if(sDecreasePixmap) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
delete sDecreasePixmap; |
|
|
|
void UBMagnifier::setSize(qreal percentFromScene)
|
|
|
|
sDecreasePixmap = NULL; |
|
|
|
{ |
|
|
|
} |
|
|
|
if(gView == NULL || mView == NULL) return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// calculate object size
|
|
|
|
void UBMagnifier::setSize(qreal percentFromScene)
|
|
|
|
params.sizePercentFromScene = percentFromScene; |
|
|
|
{ |
|
|
|
QSize sceneSize = mView->size(); |
|
|
|
if(gView == NULL || mView == NULL) return; |
|
|
|
qreal size = params.sizePercentFromScene * sceneSize.width() / 100; |
|
|
|
|
|
|
|
|
|
|
|
// calculate object size
|
|
|
|
QRect currGeom = geometry(); |
|
|
|
params.sizePercentFromScene = percentFromScene; |
|
|
|
if(currGeom.width() == currGeom.height()) |
|
|
|
QSize sceneSize = mView->size(); |
|
|
|
{ |
|
|
|
qreal size = params.sizePercentFromScene * sceneSize.width() / 100; |
|
|
|
QPoint newPos = mView->mapFromGlobal(updPointMove); |
|
|
|
|
|
|
|
setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); |
|
|
|
QRect currGeom = geometry(); |
|
|
|
} |
|
|
|
if(currGeom.width() == currGeom.height()) |
|
|
|
else |
|
|
|
{ |
|
|
|
setGeometry(0, 0, size, size); |
|
|
|
QPoint newPos = mView->mapFromGlobal(updPointMove); |
|
|
|
|
|
|
|
setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); |
|
|
|
// prepare transparent bit mask
|
|
|
|
} |
|
|
|
QImage mask_img(width(), height(), QImage::Format_Mono); |
|
|
|
else |
|
|
|
mask_img.fill(0xff); |
|
|
|
setGeometry(0, 0, size, size); |
|
|
|
QPainter mask_ptr(&mask_img); |
|
|
|
|
|
|
|
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); |
|
|
|
// prepare transparent bit mask
|
|
|
|
mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); |
|
|
|
QImage mask_img(width(), height(), QImage::Format_Mono); |
|
|
|
bmpMask = QBitmap::fromImage(mask_img); |
|
|
|
mask_img.fill(0xff); |
|
|
|
|
|
|
|
QPainter mask_ptr(&mask_img); |
|
|
|
// prepare general image
|
|
|
|
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); |
|
|
|
pMap = QPixmap(width(), height()); |
|
|
|
mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); |
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
bmpMask = QBitmap::fromImage(mask_img); |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
|
|
|
|
} |
|
|
|
// prepare general image
|
|
|
|
|
|
|
|
pMap = QPixmap(width(), height()); |
|
|
|
void UBMagnifier::setZoom(qreal zoom)
|
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
{ |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
params.zoom = zoom; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::setZoom(qreal zoom)
|
|
|
|
void UBMagnifier::paintEvent(QPaintEvent * event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
params.zoom = zoom; |
|
|
|
Q_UNUSED(event); |
|
|
|
} |
|
|
|
QPainter painter(this); |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::paintEvent(QPaintEvent * event) |
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
{ |
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
Q_UNUSED(event); |
|
|
|
|
|
|
|
QPainter painter(this); |
|
|
|
if (m_isInteractive) |
|
|
|
|
|
|
|
{ |
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
painter.setBrush(QColor(127, 127, 127, 127)); |
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); |
|
|
|
|
|
|
|
|
|
|
|
if (m_isInteractive) |
|
|
|
painter.setBrush(QColor(190, 190, 190, 255)); |
|
|
|
{ |
|
|
|
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); |
|
|
|
painter.setBrush(QColor(127, 127, 127, 127)); |
|
|
|
|
|
|
|
painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); |
|
|
|
painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); |
|
|
|
|
|
|
|
painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); |
|
|
|
painter.setBrush(QColor(190, 190, 190, 255)); |
|
|
|
painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); |
|
|
|
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); |
|
|
|
|
|
|
|
|
|
|
|
painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); |
|
|
|
painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); |
|
|
|
} |
|
|
|
painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); |
|
|
|
else |
|
|
|
painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); |
|
|
|
{ |
|
|
|
|
|
|
|
painter.setBrush(QColor(127, 127, 127, 127)); |
|
|
|
painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); |
|
|
|
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
painter.drawPixmap(0, 0, pMap); |
|
|
|
painter.setBrush(QColor(127, 127, 127, 127)); |
|
|
|
} |
|
|
|
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); |
|
|
|
|
|
|
|
} |
|
|
|
void UBMagnifier::mousePressEvent ( QMouseEvent * event ) |
|
|
|
|
|
|
|
{ |
|
|
|
painter.drawPixmap(0, 0, pMap); |
|
|
|
if(m_isInteractive) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::mousePressEvent ( QMouseEvent * event ) |
|
|
|
QWidget::mousePressEvent(event); |
|
|
|
{ |
|
|
|
|
|
|
|
if(m_isInteractive) |
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
{ |
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
|
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
QWidget::mousePressEvent(event); |
|
|
|
event->pos().y() < size().height() - - 20) |
|
|
|
|
|
|
|
{ |
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
mShouldResizeWidget = true; |
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
} |
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
else |
|
|
|
event->pos().y() < size().height() - - 20) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); |
|
|
|
mShouldResizeWidget = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
mMousePressPos = event->pos(); |
|
|
|
{ |
|
|
|
mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); |
|
|
|
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); |
|
|
|
|
|
|
|
} |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
|
|
|
|
mMousePressPos = event->pos(); |
|
|
|
update(); |
|
|
|
mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
event->accept(); |
|
|
|
event->ignore(); |
|
|
|
|
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
else |
|
|
|
{ |
|
|
|
event->ignore(); |
|
|
|
if(m_isInteractive) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
move(pos() - mMousePressPos + event->pos()); |
|
|
|
if(m_isInteractive) |
|
|
|
event->accept(); |
|
|
|
{ |
|
|
|
|
|
|
|
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
QWidget::mouseMoveEvent(event); |
|
|
|
{ |
|
|
|
emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); |
|
|
|
move(pos() - mMousePressPos + event->pos()); |
|
|
|
return; |
|
|
|
event->accept(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QWidget::mouseMoveEvent(event); |
|
|
|
if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); |
|
|
|
{ |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
QPoint currGlobalPos = event->globalPos(); |
|
|
|
|
|
|
|
qreal cvW = mView->width(); |
|
|
|
if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
|
|
|
|
{ |
|
|
|
qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; |
|
|
|
|
|
|
|
qreal newPercentSize = newXSize * 100 / cvW; |
|
|
|
QPoint currGlobalPos = event->globalPos(); |
|
|
|
|
|
|
|
qreal cvW = mView->width(); |
|
|
|
emit magnifierResized_Signal(newPercentSize); |
|
|
|
|
|
|
|
|
|
|
|
qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; |
|
|
|
event->ignore(); |
|
|
|
qreal newPercentSize = newXSize * 100 / cvW; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
emit magnifierResized_Signal(newPercentSize); |
|
|
|
|
|
|
|
|
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
event->ignore(); |
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
return; |
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
} |
|
|
|
event->pos().y() < size().height() - - 20 && |
|
|
|
|
|
|
|
isCusrsorAlreadyStored == false |
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
) |
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
{ |
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
mOldCursor = cursor(); |
|
|
|
event->pos().y() < size().height() - - 20 && |
|
|
|
isCusrsorAlreadyStored = true; |
|
|
|
isCusrsorAlreadyStored == false |
|
|
|
setCursor(mResizeCursor); |
|
|
|
) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
mOldCursor = cursor(); |
|
|
|
} |
|
|
|
isCusrsorAlreadyStored = true; |
|
|
|
else |
|
|
|
setCursor(mResizeCursor); |
|
|
|
event->ignore(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
event->ignore(); |
|
|
|
{ |
|
|
|
} |
|
|
|
if(m_isInteractive) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mShouldMoveWidget = false; |
|
|
|
void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
mShouldResizeWidget = false; |
|
|
|
{ |
|
|
|
|
|
|
|
if(m_isInteractive) |
|
|
|
if (event->pos().x() >= size().width() - sClosePixmap->width() &&
|
|
|
|
{ |
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
mShouldMoveWidget = false; |
|
|
|
event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
|
|
|
|
mShouldResizeWidget = false; |
|
|
|
event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) |
|
|
|
|
|
|
|
{ |
|
|
|
if (event->pos().x() >= size().width() - sClosePixmap->width() &&
|
|
|
|
event->accept(); |
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
emit magnifierClose_Signal(); |
|
|
|
event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
|
|
|
|
} |
|
|
|
event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
|
|
|
|
event->accept(); |
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
emit magnifierClose_Signal(); |
|
|
|
event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
|
|
|
|
} |
|
|
|
event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
|
|
|
|
event->accept(); |
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
emit magnifierZoomIn_Signal(); |
|
|
|
event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
|
|
|
|
} |
|
|
|
event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
|
|
|
|
event->accept(); |
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
emit magnifierZoomIn_Signal(); |
|
|
|
event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
|
|
|
|
} |
|
|
|
event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
|
|
|
|
event->accept(); |
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
emit magnifierZoomOut_Signal(); |
|
|
|
event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
|
|
|
|
} |
|
|
|
event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) |
|
|
|
else |
|
|
|
{ |
|
|
|
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
|
|
|
|
event->accept(); |
|
|
|
} |
|
|
|
emit magnifierZoomOut_Signal(); |
|
|
|
else |
|
|
|
} |
|
|
|
event->ignore(); |
|
|
|
else |
|
|
|
|
|
|
|
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
void UBMagnifier::slot_refresh() |
|
|
|
event->ignore(); |
|
|
|
{ |
|
|
|
|
|
|
|
if(!(updPointGrab.isNull()))
|
|
|
|
} |
|
|
|
grabPoint(updPointGrab); |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::timerEvent(QTimerEvent *e) |
|
|
|
if(isCusrsorAlreadyStored) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(inTimer) return; |
|
|
|
QPoint globalCursorPos = QCursor::pos(); |
|
|
|
if (e->timerId() == timerUpdate) |
|
|
|
QPoint cursorPos = mapFromGlobal(globalCursorPos); |
|
|
|
{ |
|
|
|
if (cursorPos.x() < size().width() - mResizeItem->width() - 20 ||
|
|
|
|
inTimer = true; |
|
|
|
cursorPos.x() > size().width() - 20 || |
|
|
|
if(!(updPointGrab.isNull()))
|
|
|
|
cursorPos.y() < size().height() - mResizeItem->height() - 20 || |
|
|
|
grabPoint(updPointGrab); |
|
|
|
cursorPos.y() > size().height() - - 20 |
|
|
|
|
|
|
|
) |
|
|
|
if(isCusrsorAlreadyStored) |
|
|
|
{ |
|
|
|
{ |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
QPoint globalCursorPos = QCursor::pos(); |
|
|
|
setCursor(mOldCursor); |
|
|
|
QPoint cursorPos = mapFromGlobal(globalCursorPos); |
|
|
|
} |
|
|
|
if (cursorPos.x() < size().width() - mResizeItem->width() - 20 ||
|
|
|
|
} |
|
|
|
cursorPos.x() > size().width() - 20 || |
|
|
|
} |
|
|
|
cursorPos.y() < size().height() - mResizeItem->height() - 20 || |
|
|
|
|
|
|
|
cursorPos.y() > size().height() - - 20 |
|
|
|
void UBMagnifier::grabPoint() |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMatrix transM = UBApplication::boardController->controlView()->matrix(); |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
QPointF itemPos = gView->mapFromGlobal(updPointGrab); |
|
|
|
setCursor(mOldCursor); |
|
|
|
|
|
|
|
} |
|
|
|
qreal zWidth = width() / (params.zoom * transM.m11()); |
|
|
|
|
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
} |
|
|
|
qreal zHeight = height() / (params.zoom * transM.m22()); |
|
|
|
|
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
inTimer = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::grabPoint() |
|
|
|
|
|
|
|
{ |
|
|
|
QRect magnifierRect = rect(); |
|
|
|
QPointF itemPos = gView->mapFromGlobal(updPointGrab); |
|
|
|
|
|
|
|
|
|
|
|
float x = pfScLtF.x() - zWidthHalf; |
|
|
|
qreal zWidth = size().width() / params.zoom; |
|
|
|
float y = pfScLtF.y() - zHeightHalf; |
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
|
|
|
|
qreal zHeight = size().height() / params.zoom; |
|
|
|
QPointF leftTop(x,y); |
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
QPointF rightBottom(x + zWidth, y + zHeight);
|
|
|
|
|
|
|
|
QRectF srcRect(leftTop, rightBottom); |
|
|
|
int x = itemPos.x() - zWidthHalf; |
|
|
|
|
|
|
|
int y = itemPos.y() - zHeightHalf; |
|
|
|
QPixmap newPixMap(QSize(width(), height())); |
|
|
|
|
|
|
|
QPainter painter(&newPixMap); |
|
|
|
QPixmap newPixMap(QSize(zWidth,zHeight)); |
|
|
|
|
|
|
|
((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); |
|
|
|
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); |
|
|
|
UBApplication::boardController->activeScene()->update(); |
|
|
|
painter.end(); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::grabPoint(const QPoint &pGrab) |
|
|
|
void UBMagnifier::grabPoint(const QPoint &pGrab) |
|
|
|
{ |
|
|
|
{ |
|
|
|
updPointGrab = pGrab; |
|
|
|
QMatrix transM = UBApplication::boardController->controlView()->matrix(); |
|
|
|
QPointF itemPos = gView->mapFromGlobal(pGrab); |
|
|
|
updPointGrab = pGrab; |
|
|
|
|
|
|
|
QPointF itemPos = gView->mapFromGlobal(pGrab); |
|
|
|
qreal zWidth = size().width() / params.zoom; |
|
|
|
|
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
qreal zWidth = width() / (params.zoom * transM.m11()); |
|
|
|
qreal zHeight = size().height() / params.zoom; |
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
qreal zHeight = height() / (params.zoom * transM.m22()); |
|
|
|
|
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
int x = itemPos.x() - zWidthHalf; |
|
|
|
|
|
|
|
int y = itemPos.y() - zHeightHalf; |
|
|
|
|
|
|
|
|
|
|
|
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); |
|
|
|
QPixmap newPixMap(QSize(zWidth,zHeight)); |
|
|
|
|
|
|
|
((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); |
|
|
|
|
|
|
|
UBApplication::boardController->activeScene()->update(); |
|
|
|
QRect magnifierRect = rect(); |
|
|
|
|
|
|
|
|
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
float x = pfScLtF.x() - zWidthHalf; |
|
|
|
pMap = newPixMap.scaled(QSize(width(), height())); |
|
|
|
float y = pfScLtF.y() - zHeightHalf; |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
|
|
|
|
|
|
|
|
QPointF leftTop(x,y); |
|
|
|
update(); |
|
|
|
QPointF rightBottom(x + zWidth, y + zHeight);
|
|
|
|
} |
|
|
|
QRectF srcRect(leftTop, rightBottom); |
|
|
|
|
|
|
|
|
|
|
|
// from global
|
|
|
|
QPixmap newPixMap(QSize(width(), height())); |
|
|
|
void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) |
|
|
|
QPainter painter(&newPixMap); |
|
|
|
{ |
|
|
|
|
|
|
|
updPointGrab = pGrab; |
|
|
|
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
|
|
|
|
updPointMove = pMove; |
|
|
|
painter.end(); |
|
|
|
|
|
|
|
|
|
|
|
if(needGrab) |
|
|
|
// pMap.fill(Qt::transparent);
|
|
|
|
grabPoint(pGrab); |
|
|
|
pMap = newPixMap; |
|
|
|
|
|
|
|
pMap.setMask(bmpMask); |
|
|
|
if(needMove) |
|
|
|
|
|
|
|
{ |
|
|
|
update(); |
|
|
|
QPoint movePos = mView->mapFromGlobal(pMove); |
|
|
|
} |
|
|
|
move(movePos.x() - width()/2, movePos.y() - height()/2); |
|
|
|
|
|
|
|
// move(itemPos.x(), itemPos.y());
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// from global
|
|
|
|
|
|
|
|
void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) |
|
|
|
void UBMagnifier::setGrabView(QWidget *view) |
|
|
|
{ |
|
|
|
{ |
|
|
|
updPointGrab = pGrab; |
|
|
|
if (timerUpdate != 0) |
|
|
|
updPointMove = pMove; |
|
|
|
killTimer(timerUpdate); |
|
|
|
|
|
|
|
gView = view; |
|
|
|
if(needGrab) |
|
|
|
timerUpdate = startTimer(200); |
|
|
|
grabPoint(pGrab); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(needMove) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QPoint movePos = mView->mapFromGlobal(pMove); |
|
|
|
|
|
|
|
move(movePos.x() - width()/2, movePos.y() - height()/2); |
|
|
|
|
|
|
|
// move(itemPos.x(), itemPos.y());
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::setGrabView(QWidget *view) |
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
gView = view; |
|
|
|
|
|
|
|
mRefreshTimer.setInterval(40); |
|
|
|
|
|
|
|
mRefreshTimer.start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|