Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/axiscontrol.cpp
Show All 22 Lines | |||||
23 | #include <QHBoxLayout> | 23 | #include <QHBoxLayout> | ||
24 | #include <QLabel> | 24 | #include <QLabel> | ||
25 | 25 | | |||
26 | AxisControl::AxisControl(QWidget *parent) : | 26 | AxisControl::AxisControl(QWidget *parent) : | ||
27 | QWidget(parent) | 27 | QWidget(parent) | ||
28 | , sbValue(new QDoubleSpinBox) | 28 | , sbValue(new QDoubleSpinBox) | ||
29 | { | 29 | { | ||
30 | auto mainLayout = new QVBoxLayout; | 30 | auto mainLayout = new QVBoxLayout; | ||
31 | auto newLabel = new QLabel(tr("Move Axis")); | 31 | auto newLabel = new QLabel(tr("Move Axis"), this); | ||
32 | sbValue->setSuffix(QStringLiteral(" mm")); | 32 | sbValue->setSuffix(QStringLiteral(" mm")); | ||
33 | sbValue->setDecimals(3); | 33 | sbValue->setDecimals(3); | ||
34 | sbValue->setMaximum(100.0); | 34 | sbValue->setMaximum(100.0); | ||
35 | sbValue->setValue(1); | 35 | sbValue->setValue(1); | ||
36 | 36 | | |||
37 | auto comboUnits = new QComboBox(); | 37 | auto comboUnits = new QComboBox(this); | ||
38 | comboUnits->addItems(QStringList {QStringLiteral("Metric"), QStringLiteral("Imperial")}); | 38 | comboUnits->addItems(QStringList {QStringLiteral("Metric"), QStringLiteral("Imperial")}); | ||
39 | 39 | | |||
40 | connect(comboUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int selection) { | 40 | connect(comboUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int selection) { | ||
41 | if (selection == 0) { | 41 | if (selection == 0) { | ||
42 | sbValue->setSuffix(QStringLiteral(" mm")); | 42 | sbValue->setSuffix(QStringLiteral(" mm")); | ||
43 | } else { | 43 | } else { | ||
44 | sbValue->setSuffix(QStringLiteral(" in")); | 44 | sbValue->setSuffix(QStringLiteral(" in")); | ||
45 | } | 45 | } | ||
46 | emit unitsChanged(selection); | 46 | emit unitsChanged(selection); | ||
47 | }); | 47 | }); | ||
48 | 48 | | |||
49 | auto layout = new QHBoxLayout(); | 49 | auto layout = new QHBoxLayout(); | ||
50 | layout->addWidget(newLabel); | 50 | layout->addWidget(newLabel); | ||
51 | layout->addWidget(sbValue); | 51 | layout->addWidget(sbValue); | ||
52 | layout->addWidget(comboUnits); | 52 | layout->addWidget(comboUnits); | ||
53 | 53 | | |||
54 | auto newWidget = new QWidget(); | 54 | auto newWidget = new QWidget(this); | ||
55 | newWidget->setLayout(layout); | 55 | newWidget->setLayout(layout); | ||
56 | newWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | 56 | newWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | ||
57 | mainLayout->addWidget(newWidget); | 57 | mainLayout->addWidget(newWidget); | ||
58 | 58 | | |||
59 | QSize iconSize = QSize(fontMetrics().height(), fontMetrics().height()); | 59 | QSize iconSize = QSize(fontMetrics().height(), fontMetrics().height()); | ||
60 | auto glayout = new QGridLayout(); | 60 | auto glayout = new QGridLayout(); | ||
61 | newLabel = new QLabel(QStringLiteral("X/Y")); | 61 | newLabel = new QLabel(QStringLiteral("X/Y"), this); | ||
62 | newLabel->setAlignment(Qt::AlignCenter); | 62 | newLabel->setAlignment(Qt::AlignCenter); | ||
63 | glayout->addWidget(newLabel, 2, 1); | 63 | glayout->addWidget(newLabel, 2, 1); | ||
64 | 64 | | |||
65 | //Y-Axis | 65 | //Y-Axis | ||
66 | glayout->addWidget(makeButton(QLatin1Char('Y'), 1, iconSize, QStringLiteral("arrow-up"), QStringLiteral("↑")), 1, 1); | 66 | glayout->addWidget(makeButton(QLatin1Char('Y'), 1, iconSize, QStringLiteral("arrow-up"), QStringLiteral("↑")), 1, 1); | ||
67 | glayout->addWidget(makeButton(QLatin1Char('Y'), -1, iconSize, QStringLiteral("arrow-down"), QStringLiteral("↓")), 3, 1); | 67 | glayout->addWidget(makeButton(QLatin1Char('Y'), -1, iconSize, QStringLiteral("arrow-down"), QStringLiteral("↓")), 3, 1); | ||
68 | 68 | | |||
69 | //X-Axis | 69 | //X-Axis | ||
Show All 10 Lines | |||||
80 | bottomLayout->addWidget(newWidget); | 80 | bottomLayout->addWidget(newWidget); | ||
81 | 81 | | |||
82 | mainLayout->addItem(bottomLayout); | 82 | mainLayout->addItem(bottomLayout); | ||
83 | setLayout(mainLayout); | 83 | setLayout(mainLayout); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | QPushButton *AxisControl::makeButton(const QLatin1Char axis, int multiplier, const QSize &iconSize, const QString &themeIcon, const QString &fallbackText) | 86 | QPushButton *AxisControl::makeButton(const QLatin1Char axis, int multiplier, const QSize &iconSize, const QString &themeIcon, const QString &fallbackText) | ||
87 | { | 87 | { | ||
88 | auto button = new QPushButton(QIcon::fromTheme(themeIcon), QString()); | 88 | auto button = new QPushButton(QIcon::fromTheme(themeIcon), QString(), this); | ||
89 | button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | 89 | button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | ||
90 | if (button->icon().isNull()) { | 90 | if (button->icon().isNull()) { | ||
91 | button->setText(fallbackText); | 91 | button->setText(fallbackText); | ||
92 | } else { | 92 | } else { | ||
93 | button->setIconSize(iconSize); | 93 | button->setIconSize(iconSize); | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | connect(button, &QPushButton::clicked, this, [this, axis, multiplier] { | 96 | connect(button, &QPushButton::clicked, this, [this, axis, multiplier] { | ||
97 | emit clicked(axis, sbValue->value() *multiplier); | 97 | emit clicked(axis, sbValue->value() *multiplier); | ||
98 | }); | 98 | }); | ||
99 | return button; | 99 | return button; | ||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | QWidget *AxisControl::makeSimpleAxis(const QLatin1Char axis, const QSize &iconSize) | 102 | QWidget *AxisControl::makeSimpleAxis(const QLatin1Char axis, const QSize &iconSize) | ||
103 | { | 103 | { | ||
104 | int multiplier = 1; | 104 | int multiplier = 1; | ||
105 | if (axis == QLatin1Char('E')) { | 105 | if (axis == QLatin1Char('E')) { | ||
106 | multiplier = -1; | 106 | multiplier = -1; | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | auto vLayout = new QVBoxLayout; | 109 | auto vLayout = new QVBoxLayout; | ||
110 | 110 | | |||
111 | vLayout->addWidget(makeButton(axis, multiplier, iconSize, QStringLiteral("arrow-up"), QStringLiteral("↑"))); | 111 | vLayout->addWidget(makeButton(axis, multiplier, iconSize, QStringLiteral("arrow-up"), QStringLiteral("↑"))); | ||
112 | 112 | | |||
113 | auto label = new QLabel(QString(axis)); | 113 | auto label = new QLabel(QString(axis), this); | ||
114 | label->setAlignment(Qt::AlignCenter); | 114 | label->setAlignment(Qt::AlignCenter); | ||
115 | vLayout->addWidget(label); | 115 | vLayout->addWidget(label); | ||
116 | 116 | | |||
117 | multiplier *= -1; | 117 | multiplier *= -1; | ||
118 | vLayout->addWidget(makeButton(axis, multiplier, iconSize, QStringLiteral("arrow-down"), QStringLiteral("↓"))); | 118 | vLayout->addWidget(makeButton(axis, multiplier, iconSize, QStringLiteral("arrow-down"), QStringLiteral("↓"))); | ||
119 | 119 | | |||
120 | auto widget = new QWidget(); | 120 | auto widget = new QWidget(this); | ||
121 | widget->setLayout(vLayout); | 121 | widget->setLayout(vLayout); | ||
122 | return widget; | 122 | return widget; | ||
123 | } | 123 | } |