Graphics ruler: drawing lines

preferencesAboutTextFull
Anatoly Mihalchenko 14 years ago
parent 4f09fe08a5
commit 3d8deb8c13
  1. BIN
      resources/images/cursors/drawRulerLine.png
  2. 1
      resources/sankore.qrc
  3. 3
      src/api/UBWidgetUniboardAPI.cpp
  4. 8
      src/board/UBBoardView.cpp
  5. 1
      src/board/UBDrawingController.cpp
  6. 4
      src/board/UBDrawingController.h
  7. 12
      src/core/UB.h
  8. 6
      src/core/UBDisplayManager.cpp
  9. 3
      src/desktop/UBDesktopAnnotationController.cpp
  10. 1
      src/domain/UBGraphicsDelegateFrame.cpp
  11. 30
      src/domain/UBGraphicsScene.cpp
  12. 8
      src/domain/UBGraphicsScene.h
  13. 5
      src/gui/UBDockPalette.cpp
  14. 3
      src/gui/UBFloatingPalette.cpp
  15. 1
      src/gui/UBResources.cpp
  16. 1
      src/gui/UBResources.h
  17. 9
      src/tools/UBAbstractDrawRuler.cpp
  18. 21
      src/tools/UBAbstractDrawRuler.h
  19. 8
      src/tools/UBGraphicsCompass.cpp
  20. 1
      src/tools/UBGraphicsProtractor.cpp
  21. 85
      src/tools/UBGraphicsRuler.cpp
  22. 12
      src/tools/UBGraphicsRuler.h
  23. 4
      src/tools/tools.pri

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

@ -173,6 +173,7 @@
<file>images/cursors/rotate.png</file>
<file>images/cursors/resize.png</file>
<file>images/cursors/drawCompass.png</file>
<file>images/cursors/drawRulerLine.png</file>
<file>images/print/onepage.png</file>
<file>images/print/thumbnails.png</file>
<file>images/print/twopages.png</file>

@ -179,7 +179,8 @@ void UBWidgetUniboardAPI::drawLineTo(const qreal x, const qreal y, const qreal p
return;
if (mScene)
mScene->drawLineTo(QPointF(x, y), pWidth);
mScene->drawLineTo(QPointF(x, y), pWidth,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}

@ -451,8 +451,11 @@ UBBoardView::mousePressEvent (QMouseEvent *event)
event->accept ();
}
else
{
if(UBDrawingController::drawingController()->mActiveRuler==NULL)
{
viewport()->setCursor (QCursor (Qt::BlankCursor));
}
if (scene () && !mTabletStylusIsPressed)
{
@ -487,6 +490,11 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
{
QGraphicsView::mouseMoveEvent (event);
}
else if ((UBDrawingController::drawingController()->isDrawingTool())
&& !mMouseButtonIsPressed)
{
QGraphicsView::mouseMoveEvent (event);
}
else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture)
{
if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone))

@ -27,6 +27,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
: QObject(parent)
, mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1)
, mActiveRuler(NULL)
{
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));

@ -12,6 +12,8 @@
#include "core/UB.h"
class UBAbstractDrawRuler;
class UBDrawingController : public QObject
{
Q_OBJECT;
@ -39,6 +41,8 @@ class UBDrawingController : public QObject
void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex);
void setMarkerAlpha(qreal alpha);
UBAbstractDrawRuler* mActiveRuler;
public slots:
void setStylusTool(int tool);

@ -16,7 +16,17 @@ struct UBStylusTool
{
enum Enum
{
Pen = 0, Eraser, Marker, Selector, Hand, ZoomIn, ZoomOut, Pointer, Line, Text, Capture
Pen = 0,
Eraser,
Marker,
Selector,
Hand,
ZoomIn,
ZoomOut,
Pointer,
Line,
Text,
Capture
};
};

@ -114,7 +114,10 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget )
mControlWidget->hide();
mControlWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex));
mControlWidget->showFullScreen();
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mControlWidget->setAttribute(Qt::WA_MacNoShadow);
#endif
}
}
@ -127,7 +130,10 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget)
mDisplayWidget->hide();
mDisplayWidget->setGeometry(mDesktop->screenGeometry(mDisplayScreenIndex));
mDisplayWidget->showFullScreen();
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mDisplayWidget->setAttribute(Qt::WA_MacNoShadow);
#endif
}
}

@ -60,7 +60,10 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingView = new UBBoardView(UBApplication::boardController, 0); // deleted in UBDesktopAnnotationController::destructor
mTransparentDrawingView->setAttribute(Qt::WA_TranslucentBackground, true);
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true);
#endif
mTransparentDrawingView->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Window);
mTransparentDrawingView->setCacheMode(QGraphicsView::CacheNone);
mTransparentDrawingView->resize(UBApplication::desktop()->width(), UBApplication::desktop()->height());

@ -19,7 +19,6 @@
#include "gui/UBResources.h"
const double PI = 4.0 * atan(1.0);
qreal const UBGraphicsDelegateFrame::mAngleTolerance = 6;
UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio)

@ -59,8 +59,6 @@ qreal UBGraphicsScene::toolOffsetEraser = 200;
qreal UBGraphicsScene::toolOffsetCurtain = 1000;
qreal UBGraphicsScene::toolOffsetPointer = 1100;
const double PI = 4.0 * atan(1.0);
UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
: UBCoreGraphicsScene(parent)
, mEraser(0)
@ -163,8 +161,18 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
mAddedItems.clear();
mRemovedItems.clear();
if (UBDrawingController::drawingController()->mActiveRuler)
{
UBDrawingController::drawingController()->mActiveRuler->StartLine(
scenePos, width);
}
else
{
moveTo(scenePos);
drawLineTo(scenePos, width);
drawLineTo(scenePos, width,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}
accepted = true;
}
else if (currentTool == UBStylusTool::Eraser)
@ -220,6 +228,12 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
width /= UBApplication::boardController->systemScaleFactor();
width /= UBApplication::boardController->currentZoom();
if (dc->mActiveRuler)
{
dc->mActiveRuler->DrawLine(position, width);
}
else
{
if (currentTool == UBStylusTool::Line)
{
QLineF radius(mPreviousPoint, position);
@ -234,7 +248,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
position = newPosition;
}
drawLineTo(position, width);
drawLineTo(position, width,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}
}
else if (currentTool == UBStylusTool::Eraser)
{
@ -348,7 +364,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint)
}
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle)
{
if (mPreviousWidth == -1.0)
mPreviousWidth = pWidth;
@ -364,7 +380,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
}
}
if (UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line)
if (bLineStyle)
{
QSetIterator<QGraphicsItem*> itItems(mAddedItems);
@ -388,7 +404,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth)
mPreviousPolygonItems.append(polygonItem);
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Line)
if (!bLineStyle)
{
mPreviousPoint = pEndPoint;
mPreviousWidth = pWidth;

@ -37,6 +37,7 @@ class UBDocumentProxy;
class UBGraphicsCurtainItem;
class UBGraphicsStroke;
const double PI = 4.0 * atan(1.0);
class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
{
@ -99,7 +100,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
QRectF normalizedSceneRect(qreal ratio = -1.0);
void moveTo(const QPointF& pPoint);
void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth);
void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth, bool bLineStyle);
void eraseLineTo(const QPointF& pEndPoint, const qreal& pWidth);
void drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle);
@ -240,6 +241,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
mTools << item;
}
const QPointF& previousPoint()
{
return mPreviousPoint;
}
public slots:
void hideEraser();

@ -33,7 +33,12 @@ UBDockPalette::UBDockPalette(QWidget *parent, const char *name)
{
// standalone window
setAttribute(Qt::WA_TranslucentBackground);
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
setAttribute(Qt::WA_MacNoShadow);
#endif
}
mBackgroundBrush = QBrush(UBSettings::paletteColor);

@ -26,10 +26,13 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
else
{
// standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setAttribute(Qt::WA_MacNonActivatingToolWindow);
setAttribute(Qt::WA_MacNoShadow);
#endif
}
mBackgroundBrush = QBrush(UBSettings::paletteColor);

@ -43,4 +43,5 @@ void UBResources::init()
arrowCursor = QCursor(Qt::ArrowCursor);
textCursor = QCursor(Qt::ArrowCursor);
rotateCursor = QCursor(QPixmap(":/images/cursors/rotate.png"), 16, 16);
drawLineRulerCursor = QCursor(QPixmap(":/images/cursors/drawRulerLine.png"), 3, 12);
}

@ -31,6 +31,7 @@ class UBResources : public QObject
QCursor arrowCursor;
QCursor textCursor;
QCursor rotateCursor;
QCursor drawLineRulerCursor;
};
#endif /* UBRESOURCES_H_ */

@ -0,0 +1,9 @@
#include "UBAbstractDrawRuler.h"
UBAbstractDrawRuler::UBAbstractDrawRuler()
{}
UBAbstractDrawRuler::~UBAbstractDrawRuler()
{}

@ -0,0 +1,21 @@
#ifndef UB_ABSTRACTDRAWRULER_H_
#define UB_ABSTRACTDRAWRULER_H_
#include <QtGui>
class UBGraphicsScene;
class UBAbstractDrawRuler : public QObject
{
Q_OBJECT;
public:
UBAbstractDrawRuler();
~UBAbstractDrawRuler();
virtual void StartLine(const QPointF& position, qreal width) = 0;
virtual void DrawLine(const QPointF& position, qreal width) = 0;
virtual void EndLine() = 0;
};
#endif

@ -16,8 +16,6 @@
#include "board/UBBoardController.h" // TODO UB 4.x clean that dependency
#include "board/UBDrawingController.h" // TODO UB 4.x clean that dependency
const double PI = 4.0 * atan(1.0);
const QRect UBGraphicsCompass::sDefaultRect = QRect(0, -20, 300, 48);
const QColor UBGraphicsCompass::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency);
const QColor UBGraphicsCompass::sLightBackgroundEdgeFillColor = QColor(0xc3, 0xc3, 0xc3, sFillTransparency);
@ -511,9 +509,11 @@ void UBGraphicsCompass::paintCenterCross()
{
QPointF needleCrossCenter = mapToScene(needlePosition());
scene()->moveTo(QPointF(needleCrossCenter.x() - 5, needleCrossCenter.y()));
scene()->drawLineTo(QPointF(needleCrossCenter.x() + 5, needleCrossCenter.y()), 1);
scene()->drawLineTo(QPointF(needleCrossCenter.x() + 5, needleCrossCenter.y()), 1,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
scene()->moveTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() - 5));
scene()->drawLineTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() + 5), 1);
scene()->drawLineTo(QPointF(needleCrossCenter.x(), needleCrossCenter.y() + 5), 1,
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}
QPointF UBGraphicsCompass::needlePosition() const

@ -13,7 +13,6 @@
#include "board/UBBoardController.h"
const double PI = 4.0 * atan(1.0);
const int UBGraphicsProtractor::sFillTransparency = 127;
const int UBGraphicsProtractor::sDrawTransparency = 192;
const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350);

@ -13,6 +13,7 @@
#include "core/UBApplication.h"
#include "gui/UBResources.h"
#include "board/UBBoardController.h" // TODO UB 4.x clean that dependency
#include "board/UBDrawingController.h"
const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96);
const QColor UBGraphicsRuler::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency);
@ -199,6 +200,10 @@ void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
}
void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
mCloseSvgItem->setParentItem(this);
mResizeSvgItem->setParentItem(this);
@ -224,6 +229,13 @@ void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
event->accept();
update();
}
else if (UBDrawingController::drawingController()->isDrawingTool())
{
setCursor(drawRulerLineCursor());
UBDrawingController::drawingController()->mActiveRuler = this;
event->accept();
}
}
void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
@ -232,11 +244,16 @@ void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
mCloseSvgItem->setVisible(mShowButtons);
mResizeSvgItem->setVisible(mShowButtons);
mRotateSvgItem->setVisible(mShowButtons);
UBDrawingController::drawingController()->mActiveRuler = NULL;
event->accept();
update();
}
void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
mCloseSvgItem->setVisible(mShowButtons);
mResizeSvgItem->setVisible(mShowButtons);
@ -256,6 +273,11 @@ void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
}
event->accept();
}
else if (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker)
{
event->accept();
}
}
void UBGraphicsRuler::fillBackground(QPainter *painter)
{
@ -456,3 +478,66 @@ void UBGraphicsRuler::updateResizeCursor()
QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
mResizeCursor = resizeCursor;
}
QCursor UBGraphicsRuler::drawRulerLineCursor() const
{
return UBResources::resources()->drawLineRulerCursor;
}
void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width)
{
QPointF itemPos = mapFromScene(scenePos);
qreal y;
if (itemPos.y() > rect().y() + rect().height() / 2)
{
drawLineDirection = 0;
y = rect().y() + rect().height() + width / 2;
}
else
{
drawLineDirection = 1;
y = rect().y() - width /2;
}
if (itemPos.x() < rect().x() + sLeftEdgeMargin)
itemPos.setX(rect().x() + sLeftEdgeMargin);
if (itemPos.x() > rect().x() + rect().width() - sLeftEdgeMargin)
itemPos.setX(rect().x() + rect().width() - sLeftEdgeMargin);
itemPos.setY(y);
itemPos = mapToScene(itemPos);
scene()->moveTo(itemPos);
scene()->drawLineTo(itemPos, width, true);
}
void UBGraphicsRuler::DrawLine(const QPointF& scenePos, qreal width)
{
QPointF itemPos = mapFromScene(scenePos);
qreal y;
if (drawLineDirection == 0)
{
y = rect().y() + rect().height() + width / 2;
}
else
{
y = rect().y() - width /2;
}
if (itemPos.x() < rect().x() + sLeftEdgeMargin)
itemPos.setX(rect().x() + sLeftEdgeMargin);
if (itemPos.x() > rect().x() + rect().width() - sLeftEdgeMargin)
itemPos.setX(rect().x() + rect().width() - sLeftEdgeMargin);
itemPos.setY(y);
itemPos = mapToScene(itemPos);
// We have to use "pointed" line for marker tool
scene()->drawLineTo(itemPos, width,
UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker);
}
void UBGraphicsRuler::EndLine()
{}

@ -14,10 +14,11 @@
#include "core/UB.h"
#include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class UBGraphicsScene;
class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, public UBItem
{
Q_OBJECT;
@ -34,6 +35,10 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
virtual UBItem* deepCopy() const;
virtual void StartLine(const QPointF& position, qreal width);
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
signals:
void hidden();
@ -63,6 +68,7 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QCursor resizeCursor() const;
QCursor rotateCursor() const;
QCursor closeCursor() const;
QCursor drawRulerLineCursor() const;
QRectF resizeButtonRect() const;
QRectF closeButtonRect() const;
QRectF rotateButtonRect() const;
@ -72,6 +78,8 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QColor edgeFillColor() const;
QFont font() const;
int drawLineDirection;
// Members
bool mResizing;
bool mRotating;
@ -82,6 +90,8 @@ class UBGraphicsRuler : public QObject, public QGraphicsRectItem, public UBItem
QCursor mResizeCursor;
qreal mAntiScaleRatio;
QPointF startDrawPosition;
// Constants
static const QRect sDefaultRect;
static const int sLeftEdgeMargin = 10;

@ -4,7 +4,8 @@ HEADERS += src/tools/UBGraphicsRuler.h \
src/tools/UBGraphicsCompass.h \
src/tools/UBToolsManager.h \
src/tools/UBGraphicsCurtainItem.h \
src/tools/UBGraphicsCurtainItemDelegate.h
src/tools/UBGraphicsCurtainItemDelegate.h \
src/tools/UBAbstractDrawRuler.h
SOURCES += src/tools/UBGraphicsRuler.cpp \
src/tools/UBGraphicsProtractor.cpp \
@ -12,3 +13,4 @@ SOURCES += src/tools/UBGraphicsRuler.cpp \
src/tools/UBToolsManager.cpp \
src/tools/UBGraphicsCurtainItem.cpp \
src/tools/UBGraphicsCurtainItemDelegate.cpp \
src/tools/UBAbstractDrawRuler.cpp
Loading…
Cancel
Save