The title bar of the qgraphicstext item is not a part of the frame

preferencesAboutTextFull
-f 11 years ago
parent cb0c5ab41f
commit 59133e42f5
  1. 1
      src/core/UB.h
  2. 17
      src/domain/UBGraphicsDelegateFrame.cpp
  3. 3
      src/domain/UBGraphicsDelegateFrame.h
  4. 30
      src/domain/UBGraphicsItemDelegate.cpp
  5. 8
      src/domain/UBGraphicsTextItem.cpp
  6. 107
      src/domain/UBGraphicsTextItemDelegate.cpp
  7. 5
      src/domain/UBGraphicsTextItemDelegate.h

@ -182,6 +182,7 @@ enum UBGraphicsFlag {
,GF_TOOLBAR_USED = 0x0100 //0000 0001 0000 0000 ,GF_TOOLBAR_USED = 0x0100 //0000 0001 0000 0000
,GF_SHOW_CONTENT_SOURCE = 0x0200 //0000 0010 0000 0000 ,GF_SHOW_CONTENT_SOURCE = 0x0200 //0000 0010 0000 0000
,GF_RESPECT_RATIO = 0x0418 //0000 0100 0001 1000 ,GF_RESPECT_RATIO = 0x0418 //0000 0100 0001 1000
,GF_TITLE_BAR_USED = 0x0800 //0000 1000 0000 0000
,GF_COMMON = 0x00F8 /*0000 0000 1111 1000 GF_SCALABLE_ALL_AXIS ,GF_COMMON = 0x00F8 /*0000 0000 1111 1000 GF_SCALABLE_ALL_AXIS
|GF_DUPLICATION_ENABLED |GF_DUPLICATION_ENABLED
|GF_MENU_SPECIFIED |GF_MENU_SPECIFIED

@ -44,7 +44,7 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio) UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio, bool hasTitleBar)
: QGraphicsRectItem(), QObject(pDelegate) : QGraphicsRectItem(), QObject(pDelegate)
, mCurrentTool(None) , mCurrentTool(None)
, mDelegate(pDelegate) , mDelegate(pDelegate)
@ -65,13 +65,14 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
, mFlippedY(false) , mFlippedY(false)
, mMirrorX(false) , mMirrorX(false)
, mMirrorY(false) , mMirrorY(false)
, mTitleBarHeight(hasTitleBar ? 20 :0)
{ {
mAngleTolerance = UBSettings::settings()->angleTolerance->get().toReal(); mAngleTolerance = UBSettings::settings()->angleTolerance->get().toReal();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
setRect(pRect.adjusted(mFrameWidth, mFrameWidth, mFrameWidth * -1, mFrameWidth * -1)); setRect(pRect.adjusted(mFrameWidth, mFrameWidth + mTitleBarHeight, mFrameWidth * -1, mFrameWidth * -1));
setBrush(QBrush(UBSettings::paletteColor)); setBrush(QBrush(UBSettings::paletteColor));
setPen(Qt::NoPen); setPen(Qt::NoPen);
@ -134,20 +135,20 @@ void UBGraphicsDelegateFrame::paint(QPainter *painter, const QStyleOptionGraphic
Q_UNUSED(option); Q_UNUSED(option);
Q_UNUSED(widget); Q_UNUSED(widget);
QPainterPath path; QPainterPath path;
path.addRoundedRect(rect(), mFrameWidth / 2, mFrameWidth / 2); path.addRoundedRect(rect(), mFrameWidth / 2, mFrameWidth / 2);
if (rect().width() > 1 && rect().height() > 1) if (rect().width() > 1 && rect().height() > 1)
{ {
QPainterPath extruded; QPainterPath extruded;
extruded.addRect(rect().adjusted(mFrameWidth, mFrameWidth, (mFrameWidth * -1), (mFrameWidth * -1))); extruded.addRect(rect().adjusted(mFrameWidth, mFrameWidth + mTitleBarHeight, (mFrameWidth * -1), (mFrameWidth * -1)));
path = path.subtracted(extruded); path = path.subtracted(extruded);
} }
painter->fillPath(path, brush()); painter->fillPath(path, brush());
} }
QPainterPath UBGraphicsDelegateFrame::shape() const QPainterPath UBGraphicsDelegateFrame::shape() const
{ {
QPainterPath path; QPainterPath path;
@ -159,7 +160,7 @@ QPainterPath UBGraphicsDelegateFrame::shape() const
if (rect().width() > 0 && rect().height() > 0) if (rect().width() > 0 && rect().height() > 0)
{ {
QPainterPath extruded; QPainterPath extruded;
extruded.addRect(rect().adjusted(mFrameWidth, mFrameWidth, mFrameWidth * -1, mFrameWidth * -1)); extruded.addRect(rect().adjusted(mFrameWidth, mFrameWidth + mTitleBarHeight, mFrameWidth * -1, mFrameWidth * -1));
path = path.subtracted(extruded); path = path.subtracted(extruded);
} }
@ -395,8 +396,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return; return;
QLineF move = QLineF(mStartingPoint, event->scenePos()); QLineF move = QLineF(mStartingPoint, event->scenePos());
// qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
// qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
qreal moveX = (event->pos() - mStartingPoint).x(); qreal moveX = (event->pos() - mStartingPoint).x();
qreal moveY = (event->pos() - mStartingPoint).y(); qreal moveY = (event->pos() - mStartingPoint).y();
qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal width = delegated()->boundingRect().width() * mTotalScaleX;
@ -554,8 +553,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (resizingRight() || resizingBottom() || resizingBottomRight()) if (resizingRight() || resizingBottom() || resizingBottomRight())
{ {
QPointF ref;
// we just detects coordinates of corner before and after scaling and then moves object at diff between them. // we just detects coordinates of corner before and after scaling and then moves object at diff between them.
if (resizingBottomRight() && (mMirrorX || mMirrorY)) if (resizingBottomRight() && (mMirrorX || mMirrorY))
{ {
@ -827,7 +824,7 @@ void UBGraphicsDelegateFrame::positionHandles()
if (mVisible) if (mVisible)
{ {
setRect(center.x() - mFrameWidth - width / 2, center.y() - mFrameWidth - h / 2, width + 2 * mFrameWidth, h + 2 * mFrameWidth); setRect(center.x() - mFrameWidth - width / 2, center.y() - mFrameWidth - mTitleBarHeight - h / 2, width + 2 * mFrameWidth, h + 2 * (mFrameWidth + mTitleBarHeight));
} }
else else
{ {

@ -40,7 +40,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
{ {
public: public:
UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio = true); UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio = true, bool hasTitleBar = false);
virtual ~UBGraphicsDelegateFrame(); virtual ~UBGraphicsDelegateFrame();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -68,6 +68,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
QList<UBGraphicsDelegateFrame *> getLinkedFrames(); QList<UBGraphicsDelegateFrame *> getLinkedFrames();
private: private:
qreal mTitleBarHeight;
QRectF bottomRightResizeGripRect() const; QRectF bottomRightResizeGripRect() const;
QRectF bottomResizeGripRect() const; QRectF bottomResizeGripRect() const;
QRectF leftResizeGripRect() const; QRectF leftResizeGripRect() const;

@ -60,8 +60,6 @@
#include "core/memcheck.h" #include "core/memcheck.h"
class UBGraphicsParaschoolEditorWidgetItem;
DelegateButton::DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent, Qt::WindowFrameSection section) DelegateButton::DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent, Qt::WindowFrameSection section)
: QGraphicsSvgItem(fileName, parent) : QGraphicsSvgItem(fileName, parent)
, mDelegated(pDelegated) , mDelegated(pDelegated)
@ -187,7 +185,7 @@ void UBGraphicsItemDelegate::createControls()
mToolBarItem = new UBGraphicsToolBarItem(mDelegated); mToolBarItem = new UBGraphicsToolBarItem(mDelegated);
if (!mFrame) { if (!mFrame) {
mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, testUBFlags(GF_RESPECT_RATIO)); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, testUBFlags(GF_RESPECT_RATIO), testUBFlags(GF_TITLE_BAR_USED));
mFrame->hide(); mFrame->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
} }
@ -225,16 +223,15 @@ void UBGraphicsItemDelegate::createControls()
mButtons << mZOrderDownButton; mButtons << mZOrderDownButton;
} }
buildButtons(); buildButtons();
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
{
if (button->getSection() != Qt::TitleBarArea)
{ {
button->hide(); button->hide();
button->setFlag(QGraphicsItem::ItemIsSelectable, true); button->setFlag(QGraphicsItem::ItemIsSelectable, true);
} }
}
} }
void UBGraphicsItemDelegate::freeControls() void UBGraphicsItemDelegate::freeControls()
@ -242,7 +239,6 @@ void UBGraphicsItemDelegate::freeControls()
QGraphicsScene *controlsScene = delegated()->scene(); QGraphicsScene *controlsScene = delegated()->scene();
Q_ASSERT(controlsScene); Q_ASSERT(controlsScene);
UB_FREE_CONTROL(mFrame, controlsScene); UB_FREE_CONTROL(mFrame, controlsScene);
freeButtons(); freeButtons();
} }
@ -770,9 +766,13 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
if (showUpdated) if (showUpdated)
mDeleteButton->show(); mDeleteButton->show();
int i = 1, j = 0, k = 0; int i = 1, j = 0, k = 0, l = 0;
while ((i + j + k) < mButtons.size()) { int frameButtonHeight = mDeleteButton->boundingRect().size().height();
DelegateButton* button = mButtons[i + j]; qreal topXTitleBar = topX + (1.6 * mFrameWidth * mAntiScaleRatio);
qreal topYTitleBar = topY + frameButtonHeight + 10;
while ((i + j + k + l) < mButtons.size()) {
DelegateButton* button = mButtons[i + j + k + l];
if (button->getSection() == Qt::TopLeftSection) { if (button->getSection() == Qt::TopLeftSection) {
button->setParentItem(mFrame); button->setParentItem(mFrame);
@ -782,8 +782,14 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
button->setParentItem(mFrame); button->setParentItem(mFrame);
button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY); button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY);
button->setTransform(tr); button->setTransform(tr);
} else if (button->getSection() == Qt::TitleBarArea || button->getSection() == Qt::NoSection){ } else if (button->getSection() == Qt::TitleBarArea){
++k; button->setParentItem(mFrame);
button->setPos(topXTitleBar + (k++ * (frameButtonHeight + 5)), topYTitleBar);
button->setTransform(tr);
button->scale(0.8,0.8);
}
else if(button->getSection() == Qt::NoSection){
++l;
} }
if (!button->scene()) if (!button->scene())
{ {

@ -131,11 +131,6 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
} }
} }
else
{
Delegate()->getToolBarItem()->show();
}
} }
if (!data(UBGraphicsItemData::ItemEditable).toBool()) if (!data(UBGraphicsItemData::ItemEditable).toBool())
@ -246,9 +241,6 @@ void UBGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
if (widget == UBApplication::boardController->controlView()->viewport() && if (widget == UBApplication::boardController->controlView()->viewport() &&
!isSelected() && toPlainText().isEmpty()) !isSelected() && toPlainText().isEmpty())
{ {
// QFontMetrics fm(font());
// setTextWidth(fm.width(mTypeTextHereLabel));
painter->setFont(font()); painter->setFont(font());
painter->setPen(UBSettings::paletteColor); painter->setPen(UBSettings::paletteColor);
painter->drawText(boundingRect(), Qt::AlignCenter, mTypeTextHereLabel); painter->drawText(boundingRect(), Qt::AlignCenter, mTypeTextHereLabel);

@ -96,7 +96,7 @@ int AlignTextButton::nextKind() const
} }
UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject *) UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject *)
: UBGraphicsItemDelegate(pDelegated,0, GF_COMMON | GF_REVOLVABLE | GF_TOOLBAR_USED) : UBGraphicsItemDelegate(pDelegated,0, GF_COMMON | GF_REVOLVABLE | GF_TITLE_BAR_USED)
, mFontButton(0) , mFontButton(0)
, mColorButton(0) , mColorButton(0)
, mDecreaseSizeButton(0) , mDecreaseSizeButton(0)
@ -123,8 +123,6 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele
connect(delegated()->document(), SIGNAL(cursorPositionChanged(QTextCursor)), this, SLOT(onCursorPositionChanged(QTextCursor))); connect(delegated()->document(), SIGNAL(cursorPositionChanged(QTextCursor)), this, SLOT(onCursorPositionChanged(QTextCursor)));
connect(delegated()->document(), SIGNAL(modificationChanged(bool)), this, SLOT(onModificationChanged(bool))); connect(delegated()->document(), SIGNAL(modificationChanged(bool)), this, SLOT(onModificationChanged(bool)));
// NOOP
} }
UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate() UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate()
@ -157,47 +155,78 @@ QFont UBGraphicsTextItemDelegate::createDefaultFont()
return font; return font;
} }
void UBGraphicsTextItemDelegate::buildButtons() void UBGraphicsTextItemDelegate::createControls()
{ {
UBGraphicsItemDelegate::buildButtons(); UBGraphicsItemDelegate::createControls();
if (!mFontButton) { if (!mFontButton) {
mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TitleBarArea);
connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont())); connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont()));
mButtons << mFontButton;
} }
if (!mColorButton) { if (!mColorButton) {
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame, Qt::TitleBarArea);
connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor())); connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor()));
mButtons << mColorButton;
} }
if (!mDecreaseSizeButton) { if (!mDecreaseSizeButton) {
mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TitleBarArea);
connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize())); connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize()));
mButtons << mDecreaseSizeButton;
} }
if (!mIncreaseSizeButton) { if (!mIncreaseSizeButton) {
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::TitleBarArea);
connect(mIncreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(increaseSize())); connect(mIncreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(increaseSize()));
mButtons << mIncreaseSizeButton;
} }
// Alignment button
if (!mAlignButton) { if (!mAlignButton) {
mAlignButton = new AlignTextButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mAlignButton = new AlignTextButton(":/images/plus.svg", mDelegated, mFrame, Qt::TitleBarArea);
connect(mAlignButton, SIGNAL(clicked()), this, SLOT(alignButtonProcess())); connect(mAlignButton, SIGNAL(clicked()), this, SLOT(alignButtonProcess()));
mButtons << mAlignButton;
} }
foreach(DelegateButton* button, mButtons)
{
button->hide();
button->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
QList<QGraphicsItem*> itemsOnToolBar;
itemsOnToolBar << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton;
itemsOnToolBar << mAlignButton;
mToolBarItem->setItemsOnToolBar(itemsOnToolBar);
mToolBarItem->setShifting(true);
mToolBarItem->setVisibleOnBoard(true);
} }
void UBGraphicsTextItemDelegate::freeButtons()
{
mButtons.removeOne(mFontButton);
delete mFontButton;
mFontButton = 0;
mButtons.removeOne(mColorButton);
delete mColorButton;
mColorButton = 0;
mButtons.removeOne(mDecreaseSizeButton);
delete mDecreaseSizeButton;
mDecreaseSizeButton = 0;
mButtons.removeOne(mIncreaseSizeButton);
delete mIncreaseSizeButton;
mIncreaseSizeButton = 0;
mButtons.removeOne(mIncreaseSizeButton);
delete mIncreaseSizeButton;
mIncreaseSizeButton = 0;
UBGraphicsItemDelegate::freeButtons();
}
void UBGraphicsTextItemDelegate::contentsChanged() void UBGraphicsTextItemDelegate::contentsChanged()
{ {
positionHandles();
delegated()->contentsChanged(); delegated()->contentsChanged();
} }
@ -368,14 +397,12 @@ void UBGraphicsTextItemDelegate::onCursorPositionChanged(const QTextCursor &curs
qDebug() << "-----------------------"; qDebug() << "-----------------------";
qDebug() << "we have a selection!" << cursor.selectionStart(); qDebug() << "we have a selection!" << cursor.selectionStart();
qDebug() << "-----------------------"; qDebug() << "-----------------------";
// updateAlighButtonState();
} }
void UBGraphicsTextItemDelegate::onModificationChanged(bool ch) void UBGraphicsTextItemDelegate::onModificationChanged(bool ch)
{ {
Q_UNUSED(ch); Q_UNUSED(ch);
qDebug() << "modification changed"; qDebug() << "modification changed";
// updateAlighButtonState();
} }
void UBGraphicsTextItemDelegate::onContentChanged() void UBGraphicsTextItemDelegate::onContentChanged()
@ -428,46 +455,6 @@ void UBGraphicsTextItemDelegate::updateMenuActionState()
UBGraphicsItemDelegate::updateMenuActionState(); UBGraphicsItemDelegate::updateMenuActionState();
} }
void UBGraphicsTextItemDelegate::positionHandles()
{
UBGraphicsItemDelegate::positionHandles();
if (mDelegated->isSelected() || (mDelegated->parentItem() && UBGraphicsGroupContainerItem::Type == mDelegated->parentItem()->type()))
{
if (mToolBarItem->isVisibleOnBoard())
{
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->positionHandles();
mToolBarItem->update();
if (mToolBarItem->isShifting())
mToolBarItem->setPos(0,-mToolBarItem->boundingRect().height()*AntiScaleRatio);
else
mToolBarItem->setPos(0, 0);
UBGraphicsGroupContainerItem *group = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(mDelegated->parentItem());
mToolBarItem->hide();
if (mToolBarItem->parentItem())
{
if (group && group->getCurrentItem() == mDelegated && group->isSelected())
mToolBarItem->show();
if (!group)
mToolBarItem->show();
}
}
}
else
{
mToolBarItem->hide();
}
}
bool UBGraphicsTextItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsTextItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
mSelectionData.mButtonIsPressed = true; mSelectionData.mButtonIsPressed = true;

@ -111,7 +111,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
bool isEditable(); bool isEditable();
void scaleTextSize(qreal multiplyer); void scaleTextSize(qreal multiplyer);
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
virtual void createControls();
public slots: public slots:
void contentsChanged(); void contentsChanged();
@ -119,11 +119,10 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
virtual void remove(bool canUndo); virtual void remove(bool canUndo);
protected: protected:
virtual void buildButtons();
virtual void decorateMenu(QMenu *menu); virtual void decorateMenu(QMenu *menu);
virtual void updateMenuActionState(); virtual void updateMenuActionState();
virtual void positionHandles(); virtual void freeButtons();
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event); virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);

Loading…
Cancel
Save