|
|
@ -19,386 +19,386 @@ |
|
|
|
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* along with Open-Sankoré. 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 "board/UBBoardView.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, mShouldResizeWidget(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())); |
|
|
|
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBMagnifier::~UBMagnifier() |
|
|
|
UBMagnifier::~UBMagnifier() |
|
|
|
{ |
|
|
|
{ |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::setSize(qreal percentFromScene)
|
|
|
|
void UBMagnifier::setSize(qreal percentFromScene)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if(gView == NULL || mView == NULL) return; |
|
|
|
if(gView == NULL || mView == NULL) return; |
|
|
|
|
|
|
|
|
|
|
|
// calculate object size
|
|
|
|
// calculate object size
|
|
|
|
params.sizePercentFromScene = percentFromScene; |
|
|
|
params.sizePercentFromScene = percentFromScene; |
|
|
|
QSize sceneSize = mView->size(); |
|
|
|
QSize sceneSize = mView->size(); |
|
|
|
qreal size = params.sizePercentFromScene * sceneSize.width() / 100; |
|
|
|
qreal size = params.sizePercentFromScene * sceneSize.width() / 100; |
|
|
|
|
|
|
|
|
|
|
|
QRect currGeom = geometry(); |
|
|
|
QRect currGeom = geometry(); |
|
|
|
if(currGeom.width() == currGeom.height()) |
|
|
|
if(currGeom.width() == currGeom.height()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPoint newPos = mView->mapFromGlobal(updPointMove); |
|
|
|
QPoint newPos = mView->mapFromGlobal(updPointMove); |
|
|
|
setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); |
|
|
|
setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
// prepare general image
|
|
|
|
// prepare general image
|
|
|
|
pMap = QPixmap(width(), height()); |
|
|
|
pMap = QPixmap(width(), height()); |
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
pMap.fill(Qt::transparent); |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::setZoom(qreal zoom)
|
|
|
|
void UBMagnifier::setZoom(qreal zoom)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
params.zoom = zoom; |
|
|
|
params.zoom = zoom; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::paintEvent(QPaintEvent * event) |
|
|
|
void UBMagnifier::paintEvent(QPaintEvent * event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_UNUSED(event); |
|
|
|
Q_UNUSED(event); |
|
|
|
QPainter painter(this); |
|
|
|
QPainter painter(this); |
|
|
|
|
|
|
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
painter.setRenderHint(QPainter::Antialiasing); |
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
|
|
|
|
|
|
|
|
if (m_isInteractive) |
|
|
|
if (m_isInteractive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
painter.setBrush(QColor(127, 127, 127, 127)); |
|
|
|
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.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); |
|
|
|
|
|
|
|
|
|
|
|
painter.setBrush(QColor(190, 190, 190, 255)); |
|
|
|
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.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); |
|
|
|
|
|
|
|
|
|
|
|
painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); |
|
|
|
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.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); |
|
|
|
painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); |
|
|
|
painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); |
|
|
|
|
|
|
|
|
|
|
|
painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); |
|
|
|
painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
painter.setBrush(QColor(127, 127, 127, 127)); |
|
|
|
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); |
|
|
|
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
painter.drawPixmap(0, 0, pMap); |
|
|
|
painter.drawPixmap(0, 0, pMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::mousePressEvent ( QMouseEvent * event ) |
|
|
|
void UBMagnifier::mousePressEvent ( QMouseEvent * event ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(m_isInteractive) |
|
|
|
if(m_isInteractive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
QWidget::mousePressEvent(event); |
|
|
|
QWidget::mousePressEvent(event); |
|
|
|
|
|
|
|
|
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
event->pos().y() < size().height() - - 20) |
|
|
|
event->pos().y() < size().height() - - 20) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mShouldResizeWidget = true; |
|
|
|
mShouldResizeWidget = true; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); |
|
|
|
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mMousePressPos = event->pos(); |
|
|
|
mMousePressPos = event->pos(); |
|
|
|
mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); |
|
|
|
mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); |
|
|
|
|
|
|
|
|
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
event->ignore(); |
|
|
|
event->ignore(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(m_isInteractive) |
|
|
|
if(m_isInteractive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
move(pos() - mMousePressPos + event->pos()); |
|
|
|
move(pos() - mMousePressPos + event->pos()); |
|
|
|
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)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
QPoint currGlobalPos = event->globalPos(); |
|
|
|
QPoint currGlobalPos = event->globalPos(); |
|
|
|
qreal cvW = mView->width(); |
|
|
|
qreal cvW = mView->width(); |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
|
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
event->pos().x() < size().width() - 20 &&
|
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
|
|
|
|
event->pos().y() < size().height() - - 20 && |
|
|
|
event->pos().y() < size().height() - - 20 && |
|
|
|
isCusrsorAlreadyStored == false |
|
|
|
isCusrsorAlreadyStored == false |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mOldCursor = cursor(); |
|
|
|
mOldCursor = cursor(); |
|
|
|
isCusrsorAlreadyStored = true; |
|
|
|
isCusrsorAlreadyStored = true; |
|
|
|
setCursor(mResizeCursor); |
|
|
|
setCursor(mResizeCursor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
event->ignore(); |
|
|
|
event->ignore(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(m_isInteractive) |
|
|
|
if(m_isInteractive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mShouldMoveWidget = false; |
|
|
|
mShouldMoveWidget = false; |
|
|
|
mShouldResizeWidget = false; |
|
|
|
mShouldResizeWidget = false; |
|
|
|
|
|
|
|
|
|
|
|
if (event->pos().x() >= size().width() - sClosePixmap->width() &&
|
|
|
|
if (event->pos().x() >= size().width() - sClosePixmap->width() &&
|
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
|
|
|
|
event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
|
|
|
|
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() &&
|
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
|
|
|
|
event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
|
|
|
|
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() &&
|
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
event->pos().x() < size().width()&&
|
|
|
|
event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
|
|
|
|
event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
|
|
|
|
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
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
event->ignore(); |
|
|
|
event->ignore(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::slot_refresh() |
|
|
|
void UBMagnifier::slot_refresh() |
|
|
|
{ |
|
|
|
{ |
|
|
|
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 || |
|
|
|
cursorPos.y() > size().height() - - 20 |
|
|
|
cursorPos.y() > size().height() - - 20 |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
isCusrsorAlreadyStored = false; |
|
|
|
setCursor(mOldCursor); |
|
|
|
setCursor(mOldCursor); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::grabPoint() |
|
|
|
void UBMagnifier::grabPoint() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMatrix transM = UBApplication::boardController->controlView()->matrix(); |
|
|
|
QMatrix transM = UBApplication::boardController->controlView()->matrix(); |
|
|
|
QPointF itemPos = gView->mapFromGlobal(updPointGrab); |
|
|
|
QPointF itemPos = gView->mapFromGlobal(updPointGrab); |
|
|
|
|
|
|
|
|
|
|
|
qreal zWidth = width() / (params.zoom * transM.m11()); |
|
|
|
qreal zWidth = width() / (params.zoom * transM.m11()); |
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
qreal zHeight = height() / (params.zoom * transM.m22()); |
|
|
|
qreal zHeight = height() / (params.zoom * transM.m22()); |
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); |
|
|
|
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); |
|
|
|
|
|
|
|
|
|
|
|
float x = pfScLtF.x() - zWidthHalf; |
|
|
|
float x = pfScLtF.x() - zWidthHalf; |
|
|
|
float y = pfScLtF.y() - zHeightHalf; |
|
|
|
float y = pfScLtF.y() - zHeightHalf; |
|
|
|
|
|
|
|
|
|
|
|
QPointF leftTop(x,y); |
|
|
|
QPointF leftTop(x,y); |
|
|
|
QPointF rightBottom(x + zWidth, y + zHeight);
|
|
|
|
QPointF rightBottom(x + zWidth, y + zHeight);
|
|
|
|
QRectF srcRect(leftTop, rightBottom); |
|
|
|
QRectF srcRect(leftTop, rightBottom); |
|
|
|
|
|
|
|
|
|
|
|
QPixmap newPixMap(QSize(width(), height())); |
|
|
|
QPixmap newPixMap(QSize(width(), height())); |
|
|
|
QPainter painter(&newPixMap); |
|
|
|
QPainter painter(&newPixMap); |
|
|
|
|
|
|
|
|
|
|
|
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); |
|
|
|
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); |
|
|
|
painter.end(); |
|
|
|
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) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMatrix transM = UBApplication::boardController->controlView()->matrix(); |
|
|
|
QMatrix transM = UBApplication::boardController->controlView()->matrix(); |
|
|
|
updPointGrab = pGrab; |
|
|
|
updPointGrab = pGrab; |
|
|
|
QPointF itemPos = gView->mapFromGlobal(pGrab); |
|
|
|
QPointF itemPos = gView->mapFromGlobal(pGrab); |
|
|
|
|
|
|
|
|
|
|
|
qreal zWidth = width() / (params.zoom * transM.m11()); |
|
|
|
qreal zWidth = width() / (params.zoom * transM.m11()); |
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
qreal zWidthHalf = zWidth / 2; |
|
|
|
qreal zHeight = height() / (params.zoom * transM.m22()); |
|
|
|
qreal zHeight = height() / (params.zoom * transM.m22()); |
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
qreal zHeightHalf = zHeight / 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); |
|
|
|
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); |
|
|
|
|
|
|
|
|
|
|
|
float x = pfScLtF.x() - zWidthHalf; |
|
|
|
float x = pfScLtF.x() - zWidthHalf; |
|
|
|
float y = pfScLtF.y() - zHeightHalf; |
|
|
|
float y = pfScLtF.y() - zHeightHalf; |
|
|
|
|
|
|
|
|
|
|
|
QPointF leftTop(x,y); |
|
|
|
QPointF leftTop(x,y); |
|
|
|
QPointF rightBottom(x + zWidth, y + zHeight);
|
|
|
|
QPointF rightBottom(x + zWidth, y + zHeight);
|
|
|
|
QRectF srcRect(leftTop, rightBottom); |
|
|
|
QRectF srcRect(leftTop, rightBottom); |
|
|
|
|
|
|
|
|
|
|
|
QPixmap newPixMap(QSize(width(), height())); |
|
|
|
QPixmap newPixMap(QSize(width(), height())); |
|
|
|
QPainter painter(&newPixMap); |
|
|
|
QPainter painter(&newPixMap); |
|
|
|
|
|
|
|
|
|
|
|
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
|
|
|
|
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
|
|
|
|
painter.end(); |
|
|
|
painter.end(); |
|
|
|
|
|
|
|
|
|
|
|
// pMap.fill(Qt::transparent);
|
|
|
|
// pMap.fill(Qt::transparent);
|
|
|
|
pMap = newPixMap; |
|
|
|
pMap = newPixMap; |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
pMap.setMask(bmpMask); |
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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); |
|
|
|
|
|
|
|
|
|
|
|
if(needMove) |
|
|
|
if(needMove) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPoint movePos = mView->mapFromGlobal(pMove); |
|
|
|
QPoint movePos = mView->mapFromGlobal(pMove); |
|
|
|
move(movePos.x() - width()/2, movePos.y() - height()/2); |
|
|
|
move(movePos.x() - width()/2, movePos.y() - height()/2); |
|
|
|
// move(itemPos.x(), itemPos.y());
|
|
|
|
// move(itemPos.x(), itemPos.y());
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBMagnifier::setGrabView(QWidget *view) |
|
|
|
void UBMagnifier::setGrabView(QWidget *view) |
|
|
|
{
|
|
|
|
{
|
|
|
|
gView = view; |
|
|
|
gView = view; |
|
|
|
mRefreshTimer.setInterval(40); |
|
|
|
mRefreshTimer.setInterval(40); |
|
|
|
mRefreshTimer.start(); |
|
|
|
mRefreshTimer.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|