Circle and rectangular magnifier

preferencesAboutTextFull
Ilia Ryabokon 11 years ago
parent 116f6f7d3d
commit c53320d6e8
  1. 2
      resources/OpenBoard.qrc
  2. 11
      resources/images/circle.svg
  3. 10
      resources/images/roundeRrectangle.svg
  4. 1
      src/core/UBSettings.cpp
  5. 1
      src/core/UBSettings.h
  6. 9
      src/domain/UBGraphicsScene.cpp
  7. 1
      src/domain/UBGraphicsScene.h
  8. 183
      src/gui/UBMagnifer.cpp
  9. 23
      src/gui/UBMagnifer.h

@ -344,5 +344,7 @@
<file>images/download_open.png</file> <file>images/download_open.png</file>
<file>images/tab_mask.png</file> <file>images/tab_mask.png</file>
<file>images/duplicateDisabled.svg</file> <file>images/duplicateDisabled.svg</file>
<file>images/roundeRrectangle.svg</file>
<file>images/circle.svg</file>
</qresource> </qresource>
</RCC> </RCC>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 13.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="26px" height="26px" viewBox="0 0 26 26" style="enable-background:new 0 0 26 26;" xml:space="preserve">
<circle style="fill:#CCCCCC;" cx="13" cy="13" r="13"/>
<circle style="fill:#999999;" cx="13" cy="13" r="11"/>
<circle style="fill:#FFFFFF;" cx="13" cy="13" r="7"/>
</svg>

After

Width:  |  Height:  |  Size: 653 B

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 13.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="26px" height="26px" viewBox="0 0 26 26" style="enable-background:new 0 0 26 26;" xml:space="preserve">
<circle style="fill:#CCCCCC;" cx="13" cy="13" r="13"/>
<circle style="fill:#999999;" cx="13" cy="13" r="11"/>
<rect rx="2" ry="2" x="4" y="9" style="fill:#FFFFFF;" width="18" height="8"/>
</svg>

After

Width:  |  Height:  |  Size: 676 B

@ -351,6 +351,7 @@ void UBSettings::init()
appOnlineUserName = new UBSetting(this, "App", "OnlineUserName", ""); appOnlineUserName = new UBSetting(this, "App", "OnlineUserName", "");
boardShowToolsPalette = new UBSetting(this, "Board", "ShowToolsPalette", "false"); boardShowToolsPalette = new UBSetting(this, "Board", "ShowToolsPalette", "false");
magnifierDrawingMode = new UBSetting(this, "Board", "MagnifierDrawingMode", "0");
svgViewBoxMargin = new UBSetting(this, "SVG", "ViewBoxMargin", "50"); svgViewBoxMargin = new UBSetting(this, "SVG", "ViewBoxMargin", "50");

@ -372,6 +372,7 @@ class UBSettings : public QObject
UBSetting* libIconSize; UBSetting* libIconSize;
UBSetting* magnifierDrawingMode;
public slots: public slots:
void setPenWidthIndex(int index); void setPenWidthIndex(int index);

@ -1947,6 +1947,7 @@ void UBGraphicsScene::addMagnifier(UBMagnifierParams params)
connect(magniferControlViewWidget, SIGNAL(magnifierClose_Signal()), this, SLOT(closeMagnifier())); connect(magniferControlViewWidget, SIGNAL(magnifierClose_Signal()), this, SLOT(closeMagnifier()));
connect(magniferControlViewWidget, SIGNAL(magnifierZoomIn_Signal()), this, SLOT(zoomInMagnifier())); connect(magniferControlViewWidget, SIGNAL(magnifierZoomIn_Signal()), this, SLOT(zoomInMagnifier()));
connect(magniferControlViewWidget, SIGNAL(magnifierZoomOut_Signal()), this, SLOT(zoomOutMagnifier())); connect(magniferControlViewWidget, SIGNAL(magnifierZoomOut_Signal()), this, SLOT(zoomOutMagnifier()));
connect(magniferControlViewWidget, SIGNAL(magnifierDrawingModeChange_Signal(int)), this, SLOT(changeMagnifierMode(int)));
connect(magniferControlViewWidget, SIGNAL(magnifierResized_Signal(qreal)), this, SLOT(resizedMagnifier(qreal))); connect(magniferControlViewWidget, SIGNAL(magnifierResized_Signal(qreal)), this, SLOT(resizedMagnifier(qreal)));
setModified(true); setModified(true);
@ -2013,6 +2014,14 @@ void UBGraphicsScene::zoomOutMagnifier()
} }
} }
void UBGraphicsScene::changeMagnifierMode(int mode)
{
if(magniferControlViewWidget)
magniferControlViewWidget->setDrawingMode(mode);
if(magniferDisplayViewWidget)
magniferDisplayViewWidget->setDrawingMode(mode);
}
void UBGraphicsScene::resizedMagnifier(qreal newPercent) void UBGraphicsScene::resizedMagnifier(qreal newPercent)
{ {
if(newPercent > 18 && newPercent < 50) if(newPercent > 18 && newPercent < 50)

@ -346,6 +346,7 @@ public slots:
void closeMagnifier(); void closeMagnifier();
void zoomInMagnifier(); void zoomInMagnifier();
void zoomOutMagnifier(); void zoomOutMagnifier();
void changeMagnifierMode(int mode);
void resizedMagnifier(qreal newPercent); void resizedMagnifier(qreal newPercent);
protected: protected:

@ -24,7 +24,6 @@
#include <QtGui> #include <QtGui>
#include "UBMagnifer.h" #include "UBMagnifer.h"
@ -62,6 +61,15 @@ UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
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");
sChangeModePixmap = new QPixmap();
qDebug() << "sClosePixmap" << sClosePixmap->size() << endl
<< "sIncreasePixmap" << sIncreasePixmap->size() << endl
<< "sDecreasePixmap" << sDecreasePixmap->size() << endl
<< "mResizeItem" << mResizeItem->size() << endl;
setDrawingMode(UBSettings::settings()->magnifierDrawingMode->get().toInt());
if (parent) if (parent)
{ {
@ -104,6 +112,12 @@ UBMagnifier::~UBMagnifier()
delete sDecreasePixmap; delete sDecreasePixmap;
sDecreasePixmap = NULL; sDecreasePixmap = NULL;
} }
if (sChangeModePixmap)
{
delete sChangeModePixmap;
sChangeModePixmap = NULL;
}
} }
void UBMagnifier::setSize(qreal percentFromScene) void UBMagnifier::setSize(qreal percentFromScene)
@ -116,23 +130,47 @@ void UBMagnifier::setSize(qreal percentFromScene)
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 (circular == mDrawingMode)
{
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);
}
else if (rectangular == mDrawingMode)
{ {
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 / 3, size, size/3);
} }
else
setGeometry(0, 0, size, size);
// prepare transparent bit mask calculateButtonsPositions();
createMask();
}
void UBMagnifier::createMask()
{
if(gView == NULL || mView == NULL) return;
// calculate object size
QSize sceneSize = mView->size();
qreal isize = params.sizePercentFromScene * sceneSize.width() / 100;
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());
if (circular == mDrawingMode)
mask_ptr.drawEllipse(QPointF(isize/2, isize/2), isize / 2 - sClosePixmap->width(), isize / 2 - sClosePixmap->width());
else if (rectangular == mDrawingMode)
mask_ptr.drawRoundedRect(QRect(sClosePixmap->width(), sClosePixmap->width(), size().width() - 2*sClosePixmap->width(), size().height() - 2*sClosePixmap->width()), sClosePixmap->width()/2, sClosePixmap->width()/2);
bmpMask = QBitmap::fromImage(mask_img); bmpMask = QBitmap::fromImage(mask_img);
// 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);
@ -143,6 +181,25 @@ void UBMagnifier::setZoom(qreal zoom)
params.zoom = zoom; params.zoom = zoom;
} }
void UBMagnifier::calculateButtonsPositions()
{
qDebug() << "current widget size is " << size();
m_iButtonInterval = 5;
mResizeItemButtonRect = QRect(size().width() - 1.5*mResizeItem->width() - m_iButtonInterval, size().height() - 1.5*mResizeItem->height() - m_iButtonInterval, mResizeItem->width(), mResizeItem->height());
sClosePixmapButtonRect = QRect(mResizeItemButtonRect.x() - sChangeModePixmap->width() - 3*m_iButtonInterval, size().height() - sChangeModePixmap->height(), sChangeModePixmap->width(), sChangeModePixmap->height());
sChangeModePixmapButtonRect = QRect(sClosePixmapButtonRect.x() - sChangeModePixmap->width() - m_iButtonInterval, size().height() - sChangeModePixmap->height(), sChangeModePixmap->width(), sChangeModePixmap->height());
sDecreasePixmapButtonRect = QRect(sChangeModePixmapButtonRect.x() - sChangeModePixmap->width() - m_iButtonInterval, size().height() - sDecreasePixmap->height(), sDecreasePixmap->width(), sDecreasePixmap->height());
sIncreasePixmapButtonRect = QRect(sDecreasePixmapButtonRect.x() - sChangeModePixmap->width() - m_iButtonInterval, size().height() - sIncreasePixmap->height(), sIncreasePixmap->width(), sIncreasePixmap->height());
qDebug() << "mResizeItemButtonRect" << mResizeItemButtonRect << endl
<< "sClosePixmapButtonRect" << sClosePixmapButtonRect << endl
<< "sChangeModePixmapButtonRect" << sChangeModePixmapButtonRect << endl
<< "sDecreasePixmapButtonRect" << sDecreasePixmapButtonRect << endl
<< "sIncreasePixmapButtonRect" << sIncreasePixmapButtonRect << endl;
}
void UBMagnifier::paintEvent(QPaintEvent * event) void UBMagnifier::paintEvent(QPaintEvent * event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
@ -155,23 +212,30 @@ void UBMagnifier::paintEvent(QPaintEvent * event)
{ {
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); if (circular == mDrawingMode)
{
painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); painter.drawEllipse(QPoint(size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2);
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 else if (rectangular == mDrawingMode)
{ {
painter.setBrush(QColor(127, 127, 127, 127)); QRect r = QRect(sClosePixmap->width()/2, sClosePixmap->width()/2, size().width()- sClosePixmap->width(), size().height() - sClosePixmap->width());
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); painter.drawRoundedRect(r, sClosePixmap->width()/2, sClosePixmap->width()/2);
} }
painter.drawPixmap(0, 0, pMap); painter.drawPixmap(0, 0, pMap);
if (m_isInteractive)
{
painter.setBrush(QColor(190, 190, 190, 255));
painter.drawPixmap(sClosePixmapButtonRect.topLeft(), *sClosePixmap);
painter.drawPixmap(sIncreasePixmapButtonRect.topLeft(), *sIncreasePixmap);
painter.drawPixmap(sDecreasePixmapButtonRect.topLeft(), *sDecreasePixmap);
painter.drawPixmap(sChangeModePixmapButtonRect.topLeft(), *sChangeModePixmap);
painter.drawPixmap(mResizeItemButtonRect.topLeft(), *mResizeItem);
}
} }
void UBMagnifier::mousePressEvent ( QMouseEvent * event ) void UBMagnifier::mousePressEvent ( QMouseEvent * event )
@ -181,10 +245,10 @@ void UBMagnifier::mousePressEvent ( QMouseEvent * event )
QWidget::mousePressEvent(event); QWidget::mousePressEvent(event);
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && if (event->pos().x() >= size().width() - mResizeItem->width() - 14 &&
event->pos().x() < size().width() - 20 && event->pos().x() < size().width() - 14 &&
event->pos().y() >= size().height() - mResizeItem->height() - 20 && event->pos().y() >= size().height() - mResizeItem->height() - 14 &&
event->pos().y() < size().height() - - 20) event->pos().y() < size().height() - - 14)
{ {
mShouldResizeWidget = true; mShouldResizeWidget = true;
} }
@ -233,10 +297,7 @@ void UBMagnifier::mouseMoveEvent ( QMouseEvent * event )
return; return;
} }
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && if (mResizeItemButtonRect.contains(event->pos())&&
event->pos().x() < size().width() - 20 &&
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
event->pos().y() < size().height() - - 20 &&
isCusrsorAlreadyStored == false isCusrsorAlreadyStored == false
) )
{ {
@ -258,32 +319,29 @@ void UBMagnifier::mouseReleaseEvent(QMouseEvent * event)
mShouldMoveWidget = false; mShouldMoveWidget = false;
mShouldResizeWidget = false; mShouldResizeWidget = false;
if (event->pos().x() >= size().width() - sClosePixmap->width() && if (sClosePixmapButtonRect.contains(event->pos()))
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(); event->accept();
emit magnifierClose_Signal(); emit magnifierClose_Signal();
} }
else else
if (event->pos().x() >= size().width() - sIncreasePixmap->width() && if (sIncreasePixmapButtonRect.contains(event->pos()))
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(); event->accept();
emit magnifierZoomIn_Signal(); emit magnifierZoomIn_Signal();
} }
else else
if (event->pos().x() >= size().width() - sDecreasePixmap->width() && if (sDecreasePixmapButtonRect.contains(event->pos()))
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(); event->accept();
emit magnifierZoomOut_Signal(); emit magnifierZoomOut_Signal();
} }
else
if (sChangeModePixmapButtonRect.contains(event->pos()))
{
event->accept();
emit magnifierDrawingModeChange_Signal(static_cast<int>(mDrawingMode+1)%modesCount);
}
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
} }
@ -301,10 +359,10 @@ void UBMagnifier::slot_refresh()
{ {
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() - 14 ||
cursorPos.x() > size().width() - 20 || cursorPos.x() > size().width() - 14 ||
cursorPos.y() < size().height() - mResizeItem->height() - 20 || cursorPos.y() < size().height() - mResizeItem->height() - 14 ||
cursorPos.y() > size().height() - - 20 cursorPos.y() > size().height() - - 14
) )
{ {
isCusrsorAlreadyStored = false; isCusrsorAlreadyStored = false;
@ -385,11 +443,12 @@ void UBMagnifier::grabPoint(const QPoint &pGrab)
// 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; QPoint pointToGrab = pGrab;
updPointGrab = pointToGrab;
updPointMove = pMove; updPointMove = pMove;
if(needGrab) if(needGrab)
grabPoint(pGrab); grabPoint(pointToGrab);
if(needMove) if(needMove)
{ {
@ -406,3 +465,37 @@ void UBMagnifier::setGrabView(QWidget *view)
mRefreshTimer.start(); mRefreshTimer.start();
} }
void UBMagnifier::setDrawingMode(int mode)
{
mDrawingMode = static_cast<DrawingMode>(mode);
QString sMode;
if (circular == mDrawingMode)
{
sMode = "roundeRrectangle";
resize(width(), width());
}
if (rectangular == mDrawingMode)
{
sMode = "circle";
resize(width(), height()/3);
if (mView)
{
qreal newPercentSize = size().width()/3 * 100 / mView->width();
emit magnifierResized_Signal(newPercentSize);
}
}
sChangeModePixmap->load(":/images/"+sMode+".svg");
calculateButtonsPositions();
if (mView && gView)
UBApplication::boardController->controlView()->scene()->moveMagnifier();
createMask();
UBSettings::settings()->magnifierDrawingMode->set(mode);
}

@ -43,15 +43,25 @@ class UBMagnifier : public QWidget
{ {
Q_OBJECT Q_OBJECT
public:
enum DrawingMode
{
circular = 0,
rectangular,
modesCount // should me last.
};
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 createMask();
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 setDrawingMode(int mode);
void grabPoint(); void grabPoint();
void grabPoint(const QPoint &point); void grabPoint(const QPoint &point);
@ -65,10 +75,13 @@ signals:
void magnifierZoomIn_Signal(); void magnifierZoomIn_Signal();
void magnifierZoomOut_Signal(); void magnifierZoomOut_Signal();
void magnifierResized_Signal(qreal newPercentSize); void magnifierResized_Signal(qreal newPercentSize);
void magnifierDrawingModeChange_Signal(int mode);
public slots: public slots:
void slot_refresh(); void slot_refresh();
private:
void calculateButtonsPositions();
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
@ -81,17 +94,25 @@ protected:
bool mShouldMoveWidget; bool mShouldMoveWidget;
bool mShouldResizeWidget; bool mShouldResizeWidget;
int m_iButtonInterval;
QPixmap *sClosePixmap; QPixmap *sClosePixmap;
QRect sClosePixmapButtonRect;
QPixmap *sIncreasePixmap; QPixmap *sIncreasePixmap;
QRect sIncreasePixmapButtonRect;
QPixmap *sDecreasePixmap; QPixmap *sDecreasePixmap;
QRect sDecreasePixmapButtonRect;
QPixmap *sChangeModePixmap;
QRect sChangeModePixmapButtonRect;
QPixmap *mResizeItem; QPixmap *mResizeItem;
QRect mResizeItemButtonRect;
bool isCusrsorAlreadyStored; bool isCusrsorAlreadyStored;
QCursor mOldCursor; QCursor mOldCursor;
QCursor mResizeCursor; QCursor mResizeCursor;
private: private:
DrawingMode mDrawingMode;
QTimer mRefreshTimer; QTimer mRefreshTimer;
bool m_isInteractive; bool m_isInteractive;

Loading…
Cancel
Save