version 2.17.0

iconedlabel icon size scale in auto scale mode
BlockItem decors visibility logic flags
This commit is contained in:
2023-06-05 23:26:23 +03:00
parent f6205cab55
commit 7ce2b31ec9
12 changed files with 243 additions and 78 deletions

View File

@@ -96,6 +96,7 @@ void BlockItem::removePin(BlockItemPin * pin) {
void BlockItem::addDecor(QGraphicsItem * item) {
if (!item) return;
if (decors_.contains(item)) return;
if (qgraphicsitem_cast<QGraphicsPixmapItem *>(item))
qgraphicsitem_cast<QGraphicsPixmapItem *>(item)->setTransformationMode(Qt::SmoothTransformation);
@@ -179,9 +180,19 @@ QVector<BlockItemPin *> BlockItem::pinsOnSide(Qt::Alignment al) const {
QByteArray BlockItem::saveModel() {
QVector<uint32_t> decor_vis_flags;
for (auto i: decors_)
decor_vis_flags << i->data(bvidDecorShowLogic).toUInt();
ChunkStream cs;
cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, size()) << cs.chunk(4, color()) << cs.chunk(5, pins())
<< cs.chunk(6, decors_) << cs.chunk(7, pins_margin) << cs.chunk(0xFF, _blockitem_current_version_);
cs.add(1, pos())
.add(2, rotation())
.add(3, size())
.add(4, color())
.add(5, pins())
.add(6, decors_)
.add(7, pins_margin)
.add(8, decor_vis_flags)
.add(0xFF, _blockitem_current_version_);
return cs.data();
}
@@ -196,6 +207,7 @@ void BlockItem::loadModel(const QByteArray & data) {
ChunkStream cs(data);
QVector<BlockItemPin *> tp;
QList<QGraphicsItem *> dl;
QVector<uint32_t> decor_vis_flags;
int version = -1;
while (!cs.atEnd()) {
switch (cs.read()) {
@@ -214,10 +226,14 @@ void BlockItem::loadModel(const QByteArray & data) {
addDecor(d);
break;
case 7: setPinsMargin(cs.getData<int>()); break;
case 8: cs.get(decor_vis_flags); break;
case 0xFF: cs.get(version); break;
}
}
for (int i = 0; i < qMin(decors_.size(), decor_vis_flags.size()); ++i)
decors_[i]->setData(bvidDecorShowLogic, decor_vis_flags[i]);
if (version <= 0) _moveToTop(true);
procDecorShowLogic();
}
@@ -228,9 +244,8 @@ QByteArray BlockItem::save() const {
// qDebug() << "save pin" << p->text() << "->" << p->properties().size();
pp[p->text()] = p->properties();
}
cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, props) << cs.chunk(5, pp) << cs.chunk(6, size());
cs << cs.chunk(10, data(2000)) << cs.chunk(11, data(2001)) << cs.chunk(12, prop_bindings)
<< cs.chunk(0xFF, _blockitem_current_version_);
cs.add(1, pos()).add(2, rotation()).add(3, props).add(5, pp).add(6, size());
cs.add(10, data(2000)).add(11, data(2001)).add(12, prop_bindings).add(0xFF, _blockitem_current_version_);
return cs.data();
}
@@ -284,16 +299,10 @@ BlockItem * BlockItem::copy() const {
np->properties() = p->properties();
ret->addPin(np);
}
QByteArray ba;
foreach(QGraphicsItem * i, decors_) {
ba.clear();
QGraphicsItem * ni = 0;
QDataStream s(&ba, QIODevice::ReadWrite);
s << i;
QDataStream s2(ba);
s2 >> ni;
if (ni) ret->addDecor(ni);
for (auto i: decors_) {
ret->addDecor(qDeserialize<QGraphicsItem *>(qSerialize(i)));
}
ret->procDecorShowLogic();
return ret;
}
@@ -332,27 +341,13 @@ QRectF BlockItem::boundingRect() const {
void BlockItem::hoverEnterEvent(QGraphicsSceneHoverEvent * e) {
bool anim = ((BlockView *)scene()->views().back())->isBlockAnimationEnabled();
if (anim) {
anim_thick.stop();
anim_thick.setStartValue(thickness());
anim_thick.setEndValue(2.5);
anim_thick.start();
} else
setThickness(2.5);
setHovered(true);
emit blockHoverEnter(this);
}
void BlockItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
bool anim = ((BlockView *)scene()->views().back())->isBlockAnimationEnabled();
if (anim) {
anim_thick.stop();
anim_thick.setStartValue(thickness());
anim_thick.setEndValue(1);
anim_thick.start();
} else
setThickness(1);
setHovered(false);
emit blockHoverLeave(this);
}
@@ -463,7 +458,7 @@ QStringList BlockItem::getBindProps() const {
QVariant BlockItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant & value) {
if (change == QGraphicsItem::ItemSelectedChange) {
// qDebug() << "select" << value.toBool();
// qDebug() << "select" << value.toBool();
if (value.toBool() && !isSelected() && ((BlockView *)scene()->views().back())->isBlockAnimationEnabled() && t_sel.elapsed() > 50) {
g_selection.setRect(enlargedRect(g_main.rect(), 0, 0, 16));
anim_sel.setStartValue(selectionRect());
@@ -473,7 +468,40 @@ QVariant BlockItem::itemChange(QGraphicsItem::GraphicsItemChange change, const Q
t_sel.restart();
g_selection.setVisible(value.toBool());
}
return QGraphicsItem::itemChange(change, value);
auto ret = QGraphicsItem::itemChange(change, value);
if (change == QGraphicsItem::ItemSelectedChange) procDecorShowLogic();
return ret;
}
void BlockItem::setHovered(bool yes) {
is_hovered = yes;
double thick = yes ? 2.5 : 1.;
if (((BlockView *)scene()->views().back())->isBlockAnimationEnabled()) {
anim_thick.stop();
anim_thick.setStartValue(thickness());
anim_thick.setEndValue(thick);
anim_thick.start();
} else
setThickness(thick);
procDecorShowLogic();
}
void BlockItem::procDecorShowLogic() {
if (is_blockeditor) return;
bool is_selected = g_selection.isVisible();
// qDebug() << "procDecorShowLogic" << is_selected << is_hovered;
for (auto i: decors_) {
BlockviewDecorShowLogics slf(i->data(bvidDecorShowLogic).toUInt());
if (slf == bvdslAlways) continue;
bool vis = false;
if (isEnabled() && slf.testFlag(bvdslEnabled)) vis = true;
if (is_hovered && slf.testFlag(bvdslHovered)) vis = true;
if (is_selected && slf.testFlag(bvdslSelected)) vis = true;
if (slf.testFlag(bvdslInverse)) vis = !vis;
i->setVisible(vis);
}
}