bug fixes, refactoring started
git-svn-id: svn://db.shs.com.ru/libs@590 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -18,16 +18,37 @@
|
||||
/// 1004 - BlockItemPin ("pin")
|
||||
/// 1005 - BlockBusItem ("connection")
|
||||
/// 1006 - BlockItem ("item")
|
||||
/// 1007 - BlockItem selection ("item_selection")
|
||||
/// 1007 - BlockItem selection (true)
|
||||
/// 1008 - item is NOT decor, ignore for function decors() (true)
|
||||
/// 1009 - item is scene decor ("decor")
|
||||
/// 1010 - BlockItem decor (src text for QGraphicsSimpleTextItem)
|
||||
/// 1011 - item is BlockItem decor ("decor")
|
||||
/// 1011 - item is BlockItem decor (true)
|
||||
/// 1100 - flag for correct move (true)
|
||||
|
||||
static const int _blockitem_current_version_ = 1;
|
||||
|
||||
|
||||
enum BlockviewItemData {
|
||||
bvidSelected = 1000, // bool
|
||||
bvidItemPos = 1001, // QpointF
|
||||
bvidMoveParent = 1002, // bool
|
||||
bvidVisualizeSelection = 1003, // bool
|
||||
bvidType = 1005, // BlockviewItemType
|
||||
bvidInvalidItem = 1008, // bool
|
||||
bvidDecorText = 1010, // QString
|
||||
bvidBlockDecor = 1011, // bool
|
||||
bvidCorrectMove = 1100, // bool
|
||||
};
|
||||
|
||||
enum BlockviewItemType {
|
||||
bvitPin,
|
||||
bvitBus,
|
||||
bvitBlock,
|
||||
bvitSelection,
|
||||
bvitDecor,
|
||||
bvitItemText,
|
||||
};
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const QGraphicsItem * item);
|
||||
QDataStream & operator >>(QDataStream & s, QGraphicsItem *& item);
|
||||
|
||||
|
||||
@@ -4,20 +4,6 @@
|
||||
#include "blockitem.h"
|
||||
|
||||
|
||||
/// data:
|
||||
/// 1002 - flag for move parent (true)
|
||||
/// 1003 - flag for visualize selection (true)
|
||||
/// 1004 - BlockItemPin ("pin")
|
||||
/// 1005 - BlockBusItem ("connection")
|
||||
/// 1006 - BlockItem ("item")
|
||||
/// 1007 - BlockItem selection ("item_selection")
|
||||
/// 1008 - item is NOT decor, ignore for function decors() (true)
|
||||
/// 1009 - item is scene decor ("decor")
|
||||
/// 1010 - BlockItem decor (src text for QGraphicsSimpleTextItem)
|
||||
/// 1011 - item is BlockItem decor ("decor")
|
||||
/// 1100 - flag for correct move (true)
|
||||
|
||||
|
||||
class BlockBusItem: public QGraphicsObject, public PropertyStorage {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
|
||||
@@ -11,7 +11,7 @@ g_main(this), g_selection(this) {
|
||||
setAcceptHoverEvents(true);
|
||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
|
||||
g_main.setData(1002, true);
|
||||
g_selection.setData(1007, "item_selection");
|
||||
g_selection.setData(1007, true);
|
||||
g_selection.setAcceptedMouseButtons(0);
|
||||
g_selection.setZValue(10.);
|
||||
g_selection.hide();
|
||||
@@ -121,7 +121,7 @@ void BlockItem::addDecor(QGraphicsItem * item) {
|
||||
if (qgraphicsitem_cast<AlignedTextItem*>(item))
|
||||
qgraphicsitem_cast<AlignedTextItem*>(item)->setData(1010, qgraphicsitem_cast<AlignedTextItem*>(item)->text());
|
||||
item->setData(1002, true);
|
||||
item->setData(1011, "decor");
|
||||
item->setData(1011, true);
|
||||
decors_ << item;
|
||||
item->setParentItem(this);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ void BlockItem::addDecor(QGraphicsItem & item) {
|
||||
if (qgraphicsitem_cast<AlignedTextItem*>(&item))
|
||||
qgraphicsitem_cast<AlignedTextItem*>(&item)->setData(1010, qgraphicsitem_cast<AlignedTextItem*>(&item)->text());
|
||||
item.setData(1002, true);
|
||||
item.setData(1011, "decor");
|
||||
item.setData(1011, true);
|
||||
//decors_ << &item;
|
||||
item.setParentItem(this);
|
||||
}
|
||||
|
||||
@@ -4,18 +4,6 @@
|
||||
#include "blockitempin.h"
|
||||
#include <QTime>
|
||||
|
||||
/// data:
|
||||
/// 1002 - flag for move parent (true)
|
||||
/// 1003 - flag for visualize selection (true)
|
||||
/// 1004 - BlockItemPin ("pin")
|
||||
/// 1005 - BlockBusItem ("connection")
|
||||
/// 1006 - BlockItem ("item")
|
||||
/// 1007 - BlockItem selection ("item_selection")
|
||||
/// 1008 - item is NOT decor, ignore for function decors() (true)
|
||||
/// 1009 - item is scene decor ("decor")
|
||||
/// 1010 - BlockItem decor (src text for QGraphicsSimpleTextItem)
|
||||
/// 1011 - item is BlockItem decor ("decor")
|
||||
/// 1100 - flag for correct move (true)
|
||||
|
||||
class BlockItem: public QGraphicsObject, public PropertyStorage
|
||||
{
|
||||
|
||||
@@ -95,46 +95,6 @@ void BlockView::_init() {
|
||||
sc.setAlphaF(0.2);
|
||||
sel_rect.setBrush(QBrush(sc));
|
||||
checkPaste(true);
|
||||
|
||||
/*AlignedTextItem * ti = new AlignedTextItem("This is text!");
|
||||
ti->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
ti->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
addItem(ti);
|
||||
ti->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
|
||||
ti->setText("text\nt");
|
||||
QGraphicsSimpleTextItem * t__ = new QGraphicsSimpleTextItem("TEXT");
|
||||
t__->setFlags(QGraphicsItem::ItemIsSelectable);
|
||||
addItem(t__);
|
||||
addItem(new QGraphicsLineItem(0, -50, 0, 50));
|
||||
addItem(new QGraphicsLineItem(-50, 0, 50, 0));
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
BlockItem * it = new BlockItem();
|
||||
it->setPos(i*150, i*20);
|
||||
it->addPin(new BlockItemPin());
|
||||
if (i == 2)
|
||||
it->setFlags(QGraphicsItem::ItemIsSelectable);
|
||||
scene_->addItem(it);
|
||||
}
|
||||
QGraphicsItem * it = new QGraphicsRectItem(0, 0, 200, 100);
|
||||
it->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
|
||||
it->setData(1001, true);
|
||||
scene_->addItem(it);
|
||||
|
||||
BlockBusItem * bus = new BlockBusItem();
|
||||
bus->setImages(QImage("icons/bus_twin.png"), QImage("icons/bus_end_rj45.png"));
|
||||
bus->setEndpointsNumber(3);
|
||||
bus->setBusType(1);
|
||||
bus->appendPoint(QPointF(20, 40));
|
||||
bus->appendPoint(QPointF(150, -20));
|
||||
bus->appendPoint(QPointF(40, -80));
|
||||
//bus->setImages(QImage("icons/bus_twin.png"), QImage("icons/bus_end_rj45.png"));
|
||||
addItem(bus);
|
||||
bus = new BlockBusItem();
|
||||
bus->appendPoint(QPointF(-20, 40));
|
||||
bus->appendPoint(QPointF(100, -30));
|
||||
bus->appendPoint(QPointF(20, -60));
|
||||
addItem(bus);*/
|
||||
}
|
||||
|
||||
|
||||
@@ -242,6 +202,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
mm_ci = 0;
|
||||
break;
|
||||
}
|
||||
if (mm_ci->data(1007).toBool()) break;
|
||||
}
|
||||
//qDebug() << "press";
|
||||
if (me->buttons().testFlag(Qt::LeftButton)) btncnt++;
|
||||
@@ -289,7 +250,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
//qDebug() << mil;
|
||||
while (!mil.isEmpty()) {
|
||||
mm_ci = mil.front();
|
||||
if (mm_ci->data(1008).toBool()) {
|
||||
if (mm_ci->data(1008).toBool() || mm_ci->data(1007).toBool()) {
|
||||
mil.pop_front();
|
||||
} else break;
|
||||
}
|
||||
@@ -377,6 +338,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
mm_ci = 0;
|
||||
break;
|
||||
}
|
||||
if (mm_ci->data(1007).toBool()) break;
|
||||
if (mm_cancel) return true;
|
||||
if (me->buttons().testFlag(Qt::LeftButton)) {
|
||||
if (!mm_drag) {
|
||||
@@ -541,6 +503,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
mm_ci = 0;
|
||||
break;
|
||||
}
|
||||
if (mm_ci->data(1007).toBool()) break;
|
||||
if (mm_copy) {
|
||||
QList<QGraphicsItem*> ai;
|
||||
blockSignals(true);
|
||||
@@ -1031,7 +994,7 @@ QList<BlockItem * > BlockView::blocks() const {
|
||||
QList<QGraphicsItem * > BlockView::decors() const {
|
||||
QList<QGraphicsItem*> ret, gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if ((i->data(1009) == "decor") && !i->data(1008).toBool() && (i->parentItem() == 0)
|
||||
if ((i->data(1009) == "decor") && !i->data(1008).toBool() && !i->data(1007).toBool() && (i->parentItem() == 0)
|
||||
&& (i != &sel_rect) && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i))
|
||||
ret << i;
|
||||
return ret;
|
||||
@@ -1185,7 +1148,7 @@ QRectF BlockView::itemsBoundingRect() const {
|
||||
QRectF ret;
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->isVisible() && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i)) {
|
||||
if ((i->data(1007) != "item_selection") && !i->data(1008).toBool()) {
|
||||
if (!(i->data(1007).toBool()) && !i->data(1008).toBool()) {
|
||||
QRectF br = i->mapRectToScene(i->boundingRect());
|
||||
if (br.width() <= 1 || br.height() <= 1) continue;
|
||||
if (f) ret = br;
|
||||
@@ -2061,7 +2024,7 @@ void BlockView::removeAll() {
|
||||
if (i->data(1006) == "item")
|
||||
ai << qgraphicsitem_cast<QGraphicsItem*>(i);
|
||||
if ((i->data(1006) == "item") || (i->data(1005) == "connection") || (i->data(1009) == "decor")) {
|
||||
if ((i != &sel_rect) && (i != &tmp_bus) && (i->parentItem() == 0) && !(i->data(1008).toBool())) {
|
||||
if ((i != &sel_rect) && (i != &tmp_bus) && (i->parentItem() == 0) && !(i->data(1008).toBool()) && !(i->data(1007).toBool())) {
|
||||
//qDebug() << "delete" << i->data(1004);
|
||||
scene_->sendEvent(i, new QGraphicsSceneEvent(QEvent::Close));
|
||||
delete i;
|
||||
|
||||
@@ -12,19 +12,6 @@
|
||||
#include "blockviewwavetrace.h"
|
||||
#include "blockbusitem.h"
|
||||
|
||||
/// data:
|
||||
/// 1002 - flag for move parent (true)
|
||||
/// 1003 - flag for visualize selection (true)
|
||||
/// 1004 - BlockItemPin ("pin")
|
||||
/// 1005 - BlockBusItem ("connection")
|
||||
/// 1006 - BlockItem ("item")
|
||||
/// 1007 - BlockItem selection ("item_selection")
|
||||
/// 1008 - item is NOT decor, ignore for function decors() (true)
|
||||
/// 1009 - item is scene decor ("decor")
|
||||
/// 1010 - BlockItem decor (src text for QGraphicsSimpleTextItem)
|
||||
/// 1011 - item is BlockItem decor ("decor")
|
||||
/// 1100 - flag for correct move (true)
|
||||
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ _DTSizeItem::_DTSizeItem(): QGraphicsObject() {
|
||||
cur_item = 0;
|
||||
grid = 10.;
|
||||
in_process = can_drag = false;
|
||||
setData(1008, true);
|
||||
setData(1007, true);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
//qDebug() << &(rects[i]);
|
||||
rects[i].setData(1008, true);
|
||||
rects[i].setData(1007, true);
|
||||
rects[i].setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||
rects[i].setZValue(10.);
|
||||
rects[i].setAcceptHoverEvents(true);
|
||||
@@ -508,11 +508,23 @@ void DrawTools::alignClicked() {
|
||||
}
|
||||
|
||||
|
||||
void DrawTools::setPenBrushEnabled(bool pen, bool brush) {
|
||||
void DrawTools::setTollButtonsEnabled(bool pen, bool brush, bool wid_hei) {
|
||||
ui->labelPen->setEnabled(pen);
|
||||
ui->colorButtonPen->setEnabled(pen);
|
||||
ui->labelBrush->setEnabled(brush);
|
||||
ui->colorButtonBrush->setEnabled(brush);
|
||||
ui->spinWidth->setEnabled(wid_hei);
|
||||
ui->spinHeight->setEnabled(wid_hei);
|
||||
ui->labelWidth->setEnabled(wid_hei);
|
||||
ui->labelHeight->setEnabled(wid_hei);
|
||||
ui->labelPen->setVisible(pen);
|
||||
ui->colorButtonPen->setVisible(pen);
|
||||
ui->labelBrush->setVisible(brush);
|
||||
ui->colorButtonBrush->setVisible(brush);
|
||||
ui->spinWidth->setVisible(wid_hei);
|
||||
ui->spinHeight->setVisible(wid_hei);
|
||||
ui->labelWidth->setVisible(wid_hei);
|
||||
ui->labelHeight->setVisible(wid_hei);
|
||||
}
|
||||
|
||||
|
||||
@@ -607,7 +619,7 @@ void DrawTools::selectionChanged() {
|
||||
font_dlg.blockSignals(true);
|
||||
font_dlg.setCurrentFont(itext->font());
|
||||
font_dlg.blockSignals(false);
|
||||
setPenBrushEnabled(true, false);
|
||||
setTollButtonsEnabled(true, false, false);
|
||||
ui->widgetAlign2->setEnabled(false);
|
||||
ui->widgetAlign9->setEnabled(false);
|
||||
size_item.assignObject(itext);
|
||||
@@ -618,7 +630,7 @@ void DrawTools::selectionChanged() {
|
||||
font_dlg.blockSignals(true);
|
||||
font_dlg.setCurrentFont(iatext->font());
|
||||
font_dlg.blockSignals(false);
|
||||
setPenBrushEnabled(true, false);
|
||||
setTollButtonsEnabled(true, false, false);
|
||||
foreach (QAction * a, menu_hor.actions()) a->setChecked(false);
|
||||
foreach (QAction * a, menu_ver.actions()) a->setChecked(false);
|
||||
align = iatext->alignment();
|
||||
@@ -642,7 +654,7 @@ void DrawTools::selectionChanged() {
|
||||
} else if (ipixmap) {
|
||||
ui->stackedProperties->setCurrentIndex(2);
|
||||
ui->spinScale->setValue(sqrt(ipixmap->transform().determinant()));
|
||||
setPenBrushEnabled(false, false);
|
||||
setTollButtonsEnabled(false, false, false);
|
||||
size_item.assignObject(ipixmap);
|
||||
} else if (irect || iell) {
|
||||
ui->stackedProperties->setCurrentIndex(1);
|
||||
@@ -662,7 +674,7 @@ void DrawTools::selectionChanged() {
|
||||
ui->colorButtonBrush->setColor(ishape->brush().color());
|
||||
ui->spinThick->setValue(ishape->pen().widthF());
|
||||
ui->comboLineStyle->setCurrentIndex(qMin<int>((int)ishape->pen().style(), ui->comboLineStyle->count() - 1));
|
||||
setPenBrushEnabled(true, true);
|
||||
setTollButtonsEnabled(true, true, true);
|
||||
if (resize_enabled)
|
||||
size_item.assignObject(ishape);
|
||||
}
|
||||
@@ -671,7 +683,7 @@ void DrawTools::selectionChanged() {
|
||||
ui->colorButtonPen->setColor(iline->pen().color());
|
||||
ui->spinThick->setValue(iline->pen().widthF());
|
||||
ui->comboLineStyle->setCurrentIndex(qMin<int>((int)iline->pen().style(), ui->comboLineStyle->count() - 1));
|
||||
setPenBrushEnabled(true, false);
|
||||
setTollButtonsEnabled(true, false, false);
|
||||
if (resize_enabled)
|
||||
size_item.assignObject(iline);
|
||||
} else {
|
||||
@@ -794,11 +806,11 @@ void DrawTools::buttonImage_clicked() {
|
||||
f += "*.";
|
||||
f += i;
|
||||
}
|
||||
QString ret = QFileDialog::getOpenFileName(0, trUtf8("Select image"), pi->data(1101).toString(), QString("Images(%1)").arg(f));
|
||||
QString ret = QFileDialog::getOpenFileName(0, trUtf8("Select image"), prev_dir, QString("Images(%1)").arg(f));
|
||||
if (ret.isEmpty()) return;
|
||||
QImage im(ret);
|
||||
if (im.isNull()) return;
|
||||
pi->setData(1101, ret);
|
||||
prev_dir = ret;
|
||||
QRectF obr = pi->boundingRect();
|
||||
pi->setPixmap(QPixmap::fromImage(im));
|
||||
QRectF nbr = pi->boundingRect();
|
||||
@@ -857,7 +869,7 @@ void DrawTools::actionZ_triggered() {
|
||||
if (!cur_item) return;
|
||||
if (cur_item->data(1009) == "decor") {
|
||||
BlockView * view = 0;
|
||||
if (cur_item) if (cur_item->scene()) if (!cur_item->scene()->views().isEmpty())
|
||||
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();
|
||||
@@ -873,7 +885,7 @@ void DrawTools::actionZ_triggered() {
|
||||
foreach (QGraphicsItem * d, dl) scene->addItem(d);
|
||||
scene->blockSignals(false);
|
||||
}
|
||||
if (cur_item->data(1011) == "decor") {
|
||||
if (cur_item->data(1011).toBool()) {
|
||||
BlockItem * bi = qgraphicsitem_cast<BlockItem*>(cur_item->parentItem());
|
||||
if (!bi) return;
|
||||
QList<QGraphicsItem*> dl = bi->decors_;
|
||||
|
||||
@@ -71,7 +71,7 @@ protected:
|
||||
bool eventFilter(QObject * o, QEvent * e);
|
||||
|
||||
QAction * newAction(const QString & text, const QIcon & icon, int type);
|
||||
void setPenBrushEnabled(bool pen, bool brush);
|
||||
void setTollButtonsEnabled(bool pen, bool brush, bool wid_hei);
|
||||
void blockPropSignals(bool block_);
|
||||
void actionAlignTrigger(bool vert, Qt::AlignmentFlag value);
|
||||
void emitZAvailabe(QGraphicsItem * item = 0);
|
||||
@@ -92,6 +92,7 @@ protected:
|
||||
Qt::Alignment align;
|
||||
int new_type;
|
||||
bool resize_enabled;
|
||||
QString prev_dir;
|
||||
|
||||
private slots:
|
||||
void toggleNewItem(bool on);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedProperties">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="pageText">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
@@ -460,7 +460,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="labelWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -495,7 +495,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<widget class="QLabel" name="labelThickness">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -511,7 +511,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="labelHeight">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -543,7 +543,7 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<widget class="QLabel" name="labelStyle">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
|
||||
Reference in New Issue
Block a user