fix _DTSizeItem visible
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
|
||||
_DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
||||
cur_item = 0;
|
||||
cur_item = nullptr;
|
||||
grid = 10.;
|
||||
in_process = can_drag = false;
|
||||
setData(bvidItemSelection, true);
|
||||
@@ -31,41 +31,44 @@ _DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
||||
|
||||
|
||||
_DTSizeItem::~_DTSizeItem() {
|
||||
assignObject(0);
|
||||
assignObject(nullptr);
|
||||
//qDebug() << "!!!";
|
||||
}
|
||||
|
||||
|
||||
void _DTSizeItem::assignObject(QGraphicsItem * item) {
|
||||
if (cur_item)
|
||||
if (qgraphicsitem_cast<QGraphicsItem*>(cur_item))
|
||||
cur_item->removeSceneEventFilter(this);
|
||||
if (cur_item) {
|
||||
cur_item->removeSceneEventFilter(this);
|
||||
}
|
||||
cur_item = item;
|
||||
if (!cur_item) {
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
rects[i].hide();
|
||||
rects[i].setParentItem(0);
|
||||
rects[i].setParentItem(nullptr);
|
||||
rects[i].removeSceneEventFilter(this);
|
||||
}
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
if (item)
|
||||
if (item->scene())
|
||||
if (!item->scene()->views().isEmpty())
|
||||
grid = ((BlockView*)(item->scene()->views()[0]))->gridStep();
|
||||
if (cur_item->scene()) {
|
||||
if (!cur_item->scene()->views().isEmpty()) {
|
||||
grid = qobject_cast<BlockView*>(cur_item->scene()->views()[0])->gridStep();
|
||||
}
|
||||
}
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
if (irect || iell || iline) {
|
||||
resizeHandles();
|
||||
is_line = qgraphicsitem_cast<QGraphicsLineItem*>(item);
|
||||
is_line = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
for (int i = 0; i < (is_line ? 2 : 8); ++i) {
|
||||
rects[i].setParentItem(item);
|
||||
rects[i].setParentItem(cur_item);
|
||||
rects[i].installSceneEventFilter(this);
|
||||
rects[i].show();
|
||||
}
|
||||
show();
|
||||
}
|
||||
item->installSceneEventFilter(this);
|
||||
cur_item->installSceneEventFilter(this);
|
||||
moveRects();
|
||||
}
|
||||
|
||||
@@ -95,12 +98,9 @@ void _DTSizeItem::applyRect() {
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
if (irect)
|
||||
irect->setRect(nrect);
|
||||
if (iell)
|
||||
iell->setRect(nrect);
|
||||
if (iline)
|
||||
iline->setLine(QLineF(nrect.topLeft(), nrect.bottomRight()));
|
||||
if (irect) irect->setRect(nrect);
|
||||
if (iell) iell->setRect(nrect);
|
||||
if (iline) iline->setLine(QLineF(nrect.topLeft(), nrect.bottomRight()));
|
||||
}
|
||||
|
||||
|
||||
@@ -120,30 +120,29 @@ void _DTSizeItem::doubleClick() {
|
||||
void _DTSizeItem::resizeHandles() {
|
||||
double sz = fontHeight() / 3.;
|
||||
QRectF r(-sz, -sz, sz*2, sz*2);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
rects[i].setRect(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QRectF _DTSizeItem::itemRect(const QGraphicsItem * item) const {
|
||||
QRectF _DTSizeItem::itemRect(const QGraphicsItem *) const {
|
||||
if (!cur_item) return QRectF();
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
if (irect)
|
||||
return irect->rect();
|
||||
if (iell)
|
||||
return iell->rect();
|
||||
if (iline)
|
||||
return QRectF(iline->line().p1(), iline->line().p2());
|
||||
if (irect) return irect->rect();
|
||||
if (iell) return iell->rect();
|
||||
if (iline) return QRectF(iline->line().p1(), iline->line().p2());
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
|
||||
QRectF _DTSizeItem::boundingRect() const {
|
||||
QRectF ret = rects[0].boundingRect().translated(rects[0].pos());
|
||||
for (int i = 1; i < 8; ++i)
|
||||
for (int i = 1; i < 8; ++i) {
|
||||
ret |= rects[i].boundingRect().translated(rects[i].pos());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -152,7 +151,7 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
QGraphicsSceneMouseEvent * me = (QGraphicsSceneMouseEvent * )event;
|
||||
if (watched == cur_item) {
|
||||
if (event->type() == QEvent::Close) {
|
||||
assignObject(0);
|
||||
assignObject(nullptr);
|
||||
return true;
|
||||
}
|
||||
if (event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
|
||||
@@ -161,9 +160,10 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
}
|
||||
return QGraphicsItem::sceneEventFilter(watched, event);
|
||||
}
|
||||
if (!cur_item)
|
||||
if (!cur_item) {
|
||||
return QGraphicsItem::sceneEventFilter(watched, event);
|
||||
view_ = 0;
|
||||
}
|
||||
view_ = nullptr;
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneHoverEnter:
|
||||
if (watched->scene()) if (!watched->scene()->views().isEmpty()) view_ = watched->scene()->views()[0];
|
||||
@@ -211,8 +211,7 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
}
|
||||
return true;
|
||||
case QEvent::GraphicsSceneMouseRelease:
|
||||
if (in_process)
|
||||
emit sizeChanged();
|
||||
if (in_process) emit sizeChanged();
|
||||
in_process = false;
|
||||
can_drag = false;
|
||||
return true;
|
||||
@@ -238,7 +237,7 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
int thick = lineThickness(this);
|
||||
QSize sz(fh * 2.5, fh);
|
||||
ui->comboLineStyle->setIconSize(sz);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
QPixmap pix(sz);
|
||||
pix.fill();
|
||||
QPainter p(&pix);
|
||||
@@ -257,8 +256,8 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
ui->buttonAlignHor->setMenu(&menu_hor);
|
||||
ui->buttonAlignVer->setMenu(&menu_ver);
|
||||
new_type = -1;
|
||||
new_item = cur_item = 0;
|
||||
view_ = 0;
|
||||
new_item = cur_item = nullptr;
|
||||
view_ = nullptr;
|
||||
resize_enabled = true;
|
||||
text_dlg.setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||
QDialogButtonBox * bbox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
||||
@@ -278,10 +277,12 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
buttons_align << ui->buttonAlignTL << ui->buttonAlignTC << ui->buttonAlignTR
|
||||
<< ui->buttonAlignCL << ui->buttonAlignCC << ui->buttonAlignCR
|
||||
<< ui->buttonAlignBL << ui->buttonAlignBC << ui->buttonAlignBR;
|
||||
foreach (QAction * a, actions_add)
|
||||
foreach (QAction * a, actions_add) {
|
||||
connect(a, SIGNAL(toggled(bool)), this, SLOT(toggleNewItem(bool)));
|
||||
foreach (QToolButton * b, buttons_align)
|
||||
}
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
connect(b, SIGNAL(clicked(bool)), this, SLOT(alignClicked()));
|
||||
}
|
||||
connect(ui->buttonImage, SIGNAL(clicked(bool)), this, SLOT(buttonImage_clicked()));
|
||||
connect(ui->buttonImagePaste, SIGNAL(clicked(bool)), this, SLOT(buttonImagePaste_clicked()));
|
||||
connect(ui->buttonFont, SIGNAL(clicked(bool)), this, SLOT(buttonFont_clicked()));
|
||||
@@ -321,7 +322,7 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
|
||||
|
||||
DrawTools::~DrawTools() {
|
||||
size_item.assignObject(0);
|
||||
size_item.assignObject(nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +330,9 @@ void DrawTools::retranslate() {
|
||||
QStringList styles;
|
||||
styles << tr("NoPen") << tr("Solid") << tr("Dash")
|
||||
<< tr("Dot") << tr("Dash-Dot") << tr("Dash-Dot-Dot");
|
||||
for (int i = 0; i < styles.size(); i++) ui->comboLineStyle->setItemText(i, styles[i]);
|
||||
for (int i = 0; i < styles.size(); i++) {
|
||||
ui->comboLineStyle->setItemText(i, styles[i]);
|
||||
}
|
||||
text_dlg.setWindowTitle(tr("Edit text"));
|
||||
actions_Z_up.setText(tr("Bring\nforward"));
|
||||
actions_Z_top.setText(tr("Bring\nto front"));
|
||||
@@ -361,33 +364,36 @@ void DrawTools::setAlignCompact(bool yes) {
|
||||
|
||||
|
||||
bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
QMouseEvent * me = (QMouseEvent*)e;
|
||||
QMouseEvent * me = (QMouseEvent *)e;
|
||||
QPointF sp;
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish)
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) {
|
||||
ui->labelPen->setMinimumSize(preferredIconSize(1.5, widget_props));
|
||||
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseMove)
|
||||
}
|
||||
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseMove) {
|
||||
sp = quantize(view_->mapToScene(me->pos()), view_->gridStep());
|
||||
}
|
||||
QRectF mr;
|
||||
switch (e->type()) {
|
||||
case QEvent::MouseButtonPress:
|
||||
if (new_type < 0) break;
|
||||
if (new_item) {
|
||||
delete new_item;
|
||||
new_item = 0;
|
||||
new_item = nullptr;
|
||||
if (!me->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
foreach (QAction * a, actions_add)
|
||||
foreach (QAction * a, actions_add) {
|
||||
a->setChecked(false);
|
||||
}
|
||||
new_type = -1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
new_item = 0;
|
||||
new_item = nullptr;
|
||||
pp = sp;
|
||||
switch (new_type) {
|
||||
case 0:
|
||||
new_item = new AlignedTextItem();
|
||||
((AlignedTextItem*)new_item)->setText("Text");
|
||||
((AlignedTextItem*)new_item)->setPos(sp);
|
||||
qgraphicsitem_cast<AlignedTextItem *>(new_item)->setText("Text");
|
||||
qgraphicsitem_cast<AlignedTextItem *>(new_item)->setPos(sp);
|
||||
break;
|
||||
case 1:
|
||||
new_item = new QGraphicsRectItem();
|
||||
@@ -397,15 +403,16 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
break;
|
||||
case 3:
|
||||
new_item = new QGraphicsPixmapItem(QPixmap(":/icons/view-preview.png"));
|
||||
((QGraphicsPixmapItem*)new_item)->setPos(sp - QPointF(new_item->boundingRect().width() / 2, new_item->boundingRect().height() / 2));
|
||||
qgraphicsitem_cast<QGraphicsPixmapItem *>(new_item)->setPos(sp - QPointF(new_item->boundingRect().width() / 2, new_item->boundingRect().height() / 2));
|
||||
break;
|
||||
case 4:
|
||||
new_item = new QGraphicsLineItem(QLineF(sp, sp));
|
||||
break;
|
||||
};
|
||||
if (new_item) {
|
||||
if (new_type == 1 || new_type == 2)
|
||||
((QAbstractGraphicsShapeItem*)new_item)->setBrush(Qt::white);
|
||||
if (new_type == 1 || new_type == 2) {
|
||||
qgraphicsitem_cast<QAbstractGraphicsShapeItem *>(new_item)->setBrush(Qt::white);
|
||||
}
|
||||
new_item->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
|
||||
new_item->setData(bvidBlockDecor, true);
|
||||
emit itemCreated(new_item);
|
||||
@@ -418,19 +425,19 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
mr = new_item->mapRectFromScene(QRectF(pp, sp).normalized());
|
||||
switch (new_type) {
|
||||
case 0:
|
||||
((AlignedTextItem*)new_item)->setPos(sp);
|
||||
qgraphicsitem_cast<AlignedTextItem *>(new_item)->setPos(sp);
|
||||
break;
|
||||
case 1:
|
||||
((QGraphicsRectItem*)new_item)->setRect(mr);
|
||||
qgraphicsitem_cast<QGraphicsRectItem *>(new_item)->setRect(mr);
|
||||
break;
|
||||
case 2:
|
||||
((QGraphicsEllipseItem*)new_item)->setRect(mr);
|
||||
qgraphicsitem_cast<QGraphicsEllipseItem *>(new_item)->setRect(mr);
|
||||
break;
|
||||
case 3:
|
||||
((QGraphicsPixmapItem*)new_item)->setPos(sp - QPointF(new_item->boundingRect().width() / 2, new_item->boundingRect().height() / 2));
|
||||
qgraphicsitem_cast<QGraphicsPixmapItem *>(new_item)->setPos(sp - QPointF(new_item->boundingRect().width() / 2, new_item->boundingRect().height() / 2));
|
||||
break;
|
||||
case 4:
|
||||
((QGraphicsLineItem*)new_item)->setLine(QLineF(pp, sp));
|
||||
qgraphicsitem_cast<QGraphicsLineItem *>(new_item)->setLine(QLineF(pp, sp));
|
||||
break;
|
||||
};
|
||||
return true;
|
||||
@@ -439,19 +446,20 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
if (new_item) {
|
||||
if (new_item->boundingRect().isEmpty())
|
||||
if (new_item->boundingRect().isEmpty()) {
|
||||
delete new_item;
|
||||
else {
|
||||
} else {
|
||||
emit itemAddConfirm(new_item);
|
||||
if (view_) {
|
||||
view_->selectNone();
|
||||
new_item->setSelected(true);
|
||||
}
|
||||
}
|
||||
new_item = 0;
|
||||
new_item = nullptr;
|
||||
if (!me->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
foreach (QAction * a, actions_add)
|
||||
foreach (QAction * a, actions_add) {
|
||||
a->setChecked(false);
|
||||
}
|
||||
new_type = -1;
|
||||
}
|
||||
return true;
|
||||
@@ -490,9 +498,9 @@ QAction * DrawTools::newAction(const QIcon & icon, int type) {
|
||||
|
||||
void DrawTools::toggleNewItem(bool on) {
|
||||
QAction * sa = (QAction * )sender();
|
||||
foreach (QAction * a, actions_add)
|
||||
if (a != sa)
|
||||
a->setChecked(false);
|
||||
foreach (QAction * a, actions_add) {
|
||||
if (a != sa) a->setChecked(false);
|
||||
}
|
||||
if (!on) {
|
||||
new_type = -1;
|
||||
view_->unsetCursor();
|
||||
@@ -505,9 +513,9 @@ void DrawTools::toggleNewItem(bool on) {
|
||||
|
||||
void DrawTools::alignClicked() {
|
||||
QToolButton * sb = (QToolButton * )sender();
|
||||
foreach (QToolButton * b, buttons_align)
|
||||
if (b != sb)
|
||||
b->setChecked(false);
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
if (b != sb) b->setChecked(false);
|
||||
}
|
||||
sb->setChecked(true);
|
||||
align = Qt::Alignment();
|
||||
QString als = sb->objectName().right(2).toLower();
|
||||
@@ -555,8 +563,9 @@ void DrawTools::blockPropSignals(bool block_) {
|
||||
ui->actionHCenter->blockSignals(block_);
|
||||
ui->actionLeft->blockSignals(block_);
|
||||
ui->actionRight->blockSignals(block_);
|
||||
foreach (QToolButton * b, buttons_align)
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
b->blockSignals(block_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -566,25 +575,27 @@ void DrawTools::actionAlignTrigger(bool vert, Qt::AlignmentFlag value) {
|
||||
else foreach (QAction * a, menu_hor.actions()) a->setChecked(false);
|
||||
align = align & (vert ? Qt::AlignHorizontal_Mask : Qt::AlignVertical_Mask);
|
||||
align |= value;
|
||||
((QAction*)sender())->setChecked(true);
|
||||
qobject_cast<QAction *>(sender())->setChecked(true);
|
||||
blockPropSignals(false);
|
||||
propertyChanged();
|
||||
}
|
||||
|
||||
|
||||
void DrawTools::emitZAvailabe(QGraphicsItem * item) {
|
||||
BlockView * view = 0;
|
||||
if (item) if (item->scene()) if (!item->scene()->views().isEmpty()) view = qobject_cast<BlockView * >(item->scene()->views()[0]);
|
||||
if (view == 0) {
|
||||
BlockView * view = nullptr;
|
||||
if (item) if (item->scene()) if (!item->scene()->views().isEmpty()) view = qobject_cast<BlockView *>(item->scene()->views()[0]);
|
||||
if (!view) {
|
||||
moveZUpAvailable(false);
|
||||
moveZDownAvailable(false);
|
||||
return;
|
||||
}
|
||||
QList<QGraphicsItem * > dl;
|
||||
if (item->parentItem() == 0) dl = view->decors();
|
||||
else {
|
||||
if (item->parentItem()->data(bvidType).toInt() == bvitBlock)
|
||||
dl = ((BlockItem*)(item->parentItem()))->decors_;
|
||||
QList<QGraphicsItem *> dl;
|
||||
if (!item->parentItem()) {
|
||||
dl = view->decors();
|
||||
} else {
|
||||
if (item->parentItem()->data(bvidType).toInt() == bvitBlock) {
|
||||
dl = qgraphicsitem_cast<BlockItem *>(item->parentItem())->decors_;
|
||||
}
|
||||
}
|
||||
if (dl.size() <= 1) {
|
||||
moveZUpAvailable(false);
|
||||
@@ -603,13 +614,13 @@ void DrawTools::emitZAvailabe(QGraphicsItem * item) {
|
||||
|
||||
|
||||
void DrawTools::selectionChanged() {
|
||||
cur_item = 0;
|
||||
size_item.assignObject(0);
|
||||
cur_item = nullptr;
|
||||
size_item.assignObject(nullptr);
|
||||
if (!view_) {
|
||||
emitZAvailabe();
|
||||
return;
|
||||
}
|
||||
QList<QGraphicsItem * > sil = view_->scene()->selectedItems();
|
||||
QList<QGraphicsItem *> sil = view_->scene()->selectedItems();
|
||||
if (sil.size() != 1) {
|
||||
emitZAvailabe();
|
||||
widget_props->setEnabled(false);
|
||||
@@ -621,12 +632,12 @@ void DrawTools::selectionChanged() {
|
||||
emitZAvailabe();
|
||||
return;
|
||||
}
|
||||
QGraphicsSimpleTextItem * itext = qgraphicsitem_cast<QGraphicsSimpleTextItem*>(cur_item);
|
||||
AlignedTextItem * iatext = qgraphicsitem_cast<AlignedTextItem*>(cur_item);
|
||||
QGraphicsPixmapItem * ipixmap = qgraphicsitem_cast<QGraphicsPixmapItem*>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
QGraphicsSimpleTextItem * itext = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(cur_item);
|
||||
AlignedTextItem * iatext = qgraphicsitem_cast<AlignedTextItem *>(cur_item);
|
||||
QGraphicsPixmapItem * ipixmap = qgraphicsitem_cast<QGraphicsPixmapItem *>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem *>(cur_item);
|
||||
blockPropSignals(true);
|
||||
if (itext) {
|
||||
ui->stackedProperties->setCurrentIndex(0);
|
||||
@@ -657,13 +668,15 @@ void DrawTools::selectionChanged() {
|
||||
if (align.testFlag(Qt::AlignLeft)) {als += "L"; ui->actionLeft->setChecked(true);}
|
||||
if (align.testFlag(Qt::AlignHCenter)) {als += "C"; ui->actionHCenter->setChecked(true);}
|
||||
if (align.testFlag(Qt::AlignRight)) {als += "R"; ui->actionRight->setChecked(true);}
|
||||
foreach (QToolButton * b, buttons_align)
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
b->setChecked(false);
|
||||
foreach (QToolButton * b, buttons_align)
|
||||
}
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
if (b->objectName().endsWith(als)) {
|
||||
b->setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ui->widgetAlign2->setEnabled(true);
|
||||
ui->widgetAlign9->setEnabled(true);
|
||||
size_item.assignObject(iatext);
|
||||
@@ -674,7 +687,7 @@ void DrawTools::selectionChanged() {
|
||||
size_item.assignObject(ipixmap);
|
||||
} else if (irect || iell) {
|
||||
ui->stackedProperties->setCurrentIndex(1);
|
||||
QAbstractGraphicsShapeItem * ishape(0);
|
||||
QAbstractGraphicsShapeItem * ishape = nullptr;
|
||||
if (irect) {
|
||||
ishape = irect;
|
||||
ui->spinWidth->setValue(irect->rect().width());
|
||||
@@ -691,8 +704,7 @@ void DrawTools::selectionChanged() {
|
||||
ui->spinThick->setValue(ishape->pen().widthF());
|
||||
ui->comboLineStyle->setCurrentIndex(qMin<int>((int)ishape->pen().style(), ui->comboLineStyle->count() - 1));
|
||||
setToolButtonsEnabled(true, true, true);
|
||||
if (resize_enabled)
|
||||
size_item.assignObject(ishape);
|
||||
if (resize_enabled) size_item.assignObject(ishape);
|
||||
}
|
||||
} else if (iline) {
|
||||
ui->stackedProperties->setCurrentIndex(1);
|
||||
@@ -700,8 +712,7 @@ void DrawTools::selectionChanged() {
|
||||
ui->spinThick->setValue(iline->pen().widthF());
|
||||
ui->comboLineStyle->setCurrentIndex(qMin<int>((int)iline->pen().style(), ui->comboLineStyle->count() - 1));
|
||||
setToolButtonsEnabled(true, false, false);
|
||||
if (resize_enabled)
|
||||
size_item.assignObject(iline);
|
||||
if (resize_enabled) size_item.assignObject(iline);
|
||||
} else {
|
||||
ui->stackedProperties->setCurrentIndex(3);
|
||||
widget_props->setEnabled(false);
|
||||
@@ -713,8 +724,8 @@ void DrawTools::selectionChanged() {
|
||||
|
||||
void DrawTools::sizeChanged() {
|
||||
blockPropSignals(true);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
|
||||
if (irect || iell) {
|
||||
if (irect) {
|
||||
ui->spinWidth->setValue(irect->rect().width());
|
||||
@@ -732,12 +743,12 @@ void DrawTools::sizeChanged() {
|
||||
|
||||
void DrawTools::propertyChanged() {
|
||||
if (!cur_item) return;
|
||||
QGraphicsSimpleTextItem * itext = qgraphicsitem_cast<QGraphicsSimpleTextItem*>(cur_item);
|
||||
AlignedTextItem * iatext = qgraphicsitem_cast<AlignedTextItem*>(cur_item);
|
||||
QGraphicsPixmapItem * ipixmap = qgraphicsitem_cast<QGraphicsPixmapItem*>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
QGraphicsSimpleTextItem * itext = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(cur_item);
|
||||
AlignedTextItem * iatext = qgraphicsitem_cast<AlignedTextItem *>(cur_item);
|
||||
QGraphicsPixmapItem * ipixmap = qgraphicsitem_cast<QGraphicsPixmapItem *>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem *>(cur_item);
|
||||
if (itext) {
|
||||
QRectF obr = itext->boundingRect();
|
||||
itext->setFont(font_dlg.currentFont());
|
||||
@@ -763,7 +774,7 @@ void DrawTools::propertyChanged() {
|
||||
QSizeF ds = (os - ns) / 2.;
|
||||
ipixmap->setPos(ipixmap->pos() + QPointF(ds.width(), ds.height()));
|
||||
} else if (irect || iell) {
|
||||
QAbstractGraphicsShapeItem * ishape(0);
|
||||
QAbstractGraphicsShapeItem * ishape = nullptr;
|
||||
if (irect) {
|
||||
ishape = irect;
|
||||
irect->setRect(QRectF(irect->rect().topLeft(), QSizeF(ui->spinWidth->value(), ui->spinHeight->value())));
|
||||
@@ -775,28 +786,24 @@ void DrawTools::propertyChanged() {
|
||||
if (ishape) {
|
||||
ishape->setPen(QPen(ui->colorButtonPen->color(), ui->spinThick->value(), (Qt::PenStyle)ui->comboLineStyle->currentIndex()));
|
||||
ishape->setBrush(ui->colorButtonBrush->color());
|
||||
if (resize_enabled)
|
||||
size_item.assignObject(ishape);
|
||||
if (resize_enabled) size_item.assignObject(ishape);
|
||||
}
|
||||
} else if (iline) {
|
||||
iline->setPen(QPen(ui->colorButtonPen->color(), ui->spinThick->value(), (Qt::PenStyle)ui->comboLineStyle->currentIndex()));
|
||||
if (resize_enabled)
|
||||
size_item.assignObject(iline);
|
||||
if (resize_enabled) size_item.assignObject(iline);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawTools::comboLineStyleChanged() {
|
||||
if (!cur_item) return;
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem*>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem*>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem*>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem *>(cur_item);
|
||||
if (irect || iell) {
|
||||
QAbstractGraphicsShapeItem * ishape(0);
|
||||
if (irect)
|
||||
ishape = irect;
|
||||
if (iell)
|
||||
ishape = iell;
|
||||
QAbstractGraphicsShapeItem * ishape = nullptr;
|
||||
if (irect) ishape = irect;
|
||||
if (iell) ishape = iell;
|
||||
if (ishape) {
|
||||
QPen p(ishape->pen());
|
||||
p.setStyle((Qt::PenStyle)ui->comboLineStyle->currentIndex());
|
||||
@@ -813,7 +820,7 @@ void DrawTools::comboLineStyleChanged() {
|
||||
|
||||
|
||||
void DrawTools::buttonImage_clicked() {
|
||||
QGraphicsPixmapItem * pi = qgraphicsitem_cast<QGraphicsPixmapItem * >(cur_item);
|
||||
QGraphicsPixmapItem * pi = qgraphicsitem_cast<QGraphicsPixmapItem *>(cur_item);
|
||||
if (!pi) return;
|
||||
QList<QByteArray> sif(QImageReader::supportedImageFormats());
|
||||
QString f;
|
||||
@@ -837,7 +844,7 @@ void DrawTools::buttonImage_clicked() {
|
||||
|
||||
|
||||
void DrawTools::buttonImagePaste_clicked() {
|
||||
QGraphicsPixmapItem * pi = qgraphicsitem_cast<QGraphicsPixmapItem * >(cur_item);
|
||||
QGraphicsPixmapItem * pi = qgraphicsitem_cast<QGraphicsPixmapItem *>(cur_item);
|
||||
if (!pi) return;
|
||||
QPixmap pm = QApplication::clipboard()->pixmap();
|
||||
if (pm.isNull()) return;
|
||||
@@ -852,8 +859,8 @@ void DrawTools::buttonImagePaste_clicked() {
|
||||
|
||||
void DrawTools::buttonFont_clicked() {
|
||||
if (!cur_item) return;
|
||||
QGraphicsSimpleTextItem * ti = qgraphicsitem_cast<QGraphicsSimpleTextItem * >(cur_item);
|
||||
AlignedTextItem * ati = qgraphicsitem_cast<AlignedTextItem * >(cur_item);
|
||||
QGraphicsSimpleTextItem * ti = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(cur_item);
|
||||
AlignedTextItem * ati = qgraphicsitem_cast<AlignedTextItem *>(cur_item);
|
||||
if (!ti && !ati) return;
|
||||
QFont font_prev;
|
||||
if (ti) font_prev = ti->font();
|
||||
@@ -861,10 +868,11 @@ void DrawTools::buttonFont_clicked() {
|
||||
font_dlg.blockSignals(true);
|
||||
font_dlg.setCurrentFont(font_prev);
|
||||
font_dlg.blockSignals(false);
|
||||
if (font_dlg.exec() == QDialog::Rejected)
|
||||
if (font_dlg.exec() == QDialog::Rejected) {
|
||||
font_dlg.setCurrentFont(font_prev);
|
||||
else
|
||||
} else {
|
||||
changeFinished();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -873,8 +881,7 @@ void DrawTools::buttonTextEdit_clicked() {
|
||||
text_edit.setPlainText(ui->comboText->lineEdit()->text());
|
||||
text_edit.selectAll();
|
||||
text_edit.setFocus();
|
||||
if (text_dlg.exec() == QDialog::Rejected)
|
||||
return;
|
||||
if (text_dlg.exec() == QDialog::Rejected) return;
|
||||
ui->comboText->lineEdit()->setText(text_edit.toPlainText());
|
||||
propertyChanged();
|
||||
changeFinished();
|
||||
@@ -884,12 +891,13 @@ void DrawTools::buttonTextEdit_clicked() {
|
||||
void DrawTools::actionZ_triggered() {
|
||||
if (!cur_item) return;
|
||||
if (cur_item->data(bvidType).toInt() == bvitDecor) {
|
||||
BlockView * view = 0;
|
||||
if (cur_item->scene()) if (!cur_item->scene()->views().isEmpty())
|
||||
view = qobject_cast<BlockView * >(cur_item->scene()->views()[0]);
|
||||
BlockView * view = nullptr;
|
||||
if (cur_item->scene()) if (!cur_item->scene()->views().isEmpty()) {
|
||||
view = qobject_cast<BlockView *>(cur_item->scene()->views()[0]);
|
||||
}
|
||||
if (!view) return;
|
||||
QGraphicsScene * scene = view->scene();
|
||||
QList<QGraphicsItem*> dl = view->decors();
|
||||
QList<QGraphicsItem *> dl = view->decors();
|
||||
scene->blockSignals(true);
|
||||
foreach (QGraphicsItem * d, dl) scene->removeItem(d);
|
||||
int ind = dl.indexOf(cur_item);
|
||||
@@ -902,10 +910,10 @@ void DrawTools::actionZ_triggered() {
|
||||
scene->blockSignals(false);
|
||||
}
|
||||
if (cur_item->data(bvidBlockDecor).toBool()) {
|
||||
BlockItem * bi = qgraphicsitem_cast<BlockItem*>(cur_item->parentItem());
|
||||
BlockItem * bi = qgraphicsitem_cast<BlockItem *>(cur_item->parentItem());
|
||||
if (!bi) return;
|
||||
QList<QGraphicsItem*> dl = bi->decors_;
|
||||
foreach (QGraphicsItem * d, dl) d->setParentItem(0);
|
||||
QList<QGraphicsItem *> dl = bi->decors_;
|
||||
foreach (QGraphicsItem * d, dl) d->setParentItem(nullptr);
|
||||
int ind = dl.indexOf(cur_item);
|
||||
dl.removeAt(ind);
|
||||
if (sender() == &actions_Z_up) dl.insert(ind + 1, cur_item);
|
||||
@@ -924,9 +932,8 @@ void DrawTools::actionZ_triggered() {
|
||||
void DrawTools::setResizeHandlesEnabled(bool on) {
|
||||
resize_enabled = on;
|
||||
if (!on) {
|
||||
size_item.assignObject(0);
|
||||
size_item.assignObject(nullptr);
|
||||
return;
|
||||
}
|
||||
if (cur_item && on)
|
||||
propertyChanged();
|
||||
if (cur_item && on) propertyChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user