diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp
index 961a2dc3..4b54b76b 100644
--- a/src/board/UBBoardController.cpp
+++ b/src/board/UBBoardController.cpp
@@ -664,6 +664,7 @@ void UBBoardController::zoom(const qreal ratio, QPointF scenePoint)
UBApplication::applicationController->adjustDisplayView();
emit controlViewportChanged();
+ mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());
}
@@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
mControlView->setScene(mActiveScene);
mDisplayView->setScene(mActiveScene);
-
+ mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());
pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize());
updatePageSizeState();
@@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor()
mControlView->setTransform(scalingTransform);
mControlView->horizontalScrollBar()->setValue(viewState.horizontalPosition);
mControlView->verticalScrollBar()->setValue(viewState.verticalPostition);
-}
+ mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());}
void UBBoardController::setWidePageSize(bool checked)
diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp
index 9cb92e4b..1f27f607 100644
--- a/src/desktop/UBDesktopAnnotationController.cpp
+++ b/src/desktop/UBDesktopAnnotationController.cpp
@@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingScene = new UBGraphicsScene(0);
mTransparentDrawingView->setScene(mTransparentDrawingScene);
+ mTransparentDrawingScene->setDrawingMode(true);
// mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView);
//mRightPalette = new UBRightPalette(mTransparentDrawingView);
diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp
index bbd4af62..6f7f4d77 100644
--- a/src/domain/UBGraphicsScene.cpp
+++ b/src/domain/UBGraphicsScene.cpp
@@ -135,6 +135,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
, enableUndoRedoStack(true)
, magniferControlViewWidget(0)
, magniferDisplayViewWidget(0)
+ , mIsDesktopMode(false)
{
@@ -160,8 +161,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
UBGraphicsScene::~UBGraphicsScene()
{
- DisposeMagnifierQWidgets();
-
if (mCurrentStroke)
if (mCurrentStroke->polygons().empty())
delete mCurrentStroke;
@@ -711,6 +710,15 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed)
}
}
+void UBGraphicsScene::setBackgroundZoomFactor(qreal zoom)
+{
+ mZoomFactor = zoom;
+}
+
+void UBGraphicsScene::setDrawingMode(bool bModeDesktop)
+{
+ mIsDesktopMode = bModeDesktop;
+}
void UBGraphicsScene::recolorAllItems()
{
@@ -1854,6 +1862,58 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems,
}
}
+void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
+{
+ if (mIsDesktopMode)
+ {
+ QGraphicsScene::drawBackground (painter, rect);
+ return;
+ }
+ bool darkBackground = isDarkBackground ();
+
+ if (darkBackground)
+ {
+ painter->fillRect (rect, QBrush (QColor (Qt::black)));
+ }
+ else
+ {
+ painter->fillRect (rect, QBrush (QColor (Qt::white)));
+ }
+
+ if (mZoomFactor > 0.5)
+ {
+ QColor bgCrossColor;
+
+ if (darkBackground)
+ bgCrossColor = UBSettings::crossDarkBackground;
+ else
+ bgCrossColor = UBSettings::crossLightBackground;
+ if (mZoomFactor < 1.0)
+ {
+ int alpha = 255 * mZoomFactor / 2;
+ bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms
+ }
+
+ painter->setPen (bgCrossColor);
+
+ if (isCrossedBackground())
+ {
+ qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize;
+
+ for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize)
+ {
+ painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
+ }
+
+ qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize;
+
+ for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize)
+ {
+ painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
+ }
+ }
+ }
+}
void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
{
diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h
index 8fa84053..1cdd37e4 100644
--- a/src/domain/UBGraphicsScene.h
+++ b/src/domain/UBGraphicsScene.h
@@ -288,7 +288,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void hideEraser();
void setBackground(bool pIsDark, bool pIsCrossed);
-
+ void setBackgroundZoomFactor(qreal zoom);
+ void setDrawingMode(bool bModeDesktop);
void deselectAllItems();
UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false);
@@ -331,6 +332,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
QGraphicsItem* rootItem(QGraphicsItem* item) const;
+ virtual void drawBackground(QPainter *painter, const QRectF &rect);
+
private:
void setDocumentUpdated();
void createEraiser();
@@ -348,6 +351,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
bool mDarkBackground;
bool mCrossedBackground;
+ bool mIsDesktopMode;
+ qreal mZoomFactor;
bool mIsModified;
diff --git a/src/gui/UBMagnifer.cpp b/src/gui/UBMagnifer.cpp
index 08285c91..93693797 100644
--- a/src/gui/UBMagnifer.cpp
+++ b/src/gui/UBMagnifer.cpp
@@ -1,388 +1,402 @@
-/*
- * 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 .
- */
-
-#include
-#include "UBMagnifer.h"
-
-#include "core/UBApplication.h"
-#include "board/UBBoardController.h"
-#include "domain/UBGraphicsScene.h"
-
-#include "core/memcheck.h"
-
-
-UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
- : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint))
- , mShouldMoveWidget(false)
- , mShouldResizeWidget(false)
- , inTimer(false)
- , borderPen(Qt::darkGray)
- , gView(0)
- , mView(0)
-{
- isCusrsorAlreadyStored = false;
- setMouseTracking(true);
-
- //--------------------------------------------------//
-
- QPixmap pix(":/images/cursors/resize.png");
- QTransform tr;
- tr.rotate(45);
- mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
-
- //--------------------------------------------------//
-
- params.sizePercentFromScene = 20;
- m_isInteractive = isInteractive;
- sClosePixmap = new QPixmap(":/images/close.svg");
- sIncreasePixmap = new QPixmap(":/images/increase.svg");
- sDecreasePixmap = new QPixmap(":/images/decrease.svg");
- mResizeItem = new QPixmap(":/images/resize.svg");
-
- if (parent)
- {
- setAttribute(Qt::WA_NoMousePropagation);
- }
- else
- {
- // standalone window
- // !!!! Should be included into Windows after QT recompilation
-#ifndef Q_WS_WIN
-// setAttribute(Qt::WA_TranslucentBackground);
- setAttribute(Qt::WA_MacAlwaysShowToolWindow);
-#endif
-#ifdef Q_WS_MAC
- setAttribute(Qt::WA_MacAlwaysShowToolWindow);
- setAttribute(Qt::WA_MacNonActivatingToolWindow);
- setAttribute(Qt::WA_MacNoShadow);
-#endif
- }
-
-}
-
-UBMagnifier::~UBMagnifier()
-{
- if (timerUpdate != 0)
- {
- killTimer(timerUpdate);
- timerUpdate = 0;
- }
-
- if(sClosePixmap)
- {
- delete sClosePixmap;
- sClosePixmap = NULL;
- }
-
- if(sIncreasePixmap)
- {
- delete sIncreasePixmap;
- sIncreasePixmap = NULL;
- }
-
- if(sDecreasePixmap)
- {
- delete sDecreasePixmap;
- sDecreasePixmap = NULL;
- }
-}
-
-void UBMagnifier::setSize(qreal percentFromScene)
-{
- if(gView == NULL || mView == NULL) return;
-
- // calculate object size
- params.sizePercentFromScene = percentFromScene;
- QSize sceneSize = mView->size();
- qreal size = params.sizePercentFromScene * sceneSize.width() / 100;
-
- QRect currGeom = geometry();
- if(currGeom.width() == currGeom.height())
- {
- QPoint newPos = mView->mapFromGlobal(updPointMove);
- setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size);
- }
- else
- setGeometry(0, 0, size, size);
-
- // prepare transparent bit mask
- QImage mask_img(width(), height(), QImage::Format_Mono);
- mask_img.fill(0xff);
- QPainter mask_ptr(&mask_img);
- mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) );
- mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width());
- bmpMask = QBitmap::fromImage(mask_img);
-
- // prepare general image
- pMap = QPixmap(width(), height());
- pMap.fill(Qt::transparent);
- pMap.setMask(bmpMask);
-}
-
-void UBMagnifier::setZoom(qreal zoom)
-{
- params.zoom = zoom;
-}
-
-void UBMagnifier::paintEvent(QPaintEvent * event)
-{
- Q_UNUSED(event);
- QPainter painter(this);
-
- painter.setRenderHint(QPainter::Antialiasing);
- painter.setPen(Qt::NoPen);
-
- if (m_isInteractive)
- {
- 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.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.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() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap);
-
- painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem);
- }
- else
- {
- 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.drawPixmap(0, 0, pMap);
-}
-
-void UBMagnifier::mousePressEvent ( QMouseEvent * event )
-{
- if(m_isInteractive)
- {
-
- QWidget::mousePressEvent(event);
-
- if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
- event->pos().x() < size().width() - 20 &&
- event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
- event->pos().y() < size().height() - - 20)
- {
- mShouldResizeWidget = true;
- }
- else
- {
- mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
- }
-
- mMousePressPos = event->pos();
- mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x();
-
- event->accept();
-
- update();
- }
- else
- event->ignore();
-}
-
-void UBMagnifier::mouseMoveEvent ( QMouseEvent * event )
-{
- if(m_isInteractive)
- {
- if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton))
- {
- move(pos() - mMousePressPos + event->pos());
- event->accept();
-
- QWidget::mouseMoveEvent(event);
- emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 ));
- return;
- }
-
- if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton))
- {
-
- QPoint currGlobalPos = event->globalPos();
- qreal cvW = mView->width();
-
- qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2;
- qreal newPercentSize = newXSize * 100 / cvW;
-
- emit magnifierResized_Signal(newPercentSize);
-
- event->ignore();
- return;
- }
-
- if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
- event->pos().x() < size().width() - 20 &&
- event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
- event->pos().y() < size().height() - - 20 &&
- isCusrsorAlreadyStored == false
- )
- {
- mOldCursor = cursor();
- isCusrsorAlreadyStored = true;
- setCursor(mResizeCursor);
- }
-
- }
- else
- event->ignore();
-}
-
-
-void UBMagnifier::mouseReleaseEvent(QMouseEvent * event)
-{
- if(m_isInteractive)
- {
- mShouldMoveWidget = false;
- mShouldResizeWidget = false;
-
- if (event->pos().x() >= size().width() - sClosePixmap->width() &&
- event->pos().x() < size().width()&&
- event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
- event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2)
- {
- event->accept();
- emit magnifierClose_Signal();
- }
- else
- if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
- event->pos().x() < size().width()&&
- event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
- event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5)
- {
- event->accept();
- emit magnifierZoomIn_Signal();
- }
- else
- if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
- event->pos().x() < size().width()&&
- event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
- event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6)
- {
- event->accept();
- emit magnifierZoomOut_Signal();
- }
- else
- QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
- }
- else
- event->ignore();
-
-}
-
-void UBMagnifier::timerEvent(QTimerEvent *e)
-{
- if(inTimer) return;
- if (e->timerId() == timerUpdate)
- {
- inTimer = true;
- if(!(updPointGrab.isNull()))
- grabPoint(updPointGrab);
-
- if(isCusrsorAlreadyStored)
- {
- QPoint globalCursorPos = QCursor::pos();
- 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
- )
- {
- isCusrsorAlreadyStored = false;
- setCursor(mOldCursor);
- }
-
- }
-
- inTimer = false;
- }
-}
-
-void UBMagnifier::grabPoint()
-{
- QPointF itemPos = gView->mapFromGlobal(updPointGrab);
-
- qreal zWidth = size().width() / params.zoom;
- qreal zWidthHalf = zWidth / 2;
- qreal zHeight = size().height() / params.zoom;
- qreal zHeightHalf = zHeight / 2;
-
- int x = itemPos.x() - zWidthHalf;
- int y = itemPos.y() - zHeightHalf;
-
- QPixmap newPixMap(QSize(zWidth,zHeight));
- ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight));
- UBApplication::boardController->activeScene()->update();
-
- pMap.fill(Qt::transparent);
- pMap = newPixMap.scaled(QSize(width(), height()));
- pMap.setMask(bmpMask);
-
- update();
-}
-
-void UBMagnifier::grabPoint(const QPoint &pGrab)
-{
- updPointGrab = pGrab;
- QPointF itemPos = gView->mapFromGlobal(pGrab);
-
- qreal zWidth = size().width() / params.zoom;
- qreal zWidthHalf = zWidth / 2;
- qreal zHeight = size().height() / params.zoom;
- qreal zHeightHalf = zHeight / 2;
-
- int x = itemPos.x() - zWidthHalf;
- int y = itemPos.y() - zHeightHalf;
-
- QPixmap newPixMap(QSize(zWidth,zHeight));
- ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight));
- UBApplication::boardController->activeScene()->update();
-
- pMap.fill(Qt::transparent);
- pMap = newPixMap.scaled(QSize(width(), height()));
- pMap.setMask(bmpMask);
-
- update();
-}
-
-// from global
-void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove)
-{
- updPointGrab = pGrab;
- updPointMove = pMove;
-
- if(needGrab)
- 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)
-{
- if (timerUpdate != 0)
- killTimer(timerUpdate);
- gView = view;
- timerUpdate = startTimer(200);
-}
-
+/*
+ * 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 .
+ */
+
+#include
+#include "UBMagnifer.h"
+
+#include "core/UBApplication.h"
+#include "board/UBBoardController.h"
+#include "domain/UBGraphicsScene.h"
+#include "board/UBBoardView.h"
+
+#include "core/memcheck.h"
+
+
+UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
+ : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint))
+ , mShouldMoveWidget(false)
+ , mShouldResizeWidget(false)
+ , borderPen(Qt::darkGray)
+ , gView(0)
+ , mView(0)
+{
+ isCusrsorAlreadyStored = false;
+ setMouseTracking(true);
+
+ //--------------------------------------------------//
+
+ QPixmap pix(":/images/cursors/resize.png");
+ QTransform tr;
+ tr.rotate(45);
+ mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
+
+ //--------------------------------------------------//
+
+ params.sizePercentFromScene = 20;
+ m_isInteractive = isInteractive;
+ sClosePixmap = new QPixmap(":/images/close.svg");
+ sIncreasePixmap = new QPixmap(":/images/increase.svg");
+ sDecreasePixmap = new QPixmap(":/images/decrease.svg");
+ mResizeItem = new QPixmap(":/images/resize.svg");
+
+ if (parent)
+ {
+ setAttribute(Qt::WA_NoMousePropagation);
+ }
+ else
+ {
+ // standalone window
+ // !!!! Should be included into Windows after QT recompilation
+#ifndef Q_WS_WIN
+// setAttribute(Qt::WA_TranslucentBackground);
+ setAttribute(Qt::WA_MacAlwaysShowToolWindow);
+#endif
+#ifdef Q_WS_MAC
+ setAttribute(Qt::WA_MacAlwaysShowToolWindow);
+ setAttribute(Qt::WA_MacNonActivatingToolWindow);
+ setAttribute(Qt::WA_MacNoShadow);
+#endif
+ }
+
+ connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh()));
+}
+
+UBMagnifier::~UBMagnifier()
+{
+ if(sClosePixmap)
+ {
+ delete sClosePixmap;
+ sClosePixmap = NULL;
+ }
+
+ if(sIncreasePixmap)
+ {
+ delete sIncreasePixmap;
+ sIncreasePixmap = NULL;
+ }
+
+ if(sDecreasePixmap)
+ {
+ delete sDecreasePixmap;
+ sDecreasePixmap = NULL;
+ }
+}
+
+void UBMagnifier::setSize(qreal percentFromScene)
+{
+ if(gView == NULL || mView == NULL) return;
+
+ // calculate object size
+ params.sizePercentFromScene = percentFromScene;
+ QSize sceneSize = mView->size();
+ qreal size = params.sizePercentFromScene * sceneSize.width() / 100;
+
+ QRect currGeom = geometry();
+ if(currGeom.width() == currGeom.height())
+ {
+ QPoint newPos = mView->mapFromGlobal(updPointMove);
+ setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size);
+ }
+ else
+ setGeometry(0, 0, size, size);
+
+ // prepare transparent bit mask
+ QImage mask_img(width(), height(), QImage::Format_Mono);
+ mask_img.fill(0xff);
+ QPainter mask_ptr(&mask_img);
+ mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) );
+ mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width());
+ bmpMask = QBitmap::fromImage(mask_img);
+
+ // prepare general image
+ pMap = QPixmap(width(), height());
+ pMap.fill(Qt::transparent);
+ pMap.setMask(bmpMask);
+}
+
+void UBMagnifier::setZoom(qreal zoom)
+{
+ params.zoom = zoom;
+}
+
+void UBMagnifier::paintEvent(QPaintEvent * event)
+{
+ Q_UNUSED(event);
+ QPainter painter(this);
+
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setPen(Qt::NoPen);
+
+ if (m_isInteractive)
+ {
+ 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.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.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() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap);
+
+ painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem);
+ }
+ else
+ {
+ 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.drawPixmap(0, 0, pMap);
+}
+
+void UBMagnifier::mousePressEvent ( QMouseEvent * event )
+{
+ if(m_isInteractive)
+ {
+
+ QWidget::mousePressEvent(event);
+
+ if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
+ event->pos().x() < size().width() - 20 &&
+ event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
+ event->pos().y() < size().height() - - 20)
+ {
+ mShouldResizeWidget = true;
+ }
+ else
+ {
+ mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
+ }
+
+ mMousePressPos = event->pos();
+ mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x();
+
+ event->accept();
+
+ update();
+ }
+ else
+ event->ignore();
+}
+
+void UBMagnifier::mouseMoveEvent ( QMouseEvent * event )
+{
+ if(m_isInteractive)
+ {
+ if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton))
+ {
+ move(pos() - mMousePressPos + event->pos());
+ event->accept();
+
+ QWidget::mouseMoveEvent(event);
+ emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 ));
+ return;
+ }
+
+ if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton))
+ {
+
+ QPoint currGlobalPos = event->globalPos();
+ qreal cvW = mView->width();
+
+ qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2;
+ qreal newPercentSize = newXSize * 100 / cvW;
+
+ emit magnifierResized_Signal(newPercentSize);
+
+ event->ignore();
+ return;
+ }
+
+ if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
+ event->pos().x() < size().width() - 20 &&
+ event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
+ event->pos().y() < size().height() - - 20 &&
+ isCusrsorAlreadyStored == false
+ )
+ {
+ mOldCursor = cursor();
+ isCusrsorAlreadyStored = true;
+ setCursor(mResizeCursor);
+ }
+
+ }
+ else
+ event->ignore();
+}
+
+
+void UBMagnifier::mouseReleaseEvent(QMouseEvent * event)
+{
+ if(m_isInteractive)
+ {
+ mShouldMoveWidget = false;
+ mShouldResizeWidget = false;
+
+ if (event->pos().x() >= size().width() - sClosePixmap->width() &&
+ event->pos().x() < size().width()&&
+ event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
+ event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2)
+ {
+ event->accept();
+ emit magnifierClose_Signal();
+ }
+ else
+ if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
+ event->pos().x() < size().width()&&
+ event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
+ event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5)
+ {
+ event->accept();
+ emit magnifierZoomIn_Signal();
+ }
+ else
+ if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
+ event->pos().x() < size().width()&&
+ event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
+ event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6)
+ {
+ event->accept();
+ emit magnifierZoomOut_Signal();
+ }
+ else
+ QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
+ }
+ else
+ event->ignore();
+
+}
+
+void UBMagnifier::slot_refresh()
+{
+ if(!(updPointGrab.isNull()))
+ grabPoint(updPointGrab);
+
+ if(isCusrsorAlreadyStored)
+ {
+ QPoint globalCursorPos = QCursor::pos();
+ 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
+ )
+ {
+ isCusrsorAlreadyStored = false;
+ setCursor(mOldCursor);
+ }
+ }
+}
+
+void UBMagnifier::grabPoint()
+{
+ QMatrix transM = UBApplication::boardController->controlView()->matrix();
+ QPointF itemPos = gView->mapFromGlobal(updPointGrab);
+
+ qreal zWidth = width() / (params.zoom * transM.m11());
+ qreal zWidthHalf = zWidth / 2;
+ qreal zHeight = height() / (params.zoom * transM.m22());
+ qreal zHeightHalf = zHeight / 2;
+
+
+ QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
+
+
+ QRect magnifierRect = rect();
+
+ float x = pfScLtF.x() - zWidthHalf;
+ float y = pfScLtF.y() - zHeightHalf;
+
+ QPointF leftTop(x,y);
+ QPointF rightBottom(x + zWidth, y + zHeight);
+ QRectF srcRect(leftTop, rightBottom);
+
+ QPixmap newPixMap(QSize(width(), height()));
+ QPainter painter(&newPixMap);
+
+ UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
+ painter.end();
+
+ pMap.fill(Qt::transparent);
+ pMap = newPixMap.scaled(QSize(width(), height()));
+ pMap.setMask(bmpMask);
+
+ update();
+}
+
+void UBMagnifier::grabPoint(const QPoint &pGrab)
+{
+ QMatrix transM = UBApplication::boardController->controlView()->matrix();
+ updPointGrab = pGrab;
+ QPointF itemPos = gView->mapFromGlobal(pGrab);
+
+ qreal zWidth = width() / (params.zoom * transM.m11());
+ qreal zWidthHalf = zWidth / 2;
+ qreal zHeight = height() / (params.zoom * transM.m22());
+ qreal zHeightHalf = zHeight / 2;
+
+
+ QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
+
+
+ QRect magnifierRect = rect();
+
+ float x = pfScLtF.x() - zWidthHalf;
+ float y = pfScLtF.y() - zHeightHalf;
+
+ QPointF leftTop(x,y);
+ QPointF rightBottom(x + zWidth, y + zHeight);
+ QRectF srcRect(leftTop, rightBottom);
+
+ QPixmap newPixMap(QSize(width(), height()));
+ QPainter painter(&newPixMap);
+
+ UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
+ painter.end();
+
+ // pMap.fill(Qt::transparent);
+ pMap = newPixMap;
+ pMap.setMask(bmpMask);
+
+ update();
+}
+
+
+
+// from global
+void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove)
+{
+ updPointGrab = pGrab;
+ updPointMove = pMove;
+
+ if(needGrab)
+ 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();
+}
+
diff --git a/src/gui/UBMagnifer.h b/src/gui/UBMagnifer.h
index 73a81692..7a118a99 100644
--- a/src/gui/UBMagnifer.h
+++ b/src/gui/UBMagnifer.h
@@ -1,96 +1,97 @@
-/*
- * 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 .
- */
-
-#ifndef UBMAGNIFIER_H
-#define UBMAGNIFIER_H
-
-#include
-
-class UBMagnifierParams
-{
-public :
- int x;
- int y;
- qreal zoom;
- qreal sizePercentFromScene;
-};
-
-class UBMagnifier : public QWidget
-{
- Q_OBJECT
-
-public:
- UBMagnifier(QWidget *parent = 0, bool isInteractive = false);
- ~UBMagnifier();
-
- void setSize(qreal percentFromScene);
- void setZoom(qreal zoom);
-
- void setGrabView(QWidget *view);
- void setMoveView(QWidget *view) {mView = view;}
-
- void grabPoint();
- void grabPoint(const QPoint &point);
- void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true);
-
- UBMagnifierParams params;
-
-signals:
- void magnifierMoved_Signal(QPoint newPos);
- void magnifierClose_Signal();
- void magnifierZoomIn_Signal();
- void magnifierZoomOut_Signal();
- void magnifierResized_Signal(qreal newPercentSize);
-
-protected:
- void paintEvent(QPaintEvent *);
- void timerEvent(QTimerEvent *);
-
- virtual void mousePressEvent ( QMouseEvent * event );
- virtual void mouseMoveEvent ( QMouseEvent * event );
- virtual void mouseReleaseEvent ( QMouseEvent * event );
-
- QPoint mMousePressPos;
- qreal mMousePressDelta;
- bool mShouldMoveWidget;
- bool mShouldResizeWidget;
-
-
- QPixmap *sClosePixmap;
- QPixmap *sIncreasePixmap;
- QPixmap *sDecreasePixmap;
- QPixmap *mResizeItem;
-
- bool isCusrsorAlreadyStored;
- QCursor mOldCursor;
- QCursor mResizeCursor;
-
-private:
- bool inTimer;
- bool m_isInteractive;
-
- int timerUpdate;
- QPoint updPointGrab;
- QPoint updPointMove;
-
- QPixmap pMap;
- QBitmap bmpMask;
- QPen borderPen;
-
- QWidget *gView;
- QWidget *mView;
-};
-
-#endif // UBMAGNIFIER_H
+/*
+ * 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 .
+ */
+
+#ifndef UBMAGNIFIER_H
+#define UBMAGNIFIER_H
+
+#include
+
+class UBMagnifierParams
+{
+public :
+ int x;
+ int y;
+ qreal zoom;
+ qreal sizePercentFromScene;
+};
+
+class UBMagnifier : public QWidget
+{
+ Q_OBJECT
+
+public:
+ UBMagnifier(QWidget *parent = 0, bool isInteractive = false);
+ ~UBMagnifier();
+
+ void setSize(qreal percentFromScene);
+ void setZoom(qreal zoom);
+
+ void setGrabView(QWidget *view);
+ void setMoveView(QWidget *view) {mView = view;}
+
+ void grabPoint();
+ void grabPoint(const QPoint &point);
+ void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true);
+
+ UBMagnifierParams params;
+
+signals:
+ void magnifierMoved_Signal(QPoint newPos);
+ void magnifierClose_Signal();
+ void magnifierZoomIn_Signal();
+ void magnifierZoomOut_Signal();
+ void magnifierResized_Signal(qreal newPercentSize);
+
+public slots:
+ void slot_refresh();
+
+protected:
+ void paintEvent(QPaintEvent *);
+
+ virtual void mousePressEvent ( QMouseEvent * event );
+ virtual void mouseMoveEvent ( QMouseEvent * event );
+ virtual void mouseReleaseEvent ( QMouseEvent * event );
+
+ QPoint mMousePressPos;
+ qreal mMousePressDelta;
+ bool mShouldMoveWidget;
+ bool mShouldResizeWidget;
+
+
+ QPixmap *sClosePixmap;
+ QPixmap *sIncreasePixmap;
+ QPixmap *sDecreasePixmap;
+ QPixmap *mResizeItem;
+
+ bool isCusrsorAlreadyStored;
+ QCursor mOldCursor;
+ QCursor mResizeCursor;
+
+private:
+ QTimer mRefreshTimer;
+ bool m_isInteractive;
+
+ QPoint updPointGrab;
+ QPoint updPointMove;
+
+ QPixmap pMap;
+ QBitmap bmpMask;
+ QPen borderPen;
+
+ QWidget *gView;
+ QWidget *mView;
+};
+
+#endif // UBMAGNIFIER_H