Skip to content

Commit 31866be

Browse files
committed
Add support for marker thickness
1 parent 3651997 commit 31866be

17 files changed

Lines changed: 87 additions & 76 deletions

File tree

plugins/robots/common/twoDModel/include/twoDModel/engine/model/metricSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TWO_D_MODEL_EXPORT SizeUnit
3737

3838
SizeUnit() = default;
3939

40+
// NOLINTNEXTLINE(google-explicit-constructor)
4041
SizeUnit(twoDModel::model::SizeUnit::Unit unit);
4142

4243
/// The current pixel value in centimeters

plugins/robots/common/twoDModel/src/engine/items/colorFieldItem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ void ColorFieldItem::setColor(const QColor &color)
7777
update();
7878
}
7979

80-
int ColorFieldItem::thickness() const
80+
qreal ColorFieldItem::thickness() const
8181
{
82-
return pen().width();
82+
return pen().widthF();
8383
}
8484

85-
void ColorFieldItem::setThickness(int thickness)
85+
void ColorFieldItem::setThickness(qreal thickness)
8686
{
8787
setPenWidth(thickness);
8888
update();

plugins/robots/common/twoDModel/src/engine/items/colorFieldItem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ColorFieldItem: public view::TwoDSceneItem
2424
Q_OBJECT
2525

2626
Q_PROPERTY(QColor color READ color WRITE setColor)
27-
Q_PROPERTY(int thickness READ thickness WRITE setThickness)
27+
Q_PROPERTY(qreal thickness READ thickness WRITE setThickness)
2828

2929
Q_DISABLE_COPY(ColorFieldItem)
3030

@@ -41,11 +41,11 @@ class ColorFieldItem: public view::TwoDSceneItem
4141
void setColor(const QColor &color);
4242

4343
/// Returns a thickness of this item in px.
44-
int thickness() const;
44+
qreal thickness() const;
4545

4646
/// Sets a thickness of this item.
4747
/// @param The thickness value in px.
48-
void setThickness(int thickness);
48+
void setThickness(qreal thickness);
4949

5050
/// Creates a copy of this graphical item. Transfers ownership to the caller.
5151
virtual AbstractItem *clone() const = 0;

plugins/robots/common/twoDModel/src/engine/view/parts/colorItemPopup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool ColorItemPopup::attachTo(const QList<QGraphicsItem *> &items)
7474
mBrushPicker->setVisible(hasProperty("filled"));
7575
mBrushPicker->setChecked(dominantPropertyValue("filled").toBool());
7676
mSpinBox->setVisible(hasProperty("thickness"));
77-
mSpinBox->setCurrentValue(dominantPropertyValue("thickness").toInt());
77+
mSpinBox->setCurrentValue(dominantPropertyValue("thickness").toDouble());
7878

7979
// Restoring values that really were picked by user.
8080
mLastColor = lastColorBackup;

plugins/robots/common/twoDModel/src/engine/view/parts/popupMetricWidget.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace twoDModel::view;
2424

2525
namespace {
2626
constexpr auto pixelMinimalValue = 1;
27-
constexpr auto pixelMaximumValue = 30;
27+
constexpr auto pixelMaximumValue = 50;
2828
}
2929

3030
PopupMetricWidget::~PopupMetricWidget() = default;
@@ -45,11 +45,11 @@ PopupMetricWidget::PopupMetricWidget(QWidget *parent): StackMetricWidget(parent)
4545

4646
createSpinBoxLambda(1, 0, twoDModel::model::SizeUnit::Unit::Pixels);
4747
createSpinBoxLambda(1, 0, twoDModel::model::SizeUnit::Unit::Millimeters);
48-
createSpinBoxLambda(0.1, 2, twoDModel::model::SizeUnit::Unit::Centimeters);
49-
createSpinBoxLambda(0.05, 3, twoDModel::model::SizeUnit::Unit::Meters);
48+
createSpinBoxLambda(0.1, 1, twoDModel::model::SizeUnit::Unit::Centimeters);
49+
createSpinBoxLambda(0.05, 2, twoDModel::model::SizeUnit::Unit::Meters);
5050
}
5151

52-
void PopupMetricWidget::setCurrentValue(int currentValuePx)
52+
void PopupMetricWidget::setCurrentValue(qreal currentValuePx)
5353
{
5454
mCurrentValuePx = currentValuePx;
5555
sizeUnitHandler(currentWidget());

plugins/robots/common/twoDModel/src/engine/view/parts/popupMetricWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PopupMetricWidget : public StackMetricWidget
2626
explicit PopupMetricWidget(QWidget *parent = nullptr);
2727
~PopupMetricWidget() override;
2828
void sizeUnitHandler(QWidget *currentWidget) override;
29-
void setCurrentValue(int currentValuePx);
29+
void setCurrentValue(qreal currentValuePx);
3030
Q_SIGNALS:
3131
void valueChanged(qreal value);
3232
private:

plugins/robots/common/twoDModel/src/engine/view/parts/robotItemPopup.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <QtWidgets/QSpinBox>
2020
#include <qrutils/graphicsUtils/abstractItem.h>
2121
#include <qrkernel/settingsManager.h>
22-
22+
#include "popupMetricWidget.h"
2323
#include "src/engine/view/scene/robotItem.h"
2424

2525
using namespace twoDModel::view;
@@ -30,19 +30,22 @@ RobotItemPopup::RobotItemPopup(graphicsUtils::AbstractScene &scene, QWidget *par
3030
initWidget();
3131
}
3232

33-
RobotItemPopup::~RobotItemPopup()
34-
{
35-
}
33+
RobotItemPopup::~RobotItemPopup() = default;
3634

3735
bool RobotItemPopup::suits(QGraphicsItem *item)
3836
{
3937
return dynamic_cast<RobotItem *>(item) != nullptr;
4038
}
4139

40+
void RobotItemPopup::onSizeUnitChanged(const QSharedPointer<twoDModel::model::SizeUnit> &unit)
41+
{
42+
mSpinBox->onSizeUnitChanged(unit);
43+
}
44+
4245
bool RobotItemPopup::attachTo(QGraphicsItem *item)
4346
{
4447
mCurrentItem = dynamic_cast<RobotItem *>(item);
45-
mSpinBox->setValue(mCurrentItem->pen().width());
48+
mSpinBox->setCurrentValue(mCurrentItem->pen().widthF());
4649

4750
const bool followingEnabled = qReal::SettingsManager::value("2dFollowingRobot").toBool();
4851
mFollowButton->setChecked(followingEnabled);
@@ -57,7 +60,7 @@ bool RobotItemPopup::attachTo(const QList<QGraphicsItem *> &items)
5760

5861
void RobotItemPopup::initWidget()
5962
{
60-
QGridLayout * const layout = new QGridLayout(this);
63+
auto * const layout = new QGridLayout(this);
6164
layout->addWidget(initFollowButton(), 0, 0, Qt::AlignCenter);
6265
layout->addWidget(initReturnButton(), 0, 1);
6366
layout->addWidget(initSpinBox(), 1, 0);
@@ -94,7 +97,7 @@ QWidget *RobotItemPopup::initSetStartButton()
9497

9598
QAbstractButton *RobotItemPopup::initButton(const QString &icon, const QString &toolTip)
9699
{
97-
QPushButton * const result = new QPushButton(
100+
auto * const result = new QPushButton(
98101
graphicsUtils::AbstractItem::loadThemedIcon(icon, Qt::red), QString(), this
99102
);
100103
result->setToolTip(toolTip);
@@ -105,14 +108,13 @@ QAbstractButton *RobotItemPopup::initButton(const QString &icon, const QString &
105108

106109
QWidget *RobotItemPopup::initSpinBox()
107110
{
108-
QSpinBox * const spinBox = new QSpinBox(this);
109-
spinBox->setRange(1, 30);
111+
auto * const spinBox = new PopupMetricWidget(this);
110112
spinBox->setToolTip(tr("Marker thickness"));
111113
QPalette spinBoxPalette;
112114
spinBoxPalette.setColor(QPalette::Window, Qt::transparent);
113115
spinBoxPalette.setColor(QPalette::Base, Qt::transparent);
114116
spinBox->setPalette(spinBoxPalette);
115-
connect(spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [=](int value) {
117+
connect(spinBox, &PopupMetricWidget::valueChanged, this, [=](qreal value) {
116118
mCurrentItem->setPenWidth(value);
117119
});
118120

plugins/robots/common/twoDModel/src/engine/view/parts/robotItemPopup.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ class QAbstractButton;
2020
class QSpinBox;
2121

2222
namespace twoDModel {
23+
24+
namespace model {
25+
class SizeUnit;
26+
}
27+
2328
namespace view {
2429

30+
class PopupMetricWidget;
2531
class RobotItem;
2632

2733
/// A popup for RobotItem on 2D model scene.
@@ -32,8 +38,9 @@ class RobotItemPopup : public graphicsUtils::ItemPopup
3238

3339
public:
3440
explicit RobotItemPopup(graphicsUtils::AbstractScene &scene, QWidget *parent = nullptr);
35-
~RobotItemPopup();
36-
41+
~RobotItemPopup() override;
42+
public Q_SLOTS:
43+
void onSizeUnitChanged(const QSharedPointer<twoDModel::model::SizeUnit> &unit);
3744
Q_SIGNALS:
3845
/// Emitted when user decides to follow or unfollow robot item.
3946
void followingChanged(bool enabled);
@@ -58,7 +65,7 @@ class RobotItemPopup : public graphicsUtils::ItemPopup
5865

5966
QAbstractButton *mFollowButton {}; // Takes ownership
6067
QAbstractButton *mReturnButton {}; // Takes ownership
61-
QSpinBox *mSpinBox {}; // Takes ownership
68+
PopupMetricWidget *mSpinBox {}; // Takes ownership
6269
QAbstractButton *mSetStartButton {}; // Takes ownership
6370
RobotItem *mCurrentItem {}; // Does not take ownership
6471
};

plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ void TwoDModelWidget::connectMetricComboBoxes()
11101110
mUi->horizontalRuler->onSizeUnitChanged(unit);
11111111
mUi->verticalRuler->onSizeUnitChanged(unit);
11121112
mColorFieldItemPopup->onSizeUnitChanged(unit);
1113+
mRobotItemPopup->onSizeUnitChanged(unit);
11131114
updateRobotInfoWidget(unit);
11141115
};
11151116

qrgui/mainWindow/shapeEdit/scene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ void Scene::changePenStyle(const QString &text)
525525
update();
526526
}
527527

528-
void Scene::changePenWidth(int width)
528+
void Scene::changePenWidth(qreal width)
529529
{
530530
mPenWidthItems = width;
531531
for (auto &&item : selectedSceneItems())

0 commit comments

Comments
 (0)