diff --git a/CMakeLists.txt b/CMakeLists.txt index d975692..8b502d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default project(QAD) set(QAD_MAJOR 2) -set(QAD_MINOR 16) -set(QAD_REVISION 3) +set(QAD_MINOR 17) +set(QAD_REVISION 0) set(QAD_SUFFIX ) set(QAD_COMPANY SHS) set(QAD_DOMAIN org.SHS) diff --git a/libs/blockview/blockbase.h b/libs/blockview/blockbase.h index cfa9bc1..d51ddda 100644 --- a/libs/blockview/blockbase.h +++ b/libs/blockview/blockbase.h @@ -48,8 +48,19 @@ enum BlockviewItemData { bvidBlockDecor, // bool item is BlockItem decor bvidDTHandle, // bool bvidCorrectMove, // bool + bvidDecorShowLogic, // uint }; +enum BlockviewDecorShowLogic { + bvdslAlways = 0x0, + bvdslEnabled = 0x1, + bvdslHovered = 0x2, + bvdslSelected = 0x4, + bvdslInverse = 0x8, +}; + +Q_DECLARE_FLAGS(BlockviewDecorShowLogics, BlockviewDecorShowLogic) + enum BlockviewItemType { bvitInvalid, bvitPin, diff --git a/libs/blockview/blockeditor.cpp b/libs/blockview/blockeditor.cpp index defd9e1..2366225 100644 --- a/libs/blockview/blockeditor.cpp +++ b/libs/blockview/blockeditor.cpp @@ -19,6 +19,7 @@ BlockEditor::BlockEditor(QWidget * parent): QWidget(parent), ui(new Ui::BlockEdi src_title = windowTitle(); connect(ui->blockView->scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); block.setFlags(QGraphicsItem::GraphicsItemFlags()); + block.is_blockeditor = true; ui->blockView->addItem(&block); ui->blockView->viewport()->installEventFilter(this); DrawTools * drawtools = new DrawTools(ui->blockView); diff --git a/libs/blockview/blockitem.cpp b/libs/blockview/blockitem.cpp index 539e96e..d078b9c 100644 --- a/libs/blockview/blockitem.cpp +++ b/libs/blockview/blockitem.cpp @@ -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(item)) qgraphicsitem_cast(item)->setTransformationMode(Qt::SmoothTransformation); @@ -179,9 +180,19 @@ QVector BlockItem::pinsOnSide(Qt::Alignment al) const { QByteArray BlockItem::saveModel() { + QVector 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 tp; QList dl; + QVector 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()); 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(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); + } } diff --git a/libs/blockview/blockitem.h b/libs/blockview/blockitem.h index e53a4e1..9ec017c 100644 --- a/libs/blockview/blockitem.h +++ b/libs/blockview/blockitem.h @@ -32,6 +32,7 @@ class QAD_BLOCKVIEW_EXPORT BlockItem friend class BlockView; friend class BlockItemPin; friend class DrawTools; + friend class BlockEditor; Q_OBJECT Q_PROPERTY(double _thickness READ thickness WRITE setThickness DESIGNABLE false SCRIPTABLE false) Q_PROPERTY(QRectF _selRect READ selectionRect WRITE setSelectionRect DESIGNABLE false SCRIPTABLE false) @@ -109,6 +110,8 @@ protected: double bottom() const { return boundingRect().bottom(); } void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr) {} QVariant itemChange(GraphicsItemChange change, const QVariant & value); + void setHovered(bool yes); + void procDecorShowLogic(); QGraphicsRectItem g_main, g_selection; int pins_margin; @@ -125,6 +128,7 @@ private: QPropertyAnimation anim_thick, anim_sel; QElapsedTimer t_sel; + bool is_hovered = false, is_blockeditor = false; signals: void blockHoverEnter(BlockItem * b); diff --git a/libs/blockview/drawtools.cpp b/libs/blockview/drawtools.cpp index 45ef5b8..49e4569 100644 --- a/libs/blockview/drawtools.cpp +++ b/libs/blockview/drawtools.cpp @@ -250,10 +250,8 @@ DrawTools::DrawTools(BlockView * parent) widget_props = new QWidget(); 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()); + ui->labelPen->setIconSizeAutoScale(1.5); + ui->labelBrush->setIconSizeAutoScale(1.5); widget_props->setEnabled(false); int fh = qMax(fontHeight(this), 22); int thick = lineThickness(this); @@ -331,6 +329,11 @@ DrawTools::DrawTools(BlockView * parent) connect(ui->actionLeft, SIGNAL(triggered(bool)), this, SLOT(actionLeft_triggered(bool))); connect(ui->actionHCenter, SIGNAL(triggered(bool)), this, SLOT(actionHCenter_triggered(bool))); connect(ui->actionRight, SIGNAL(triggered(bool)), this, SLOT(actionRight_triggered(bool))); + connect(ui->groupShowLogic, SIGNAL(toggled(bool)), this, SLOT(decorVisibleLogicChanged())); + connect(ui->checkVLEnabled, SIGNAL(toggled(bool)), this, SLOT(decorVisibleLogicChanged())); + connect(ui->checkVLHovered, SIGNAL(toggled(bool)), this, SLOT(decorVisibleLogicChanged())); + connect(ui->checkVLSelected, SIGNAL(toggled(bool)), this, SLOT(decorVisibleLogicChanged())); + connect(ui->checkVLInverse, SIGNAL(toggled(bool)), this, SLOT(decorVisibleLogicChanged())); connect(&font_dlg, SIGNAL(currentFontChanged(QFont)), this, SLOT(propertyChanged())); connect(&size_item, SIGNAL(sizeChanged()), this, SLOT(sizeChanged())); connect(&size_item, SIGNAL(textEditRequest()), this, SLOT(buttonTextEdit_clicked())); @@ -573,9 +576,13 @@ void DrawTools::blockPropSignals(bool block_) { ui->actionHCenter->blockSignals(block_); ui->actionLeft->blockSignals(block_); ui->actionRight->blockSignals(block_); - foreach(QToolButton * b, buttons_align) { + for (auto * b: buttons_align) b->blockSignals(block_); - } + ui->groupShowLogic->blockSignals(block_); + ui->checkVLEnabled->blockSignals(block_); + ui->checkVLHovered->blockSignals(block_); + ui->checkVLSelected->blockSignals(block_); + ui->checkVLInverse->blockSignals(block_); } @@ -643,8 +650,9 @@ void DrawTools::selectionChanged() { return; } widget_props->setEnabled(true); - cur_item = sil[0]; + if (!sil.isEmpty()) cur_item = sil[0]; if (!cur_item) { + ui->groupShowLogic->setEnabled(false); emitZAvailabe(); return; } @@ -654,8 +662,10 @@ void DrawTools::selectionChanged() { QGraphicsRectItem * irect = qgraphicsitem_cast(cur_item); QGraphicsEllipseItem * iell = qgraphicsitem_cast(cur_item); QGraphicsLineItem * iline = qgraphicsitem_cast(cur_item); + bool is_decor = false; blockPropSignals(true); if (itext) { + is_decor = true; ui->stackedProperties->setCurrentIndex(0); ui->comboText->setEditText(itext->text()); ui->colorButtonPen->setColor(itext->brush().color()); @@ -667,6 +677,7 @@ void DrawTools::selectionChanged() { ui->widgetAlign9->setEnabled(false); size_item.assignObject(itext); } else if (iatext) { + is_decor = true; ui->stackedProperties->setCurrentIndex(0); ui->comboText->setEditText(iatext->text()); ui->colorButtonPen->setColor(iatext->brush().color()); @@ -717,11 +728,13 @@ void DrawTools::selectionChanged() { ui->widgetAlign9->setEnabled(true); size_item.assignObject(iatext); } else if (ipixmap) { + is_decor = true; ui->stackedProperties->setCurrentIndex(2); ui->spinScale->setValue(sqrt(ipixmap->transform().determinant())); setToolButtonsEnabled(false, false, false); size_item.assignObject(ipixmap); } else if (irect || iell) { + is_decor = true; ui->stackedProperties->setCurrentIndex(1); QAbstractGraphicsShapeItem * ishape = nullptr; if (irect) { @@ -743,6 +756,7 @@ void DrawTools::selectionChanged() { if (resize_enabled) size_item.assignObject(ishape); } } else if (iline) { + is_decor = true; ui->stackedProperties->setCurrentIndex(1); ui->colorButtonPen->setColor(iline->pen().color()); ui->spinThick->setValue(iline->pen().widthF()); @@ -753,6 +767,15 @@ void DrawTools::selectionChanged() { ui->stackedProperties->setCurrentIndex(3); widget_props->setEnabled(false); } + ui->groupShowLogic->setEnabled(is_decor); + if (is_decor) { + BlockviewDecorShowLogics slf(cur_item->data(bvidDecorShowLogic).toUInt()); + ui->groupShowLogic->setChecked(slf != bvdslAlways); + ui->checkVLEnabled->setChecked(slf.testFlag(bvdslEnabled)); + ui->checkVLHovered->setChecked(slf.testFlag(bvdslHovered)); + ui->checkVLSelected->setChecked(slf.testFlag(bvdslSelected)); + ui->checkVLInverse->setChecked(slf.testFlag(bvdslInverse)); + } emitZAvailabe(cur_item); blockPropSignals(false); } @@ -855,6 +878,19 @@ void DrawTools::comboLineStyleChanged() { } +void DrawTools::decorVisibleLogicChanged() { + if (!cur_item) return; + uint f = 0; + if (ui->groupShowLogic->isChecked()) { + if (ui->checkVLEnabled->isChecked()) f |= bvdslEnabled; + if (ui->checkVLHovered->isChecked()) f |= bvdslHovered; + if (ui->checkVLSelected->isChecked()) f |= bvdslSelected; + if (ui->checkVLInverse->isChecked()) f |= bvdslInverse; + } + cur_item->setData(bvidDecorShowLogic, f); +} + + void DrawTools::buttonImage_clicked() { QGraphicsPixmapItem * pi = qgraphicsitem_cast(cur_item); if (!pi) return; diff --git a/libs/blockview/drawtools.h b/libs/blockview/drawtools.h index 0fafe71..572bee3 100644 --- a/libs/blockview/drawtools.h +++ b/libs/blockview/drawtools.h @@ -139,6 +139,7 @@ private slots: actions_Z_down.setEnabled(yes); actions_Z_bottom.setEnabled(yes); } + void decorVisibleLogicChanged(); void buttonImage_clicked(); void buttonImagePaste_clicked(); diff --git a/libs/blockview/drawtools.ui b/libs/blockview/drawtools.ui index 1977dcb..5f1ac52 100644 --- a/libs/blockview/drawtools.ui +++ b/libs/blockview/drawtools.ui @@ -6,8 +6,8 @@ 0 0 - 1197 - 268 + 1166 + 108 @@ -29,7 +29,7 @@ - 1 + 0 @@ -686,12 +686,16 @@ - - - :/icons/format-stroke-color.png + + + + 0 + 0 + - - true + + + :/icons/format-stroke-color.png:/icons/format-stroke-color.png @@ -722,12 +726,16 @@ - - - :/icons/format-fill-color.png + + + + 0 + 0 + - - true + + + :/icons/format-fill-color.png:/icons/format-fill-color.png @@ -741,6 +749,68 @@ + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 16 + 20 + + + + + + + + Visible logic + + + true + + + false + + + + 4 + + + + + Enabled + + + + + + + Hovered + + + + + + + Selected + + + + + + + Iversed + + + + + + @@ -812,6 +882,11 @@ QPushButton
colorbutton.h
+ + IconedLabel + QFrame +
iconedlabel.h
+
diff --git a/libs/piqt/piqt.h b/libs/piqt/piqt.h index 994a62a..6477c79 100644 --- a/libs/piqt/piqt.h +++ b/libs/piqt/piqt.h @@ -696,29 +696,6 @@ BINARY_STREAM_READ(QImage) { #endif -/// pure Qt - -template -QByteArray qSerialize(const T & value, int version = -1) { - QByteArray ret; - QDataStream s(&ret, QIODevice::ReadWrite); - if (version > 0) s.setVersion((QDataStream::Version)version); - s << value; - return ret; -} - -template -T qDeserialize(const QByteArray & data, int version = -1) { - T ret; - if (!data.isEmpty()) { - QDataStream s(data); - if (version > 0) s.setVersion((QDataStream::Version)version); - s >> ret; - } - return ret; -} - - /// PIP with QByteArray diff --git a/libs/utils/qad_types.h b/libs/utils/qad_types.h index 412a0b0..b7f7aef 100644 --- a/libs/utils/qad_types.h +++ b/libs/utils/qad_types.h @@ -306,4 +306,25 @@ QAD_UTILS_EXPORT void enableHighDPI(); QAD_UTILS_EXPORT const QMetaObject * getQtMetaObject(); +template +QByteArray qSerialize(const T & value, int version = -1) { + QByteArray ret; + QDataStream s(&ret, QIODevice::ReadWrite); + if (version > 0) s.setVersion((QDataStream::Version)version); + s << value; + return ret; +} + +template +T qDeserialize(const QByteArray & data, int version = -1) { + T ret; + if (!data.isEmpty()) { + QDataStream s(data); + if (version > 0) s.setVersion((QDataStream::Version)version); + s >> ret; + } + return ret; +} + + #endif // QAD_TYPES_H diff --git a/libs/widgets/iconedlabel.cpp b/libs/widgets/iconedlabel.cpp index 4e6f683..49b2c6d 100644 --- a/libs/widgets/iconedlabel.cpp +++ b/libs/widgets/iconedlabel.cpp @@ -55,7 +55,7 @@ void IconedLabel::checkSpacing() { QSize IconedLabel::realIconSize() const { - return size_.isValid() ? size_ : preferredIconSize(1.f, this); + return size_.isEmpty() ? preferredIconSize(m_iconSizeAutoScale, this) : size_; } @@ -96,3 +96,9 @@ void IconedLabel::setDirection(IconedLabel::Direction d) { checkSpacing(); update(); } + + +void IconedLabel::setIconSizeAutoScale(double newIconSizeAutoScale) { + m_iconSizeAutoScale = newIconSizeAutoScale; + setIconSize(iconSize()); +} diff --git a/libs/widgets/iconedlabel.h b/libs/widgets/iconedlabel.h index 0b185ed..71df5cd 100644 --- a/libs/widgets/iconedlabel.h +++ b/libs/widgets/iconedlabel.h @@ -33,6 +33,7 @@ class QAD_WIDGETS_EXPORT IconedLabel: public QFrame { Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) Q_PROPERTY(Direction direction READ direction WRITE setDirection) + Q_PROPERTY(double iconSizeAutoScale READ iconSizeAutoScale WRITE setIconSizeAutoScale) public: enum Direction { @@ -51,6 +52,9 @@ public: QLabel * textLabel() { return &label_; } + double iconSizeAutoScale() const { return m_iconSizeAutoScale; } + void setIconSizeAutoScale(double newIconSizeAutoScale); + public slots: void setText(const QString & t); void setIcon(const QIcon & i); @@ -66,6 +70,7 @@ protected: QIcon sicon_; QSize size_; Direction dir_; + double m_iconSizeAutoScale = 1.; }; #endif // ICONEDLABEL_H