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

@@ -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)

View File

@@ -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,

View File

@@ -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);

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);
}
@@ -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);
}
}

View File

@@ -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);

View File

@@ -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<int>(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<QGraphicsRectItem *>(cur_item);
QGraphicsEllipseItem * iell = qgraphicsitem_cast<QGraphicsEllipseItem *>(cur_item);
QGraphicsLineItem * iline = qgraphicsitem_cast<QGraphicsLineItem *>(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<QGraphicsPixmapItem *>(cur_item);
if (!pi) return;

View File

@@ -139,6 +139,7 @@ private slots:
actions_Z_down.setEnabled(yes);
actions_Z_bottom.setEnabled(yes);
}
void decorVisibleLogicChanged();
void buttonImage_clicked();
void buttonImagePaste_clicked();

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1197</width>
<height>268</height>
<width>1166</width>
<height>108</height>
</rect>
</property>
<property name="windowTitle">
@@ -29,7 +29,7 @@
<item>
<widget class="QStackedWidget" name="stackedProperties">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="pageText">
<layout class="QHBoxLayout" name="horizontalLayout_6">
@@ -686,12 +686,16 @@
</spacer>
</item>
<item>
<widget class="QLabel" name="labelPen">
<property name="pixmap">
<pixmap resource="qad_blockview.qrc">:/icons/format-stroke-color.png</pixmap>
<widget class="IconedLabel" name="labelPen">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="icon">
<iconset resource="qad_blockview.qrc">
<normaloff>:/icons/format-stroke-color.png</normaloff>:/icons/format-stroke-color.png</iconset>
</property>
</widget>
</item>
@@ -722,12 +726,16 @@
</spacer>
</item>
<item>
<widget class="QLabel" name="labelBrush">
<property name="pixmap">
<pixmap resource="qad_blockview.qrc">:/icons/format-fill-color.png</pixmap>
<widget class="IconedLabel" name="labelBrush">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="icon">
<iconset resource="qad_blockview.qrc">
<normaloff>:/icons/format-fill-color.png</normaloff>:/icons/format-fill-color.png</iconset>
</property>
</widget>
</item>
@@ -741,6 +749,68 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupShowLogic">
<property name="title">
<string>Visible logic</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="bottomMargin">
<number>4</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="checkVLEnabled">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkVLHovered">
<property name="text">
<string>Hovered</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkVLSelected">
<property name="text">
<string>Selected</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkVLInverse">
<property name="text">
<string>Iversed</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
<action name="actionTop">
<property name="checkable">
@@ -812,6 +882,11 @@
<extends>QPushButton</extends>
<header>colorbutton.h</header>
</customwidget>
<customwidget>
<class>IconedLabel</class>
<extends>QFrame</extends>
<header>iconedlabel.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="qad_blockview.qrc"/>

View File

@@ -696,29 +696,6 @@ BINARY_STREAM_READ(QImage) {
#endif
/// pure Qt
template<typename T>
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<typename T>
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

View File

@@ -306,4 +306,25 @@ QAD_UTILS_EXPORT void enableHighDPI();
QAD_UTILS_EXPORT const QMetaObject * getQtMetaObject();
template<typename T>
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<typename T>
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

View File

@@ -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());
}

View File

@@ -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