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. 34
      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_SHOW_CONTENT_SOURCE = 0x0200 //0000 0010 0000 0000
,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_DUPLICATION_ENABLED
|GF_MENU_SPECIFIED

@ -44,7 +44,7 @@
#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)
, mCurrentTool(None)
, mDelegate(pDelegate)
@ -65,13 +65,14 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
, mFlippedY(false)
, mMirrorX(false)
, mMirrorY(false)
, mTitleBarHeight(hasTitleBar ? 20 :0)
{
mAngleTolerance = UBSettings::settings()->angleTolerance->get().toReal();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
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));
setPen(Qt::NoPen);
@ -134,20 +135,20 @@ void UBGraphicsDelegateFrame::paint(QPainter *painter, const QStyleOptionGraphic
Q_UNUSED(option);
Q_UNUSED(widget);
QPainterPath path;
path.addRoundedRect(rect(), mFrameWidth / 2, mFrameWidth / 2);
if (rect().width() > 1 && rect().height() > 1)
{
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);
}
painter->fillPath(path, brush());
}
QPainterPath UBGraphicsDelegateFrame::shape() const
{
QPainterPath path;
@ -159,7 +160,7 @@ QPainterPath UBGraphicsDelegateFrame::shape() const
if (rect().width() > 0 && rect().height() > 0)
{
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);
}
@ -395,8 +396,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return;
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 moveY = (event->pos() - mStartingPoint).y();
qreal width = delegated()->boundingRect().width() * mTotalScaleX;
@ -554,8 +553,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (resizingRight() || resizingBottom() || resizingBottomRight())
{
QPointF ref;
// we just detects coordinates of corner before and after scaling and then moves object at diff between them.
if (resizingBottomRight() && (mMirrorX || mMirrorY))
{
@ -827,7 +824,7 @@ void UBGraphicsDelegateFrame::positionHandles()
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
{

@ -40,7 +40,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
{
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();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -68,6 +68,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
QList<UBGraphicsDelegateFrame *> getLinkedFrames();
private:
qreal mTitleBarHeight;
QRectF bottomRightResizeGripRect() const;
QRectF bottomResizeGripRect() const;
QRectF leftResizeGripRect() const;

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

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

@ -96,7 +96,7 @@ int AlignTextButton::nextKind() const
}
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)
, mColorButton(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(modificationChanged(bool)), this, SLOT(onModificationChanged(bool)));
// NOOP
}
UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate()
@ -157,47 +155,78 @@ QFont UBGraphicsTextItemDelegate::createDefaultFont()
return font;
}
void UBGraphicsTextItemDelegate::buildButtons()
void UBGraphicsTextItemDelegate::createControls()
{
UBGraphicsItemDelegate::buildButtons();
UBGraphicsItemDelegate::createControls();
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()));
mButtons << mFontButton;
}
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()));
mButtons << mColorButton;
}
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()));
mButtons << mDecreaseSizeButton;
}
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()));
mButtons << mIncreaseSizeButton;
}
// Alignment button
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()));
mButtons << mAlignButton;
}
foreach(DelegateButton* button, mButtons)
{
button->hide();
button->setFlag(QGraphicsItem::ItemIsSelectable, 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;
QList<QGraphicsItem*> itemsOnToolBar;
itemsOnToolBar << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton;
itemsOnToolBar << mAlignButton;
mToolBarItem->setItemsOnToolBar(itemsOnToolBar);
mToolBarItem->setShifting(true);
mToolBarItem->setVisibleOnBoard(true);
mButtons.removeOne(mIncreaseSizeButton);
delete mIncreaseSizeButton;
mIncreaseSizeButton = 0;
UBGraphicsItemDelegate::freeButtons();
}
void UBGraphicsTextItemDelegate::contentsChanged()
{
positionHandles();
delegated()->contentsChanged();
}
@ -368,14 +397,12 @@ void UBGraphicsTextItemDelegate::onCursorPositionChanged(const QTextCursor &curs
qDebug() << "-----------------------";
qDebug() << "we have a selection!" << cursor.selectionStart();
qDebug() << "-----------------------";
// updateAlighButtonState();
}
void UBGraphicsTextItemDelegate::onModificationChanged(bool ch)
{
Q_UNUSED(ch);
qDebug() << "modification changed";
// updateAlighButtonState();
}
void UBGraphicsTextItemDelegate::onContentChanged()
@ -428,46 +455,6 @@ void UBGraphicsTextItemDelegate::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)
{
mSelectionData.mButtonIsPressed = true;

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

Loading…
Cancel
Save