Commit 1e67bf6e authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

SANKORE-475

Improve the rendering of the magnifier
parent 9745c5d0
......@@ -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;
......
This diff is collapsed.
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H
#include <QtGui>
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 <http://www.gnu.org/licenses/>.
*/
#ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H
#include <QtGui>
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment