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) ...@@ -664,6 +664,7 @@ void UBBoardController::zoom(const qreal ratio, QPointF scenePoint)
UBApplication::applicationController->adjustDisplayView(); UBApplication::applicationController->adjustDisplayView();
emit controlViewportChanged(); emit controlViewportChanged();
mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());
} }
...@@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, ...@@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
mControlView->setScene(mActiveScene); mControlView->setScene(mActiveScene);
mDisplayView->setScene(mActiveScene); mDisplayView->setScene(mActiveScene);
mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());
pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize()); pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize());
updatePageSizeState(); updatePageSizeState();
...@@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor() ...@@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor()
mControlView->setTransform(scalingTransform); mControlView->setTransform(scalingTransform);
mControlView->horizontalScrollBar()->setValue(viewState.horizontalPosition); mControlView->horizontalScrollBar()->setValue(viewState.horizontalPosition);
mControlView->verticalScrollBar()->setValue(viewState.verticalPostition); mControlView->verticalScrollBar()->setValue(viewState.verticalPostition);
} mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());}
void UBBoardController::setWidePageSize(bool checked) void UBBoardController::setWidePageSize(bool checked)
......
...@@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent) ...@@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingScene = new UBGraphicsScene(0); mTransparentDrawingScene = new UBGraphicsScene(0);
mTransparentDrawingView->setScene(mTransparentDrawingScene); mTransparentDrawingView->setScene(mTransparentDrawingScene);
mTransparentDrawingScene->setDrawingMode(true);
// mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView); // mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView);
//mRightPalette = new UBRightPalette(mTransparentDrawingView); //mRightPalette = new UBRightPalette(mTransparentDrawingView);
......
...@@ -135,6 +135,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) ...@@ -135,6 +135,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
, enableUndoRedoStack(true) , enableUndoRedoStack(true)
, magniferControlViewWidget(0) , magniferControlViewWidget(0)
, magniferDisplayViewWidget(0) , magniferDisplayViewWidget(0)
, mIsDesktopMode(false)
{ {
...@@ -160,8 +161,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) ...@@ -160,8 +161,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
UBGraphicsScene::~UBGraphicsScene() UBGraphicsScene::~UBGraphicsScene()
{ {
DisposeMagnifierQWidgets();
if (mCurrentStroke) if (mCurrentStroke)
if (mCurrentStroke->polygons().empty()) if (mCurrentStroke->polygons().empty())
delete mCurrentStroke; delete mCurrentStroke;
...@@ -711,6 +710,15 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) ...@@ -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() void UBGraphicsScene::recolorAllItems()
{ {
...@@ -1854,6 +1862,58 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems, ...@@ -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) void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
{ {
......
...@@ -288,7 +288,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem ...@@ -288,7 +288,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void hideEraser(); void hideEraser();
void setBackground(bool pIsDark, bool pIsCrossed); void setBackground(bool pIsDark, bool pIsCrossed);
void setBackgroundZoomFactor(qreal zoom);
void setDrawingMode(bool bModeDesktop);
void deselectAllItems(); void deselectAllItems();
UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false); 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 ...@@ -331,6 +332,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
QGraphicsItem* rootItem(QGraphicsItem* item) const; QGraphicsItem* rootItem(QGraphicsItem* item) const;
virtual void drawBackground(QPainter *painter, const QRectF &rect);
private: private:
void setDocumentUpdated(); void setDocumentUpdated();
void createEraiser(); void createEraiser();
...@@ -348,6 +351,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem ...@@ -348,6 +351,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
bool mDarkBackground; bool mDarkBackground;
bool mCrossedBackground; bool mCrossedBackground;
bool mIsDesktopMode;
qreal mZoomFactor;
bool mIsModified; bool mIsModified;
......
This diff is collapsed.
/* /*
* 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/>.
*/ */
#ifndef UBMAGNIFIER_H #ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H #define UBMAGNIFIER_H
#include <QtGui> #include <QtGui>
class UBMagnifierParams class UBMagnifierParams
{ {
public : public :
int x; int x;
int y; int y;
qreal zoom; qreal zoom;
qreal sizePercentFromScene; qreal sizePercentFromScene;
}; };
class UBMagnifier : public QWidget class UBMagnifier : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
UBMagnifier(QWidget *parent = 0, bool isInteractive = false); UBMagnifier(QWidget *parent = 0, bool isInteractive = false);
~UBMagnifier(); ~UBMagnifier();
void setSize(qreal percentFromScene); void setSize(qreal percentFromScene);
void setZoom(qreal zoom); void setZoom(qreal zoom);
void setGrabView(QWidget *view); void setGrabView(QWidget *view);
void setMoveView(QWidget *view) {mView = view;} void setMoveView(QWidget *view) {mView = view;}
void grabPoint(); void grabPoint();
void grabPoint(const QPoint &point); void grabPoint(const QPoint &point);
void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true);
UBMagnifierParams params; UBMagnifierParams params;
signals: signals:
void magnifierMoved_Signal(QPoint newPos); void magnifierMoved_Signal(QPoint newPos);
void magnifierClose_Signal(); void magnifierClose_Signal();
void magnifierZoomIn_Signal(); void magnifierZoomIn_Signal();
void magnifierZoomOut_Signal(); void magnifierZoomOut_Signal();
void magnifierResized_Signal(qreal newPercentSize); void magnifierResized_Signal(qreal newPercentSize);
protected: public slots:
void paintEvent(QPaintEvent *); void slot_refresh();
void timerEvent(QTimerEvent *);
protected:
virtual void mousePressEvent ( QMouseEvent * event ); void paintEvent(QPaintEvent *);
virtual void mouseMoveEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event ); virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
QPoint mMousePressPos; virtual void mouseReleaseEvent ( QMouseEvent * event );
qreal mMousePressDelta;
bool mShouldMoveWidget; QPoint mMousePressPos;
bool mShouldResizeWidget; qreal mMousePressDelta;
bool mShouldMoveWidget;
bool mShouldResizeWidget;
QPixmap *sClosePixmap;
QPixmap *sIncreasePixmap;
QPixmap *sDecreasePixmap; QPixmap *sClosePixmap;
QPixmap *mResizeItem; QPixmap *sIncreasePixmap;
QPixmap *sDecreasePixmap;
bool isCusrsorAlreadyStored; QPixmap *mResizeItem;
QCursor mOldCursor;
QCursor mResizeCursor; bool isCusrsorAlreadyStored;
QCursor mOldCursor;
private: QCursor mResizeCursor;
bool inTimer;
bool m_isInteractive; private:
QTimer mRefreshTimer;
int timerUpdate; bool m_isInteractive;
QPoint updPointGrab;
QPoint updPointMove; QPoint updPointGrab;
QPoint updPointMove;
QPixmap pMap;
QBitmap bmpMask; QPixmap pMap;
QPen borderPen; QBitmap bmpMask;
QPen borderPen;
QWidget *gView;
QWidget *mView; QWidget *gView;
}; QWidget *mView;
};
#endif // UBMAGNIFIER_H
#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