fix various things

Mon, 20 Jun 2022 16:43:56 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 20 Jun 2022 16:43:56 +0300
changeset 233
5509bec02c81
parent 232
8efa3a33172e
child 234
87ee9824210b

fix various things

CMakeLists.txt file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/model.h file | annotate | diff | comparison | revisions
src/settings.h file | annotate | diff | comparison | revisions
src/ui/circletooloptionswidget.cpp file | annotate | diff | comparison | revisions
src/ui/circletooloptionswidget.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Mon Jun 20 02:04:51 2022 +0300
+++ b/CMakeLists.txt	Mon Jun 20 16:43:56 2022 +0300
@@ -46,8 +46,7 @@
 	src/settingseditor/librarieseditor.cpp
 	src/settingseditor/settingseditor.cpp
 	src/types/boundingbox.cpp
-#	src/ui/canvas.cpp
-	src/ui/circletooloptions.cpp
+	src/ui/circletooloptionswidget.cpp
 	src/ui/multiplyfactordialog.cpp
 	src/ui/objecteditor.cpp
 	src/widgets/colorbutton.cpp
@@ -89,8 +88,7 @@
 	src/settingseditor/librarieseditor.h
 	src/settingseditor/settingseditor.h
 	src/types/boundingbox.h
-#	src/ui/canvas.h
-	src/ui/circletooloptions.h
+	src/ui/circletooloptionswidget.h
 	src/ui/multiplyfactordialog.h
 	src/ui/objecteditor.h
 	src/widgets/colorbutton.h
--- a/src/main.cpp	Mon Jun 20 02:04:51 2022 +0300
+++ b/src/main.cpp	Mon Jun 20 16:43:56 2022 +0300
@@ -14,7 +14,7 @@
 #include "settingseditor/settingseditor.h"
 #include "widgets/colorselectdialog.h"
 #include "settings.h"
-#include "ui/circletooloptions.h"
+#include "ui/circletooloptionswidget.h"
 
 static const QDir LOCALE_DIR {":/locale"};
 
--- a/src/model.h	Mon Jun 20 02:04:51 2022 +0300
+++ b/src/model.h	Mon Jun 20 16:43:56 2022 +0300
@@ -78,6 +78,8 @@
 	glm::mat4 transformation;
 };
 
+Q_DECLARE_METATYPE(CircularPrimitive::Type)
+
 struct CircleToolOptions
 {
 	CircularFraction fraction;
--- a/src/settings.h	Mon Jun 20 02:04:51 2022 +0300
+++ b/src/settings.h	Mon Jun 20 16:43:56 2022 +0300
@@ -5,16 +5,11 @@
 #include "libraries.h"
 #include "gl/common.h"
 
-// SettingType - get type of setting by enumerator
-template<typename>
-struct SettingId{};
-
-template<SettingId>
+template<class>
 struct SettingInfo{};
 
 #define SETTING(NAME, DEFVALUE) \
-	namespace SettingIdTypes { class NAME; } \
-	namespace Setting { constexpr SettingId<class NAME##_SettingType> NAME; } \
+	namespace Setting { class NAME;  } \
 	template<> \
 	struct SettingInfo<Setting::NAME> \
 	{ \
@@ -51,21 +46,21 @@
 // -----------------------------------------------------------------------------
 #undef SETTING
 
-template<SettingId X>
+template<class X>
 using SettingType_t = typename SettingInfo<X>::type;
 static_assert(std::is_same_v<SettingType_t<Setting::DrawAxes>, bool>);
 
-template<SettingId X>
+template<class X>
 const char* settingName = SettingInfo<X>::name;
 
-template<SettingId X>
+template<class X>
 inline auto settingDefaultValue()
 {
 	return SettingInfo<X>::defaultValue();
 }
 
 // get() - get setting by enumerator
-template<SettingId X>
+template<class X>
 inline SettingType_t<X> setting()
 {
 	static const QVariant defvariant = QVariant::fromValue(settingDefaultValue<X>());
@@ -74,7 +69,7 @@
 }
 
 // setSetting() - set value of setting
-template<SettingId X>
+template<class X>
 inline void setSetting(const SettingType_t<X>& value)
 {
 	if (value == settingDefaultValue<X>()) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ui/circletooloptionswidget.cpp	Mon Jun 20 16:43:56 2022 +0300
@@ -0,0 +1,77 @@
+#include "circletooloptionswidget.h"
+
+static QString circularPrimitiveTypeName(CircularPrimitive::Type type)
+{
+	switch (type) {
+	case CircularPrimitive::Circle:
+		return CircleToolOptionsWidget::tr("Circle");
+	case CircularPrimitive::Disc:
+		return CircleToolOptionsWidget::tr("Disc");
+	case CircularPrimitive::Cylinder:
+		return CircleToolOptionsWidget::tr("Cylinder");
+	case CircularPrimitive::CylinderOpen:
+		return CircleToolOptionsWidget::tr("Cylinder open");
+	case CircularPrimitive::CylinderClosed:
+		return CircleToolOptionsWidget::tr("Cylinder closed");
+	case CircularPrimitive::DiscNegative:
+		return CircleToolOptionsWidget::tr("Disc negative");
+	case CircularPrimitive::Chord:
+		return CircleToolOptionsWidget::tr("Chord");
+	}
+	return "";
+}
+
+CircleToolOptionsWidget::CircleToolOptionsWidget(QWidget *parent) :
+	QWidget{parent}
+{
+	this->ui.setupUi(this);
+	for (int i = 0; i < CircularPrimitive::NUM_TYPES; ++i) {
+		const auto type = static_cast<CircularPrimitive::Type>(i);
+		this->ui.type->addItem(circularPrimitiveTypeName(type), type);
+	}
+	connect(ui.segments, qOverload<int>(&QSpinBox::valueChanged), this, &CircleToolOptionsWidget::handleInputChange);
+	connect(ui.divisions, &QComboBox::currentTextChanged, this, &CircleToolOptionsWidget::handleInputChange);
+	connect(ui.type, &QComboBox::currentTextChanged, this, &CircleToolOptionsWidget::handleInputChange);
+}
+
+CircleToolOptionsWidget::~CircleToolOptionsWidget()
+{
+}
+
+unsigned int CircleToolOptionsWidget::segments() const
+{
+	return this->ui.segments->value();
+}
+
+unsigned int CircleToolOptionsWidget::divisions() const
+{
+	bool ok;
+	const int divs = this->ui.divisions->currentText().toInt(&ok);
+	if (ok) {
+		return divs;
+	}
+	else {
+		return 16;
+	}
+}
+
+CircularPrimitive::Type CircleToolOptionsWidget::type() const
+{
+	return this->ui.type->currentData().value<CircularPrimitive::Type>();
+}
+
+void CircleToolOptionsWidget::handleInputChange()
+{
+	const int olddivs = this->ui.segments->maximum();
+	const int newdivs = this->divisions();
+	if (olddivs != newdivs) {
+		this->ui.segments->setMaximum(newdivs);
+		this->ui.segments->setValue(this->segments() * newdivs / olddivs);
+	}
+	const qreal ratio = static_cast<qreal>(this->segments()) / newdivs;
+	this->ui.ratio->setText(QString::number(ratio, 'g', 4));
+	Q_EMIT this->optionsChanged(CircleToolOptions{
+		.fraction = CircularFraction{this->segments(), this->divisions()},
+		.type = this->type(),
+	});
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ui/circletooloptionswidget.h	Mon Jun 20 16:43:56 2022 +0300
@@ -0,0 +1,20 @@
+#pragma once
+#include <QWidget>
+#include "ui_circletool.h"
+#include "model.h"
+
+class CircleToolOptionsWidget : public QWidget
+{
+	Q_OBJECT
+	Ui_CircleToolOptions ui;
+public:
+	CircleToolOptionsWidget(QWidget* parent);
+	virtual ~CircleToolOptionsWidget();
+	unsigned int segments() const;
+	unsigned int divisions() const;
+	CircularPrimitive::Type type() const;
+Q_SIGNALS:
+	void optionsChanged(const CircleToolOptions& options);
+private:
+	Q_SLOT void handleInputChange();
+};

mercurial