From 4b0a4ab3bee6868919b8dd523078d0e1b826feeb Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 29 Apr 2013 09:53:08 +0200 Subject: [PATCH] restored old graphics delegate behavior and added new stroke smoothing behavior --- src/board/UBBoardController.cpp | 4 +- src/domain/UBGraphicsDelegateFrame.h | 5 +- src/domain/UBGraphicsItemDelegate.cpp | 140 +++++++------------- src/domain/UBGraphicsItemDelegate.h | 3 +- src/domain/UBGraphicsPolygonItem.cpp | 23 ++-- src/domain/UBGraphicsPolygonItem.h | 1 + src/domain/UBGraphicsScene.cpp | 14 +- src/domain/UBGraphicsScene.h | 10 +- src/domain/UBGraphicsTextItem.cpp | 18 ++- src/domain/UBGraphicsTextItemDelegate.cpp | 23 ++-- src/frameworks/UBGeometryUtils.cpp | 43 ++++++ src/frameworks/UBGeometryUtils.h | 1 + src/tools/UBGraphicsCurtainItemDelegate.cpp | 3 +- 13 files changed, 148 insertions(+), 140 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 0a5e1984..99f234ed 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -2068,7 +2068,9 @@ void UBBoardController::grabScene(const QRectF& pSceneRect) mActiveScene->render(&painter, targetRect, pSceneRect); mActiveScene->setRenderingContext(UBGraphicsScene::Screen); - mActiveScene->setRenderingQuality(UBItem::RenderingQualityNormal); +// mActiveScene->setRenderingQuality(UBItem::RenderingQualityNormal); + mActiveScene->setRenderingQuality(UBItem::RenderingQualityHigh); + mPaletteManager->addItem(QPixmap::fromImage(image)); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 0afcfa65..27b17ace 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -39,8 +39,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio = true); virtual ~UBGraphicsDelegateFrame(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QPainterPath shape() const; @@ -54,7 +53,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject void positionHandles(); void setVisible(bool visible); - virtual void setAntiScale(qreal pAntiScale); + virtual void setAntiScale(qreal pAntiScale); enum OperationMode {Scaling, Resizing, ResizingHorizontally}; void setOperationMode(OperationMode pMode) {mOperationMode = pMode;} diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 0176484c..440c4c15 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -179,51 +179,51 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec void UBGraphicsItemDelegate::init() { -// if (mToolBarUsed) -// mToolBarItem = new UBGraphicsToolBarItem(mDelegated); - -// mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); -// mFrame->hide(); -// mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); - -// mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); -// mButtons << mDeleteButton; -// connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); -// if (canDuplicate()){ -// mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); -// connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); -// mButtons << mDuplicateButton; -// } -// mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); -// connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); -// mButtons << mMenuButton; - -// mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); -// mZOrderUpButton->setShowProgressIndicator(true); -// connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); -// connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); -// mButtons << mZOrderUpButton; - -// mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); -// mZOrderDownButton->setShowProgressIndicator(true); -// connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); -// connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); -// mButtons << mZOrderDownButton; - -// buildButtons(); - -// foreach(DelegateButton* button, mButtons) -// { -// if (button->getSection() != Qt::TitleBarArea) -// { -// button->hide(); -// button->setFlag(QGraphicsItem::ItemIsSelectable, true); -// } -// } - -// //Wrapper function. Use it to set correct data() to QGraphicsItem as well -// setFlippable(false); -// setRotatable(false); + if (mToolBarUsed) + mToolBarItem = new UBGraphicsToolBarItem(mDelegated); + + mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); + mFrame->hide(); + mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); + + mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); + mButtons << mDeleteButton; + connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); + if (canDuplicate()){ + mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); + connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); + mButtons << mDuplicateButton; + } + mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); + connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); + mButtons << mMenuButton; + + mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); + mZOrderUpButton->setShowProgressIndicator(true); + connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); + connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); + mButtons << mZOrderUpButton; + + mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); + mZOrderDownButton->setShowProgressIndicator(true); + connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); + connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); + mButtons << mZOrderDownButton; + + buildButtons(); + + foreach(DelegateButton* button, mButtons) + { + if (button->getSection() != Qt::TitleBarArea) + { + button->hide(); + button->setFlag(QGraphicsItem::ItemIsSelectable, true); + } + } + + //Wrapper function. Use it to set correct data() to QGraphicsItem as well + setFlippable(false); + setRotatable(false); } @@ -236,53 +236,6 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate() } -void UBGraphicsItemDelegate::decorate() -{ - - if (mToolBarUsed) - mToolBarItem = new UBGraphicsToolBarItem(mDelegated); - - if(!mFrame){ - mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); - mFrame->hide(); - mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); - - mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); - mButtons << mDeleteButton; - connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); - if (canDuplicate()){ - mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); - connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); - mButtons << mDuplicateButton; - } - mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); - connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); - mButtons << mMenuButton; - - mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); - mZOrderUpButton->setShowProgressIndicator(true); - connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); - connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); - mButtons << mZOrderUpButton; - - mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); - mZOrderDownButton->setShowProgressIndicator(true); - connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); - connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); - mButtons << mZOrderDownButton; - - buildButtons(); - - foreach(DelegateButton* button, mButtons) - { - if (button->getSection() != Qt::TitleBarArea) - { - button->hide(); - button->setFlag(QGraphicsItem::ItemIsSelectable, true); - } - } - } -} QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { @@ -736,11 +689,8 @@ bool UBGraphicsItemDelegate::isFlippable() void UBGraphicsItemDelegate::updateFrame() { - decorate(); if (mFrame && !mFrame->scene() && mDelegated->scene()) - { mDelegated->scene()->addItem(mFrame); - } mFrame->setAntiScale(mAntiScaleRatio); mFrame->positionHandles(); diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 076ff7ec..6715cf99 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -220,7 +220,6 @@ class UBGraphicsItemDelegate : public QObject virtual ~UBGraphicsItemDelegate(); void init(); - void decorate(); virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event); @@ -246,7 +245,7 @@ class UBGraphicsItemDelegate : public QObject void startUndoStep(); void commitUndoStep(); - UBGraphicsDelegateFrame* frame() { if(!mFrame) decorate(); return mFrame; } + UBGraphicsDelegateFrame* frame() {return mFrame;} bool canRotate() const { return mCanRotate; } bool isLocked() const; diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index f4b761a8..789daff3 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -65,6 +65,18 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth) initialize(); } +UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pStartWidth, qreal pEndWidth) + : QGraphicsPolygonItem(UBGeometryUtils::lineToPolygon(pLine, pStartWidth, pEndWidth)) + , mOriginalLine(pLine) + , mOriginalWidth(pEndWidth) + , mIsNominalLine(true) + , mStroke(0) +{ + // NOOP + initialize(); +} + + void UBGraphicsPolygonItem::initialize() { setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly @@ -157,11 +169,11 @@ QColor UBGraphicsPolygonItem::color() const UBItem* UBGraphicsPolygonItem::deepCopy() const -{ +{ UBGraphicsPolygonItem* copy = new UBGraphicsPolygonItem(polygon(), 0); UBGraphicsStroke *stroke = new UBGraphicsStroke(); - + copyItemParameters(copy); copy->setStroke(stroke); @@ -186,7 +198,6 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const cp->setColorOnDarkBackground(this->colorOnDarkBackground()); cp->setColorOnLightBackground(this->colorOnLightBackground()); - //cp->setTransform(transform()); cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); } @@ -195,9 +206,7 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { if(mHasAlpha && scene() && scene()->isLightBackground()) - { painter->setCompositionMode(QPainter::CompositionMode_Darken); - } QGraphicsPolygonItem::paint(painter, option, widget); } @@ -209,10 +218,6 @@ QPainterPath UBGraphicsPolygonItem::shape() const path.addRect(boundingRect()); return path; - -// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); - -// return shapePath; } diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index d93ac1e0..512a2346 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -42,6 +42,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem UBGraphicsPolygonItem(QGraphicsItem * parent = 0 ); UBGraphicsPolygonItem(const QLineF& line, qreal pWidth); + UBGraphicsPolygonItem(const QLineF& pLine, qreal pStartWidth, qreal pEndWidth); UBGraphicsPolygonItem(const QPolygonF & polygon, QGraphicsItem * parent = 0); ~UBGraphicsPolygonItem(); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index fc49ef78..522c35af 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -707,7 +707,9 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, if (mPreviousWidth == -1.0) mPreviousWidth = pWidth; - UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), pWidth); +// UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), pWidth); + + UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), mPreviousWidth,pWidth); if (!polygonItem->brush().isOpaque()) { @@ -949,6 +951,16 @@ UBGraphicsPolygonItem* UBGraphicsScene::lineToPolygonItem(const QLineF &pLine, c return polygonItem; } + +UBGraphicsPolygonItem* UBGraphicsScene::lineToPolygonItem(const QLineF &pLine, const qreal &pStartWidth, const qreal &pEndWidth) +{ + UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pLine, pStartWidth, pEndWidth); + + initPolygonItem(polygonItem); + + return polygonItem; +} + void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem) { QColor colorOnDarkBG; diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 2f3d3624..b97b136b 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -149,7 +149,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0)); void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0)); - + UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); @@ -320,10 +320,10 @@ public slots: void setDrawingMode(bool bModeDesktop); void deselectAllItems(); - UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, + UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, QGraphicsItem* replaceFor, - const QPointF& pPos = QPointF(0,0), - qreal scaleFactor = 1.0, + const QPointF& pPos = QPointF(0,0), + qreal scaleFactor = 1.0, bool pUseAnimation = false); void textUndoCommandAdded(UBGraphicsTextItem *textItem); @@ -346,6 +346,8 @@ public slots: protected: UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth); + UBGraphicsPolygonItem* lineToPolygonItem(const QLineF &pLine, const qreal &pStartWidth, const qreal &pEndWidth); + UBGraphicsPolygonItem* arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth); void initPolygonItem(UBGraphicsPolygonItem*); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index e5f4dc6d..2e724cbe 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -55,12 +55,10 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) : setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); -// setData(UBGraphicsItemData::ItemEditable, QVariant(true)); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemIsSelectable, true); -// setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setTextInteractionFlags(Qt::TextEditorInteraction); @@ -91,8 +89,8 @@ QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVarian void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - // scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes. - // It is a cludge... + // scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes. + // It is a cludge... if (UBStylusTool::Play == UBDrawingController::drawingController()->stylusTool()) { event->accept(); @@ -110,13 +108,13 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QGraphicsItem *curItem = group->getCurrentItem(); if (curItem && this != curItem) - { - group->deselectCurrentItem(); - } + { + group->deselectCurrentItem(); + } group->setCurrentItem(this); this->setSelected(true); Delegate()->positionHandles(); - } + } } else @@ -178,8 +176,8 @@ void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - // scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes. - // It is a cludge... + // scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes. + // It is a cludge... if (UBStylusTool::Play == UBDrawingController::drawingController()->stylusTool()) { event->accept(); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 8cd054d9..92dbc62d 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -87,14 +87,8 @@ QFont UBGraphicsTextItemDelegate::createDefaultFont() textFormat.setFontItalic(true); QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic); -// int pixSize = UBSettings::settings()->fontPixelSize(); -// if (pixSize > 0) { -// mLastFontPixelSize = pixSize; -// font.setPixelSize(pixSize); -// } int pointSize = UBSettings::settings()->fontPointSize(); if (pointSize > 0) { -// mLastFontPixelSize = pointSize; font.setPointSize(pointSize); } @@ -227,8 +221,6 @@ void UBGraphicsTextItemDelegate::pickColor() { QColor selectedColor = colorDialog.selectedColor(); delegated()->setDefaultTextColor(selectedColor); -// delegated()->setColorOnDarkBackground(selectedColor); -// delegated()->setColorOnLightBackground(selectedColor); QTextCursor curCursor = delegated()->textCursor(); QTextCharFormat format; format.setForeground(QBrush(selectedColor)); @@ -257,6 +249,7 @@ UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated() { return static_cast(mDelegated); } + void UBGraphicsTextItemDelegate::setEditable(bool editable) { if (editable) { @@ -271,6 +264,7 @@ void UBGraphicsTextItemDelegate::setEditable(bool editable) mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false)); } } + void UBGraphicsTextItemDelegate::remove(bool canUndo) { UBGraphicsItemDelegate::remove(canUndo); @@ -280,6 +274,7 @@ bool UBGraphicsTextItemDelegate::isEditable() { return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool(); } + void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu) { UBGraphicsItemDelegate::decorateMenu(menu); @@ -289,23 +284,25 @@ void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu) mEditableAction->setChecked(isEditable()); } + void UBGraphicsTextItemDelegate::updateMenuActionState() { UBGraphicsItemDelegate::updateMenuActionState(); } + void UBGraphicsTextItemDelegate::positionHandles() { UBGraphicsItemDelegate::positionHandles(); - if (mDelegated->isSelected() || (mDelegated->parentItem() && UBGraphicsGroupContainerItem::Type == mDelegated->parentItem()->type())) + if (mDelegated->isSelected() || (mDelegated->parentItem() && UBGraphicsGroupContainerItem::Type == mDelegated->parentItem()->type())) { if (mToolBarItem->isVisibleOnBoard()) { - qreal AntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + qreal AntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); mToolBarItem->setScale(AntiScaleRatio); QRectF toolBarRect = mToolBarItem->rect(); toolBarRect.setWidth(delegated()->boundingRect().width()/AntiScaleRatio); - mToolBarItem->setRect(toolBarRect); + mToolBarItem->setRect(toolBarRect); mToolBarItem->positionHandles(); mToolBarItem->update(); if (mToolBarItem->isShifting()) @@ -374,9 +371,9 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha // we search continuous blocks of the text with the same PointSize and allpy new settings for them. cursor.setPosition (startPos, QTextCursor::MoveAnchor); while(iCursorPos < endPos) - { + { bEndofTheSameBlock = false; - iBlockLen = 0; + iBlockLen = 0; cursor.setPosition (iCursorPos+1, QTextCursor::KeepAnchor); iPointSize = cursor.charFormat().font().pointSize(); diff --git a/src/frameworks/UBGeometryUtils.cpp b/src/frameworks/UBGeometryUtils.cpp index d1cc1fe2..a006b191 100644 --- a/src/frameworks/UBGeometryUtils.cpp +++ b/src/frameworks/UBGeometryUtils.cpp @@ -81,6 +81,49 @@ QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidt return painterPath.toFillPolygon(); } + + +QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pStartWidth, const qreal& pEndWidth) +{ + qreal x1 = pLine.x1(); + qreal y1 = pLine.y1(); + + qreal x2 = pLine.x2(); + qreal y2 = pLine.y2(); + + qreal alpha = (90.0 - pLine.angle()) * PI / 180.0; + qreal startHypothenuse = pStartWidth / 2; + qreal endHypothenuse = pEndWidth / 2; + + // TODO UB 4.x PERF cache sin/cos table + qreal startOpposite = sin(alpha) * startHypothenuse; + qreal startAdjacent = cos(alpha) * startHypothenuse; + + qreal endOpposite = sin(alpha) * endHypothenuse; + qreal endAdjacent = cos(alpha) * endHypothenuse; + + QPointF p1a(x1 - startAdjacent, y1 - startOpposite); + QPointF p1b(x1 + startAdjacent, y1 + startOpposite); + + QPointF p2a(x2 - endAdjacent, y2 - endOpposite); + QPointF p2b(x2 + endAdjacent, y2 + endOpposite); + + QPainterPath painterPath; + painterPath.moveTo(p1a); + painterPath.lineTo(p2a); + + painterPath.arcTo(x2 - endHypothenuse, y2 - endHypothenuse, pEndWidth, pEndWidth, (90.0 + pLine.angle()), -180.0); + + //painterPath.lineTo(p2b); + painterPath.lineTo(p1b); + + painterPath.arcTo(x1 - startHypothenuse, y1 - startHypothenuse, pStartWidth, pStartWidth, -1 * (90.0 - pLine.angle()), -180.0); + + painterPath.closeSubpath(); + + return painterPath.toFillPolygon(); +} + QPolygonF UBGeometryUtils::lineToPolygon(const QPointF& pStart, const QPointF& pEnd, const qreal& pStartWidth, const qreal& pEndWidth) { diff --git a/src/frameworks/UBGeometryUtils.h b/src/frameworks/UBGeometryUtils.h index 383b7547..49ca8843 100644 --- a/src/frameworks/UBGeometryUtils.h +++ b/src/frameworks/UBGeometryUtils.h @@ -34,6 +34,7 @@ class UBGeometryUtils public: static QPolygonF lineToPolygon(const QLineF& pLine, const qreal& pWidth); + static QPolygonF lineToPolygon(const QLineF& pLine, const qreal& pStartWidth, const qreal& pEndWidth); static QRectF lineToInnerRect(const QLineF& pLine, const qreal& pWidth); static QPolygonF arcToPolygon(const QLineF& startRadius, qreal spanAngle, qreal width); diff --git a/src/tools/UBGraphicsCurtainItemDelegate.cpp b/src/tools/UBGraphicsCurtainItemDelegate.cpp index c5360f4f..06f24a27 100644 --- a/src/tools/UBGraphicsCurtainItemDelegate.cpp +++ b/src/tools/UBGraphicsCurtainItemDelegate.cpp @@ -45,8 +45,7 @@ UBGraphicsCurtainItemDelegate::~UBGraphicsCurtainItemDelegate() void UBGraphicsCurtainItemDelegate::init() { - //UBGraphicsItemDelegate::init(); - decorate(); + UBGraphicsItemDelegate::init(); mFrame->hide(); mZOrderUpButton->hide(); mZOrderDownButton->hide();