restored old graphics delegate behavior and added new stroke smoothing behavior

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 10a22d7c13
commit 4b0a4ab3be
  1. 4
      src/board/UBBoardController.cpp
  2. 3
      src/domain/UBGraphicsDelegateFrame.h
  3. 78
      src/domain/UBGraphicsItemDelegate.cpp
  4. 3
      src/domain/UBGraphicsItemDelegate.h
  5. 19
      src/domain/UBGraphicsPolygonItem.cpp
  6. 1
      src/domain/UBGraphicsPolygonItem.h
  7. 14
      src/domain/UBGraphicsScene.cpp
  8. 2
      src/domain/UBGraphicsScene.h
  9. 2
      src/domain/UBGraphicsTextItem.cpp
  10. 13
      src/domain/UBGraphicsTextItemDelegate.cpp
  11. 43
      src/frameworks/UBGeometryUtils.cpp
  12. 1
      src/frameworks/UBGeometryUtils.h
  13. 3
      src/tools/UBGraphicsCurtainItemDelegate.cpp

@ -2068,7 +2068,9 @@ void UBBoardController::grabScene(const QRectF& pSceneRect)
mActiveScene->render(&painter, targetRect, pSceneRect); mActiveScene->render(&painter, targetRect, pSceneRect);
mActiveScene->setRenderingContext(UBGraphicsScene::Screen); mActiveScene->setRenderingContext(UBGraphicsScene::Screen);
mActiveScene->setRenderingQuality(UBItem::RenderingQualityNormal); // mActiveScene->setRenderingQuality(UBItem::RenderingQualityNormal);
mActiveScene->setRenderingQuality(UBItem::RenderingQualityHigh);
mPaletteManager->addItem(QPixmap::fromImage(image)); mPaletteManager->addItem(QPixmap::fromImage(image));
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));

@ -39,8 +39,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio = true); UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio = true);
virtual ~UBGraphicsDelegateFrame(); virtual ~UBGraphicsDelegateFrame();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QWidget *widget);
QPainterPath shape() const; QPainterPath shape() const;

@ -179,70 +179,9 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
void UBGraphicsItemDelegate::init() 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);
}
UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{
if (UBApplication::boardController)
disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged()));
// do not release mMimeData.
// the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation
}
void UBGraphicsItemDelegate::decorate()
{
if (mToolBarUsed) if (mToolBarUsed)
mToolBarItem = new UBGraphicsToolBarItem(mDelegated); mToolBarItem = new UBGraphicsToolBarItem(mDelegated);
if(!mFrame){
mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio);
mFrame->hide(); mFrame->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -281,9 +220,23 @@ void UBGraphicsItemDelegate::decorate()
button->setFlag(QGraphicsItem::ItemIsSelectable, true); button->setFlag(QGraphicsItem::ItemIsSelectable, true);
} }
} }
//Wrapper function. Use it to set correct data() to QGraphicsItem as well
setFlippable(false);
setRotatable(false);
} }
UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{
if (UBApplication::boardController)
disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged()));
// do not release mMimeData.
// the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation
} }
QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if (change == QGraphicsItem::ItemSelectedHasChanged) { if (change == QGraphicsItem::ItemSelectedHasChanged) {
@ -736,11 +689,8 @@ bool UBGraphicsItemDelegate::isFlippable()
void UBGraphicsItemDelegate::updateFrame() void UBGraphicsItemDelegate::updateFrame()
{ {
decorate();
if (mFrame && !mFrame->scene() && mDelegated->scene()) if (mFrame && !mFrame->scene() && mDelegated->scene())
{
mDelegated->scene()->addItem(mFrame); mDelegated->scene()->addItem(mFrame);
}
mFrame->setAntiScale(mAntiScaleRatio); mFrame->setAntiScale(mAntiScaleRatio);
mFrame->positionHandles(); mFrame->positionHandles();

@ -220,7 +220,6 @@ class UBGraphicsItemDelegate : public QObject
virtual ~UBGraphicsItemDelegate(); virtual ~UBGraphicsItemDelegate();
void init(); void init();
void decorate();
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event); virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);
@ -246,7 +245,7 @@ class UBGraphicsItemDelegate : public QObject
void startUndoStep(); void startUndoStep();
void commitUndoStep(); void commitUndoStep();
UBGraphicsDelegateFrame* frame() { if(!mFrame) decorate(); return mFrame; } UBGraphicsDelegateFrame* frame() {return mFrame;}
bool canRotate() const { return mCanRotate; } bool canRotate() const { return mCanRotate; }
bool isLocked() const; bool isLocked() const;

@ -65,6 +65,18 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth)
initialize(); 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() void UBGraphicsPolygonItem::initialize()
{ {
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly
@ -186,7 +198,6 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const
cp->setColorOnDarkBackground(this->colorOnDarkBackground()); cp->setColorOnDarkBackground(this->colorOnDarkBackground());
cp->setColorOnLightBackground(this->colorOnLightBackground()); cp->setColorOnLightBackground(this->colorOnLightBackground());
//cp->setTransform(transform());
cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); 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) void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{ {
if(mHasAlpha && scene() && scene()->isLightBackground()) if(mHasAlpha && scene() && scene()->isLightBackground())
{
painter->setCompositionMode(QPainter::CompositionMode_Darken); painter->setCompositionMode(QPainter::CompositionMode_Darken);
}
QGraphicsPolygonItem::paint(painter, option, widget); QGraphicsPolygonItem::paint(painter, option, widget);
} }
@ -209,10 +218,6 @@ QPainterPath UBGraphicsPolygonItem::shape() const
path.addRect(boundingRect()); path.addRect(boundingRect());
return path; return path;
// static QPainterPath shapePath = QGraphicsPolygonItem::shape();
// return shapePath;
} }

@ -42,6 +42,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
UBGraphicsPolygonItem(QGraphicsItem * parent = 0 ); UBGraphicsPolygonItem(QGraphicsItem * parent = 0 );
UBGraphicsPolygonItem(const QLineF& line, qreal pWidth); UBGraphicsPolygonItem(const QLineF& line, qreal pWidth);
UBGraphicsPolygonItem(const QLineF& pLine, qreal pStartWidth, qreal pEndWidth);
UBGraphicsPolygonItem(const QPolygonF & polygon, QGraphicsItem * parent = 0); UBGraphicsPolygonItem(const QPolygonF & polygon, QGraphicsItem * parent = 0);
~UBGraphicsPolygonItem(); ~UBGraphicsPolygonItem();

@ -707,7 +707,9 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
if (mPreviousWidth == -1.0) if (mPreviousWidth == -1.0)
mPreviousWidth = pWidth; 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()) if (!polygonItem->brush().isOpaque())
{ {
@ -949,6 +951,16 @@ UBGraphicsPolygonItem* UBGraphicsScene::lineToPolygonItem(const QLineF &pLine, c
return polygonItem; 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) void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem)
{ {
QColor colorOnDarkBG; QColor colorOnDarkBG;

@ -346,6 +346,8 @@ public slots:
protected: protected:
UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth); 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); UBGraphicsPolygonItem* arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth);
void initPolygonItem(UBGraphicsPolygonItem*); void initPolygonItem(UBGraphicsPolygonItem*);

@ -55,12 +55,10 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) :
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); 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 setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
// setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setTextInteractionFlags(Qt::TextEditorInteraction); setTextInteractionFlags(Qt::TextEditorInteraction);

@ -87,14 +87,8 @@ QFont UBGraphicsTextItemDelegate::createDefaultFont()
textFormat.setFontItalic(true); textFormat.setFontItalic(true);
QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic); 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(); int pointSize = UBSettings::settings()->fontPointSize();
if (pointSize > 0) { if (pointSize > 0) {
// mLastFontPixelSize = pointSize;
font.setPointSize(pointSize); font.setPointSize(pointSize);
} }
@ -227,8 +221,6 @@ void UBGraphicsTextItemDelegate::pickColor()
{ {
QColor selectedColor = colorDialog.selectedColor(); QColor selectedColor = colorDialog.selectedColor();
delegated()->setDefaultTextColor(selectedColor); delegated()->setDefaultTextColor(selectedColor);
// delegated()->setColorOnDarkBackground(selectedColor);
// delegated()->setColorOnLightBackground(selectedColor);
QTextCursor curCursor = delegated()->textCursor(); QTextCursor curCursor = delegated()->textCursor();
QTextCharFormat format; QTextCharFormat format;
format.setForeground(QBrush(selectedColor)); format.setForeground(QBrush(selectedColor));
@ -257,6 +249,7 @@ UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated()
{ {
return static_cast<UBGraphicsTextItem*>(mDelegated); return static_cast<UBGraphicsTextItem*>(mDelegated);
} }
void UBGraphicsTextItemDelegate::setEditable(bool editable) void UBGraphicsTextItemDelegate::setEditable(bool editable)
{ {
if (editable) { if (editable) {
@ -271,6 +264,7 @@ void UBGraphicsTextItemDelegate::setEditable(bool editable)
mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false)); mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false));
} }
} }
void UBGraphicsTextItemDelegate::remove(bool canUndo) void UBGraphicsTextItemDelegate::remove(bool canUndo)
{ {
UBGraphicsItemDelegate::remove(canUndo); UBGraphicsItemDelegate::remove(canUndo);
@ -280,6 +274,7 @@ bool UBGraphicsTextItemDelegate::isEditable()
{ {
return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool(); return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool();
} }
void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu) void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu)
{ {
UBGraphicsItemDelegate::decorateMenu(menu); UBGraphicsItemDelegate::decorateMenu(menu);
@ -289,10 +284,12 @@ void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu)
mEditableAction->setChecked(isEditable()); mEditableAction->setChecked(isEditable());
} }
void UBGraphicsTextItemDelegate::updateMenuActionState() void UBGraphicsTextItemDelegate::updateMenuActionState()
{ {
UBGraphicsItemDelegate::updateMenuActionState(); UBGraphicsItemDelegate::updateMenuActionState();
} }
void UBGraphicsTextItemDelegate::positionHandles() void UBGraphicsTextItemDelegate::positionHandles()
{ {
UBGraphicsItemDelegate::positionHandles(); UBGraphicsItemDelegate::positionHandles();

@ -81,6 +81,49 @@ QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidt
return painterPath.toFillPolygon(); 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, QPolygonF UBGeometryUtils::lineToPolygon(const QPointF& pStart, const QPointF& pEnd,
const qreal& pStartWidth, const qreal& pEndWidth) const qreal& pStartWidth, const qreal& pEndWidth)
{ {

@ -34,6 +34,7 @@ class UBGeometryUtils
public: public:
static QPolygonF lineToPolygon(const QLineF& pLine, const qreal& pWidth); 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 QRectF lineToInnerRect(const QLineF& pLine, const qreal& pWidth);
static QPolygonF arcToPolygon(const QLineF& startRadius, qreal spanAngle, qreal width); static QPolygonF arcToPolygon(const QLineF& startRadius, qreal spanAngle, qreal width);

@ -45,8 +45,7 @@ UBGraphicsCurtainItemDelegate::~UBGraphicsCurtainItemDelegate()
void UBGraphicsCurtainItemDelegate::init() void UBGraphicsCurtainItemDelegate::init()
{ {
//UBGraphicsItemDelegate::init(); UBGraphicsItemDelegate::init();
decorate();
mFrame->hide(); mFrame->hide();
mZOrderUpButton->hide(); mZOrderUpButton->hide();
mZOrderDownButton->hide(); mZOrderDownButton->hide();

Loading…
Cancel
Save