Merge pull request #1398 from saschbe/fix/local-small-handles

Add smaller resize handle sizes
This commit is contained in:
Laurent Trinques
2026-10-08 16:29:07 +02:00
committed by GitHub
12 changed files with 561 additions and 26 deletions
@@ -34,10 +34,16 @@ QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size)
void QetGraphicsHandlerItem::setSize(qreal size)
{
if (m_size_animation) {
m_size_animation->stop();
m_size_animation->deleteLater();
m_size_animation.clear();
}
prepareGeometryChange();
m_current_size = m_original_size = size;
m_handler_rect.setRect(0-m_current_size/2, 0-m_current_size/2, m_current_size, m_current_size);
m_br.setRect(-1-m_current_size/2, -1-m_current_size/2, m_current_size+2, m_current_size+2);
update();
}
/**
@@ -90,7 +96,12 @@ void QetGraphicsHandlerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
auto animation_ = new QPropertyAnimation(this, "currentSize");
if (m_size_animation) {
m_size_animation->stop();
m_size_animation->deleteLater();
}
auto animation_ = new QPropertyAnimation(this, "currentSize", this);
m_size_animation = animation_;
animation_->setStartValue(m_original_size);
animation_->setEndValue(m_original_size*1.5);
animation_->setDuration(200);
@@ -102,7 +113,12 @@ void QetGraphicsHandlerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
auto animation_ = new QPropertyAnimation(this, "currentSize");
if (m_size_animation) {
m_size_animation->stop();
m_size_animation->deleteLater();
}
auto animation_ = new QPropertyAnimation(this, "currentSize", this);
m_size_animation = animation_;
animation_->setStartValue(m_current_size);
animation_->setEndValue(m_original_size);
animation_->setDuration(200);
@@ -126,7 +142,7 @@ void QetGraphicsHandlerItem::setCurrentSize(qreal size)
*/
QVector<QetGraphicsHandlerItem *> QetGraphicsHandlerItem::handlerForPoint(
const QVector<QPointF> &points,
int size)
qreal size)
{
QVector <QetGraphicsHandlerItem *> list_;
for (QPointF point : points)
@@ -20,6 +20,8 @@
#include <QGraphicsObject>
#include <QPen>
#include <QPointer>
class QPropertyAnimation;
/**
@brief The QetGraphicsHandlerItem class
@@ -69,10 +71,11 @@ class QetGraphicsHandlerItem : public QGraphicsObject
qreal m_original_size;
QColor m_color;
QPen m_pen;
QPointer<QPropertyAnimation> m_size_animation;
public:
static QVector<QetGraphicsHandlerItem *> handlerForPoint(
const QVector<QPointF> &points, int size = 10);
const QVector<QPointF> &points, qreal size = 10);
};
#endif // QETGRAPHICSHANDLERITEM_H
+22 -21
View File
@@ -22,24 +22,27 @@
#include "../projectview.h"
#include "../diagramview.h"
#include "../diagram.h"
#include "../../QetGraphicsItemModeler/qetgraphicshandleritem.h"
#include "../qetproject.h"
#include <QSignalBlocker>
#include "../QetGraphicsItemModeler/qetgraphicshandleritem.h"
DiagramEditorHandlerSizeWidget::DiagramEditorHandlerSizeWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DiagramEditorHandlerSizeWidget)
{
ui->setupUi(this);
const QSignalBlocker blocker(ui->comboBox);
const qreal sizes[] = {2.5, 5.0, 7.5, 10.0, 20.0, 30.0};
for (int i = 0; i < ui->comboBox->count(); ++i)
ui->comboBox->setItemData(i, sizes[i]);
ui->comboBox->setCurrentIndex(3); // x1 remains the default.
if (auto editor = QETApp::instance()->diagramEditorAncestorOf(this))
{
const auto size = editor->property("graphics_handler_size").toInt();
if (size == 10 || size < 10)
ui->comboBox->setCurrentIndex(0);
else if (size == 20)
ui->comboBox->setCurrentIndex(1);
else if (size == 30 || size > 30)
ui->comboBox->setCurrentIndex(2);
const auto size = editor->property("graphics_handler_size").toReal();
const int index = ui->comboBox->findData(size);
if (index >= 0)
ui->comboBox->setCurrentIndex(index);
}
}
@@ -50,20 +53,18 @@ DiagramEditorHandlerSizeWidget::~DiagramEditorHandlerSizeWidget()
void DiagramEditorHandlerSizeWidget::on_comboBox_currentIndexChanged(int index)
{
if (index < 0 || !ui->comboBox->itemData(index).isValid())
return;
const qreal size = ui->comboBox->itemData(index).toReal();
if (auto editor_ = QETApp::instance()->diagramEditorAncestorOf(this))
{
editor_->setProperty("graphics_handler_size", (index+1) * 10);
if (auto project_view = editor_->currentProjectView()) {
if (auto diagram_view = project_view->currentDiagram()) {
if (auto diagram = diagram_view->diagram())
{
for (const auto item : diagram->items())
{
if (item->type() == QetGraphicsHandlerItem::Type)
{
auto handler = qgraphicsitem_cast<QetGraphicsHandlerItem *>(item);
handler->setSize((index+1) * 10);
}
editor_->setProperty("graphics_handler_size", size);
for (auto project_view : editor_->openedProjects()) {
for (auto diagram : project_view->project()->diagrams()) {
for (const auto item : diagram->items()) {
if (item->type() == QetGraphicsHandlerItem::Type) {
auto handler = qgraphicsitem_cast<QetGraphicsHandlerItem *>(item);
handler->setSize(size);
}
}
}
@@ -23,6 +23,24 @@
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="currentIndex">
<number>3</number>
</property>
<item>
<property name="text">
<string>x 0,25</string>
</property>
</item>
<item>
<property name="text">
<string>x 0,5</string>
</property>
</item>
<item>
<property name="text">
<string>x 0,75</string>
</property>
</item>
<item>
<property name="text">
<string>x 1</string>