SANKORE-475

Improve the rendering of the magnifier
preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 9745c5d058
commit 1e67bf6e4a
  1. 5
      src/board/UBBoardController.cpp
  2. 1
      src/desktop/UBDesktopAnnotationController.cpp
  3. 64
      src/domain/UBGraphicsScene.cpp
  4. 7
      src/domain/UBGraphicsScene.h
  5. 110
      src/gui/UBMagnifer.cpp
  6. 7
      src/gui/UBMagnifer.h

@ -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)

@ -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);

@ -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)
{

@ -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;

@ -19,6 +19,7 @@
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardView.h"
#include "core/memcheck.h"
@ -27,7 +28,6 @@ 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)
@ -70,16 +70,11 @@ UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
#endif
}
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh()));
}
UBMagnifier::~UBMagnifier()
{
if (timerUpdate != 0)
{
killTimer(timerUpdate);
timerUpdate = 0;
}
if(sClosePixmap)
{
delete sClosePixmap;
@ -285,50 +280,55 @@ void UBMagnifier::mouseReleaseEvent(QMouseEvent * event)
}
void UBMagnifier::timerEvent(QTimerEvent *e)
void UBMagnifier::slot_refresh()
{
if(inTimer) return;
if (e->timerId() == timerUpdate)
{
inTimer = true;
if(!(updPointGrab.isNull()))
grabPoint(updPointGrab);
if(!(updPointGrab.isNull()))
grabPoint(updPointGrab);
if(isCusrsorAlreadyStored)
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
)
{
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);
}
isCusrsorAlreadyStored = false;
setCursor(mOldCursor);
}
inTimer = false;
}
}
void UBMagnifier::grabPoint()
{
QMatrix transM = UBApplication::boardController->controlView()->matrix();
QPointF itemPos = gView->mapFromGlobal(updPointGrab);
qreal zWidth = size().width() / params.zoom;
qreal zWidth = width() / (params.zoom * transM.m11());
qreal zWidthHalf = zWidth / 2;
qreal zHeight = size().height() / params.zoom;
qreal zHeight = height() / (params.zoom * transM.m22());
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();
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()));
@ -339,28 +339,43 @@ void UBMagnifier::grabPoint()
void UBMagnifier::grabPoint(const QPoint &pGrab)
{
QMatrix transM = UBApplication::boardController->controlView()->matrix();
updPointGrab = pGrab;
QPointF itemPos = gView->mapFromGlobal(pGrab);
qreal zWidth = size().width() / params.zoom;
qreal zWidth = width() / (params.zoom * transM.m11());
qreal zWidthHalf = zWidth / 2;
qreal zHeight = size().height() / params.zoom;
qreal zHeight = height() / (params.zoom * transM.m22());
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();
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
pMap.fill(Qt::transparent);
pMap = newPixMap.scaled(QSize(width(), height()));
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)
{
@ -380,9 +395,8 @@ void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needG
void UBMagnifier::setGrabView(QWidget *view)
{
if (timerUpdate != 0)
killTimer(timerUpdate);
gView = view;
timerUpdate = startTimer(200);
mRefreshTimer.setInterval(40);
mRefreshTimer.start();
}

@ -54,9 +54,11 @@ signals:
void magnifierZoomOut_Signal();
void magnifierResized_Signal(qreal newPercentSize);
public slots:
void slot_refresh();
protected:
void paintEvent(QPaintEvent *);
void timerEvent(QTimerEvent *);
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
@ -78,10 +80,9 @@ protected:
QCursor mResizeCursor;
private:
bool inTimer;
QTimer mRefreshTimer;
bool m_isInteractive;
int timerUpdate;
QPoint updPointGrab;
QPoint updPointMove;

Loading…
Cancel
Save