UBGraphicsRuler.cpp 16.9 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
2
 * Copyright (C) 2015-2018 Département de l'Instruction Publique (DIP-SEM)
Craig Watson's avatar
Craig Watson committed
3
 *
Claudio Valerio's avatar
Claudio Valerio committed
4
 * Copyright (C) 2013 Open Education Foundation
Claudio Valerio's avatar
Claudio Valerio committed
5
 *
Claudio Valerio's avatar
Claudio Valerio committed
6 7
 * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
 * l'Education Numérique en Afrique (GIP ENA)
8
 *
Claudio Valerio's avatar
Claudio Valerio committed
9 10 11
 * This file is part of OpenBoard.
 *
 * OpenBoard is free software: you can redistribute it and/or modify
Claudio Valerio's avatar
Claudio Valerio committed
12 13
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
14 15 16 17
 * with a specific linking exception for the OpenSSL project's
 * "OpenSSL" library (or with modified versions of it that use the
 * same license as the "OpenSSL" library).
 *
Claudio Valerio's avatar
Claudio Valerio committed
18
 * OpenBoard is distributed in the hope that it will be useful,
Claudio Valerio's avatar
Claudio Valerio committed
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Claudio Valerio's avatar
Claudio Valerio committed
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Claudio Valerio's avatar
Claudio Valerio committed
21
 * GNU General Public License for more details.
Claudio Valerio's avatar
Claudio Valerio committed
22
 *
Claudio Valerio's avatar
Claudio Valerio committed
23
 * You should have received a copy of the GNU General Public License
Claudio Valerio's avatar
Claudio Valerio committed
24
 * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
25 26
 */

27

Claudio Valerio's avatar
Claudio Valerio committed
28

Claudio Valerio's avatar
Claudio Valerio committed
29

Claudio Valerio's avatar
Claudio Valerio committed
30 31 32 33 34 35 36
#include <QPixmap>

#include "tools/UBGraphicsRuler.h"
#include "domain/UBGraphicsScene.h"
#include "core/UBApplication.h"
#include "gui/UBResources.h"
#include "board/UBBoardController.h" // TODO UB 4.x clean that dependency
37
#include "board/UBDrawingController.h"
Claudio Valerio's avatar
Claudio Valerio committed
38

39 40
#include "core/memcheck.h"

unknown's avatar
unknown committed
41
const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96);
Claudio Valerio's avatar
Claudio Valerio committed
42 43 44 45


UBGraphicsRuler::UBGraphicsRuler()
    : QGraphicsRectItem()
46
    , mResizing(false)
unknown's avatar
unknown committed
47
    , mRotating(false)
Claudio Valerio's avatar
Claudio Valerio committed
48 49 50
{
    setRect(sDefaultRect);

51
    mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeRuler.svg", this);
Claudio Valerio's avatar
Claudio Valerio committed
52 53 54
    mResizeSvgItem->setVisible(false);
    mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));

unknown's avatar
unknown committed
55 56 57
    mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
    mRotateSvgItem->setVisible(false);
    mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
58

59
    create(*this);
unknown's avatar
unknown committed
60

shibakaneki's avatar
shibakaneki committed
61 62
    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly

Ivan Ilyin's avatar
Ivan Ilyin committed
63 64
    setFlag(QGraphicsItem::ItemIsSelectable, false);
    updateResizeCursor();
unknown's avatar
unknown committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
}

void UBGraphicsRuler::updateResizeCursor()
{
    QPixmap pix(":/images/cursors/resize.png");
    QTransform itemTransform = sceneTransform();
    QRectF itemRect = boundingRect();
    QPointF topLeft = itemTransform.map(itemRect.topLeft());
    QPointF topRight = itemTransform.map(itemRect.topRight());
    QLineF topLine(topLeft, topRight);
    qreal angle = topLine.angle();
    QTransform tr;
    tr.rotate(- angle);
    QCursor resizeCursor  = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2,  pix.height() / 2);
    mResizeCursor = resizeCursor;
Claudio Valerio's avatar
Claudio Valerio committed
80 81
}

unknown's avatar
unknown committed
82

Claudio Valerio's avatar
Claudio Valerio committed
83 84 85 86 87 88 89 90 91
UBGraphicsRuler::~UBGraphicsRuler()
{
    // NOOP
}

UBItem* UBGraphicsRuler::deepCopy() const
{
    UBGraphicsRuler* copy = new UBGraphicsRuler();

92
    copyItemParameters(copy);
Claudio Valerio's avatar
Claudio Valerio committed
93 94 95 96 97 98

    // TODO UB 4.7 ... complete all members ?

    return copy;
}

99 100 101 102 103 104 105 106 107 108 109
void UBGraphicsRuler::copyItemParameters(UBItem *copy) const
{
    UBGraphicsRuler *cp = dynamic_cast<UBGraphicsRuler*>(copy);
    if (cp)
    {
        cp->setPos(this->pos());
        cp->setRect(this->rect());
        cp->setTransform(this->transform());
    }
}

Claudio Valerio's avatar
Claudio Valerio committed
110 111 112 113 114
void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget)
{
    Q_UNUSED(styleOption);
    Q_UNUSED(widget);

115
    UBAbstractDrawRuler::paint();
Claudio Valerio's avatar
Claudio Valerio committed
116

117
    QTransform antiScaleTransform2;
Claudio Valerio's avatar
Claudio Valerio committed
118 119
    qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0;
    antiScaleTransform2.scale(ratio, 1.0);
unknown's avatar
unknown committed
120

Claudio Valerio's avatar
Claudio Valerio committed
121 122 123
    mResizeSvgItem->setTransform(antiScaleTransform2);
    mResizeSvgItem->setPos(resizeButtonRect().topLeft());

unknown's avatar
unknown committed
124 125 126 127
    mRotateSvgItem->setTransform(antiScaleTransform2);
    mRotateSvgItem->setPos(rotateButtonRect().topLeft());


128

Claudio Valerio's avatar
Claudio Valerio committed
129
    painter->setPen(drawColor());
130
    painter->setBrush(edgeFillColor());
131
    painter->setRenderHint(QPainter::Antialiasing, true);
Claudio Valerio's avatar
Claudio Valerio committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius);
    fillBackground(painter);
    paintGraduations(painter);
    if (mRotating)
        paintRotationCenter(painter);
}


QVariant UBGraphicsRuler::itemChange(GraphicsItemChange change, const QVariant &value)
{
    if (change == QGraphicsItem::ItemVisibleHasChanged)
    {
        mCloseSvgItem->setParentItem(this);
        mResizeSvgItem->setParentItem(this);
        mRotateSvgItem->setParentItem(this);
    }

    return QGraphicsRectItem::itemChange(change, value);
}

void UBGraphicsRuler::fillBackground(QPainter *painter)
{
    QRectF rect1(rect().topLeft(), QSizeF(rect().width(), rect().height() / 4));
    QLinearGradient linearGradient1(
        rect1.topLeft(),
        rect1.bottomLeft());
    linearGradient1.setColorAt(0, edgeFillColor());
    linearGradient1.setColorAt(1, middleFillColor());
    painter->fillRect(rect1, linearGradient1);

    QRectF rect2(rect1.bottomLeft(), QSizeF(rect().width(), rect().height() / 2));
    painter->fillRect(rect2, middleFillColor());

    QRectF rect3(rect2.bottomLeft(), rect1.size());
    QLinearGradient linearGradient3(
        rect3.topLeft(),
        rect3.bottomLeft());
    linearGradient3.setColorAt(0, middleFillColor());
    linearGradient3.setColorAt(1, edgeFillColor());
    painter->fillRect(rect3, linearGradient3);
}

void UBGraphicsRuler::paintGraduations(QPainter *painter)
{
    painter->save();
    painter->setFont(font());
    QFontMetricsF fontMetrics(painter->font());
179 180 181 182

    // Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not)
    sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();

183
    qreal pixelsPerMillimeter = sPixelsPerCentimeter/10.0;
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    int rulerLengthInMillimeters = (rect().width() - sLeftEdgeMargin - sRoundingRadius)/pixelsPerMillimeter;

    // When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark
    double numbersWidth = fontMetrics.width("00");
    bool shouldDisplayAllNumbers = (numbersWidth <= (sPixelsPerCentimeter - 5));

    for (int millimeters(0); millimeters < rulerLengthInMillimeters; millimeters++) {

        double graduationX = rotationCenter().x() + pixelsPerMillimeter * millimeters;
        double graduationHeight = 0;

        if (millimeters % UBGeometryUtils::millimetersPerCentimeter == 0)
            graduationHeight = UBGeometryUtils::centimeterGraduationHeight;

        else if (millimeters % UBGeometryUtils::millimetersPerHalfCentimeter == 0)
            graduationHeight = UBGeometryUtils::halfCentimeterGraduationHeight;

        else
            graduationHeight = UBGeometryUtils::millimeterGraduationHeight;


        if (shouldDisplayAllNumbers || millimeters % UBGeometryUtils::millimetersPerHalfCentimeter == 0) {
            painter->drawLine(QLineF(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight));
            painter->drawLine(QLineF(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight));
        }


        if ((shouldDisplayAllNumbers && millimeters % UBGeometryUtils::millimetersPerCentimeter == 0)
            || millimeters % (UBGeometryUtils::millimetersPerCentimeter*5) == 0)
Claudio Valerio's avatar
Claudio Valerio committed
213
        {
214
            QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter));
215 216

            if (graduationX + fontMetrics.width(text) / 2 < rect().right()) {
Claudio Valerio's avatar
Claudio Valerio committed
217 218 219
                qreal textWidth = fontMetrics.width(text);
                qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5;
                painter->drawText(
220
                    QRectF(graduationX - textWidth / 2, rect().top() + 5 + UBGeometryUtils::centimeterGraduationHeight, textWidth, textHeight),
Claudio Valerio's avatar
Claudio Valerio committed
221 222
                    Qt::AlignVCenter, text);
                painter->drawText(
223
                    QRectF(graduationX - textWidth / 2, rect().bottom() - 5 - UBGeometryUtils::centimeterGraduationHeight - textHeight, textWidth, textHeight),
Claudio Valerio's avatar
Claudio Valerio committed
224 225 226 227
                    Qt::AlignVCenter, text);
            }
        }
    }
228 229


Claudio Valerio's avatar
Claudio Valerio committed
230
    painter->restore();
231

Claudio Valerio's avatar
Claudio Valerio committed
232 233 234 235 236
}

void UBGraphicsRuler::paintRotationCenter(QPainter *painter)
{
    painter->drawArc(
unknown's avatar
unknown committed
237
        rotationCenter().x() - sRotationRadius, rotationCenter().y() - sRotationRadius,
Claudio Valerio's avatar
Claudio Valerio committed
238 239 240 241
        2 * sRotationRadius, 2 * sRotationRadius,
        270 * sDegreeToQtAngleUnit, 90 * sDegreeToQtAngleUnit);
}

unknown's avatar
unknown committed
242
void UBGraphicsRuler::rotateAroundCenter(qreal angle)
Claudio Valerio's avatar
Claudio Valerio committed
243 244
{
    QTransform transform;
unknown's avatar
unknown committed
245
    transform.translate(rotationCenter().x(), rotationCenter().y());
Claudio Valerio's avatar
Claudio Valerio committed
246
    transform.rotate(angle);
unknown's avatar
unknown committed
247
    transform.translate(- rotationCenter().x(), - rotationCenter().y());
Claudio Valerio's avatar
Claudio Valerio committed
248 249 250
    setTransform(transform, true);
}

unknown's avatar
unknown committed
251
QPointF UBGraphicsRuler::rotationCenter() const
Claudio Valerio's avatar
Claudio Valerio committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
{
    return QPointF(rect().x() + sLeftEdgeMargin, rect().y());
}


QRectF UBGraphicsRuler::resizeButtonRect() const
{
    QPixmap resizePixmap(":/images/resizeRuler.svg");
    QSizeF resizeRectSize(
        resizePixmap.rect().width(),
        rect().height());

    qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0;
    QPointF resizeRectTopLeft(rect().width() - resizeRectSize.width() * ratio, 0);

    QRectF resizeRect(resizeRectTopLeft, resizeRectSize);
    resizeRect.translate(rect().topLeft());

    return resizeRect;
}

QRectF UBGraphicsRuler::closeButtonRect() const
{
    QPixmap closePixmap(":/images/closeTool.svg");

    QSizeF closeRectSize(
        closePixmap.width() * mAntiScaleRatio,
        closePixmap.height() * mAntiScaleRatio);

    QPointF closeRectCenter(
282
        rect().left() + sLeftEdgeMargin + sPixelsPerCentimeter/2,
Claudio Valerio's avatar
Claudio Valerio committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
        rect().center().y());

    QPointF closeRectTopLeft(
        closeRectCenter.x() - closeRectSize.width() / 2,
        closeRectCenter.y() - closeRectSize.height() / 2);

    return QRectF(closeRectTopLeft, closeRectSize);
}

QRectF UBGraphicsRuler::rotateButtonRect() const
{
    QPixmap rotatePixmap(":/images/closeTool.svg");

    QSizeF rotateRectSize(
        rotatePixmap.width() * mAntiScaleRatio,
        rotatePixmap.height() * mAntiScaleRatio);

300
    int centimeters = (int)(rect().width() - sLeftEdgeMargin - resizeButtonRect().width()) / (sPixelsPerCentimeter);
Claudio Valerio's avatar
Claudio Valerio committed
301
    QPointF rotateRectCenter(
302
        rect().left() + sLeftEdgeMargin + (centimeters - 0.5) * sPixelsPerCentimeter,
Claudio Valerio's avatar
Claudio Valerio committed
303 304 305 306 307 308 309 310 311
        rect().center().y());

    QPointF rotateRectTopLeft(
        rotateRectCenter.x() - rotateRectSize.width() / 2,
        rotateRectCenter.y() - rotateRectSize.height() / 2);

    return QRectF(rotateRectTopLeft, rotateRectSize);
}

312
void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Claudio Valerio's avatar
Claudio Valerio committed
313
{
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();

    if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
    {
        mCloseSvgItem->setVisible(mShowButtons);
        mResizeSvgItem->setVisible(mShowButtons);
        mRotateSvgItem->setVisible(mShowButtons);
        if (resizeButtonRect().contains(event->pos()))
            setCursor(resizeCursor());
        else if (closeButtonRect().contains(event->pos()))
            setCursor(closeCursor());
        else if (rotateButtonRect().contains(event->pos()))
            setCursor(rotateCursor());
        else
            setCursor(moveCursor());

        event->accept();
    }
    else if (UBDrawingController::drawingController()->isDrawingTool())
    {
        event->accept();
    }
Claudio Valerio's avatar
Claudio Valerio committed
336 337
}

338
void UBGraphicsRuler::mousePressEvent(QGraphicsSceneMouseEvent *event)
Claudio Valerio's avatar
Claudio Valerio committed
339
{
340 341 342 343 344 345 346 347 348 349 350 351 352 353
    if (event->pos().x() > resizeButtonRect().left())
    {
        mResizing = true;
        event->accept();
    }
    else if (rotateButtonRect().contains(event->pos()))
    {
        mRotating = true;
        event->accept();
    }
    else
    {
        mResizeSvgItem->setVisible(false);
        mRotateSvgItem->setVisible(false);
354
        QGraphicsItem::mousePressEvent(event);
355 356 357 358
    }
    mResizeSvgItem->setVisible(mShowButtons && mResizing);
    mRotateSvgItem->setVisible(mShowButtons && mRotating);
    mCloseSvgItem->setVisible(false);
Claudio Valerio's avatar
Claudio Valerio committed
359 360
}

361
void UBGraphicsRuler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Claudio Valerio's avatar
Claudio Valerio committed
362
{
363 364
    if (!mResizing && !mRotating)
    {
365
        QGraphicsItem::mouseMoveEvent(event);
366 367 368 369 370
    }
    else
    {
        if (mResizing)
        {
371 372 373
            QPointF delta = event->pos() - event->lastPos();
            if (rect().width() + delta.x() < sMinLength)
                delta.setX(sMinLength - rect().width());
374 375 376 377

            if (rect().width() + delta.x() > sMaxLength)
                delta.setX(sMaxLength - rect().width());

378
            setRect(QRectF(rect().topLeft(), QSizeF(rect().width() + delta.x(), rect().height())));
379 380 381
        }
        else
        {
unknown's avatar
unknown committed
382 383 384
            QLineF currentLine(rotationCenter(), event->pos());
            QLineF lastLine(rotationCenter(), event->lastPos());
            rotateAroundCenter(currentLine.angleTo(lastLine));
385 386 387 388
        }

        event->accept();
    }
Claudio Valerio's avatar
Claudio Valerio committed
389 390
}

391
void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Claudio Valerio's avatar
Claudio Valerio committed
392
{
393 394 395 396 397 398 399 400
    if (mResizing)
    {
        mResizing = false;
        event->accept();
    }
    else if (mRotating)
    {
        mRotating = false;
unknown's avatar
unknown committed
401 402
        updateResizeCursor();
        update(QRectF(rotationCenter(), QSizeF(sRotationRadius, sRotationRadius)));
403 404 405 406
        event->accept();
    }
    else if (closeButtonRect().contains(event->pos()))
    {
407
        hide();
408 409 410 411
        event->accept();
    }
    else
    {
412
        QGraphicsItem::mouseReleaseEvent(event);
413 414 415 416
    }

    if (scene())
        scene()->setModified(true);
Claudio Valerio's avatar
Claudio Valerio committed
417 418
}

419
void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Claudio Valerio's avatar
Claudio Valerio committed
420
{
421
    UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
422

423
    if (currentTool == UBStylusTool::Selector ||
424
        currentTool == UBStylusTool::Play)
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
    {
        mCloseSvgItem->setParentItem(this);
        mResizeSvgItem->setParentItem(this);
        mRotateSvgItem->setParentItem(this);

        mShowButtons = true;
        mCloseSvgItem->setVisible(mShowButtons);
        mResizeSvgItem->setVisible(mShowButtons);
        mRotateSvgItem->setVisible(mShowButtons);
        if (event->pos().x() >= resizeButtonRect().left())
        {
            setCursor(resizeCursor());
        }
        else
        {
            if (closeButtonRect().contains(event->pos()))
                setCursor(closeCursor());
            else if (rotateButtonRect().contains(event->pos()))
                setCursor(rotateCursor());
            else
                setCursor(moveCursor());
        }
        event->accept();
        update();
    }
    else if (UBDrawingController::drawingController()->isDrawingTool())
    {
        setCursor(drawRulerLineCursor());
        UBDrawingController::drawingController()->mActiveRuler = this;
        event->accept();
    }
Claudio Valerio's avatar
Claudio Valerio committed
456 457
}

458
void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Claudio Valerio's avatar
Claudio Valerio committed
459
{
460 461 462 463 464
    mShowButtons = false;
    setCursor(Qt::ArrowCursor);
    mCloseSvgItem->setVisible(mShowButtons);
    mResizeSvgItem->setVisible(mShowButtons);
    mRotateSvgItem->setVisible(mShowButtons);
465
    UBDrawingController::drawingController()->mActiveRuler = NULL;
466 467
    event->accept();
    update();
Claudio Valerio's avatar
Claudio Valerio committed
468
}
469

470 471 472


UBGraphicsScene* UBGraphicsRuler::scene() const
473
{
474
    return static_cast<UBGraphicsScene*>(QGraphicsRectItem::scene());
475 476 477 478
}

void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width)
{
479 480
    Q_UNUSED(width);

481 482
    QPointF itemPos = mapFromScene(scenePos);

483
    mStrokeWidth = UBDrawingController::drawingController()->currentToolWidth();
484

485 486 487 488 489
    qreal y;

    if (itemPos.y() > rect().y() + rect().height() / 2)
    {
        drawLineDirection = 0;
490
        y = rect().y() + rect().height() + mStrokeWidth / 2;
491 492 493 494
    }
    else
    {
        drawLineDirection = 1;
495
        y = rect().y() - mStrokeWidth /2;
496 497 498 499 500 501 502 503 504
    }

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

506
    scene()->moveTo(itemPos);
507
    scene()->drawLineTo(itemPos, mStrokeWidth, true);
508 509 510 511
}

void UBGraphicsRuler::DrawLine(const QPointF& scenePos, qreal width)
{
512
    Q_UNUSED(width);
513 514 515 516 517
    QPointF itemPos = mapFromScene(scenePos);

    qreal y;
    if (drawLineDirection == 0)
    {
518
        y = rect().y() + rect().height() + mStrokeWidth / 2;
519 520 521
    }
    else
    {
522
        y = rect().y() - mStrokeWidth /2;
523 524 525 526 527 528 529 530 531 532
    }
    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
533
    scene()->drawLineTo(itemPos, mStrokeWidth, UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker);
534 535 536
}

void UBGraphicsRuler::EndLine()
537 538 539 540
{
    // We never come to this place
    scene()->inputDeviceRelease();
}