code format
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
#include "drawtools.h"
|
||||
#include "ui_drawtools.h"
|
||||
|
||||
#include "alignedtextitem.h"
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QImageReader>
|
||||
#include <QDialogButtonBox>
|
||||
#include "ui_drawtools.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QImageReader>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
_DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
||||
cur_item = nullptr;
|
||||
grid = 10.;
|
||||
cur_item = nullptr;
|
||||
grid = 10.;
|
||||
in_process = can_drag = false;
|
||||
setData(bvidItemSelection, true);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
//qDebug() << &(rects[i]);
|
||||
// qDebug() << &(rects[i]);
|
||||
rects[i].setData(bvidItemSelection, true);
|
||||
rects[i].setData(bvidDTHandle, true);
|
||||
rects[i].setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||
@@ -32,7 +34,7 @@ _DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
||||
|
||||
_DTSizeItem::~_DTSizeItem() {
|
||||
assignObject(nullptr);
|
||||
//qDebug() << "!!!";
|
||||
// qDebug() << "!!!";
|
||||
}
|
||||
|
||||
|
||||
@@ -52,15 +54,15 @@ void _DTSizeItem::assignObject(QGraphicsItem * item) {
|
||||
}
|
||||
if (cur_item->scene()) {
|
||||
if (!cur_item->scene()->views().isEmpty()) {
|
||||
grid = qobject_cast<BlockView*>(cur_item->scene()->views()[0])->gridStep();
|
||||
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);
|
||||
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*>(cur_item);
|
||||
is_line = qgraphicsitem_cast<QGraphicsLineItem *>(cur_item);
|
||||
for (int i = 0; i < (is_line ? 2 : 8); ++i) {
|
||||
rects[i].setParentItem(cur_item);
|
||||
rects[i].installSceneEventFilter(this);
|
||||
@@ -78,26 +80,36 @@ void _DTSizeItem::moveRects() {
|
||||
QRectF rect = itemRect(cur_item);
|
||||
QPointF tl = rect.topLeft(), tr = rect.topRight(), bl = rect.bottomLeft(), br = rect.bottomRight();
|
||||
if (is_line) {
|
||||
rects[0].setPos(tl); rects[0].setData(2001, int(Qt::SizeAllCursor));
|
||||
rects[1].setPos(br); rects[1].setData(2001, int(Qt::SizeAllCursor));
|
||||
rects[0].setPos(tl);
|
||||
rects[0].setData(2001, int(Qt::SizeAllCursor));
|
||||
rects[1].setPos(br);
|
||||
rects[1].setData(2001, int(Qt::SizeAllCursor));
|
||||
} else {
|
||||
rects[0].setPos(tl); rects[0].setData(2001, int(Qt::SizeFDiagCursor));
|
||||
rects[1].setPos((tl + tr) / 2.); rects[1].setData(2001, int(Qt::SizeVerCursor));
|
||||
rects[2].setPos(tr); rects[2].setData(2001, int(Qt::SizeBDiagCursor));
|
||||
rects[3].setPos((tr + br) / 2.); rects[3].setData(2001, int(Qt::SizeHorCursor));
|
||||
rects[4].setPos(br); rects[4].setData(2001, int(Qt::SizeFDiagCursor));
|
||||
rects[5].setPos((br + bl) / 2.); rects[5].setData(2001, int(Qt::SizeVerCursor));
|
||||
rects[6].setPos(bl); rects[6].setData(2001, int(Qt::SizeBDiagCursor));
|
||||
rects[7].setPos((bl + tl) / 2.); rects[7].setData(2001, int(Qt::SizeHorCursor));
|
||||
rects[0].setPos(tl);
|
||||
rects[0].setData(2001, int(Qt::SizeFDiagCursor));
|
||||
rects[1].setPos((tl + tr) / 2.);
|
||||
rects[1].setData(2001, int(Qt::SizeVerCursor));
|
||||
rects[2].setPos(tr);
|
||||
rects[2].setData(2001, int(Qt::SizeBDiagCursor));
|
||||
rects[3].setPos((tr + br) / 2.);
|
||||
rects[3].setData(2001, int(Qt::SizeHorCursor));
|
||||
rects[4].setPos(br);
|
||||
rects[4].setData(2001, int(Qt::SizeFDiagCursor));
|
||||
rects[5].setPos((br + bl) / 2.);
|
||||
rects[5].setData(2001, int(Qt::SizeVerCursor));
|
||||
rects[6].setPos(bl);
|
||||
rects[6].setData(2001, int(Qt::SizeBDiagCursor));
|
||||
rects[7].setPos((bl + tl) / 2.);
|
||||
rects[7].setData(2001, int(Qt::SizeHorCursor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _DTSizeItem::applyRect() {
|
||||
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) irect->setRect(nrect);
|
||||
if (iell) iell->setRect(nrect);
|
||||
if (iline) iline->setLine(QLineF(nrect.topLeft(), nrect.bottomRight()));
|
||||
@@ -105,21 +117,27 @@ void _DTSizeItem::applyRect() {
|
||||
|
||||
|
||||
void _DTSizeItem::doubleClick() {
|
||||
QGraphicsSimpleTextItem * itext = qgraphicsitem_cast<QGraphicsSimpleTextItem*>(cur_item);
|
||||
AlignedTextItem * iatext = qgraphicsitem_cast<AlignedTextItem*>(cur_item);
|
||||
QGraphicsPixmapItem * ipixmap = qgraphicsitem_cast<QGraphicsPixmapItem*>(cur_item);
|
||||
QGraphicsSimpleTextItem * itext = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(cur_item);
|
||||
AlignedTextItem * iatext = qgraphicsitem_cast<AlignedTextItem *>(cur_item);
|
||||
QGraphicsPixmapItem * ipixmap = qgraphicsitem_cast<QGraphicsPixmapItem *>(cur_item);
|
||||
if (itext || iatext) {
|
||||
QMetaObject::invokeMethod(this, [this](){textEditRequest();}, Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() { textEditRequest(); },
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
if (ipixmap) {
|
||||
QMetaObject::invokeMethod(this, [this](){pixmapEditRequest();}, Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() { pixmapEditRequest(); },
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _DTSizeItem::resizeHandles() {
|
||||
double sz = fontHeight() / 3.;
|
||||
QRectF r(-sz, -sz, sz*2, sz*2);
|
||||
QRectF r(-sz, -sz, sz * 2, sz * 2);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
rects[i].setRect(r);
|
||||
}
|
||||
@@ -128,9 +146,9 @@ void _DTSizeItem::resizeHandles() {
|
||||
|
||||
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);
|
||||
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());
|
||||
@@ -148,7 +166,7 @@ QRectF _DTSizeItem::boundingRect() const {
|
||||
|
||||
|
||||
bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
QGraphicsSceneMouseEvent * me = (QGraphicsSceneMouseEvent * )event;
|
||||
QGraphicsSceneMouseEvent * me = (QGraphicsSceneMouseEvent *)event;
|
||||
if (watched == cur_item) {
|
||||
if (event->type() == QEvent::Close) {
|
||||
assignObject(nullptr);
|
||||
@@ -166,11 +184,13 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
view_ = nullptr;
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneHoverEnter:
|
||||
if (watched->scene()) if (!watched->scene()->views().isEmpty()) view_ = watched->scene()->views()[0];
|
||||
if (watched->scene())
|
||||
if (!watched->scene()->views().isEmpty()) view_ = watched->scene()->views()[0];
|
||||
if (view_) view_->setCursor(Qt::CursorShape(watched->data(2001).toInt()));
|
||||
break;
|
||||
case QEvent::GraphicsSceneHoverLeave:
|
||||
if (watched->scene()) if (!watched->scene()->views().isEmpty()) view_ = watched->scene()->views()[0];
|
||||
if (watched->scene())
|
||||
if (!watched->scene()->views().isEmpty()) view_ = watched->scene()->views()[0];
|
||||
if (view_) view_->unsetCursor();
|
||||
break;
|
||||
case QEvent::GraphicsSceneMousePress:
|
||||
@@ -181,7 +201,7 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
moveRects();
|
||||
}
|
||||
in_process = false;
|
||||
pp = quantize(me->scenePos(), grid);
|
||||
pp = quantize(me->scenePos(), grid);
|
||||
cur_item->setData(2000, itemRect(cur_item));
|
||||
return true;
|
||||
case QEvent::GraphicsSceneMouseMove:
|
||||
@@ -189,7 +209,7 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
sp = quantize(me->scenePos(), grid);
|
||||
if (pp != sp && can_drag) {
|
||||
in_process = true;
|
||||
nrect = itemRect(cur_item);
|
||||
nrect = itemRect(cur_item);
|
||||
if (is_line) {
|
||||
if (watched == &(rects[0])) nrect.setTopLeft(rects[0].pos() + (sp - pp));
|
||||
if (watched == &(rects[1])) nrect.setBottomRight(rects[1].pos() + (sp - pp));
|
||||
@@ -213,7 +233,7 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
case QEvent::GraphicsSceneMouseRelease:
|
||||
if (in_process) emit sizeChanged();
|
||||
in_process = false;
|
||||
can_drag = false;
|
||||
can_drag = false;
|
||||
return true;
|
||||
default: break;
|
||||
}
|
||||
@@ -221,19 +241,21 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DrawTools::DrawTools(BlockView * parent): QWidget(parent),
|
||||
actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(this) {
|
||||
DrawTools::DrawTools(BlockView * parent)
|
||||
: QWidget(parent)
|
||||
, actions_Z_up(this)
|
||||
, actions_Z_top(this)
|
||||
, actions_Z_down(this)
|
||||
, actions_Z_bottom(this) {
|
||||
widget_props = new QWidget();
|
||||
ui = new Ui::DrawTools();
|
||||
ui = new Ui::DrawTools();
|
||||
ui->setupUi(widget_props);
|
||||
ui->labelPen->setMinimumSize(preferredIconSize(1.5, widget_props));
|
||||
ui->labelPen->setMaximumSize(ui->labelPen->minimumSize());
|
||||
ui->labelBrush->setMinimumSize(ui->labelPen->minimumSize());
|
||||
ui->labelBrush->setMaximumSize(ui->labelBrush->minimumSize());
|
||||
widget_props->setEnabled(false);
|
||||
int fh = qMax<int>(fontHeight(this), 22);
|
||||
int fh = qMax<int>(fontHeight(this), 22);
|
||||
int thick = lineThickness(this);
|
||||
QSize sz(fh * 2.5, fh);
|
||||
ui->comboLineStyle->setIconSize(sz);
|
||||
@@ -251,36 +273,37 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
#else
|
||||
setAlignCompact(false);
|
||||
#endif
|
||||
menu_hor.addActions(QList<QAction*>() << ui->actionLeft << ui->actionHCenter << ui->actionRight);
|
||||
menu_ver.addActions(QList<QAction*>() << ui->actionTop << ui->actionVCenter << ui->actionBottom);
|
||||
menu_hor.addActions(QList<QAction *>() << ui->actionLeft << ui->actionHCenter << ui->actionRight);
|
||||
menu_ver.addActions(QList<QAction *>() << ui->actionTop << ui->actionVCenter << ui->actionBottom);
|
||||
ui->buttonAlignHor->setMenu(&menu_hor);
|
||||
ui->buttonAlignVer->setMenu(&menu_ver);
|
||||
new_type = -1;
|
||||
new_item = cur_item = nullptr;
|
||||
view_ = nullptr;
|
||||
resize_enabled = true;
|
||||
view_ = nullptr;
|
||||
resize_enabled = true;
|
||||
text_dlg.setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||
QDialogButtonBox * bbox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
||||
connect(bbox, SIGNAL(accepted()), &text_dlg, SLOT(accept()));
|
||||
connect(bbox, SIGNAL(rejected()), &text_dlg, SLOT(reject()));
|
||||
text_dlg.layout()->addWidget(&text_edit);
|
||||
text_dlg.layout()->addWidget(bbox);
|
||||
actions_Z_up.setIcon(QIcon(":/icons/z-up.png")); actions_Z_up.setEnabled(false);
|
||||
actions_Z_top.setIcon(QIcon(":/icons/z-top.png")); actions_Z_top.setEnabled(false);
|
||||
actions_Z_down.setIcon(QIcon(":/icons/z-down.png")); actions_Z_down.setEnabled(false);
|
||||
actions_Z_bottom.setIcon(QIcon(":/icons/z-bottom.png")); actions_Z_bottom.setEnabled(false);
|
||||
actions_add << newAction(QIcon(":/icons/draw-rectangle.png"), 1)
|
||||
<< newAction(QIcon(":/icons/draw-ellipse.png"), 2)
|
||||
<< newAction(QIcon(":/icons/draw-line.png"), 4)
|
||||
<< newAction(QIcon(":/icons/draw-text.png"), 0)
|
||||
actions_Z_up.setIcon(QIcon(":/icons/z-up.png"));
|
||||
actions_Z_up.setEnabled(false);
|
||||
actions_Z_top.setIcon(QIcon(":/icons/z-top.png"));
|
||||
actions_Z_top.setEnabled(false);
|
||||
actions_Z_down.setIcon(QIcon(":/icons/z-down.png"));
|
||||
actions_Z_down.setEnabled(false);
|
||||
actions_Z_bottom.setIcon(QIcon(":/icons/z-bottom.png"));
|
||||
actions_Z_bottom.setEnabled(false);
|
||||
actions_add << newAction(QIcon(":/icons/draw-rectangle.png"), 1) << newAction(QIcon(":/icons/draw-ellipse.png"), 2)
|
||||
<< newAction(QIcon(":/icons/draw-line.png"), 4) << newAction(QIcon(":/icons/draw-text.png"), 0)
|
||||
<< newAction(QIcon(":/icons/view-preview.png"), 3);
|
||||
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) {
|
||||
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) {
|
||||
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()));
|
||||
@@ -328,8 +351,7 @@ DrawTools::~DrawTools() {
|
||||
|
||||
void DrawTools::retranslate() {
|
||||
QStringList styles;
|
||||
styles << tr("NoPen") << tr("Solid") << tr("Dash")
|
||||
<< tr("Dot") << tr("Dash-Dot") << tr("Dash-Dot-Dot");
|
||||
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]);
|
||||
}
|
||||
@@ -380,7 +402,7 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
delete new_item;
|
||||
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;
|
||||
@@ -388,26 +410,21 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
}
|
||||
new_item = nullptr;
|
||||
pp = sp;
|
||||
pp = sp;
|
||||
switch (new_type) {
|
||||
case 0:
|
||||
new_item = new AlignedTextItem();
|
||||
qgraphicsitem_cast<AlignedTextItem *>(new_item)->setText("Text");
|
||||
qgraphicsitem_cast<AlignedTextItem *>(new_item)->setPos(sp);
|
||||
break;
|
||||
case 1:
|
||||
new_item = new QGraphicsRectItem();
|
||||
break;
|
||||
case 2:
|
||||
new_item = new QGraphicsEllipseItem();
|
||||
break;
|
||||
case 1: new_item = new QGraphicsRectItem(); break;
|
||||
case 2: new_item = new QGraphicsEllipseItem(); break;
|
||||
case 3:
|
||||
new_item = new QGraphicsPixmapItem(QPixmap(":/icons/view-preview.png"));
|
||||
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));
|
||||
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) {
|
||||
@@ -424,21 +441,14 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
if (new_item) {
|
||||
mr = new_item->mapRectFromScene(QRectF(pp, sp).normalized());
|
||||
switch (new_type) {
|
||||
case 0:
|
||||
qgraphicsitem_cast<AlignedTextItem *>(new_item)->setPos(sp);
|
||||
break;
|
||||
case 1:
|
||||
qgraphicsitem_cast<QGraphicsRectItem *>(new_item)->setRect(mr);
|
||||
break;
|
||||
case 2:
|
||||
qgraphicsitem_cast<QGraphicsEllipseItem *>(new_item)->setRect(mr);
|
||||
break;
|
||||
case 0: qgraphicsitem_cast<AlignedTextItem *>(new_item)->setPos(sp); break;
|
||||
case 1: qgraphicsitem_cast<QGraphicsRectItem *>(new_item)->setRect(mr); break;
|
||||
case 2: qgraphicsitem_cast<QGraphicsEllipseItem *>(new_item)->setRect(mr); break;
|
||||
case 3:
|
||||
qgraphicsitem_cast<QGraphicsPixmapItem *>(new_item)->setPos(sp - QPointF(new_item->boundingRect().width() / 2, new_item->boundingRect().height() / 2));
|
||||
break;
|
||||
case 4:
|
||||
qgraphicsitem_cast<QGraphicsLineItem *>(new_item)->setLine(QLineF(pp, sp));
|
||||
qgraphicsitem_cast<QGraphicsPixmapItem *>(new_item)->setPos(
|
||||
sp - QPointF(new_item->boundingRect().width() / 2, new_item->boundingRect().height() / 2));
|
||||
break;
|
||||
case 4: qgraphicsitem_cast<QGraphicsLineItem *>(new_item)->setLine(QLineF(pp, sp)); break;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
@@ -457,7 +467,7 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
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;
|
||||
@@ -497,8 +507,8 @@ QAction * DrawTools::newAction(const QIcon & icon, int type) {
|
||||
|
||||
|
||||
void DrawTools::toggleNewItem(bool on) {
|
||||
QAction * sa = (QAction * )sender();
|
||||
foreach (QAction * a, actions_add) {
|
||||
QAction * sa = (QAction *)sender();
|
||||
foreach(QAction * a, actions_add) {
|
||||
if (a != sa) a->setChecked(false);
|
||||
}
|
||||
if (!on) {
|
||||
@@ -512,12 +522,12 @@ void DrawTools::toggleNewItem(bool on) {
|
||||
|
||||
|
||||
void DrawTools::alignClicked() {
|
||||
QToolButton * sb = (QToolButton * )sender();
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
QToolButton * sb = (QToolButton *)sender();
|
||||
foreach(QToolButton * b, buttons_align) {
|
||||
if (b != sb) b->setChecked(false);
|
||||
}
|
||||
sb->setChecked(true);
|
||||
align = Qt::Alignment();
|
||||
align = Qt::Alignment();
|
||||
QString als = sb->objectName().right(2).toLower();
|
||||
if (als[0] == 't') align |= Qt::AlignTop;
|
||||
if (als[0] == 'c') align |= Qt::AlignVCenter;
|
||||
@@ -563,7 +573,7 @@ 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_);
|
||||
}
|
||||
}
|
||||
@@ -571,8 +581,12 @@ void DrawTools::blockPropSignals(bool block_) {
|
||||
|
||||
void DrawTools::actionAlignTrigger(bool vert, Qt::AlignmentFlag value) {
|
||||
blockPropSignals(true);
|
||||
if (vert) foreach (QAction * a, menu_ver.actions()) a->setChecked(false);
|
||||
else foreach (QAction * a, menu_hor.actions()) a->setChecked(false);
|
||||
if (vert)
|
||||
foreach(QAction * a, menu_ver.actions())
|
||||
a->setChecked(false);
|
||||
else
|
||||
foreach(QAction * a, menu_hor.actions())
|
||||
a->setChecked(false);
|
||||
align = align & (vert ? Qt::AlignHorizontal_Mask : Qt::AlignVertical_Mask);
|
||||
align |= value;
|
||||
qobject_cast<QAction *>(sender())->setChecked(true);
|
||||
@@ -583,7 +597,9 @@ void DrawTools::actionAlignTrigger(bool vert, Qt::AlignmentFlag value) {
|
||||
|
||||
void DrawTools::emitZAvailabe(QGraphicsItem * item) {
|
||||
BlockView * view = nullptr;
|
||||
if (item) if (item->scene()) if (!item->scene()->views().isEmpty()) view = qobject_cast<BlockView *>(item->scene()->views()[0]);
|
||||
if (item)
|
||||
if (item->scene())
|
||||
if (!item->scene()->views().isEmpty()) view = qobject_cast<BlockView *>(item->scene()->views()[0]);
|
||||
if (!view) {
|
||||
moveZUpAvailable(false);
|
||||
moveZDownAvailable(false);
|
||||
@@ -633,11 +649,11 @@ void DrawTools::selectionChanged() {
|
||||
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);
|
||||
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);
|
||||
@@ -658,20 +674,40 @@ void DrawTools::selectionChanged() {
|
||||
font_dlg.setCurrentFont(iatext->font());
|
||||
font_dlg.blockSignals(false);
|
||||
setToolButtonsEnabled(true, false, false);
|
||||
foreach (QAction * a, menu_hor.actions()) a->setChecked(false);
|
||||
foreach (QAction * a, menu_ver.actions()) a->setChecked(false);
|
||||
foreach(QAction * a, menu_hor.actions())
|
||||
a->setChecked(false);
|
||||
foreach(QAction * a, menu_ver.actions())
|
||||
a->setChecked(false);
|
||||
align = iatext->alignment();
|
||||
QString als;
|
||||
if (align.testFlag(Qt::AlignTop)) {als += "T"; ui->actionTop->setChecked(true);}
|
||||
if (align.testFlag(Qt::AlignVCenter)) {als += "C"; ui->actionVCenter->setChecked(true);}
|
||||
if (align.testFlag(Qt::AlignBottom)) {als += "B"; ui->actionBottom->setChecked(true);}
|
||||
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) {
|
||||
if (align.testFlag(Qt::AlignTop)) {
|
||||
als += "T";
|
||||
ui->actionTop->setChecked(true);
|
||||
}
|
||||
if (align.testFlag(Qt::AlignVCenter)) {
|
||||
als += "C";
|
||||
ui->actionVCenter->setChecked(true);
|
||||
}
|
||||
if (align.testFlag(Qt::AlignBottom)) {
|
||||
als += "B";
|
||||
ui->actionBottom->setChecked(true);
|
||||
}
|
||||
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) {
|
||||
b->setChecked(false);
|
||||
}
|
||||
foreach (QToolButton * b, buttons_align) {
|
||||
foreach(QToolButton * b, buttons_align) {
|
||||
if (b->objectName().endsWith(als)) {
|
||||
b->setChecked(true);
|
||||
break;
|
||||
@@ -724,7 +760,7 @@ void DrawTools::selectionChanged() {
|
||||
|
||||
void DrawTools::sizeChanged() {
|
||||
blockPropSignals(true);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
|
||||
if (irect || iell) {
|
||||
if (irect) {
|
||||
@@ -744,17 +780,17 @@ 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);
|
||||
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());
|
||||
itext->setText(ui->comboText->currentText());
|
||||
QRectF nbr = itext->boundingRect();
|
||||
QSizeF ds = (obr.size() - nbr.size()) / 2.;
|
||||
QSizeF ds = (obr.size() - nbr.size()) / 2.;
|
||||
itext->setPos(itext->pos() + QPointF(ds.width(), ds.height()));
|
||||
itext->setBrush(ui->colorButtonPen->color());
|
||||
} else if (iatext) {
|
||||
@@ -764,8 +800,8 @@ void DrawTools::propertyChanged() {
|
||||
iatext->setAlignment(align);
|
||||
} else if (ipixmap) {
|
||||
QTransform t = ipixmap->transform();
|
||||
double det = sqrt(t.determinant());
|
||||
QSizeF os = ipixmap->boundingRect().size() * det;
|
||||
double det = sqrt(t.determinant());
|
||||
QSizeF os = ipixmap->boundingRect().size() * det;
|
||||
if (det != 0.) t.scale(1. / det, 1. / det);
|
||||
det = ui->spinScale->value();
|
||||
t.scale(det, det);
|
||||
@@ -797,9 +833,9 @@ void DrawTools::propertyChanged() {
|
||||
|
||||
void DrawTools::comboLineStyleChanged() {
|
||||
if (!cur_item) return;
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsRectItem * irect = qgraphicsitem_cast<QGraphicsRectItem *>(cur_item);
|
||||
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem *>(cur_item);
|
||||
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem *>(cur_item);
|
||||
if (irect || iell) {
|
||||
QAbstractGraphicsShapeItem * ishape = nullptr;
|
||||
if (irect) ishape = irect;
|
||||
@@ -824,7 +860,7 @@ void DrawTools::buttonImage_clicked() {
|
||||
if (!pi) return;
|
||||
QList<QByteArray> sif(QImageReader::supportedImageFormats());
|
||||
QString f;
|
||||
foreach (const QByteArray & i, sif) {
|
||||
foreach(const QByteArray & i, sif) {
|
||||
if (!f.isEmpty()) f += " ";
|
||||
f += "*.";
|
||||
f += i;
|
||||
@@ -833,11 +869,11 @@ void DrawTools::buttonImage_clicked() {
|
||||
if (ret.isEmpty()) return;
|
||||
QImage im(ret);
|
||||
if (im.isNull()) return;
|
||||
prev_dir = ret;
|
||||
prev_dir = ret;
|
||||
QRectF obr = pi->boundingRect();
|
||||
pi->setPixmap(QPixmap::fromImage(im));
|
||||
QRectF nbr = pi->boundingRect();
|
||||
QSizeF ds = (obr.size() - nbr.size()) / 2.;
|
||||
QSizeF ds = (obr.size() - nbr.size()) / 2.;
|
||||
pi->setPos(pi->pos() + QPointF(ds.width(), ds.height()));
|
||||
changeFinished();
|
||||
}
|
||||
@@ -851,7 +887,7 @@ void DrawTools::buttonImagePaste_clicked() {
|
||||
QRectF obr = pi->boundingRect();
|
||||
pi->setPixmap(pm);
|
||||
QRectF nbr = pi->boundingRect();
|
||||
QSizeF ds = (obr.size() - nbr.size()) / 2.;
|
||||
QSizeF ds = (obr.size() - nbr.size()) / 2.;
|
||||
pi->setPos(pi->pos() + QPointF(ds.width(), ds.height()));
|
||||
changeFinished();
|
||||
}
|
||||
@@ -860,7 +896,7 @@ 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);
|
||||
AlignedTextItem * ati = qgraphicsitem_cast<AlignedTextItem *>(cur_item);
|
||||
if (!ti && !ati) return;
|
||||
QFont font_prev;
|
||||
if (ti) font_prev = ti->font();
|
||||
@@ -892,28 +928,32 @@ void DrawTools::actionZ_triggered() {
|
||||
if (!cur_item) return;
|
||||
if (cur_item->data(bvidType).toInt() == bvitDecor) {
|
||||
BlockView * view = nullptr;
|
||||
if (cur_item->scene()) if (!cur_item->scene()->views().isEmpty()) {
|
||||
view = qobject_cast<BlockView *>(cur_item->scene()->views()[0]);
|
||||
}
|
||||
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();
|
||||
QGraphicsScene * scene = view->scene();
|
||||
QList<QGraphicsItem *> dl = view->decors();
|
||||
scene->blockSignals(true);
|
||||
foreach (QGraphicsItem * d, dl) scene->removeItem(d);
|
||||
foreach(QGraphicsItem * d, dl)
|
||||
scene->removeItem(d);
|
||||
int ind = dl.indexOf(cur_item);
|
||||
dl.removeAt(ind);
|
||||
if (sender() == &actions_Z_up) dl.insert(ind + 1, cur_item);
|
||||
if (sender() == &actions_Z_top) dl.append(cur_item);
|
||||
if (sender() == &actions_Z_down) dl.insert(ind - 1, cur_item);
|
||||
if (sender() == &actions_Z_bottom) dl.prepend(cur_item);
|
||||
foreach (QGraphicsItem * d, dl) scene->addItem(d);
|
||||
foreach(QGraphicsItem * d, dl)
|
||||
scene->addItem(d);
|
||||
scene->blockSignals(false);
|
||||
}
|
||||
if (cur_item->data(bvidBlockDecor).toBool()) {
|
||||
BlockItem * bi = qgraphicsitem_cast<BlockItem *>(cur_item->parentItem());
|
||||
if (!bi) return;
|
||||
QList<QGraphicsItem *> dl = bi->decors_;
|
||||
foreach (QGraphicsItem * d, dl) d->setParentItem(nullptr);
|
||||
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);
|
||||
@@ -921,7 +961,8 @@ void DrawTools::actionZ_triggered() {
|
||||
if (sender() == &actions_Z_down) dl.insert(ind - 1, cur_item);
|
||||
if (sender() == &actions_Z_bottom) dl.prepend(cur_item);
|
||||
bi->decors_ = dl;
|
||||
foreach (QGraphicsItem * d, dl) d->setParentItem(bi);
|
||||
foreach(QGraphicsItem * d, dl)
|
||||
d->setParentItem(bi);
|
||||
}
|
||||
size_item.assignObject(cur_item);
|
||||
emitZAvailabe(cur_item);
|
||||
|
||||
Reference in New Issue
Block a user