Thu, 04 Jul 2013 20:08:14 +0300
Converted rotation point prompt
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.h | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions | |
src/ui/rotpoint.ui | file | annotate | diff | comparison | revisions |
--- a/src/dialogs.cpp Thu Jul 04 19:18:42 2013 +0300 +++ b/src/dialogs.cpp Thu Jul 04 20:08:14 2013 +0300 @@ -292,59 +292,6 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -RotationPointDialog::RotationPointDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { - rb_rotpoint = new RadioBox ("Rotation Point", { "Object center", "Custom" }, 0, Qt::Vertical, this); - connect (rb_rotpoint, SIGNAL (valueChanged (int)), this, SLOT (radioBoxChanged ())); - - gb_customPos = new QGroupBox ("Custom point", this); - dsb_customX = new QDoubleSpinBox; - dsb_customY = new QDoubleSpinBox; - dsb_customZ = new QDoubleSpinBox; - - for (auto x : initlist<QDoubleSpinBox*> ({dsb_customX, dsb_customY, dsb_customZ})) - x->setRange (-10000.0f, 10000.0f); - - QGridLayout* customLayout = new QGridLayout (gb_customPos); - customLayout->setColumnStretch (1, 1); - customLayout->addWidget (new QLabel ("X"), 0, 0); - customLayout->addWidget (dsb_customX, 0, 1); - customLayout->addWidget (new QLabel ("Y"), 1, 0); - customLayout->addWidget (dsb_customY, 1, 1); - customLayout->addWidget (new QLabel ("Z"), 2, 0); - customLayout->addWidget (dsb_customZ, 2, 1); - - QVBoxLayout* layout = new QVBoxLayout (this); - layout->addWidget (rb_rotpoint); - layout->addWidget (gb_customPos); - layout->addWidget (makeButtonBox (*this)); -} - -bool RotationPointDialog::custom () const { - return rb_rotpoint->value () == 1; -} - -vertex RotationPointDialog::customPos () const { - return vertex (dsb_customX->value (), dsb_customY->value (), dsb_customZ->value ()); -} - -void RotationPointDialog::setCustom (bool custom) { - rb_rotpoint->setValue (custom == true ? 1 : 0); - gb_customPos->setEnabled (custom); -} - -void RotationPointDialog::setCustomPos (const vertex& pos) { - dsb_customX->setValue (pos[X]); - dsb_customY->setValue (pos[Y]); - dsb_customZ->setValue (pos[Z]); -} - -void RotationPointDialog::radioBoxChanged () { - setCustom (rb_rotpoint->value ()); -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { progressBar = new QProgressBar; progressText = new QLabel( "Parsing..." );
--- a/src/dialogs.h Thu Jul 04 19:18:42 2013 +0300 +++ b/src/dialogs.h Thu Jul 04 20:08:14 2013 +0300 @@ -109,27 +109,6 @@ }; // ============================================================================= -class RotationPointDialog : public QDialog { - Q_OBJECT - -public: - explicit RotationPointDialog (QWidget* parent = null, Qt::WindowFlags f = 0); - - vertex customPos () const; - bool custom () const; - void setCustom (bool custom); - void setCustomPos (const vertex& pos); - -private: - QDoubleSpinBox* dsb_customX, *dsb_customY, *dsb_customZ; - RadioBox* rb_rotpoint; - QGroupBox* gb_customPos; - -private slots: - void radioBoxChanged (); -}; - -// ============================================================================= class OpenProgressDialog : public QDialog { Q_OBJECT READ_PROPERTY (ulong, progress, setProgress)
--- a/src/misc.cpp Thu Jul 04 19:18:42 2013 +0300 +++ b/src/misc.cpp Thu Jul 04 20:08:14 2013 +0300 @@ -24,6 +24,7 @@ #include "gui.h" #include "bbox.h" #include "dialogs.h" +#include "ui_rotpoint.h" // Prime number table. const ushort g_primes[NUM_PRIMES] = { @@ -208,37 +209,70 @@ } // ============================================================================= -vertex rotPoint (const vector<LDObject*>& objs) { - if (edit_rotpoint == 1) - return vertex (edit_rotpoint_x, edit_rotpoint_y, edit_rotpoint_z); - +vertex rotPoint( const vector<LDObject*>& objs ) +{ bbox box; - // Calculate center vertex - for (LDObject* obj : objs) { - if (obj->hasMatrix ()) - box << dynamic_cast<LDMatrixObject*> (obj)->position (); - else - box << obj; + switch( edit_rotpoint ) + { + case ObjectOrigin: + // Calculate center vertex + for( LDObject * obj : objs ) + { + if( obj->hasMatrix() ) + box << dynamic_cast<LDMatrixObject*>( obj )->position(); + else + box << obj; + } + + return box.center (); + + case WorldOrigin: + return g_origin; + + case CustomPoint: + return vertex (edit_rotpoint_x, edit_rotpoint_y, edit_rotpoint_z); } - return box.center (); + return vertex(); } -void configRotationPoint () { - RotationPointDialog dlg; - dlg.setCustom (edit_rotpoint); - dlg.setCustomPos (vertex (edit_rotpoint_x, edit_rotpoint_y, edit_rotpoint_z)); +void configRotationPoint() +{ + QDialog* dlg = new QDialog; + Ui::RotPointUI ui; + ui.setupUi( dlg ); + + switch( edit_rotpoint ) + { + case ObjectOrigin: + ui.objectPoint->setChecked( true ); + break; - if (!dlg.exec ()) + case WorldOrigin: + ui.worldPoint->setChecked( true ); + break; + + case CustomPoint: + ui.customPoint->setChecked( true ); + break; + } + + ui.customX->setValue( edit_rotpoint_x ); + ui.customY->setValue( edit_rotpoint_y ); + ui.customZ->setValue( edit_rotpoint_z ); + + if (!dlg->exec ()) return; - edit_rotpoint = dlg.custom (); + edit_rotpoint = + ( ui.objectPoint->isChecked() ) ? ObjectOrigin : + ( ui.worldPoint->isChecked() ) ? WorldOrigin : + CustomPoint; - vertex pos = dlg.customPos (); - edit_rotpoint_x = pos[X]; - edit_rotpoint_y = pos[Y]; - edit_rotpoint_z = pos[Z]; + edit_rotpoint_x = ui.customX->value(); + edit_rotpoint_y = ui.customY->value(); + edit_rotpoint_z = ui.customZ->value(); } str join (initlist<StringFormatArg> vals, str delim) {
--- a/src/misc.h Thu Jul 04 19:18:42 2013 +0300 +++ b/src/misc.h Thu Jul 04 20:08:14 2013 +0300 @@ -60,6 +60,13 @@ } // ============================================================================= +enum RotationPoint +{ + ObjectOrigin, + WorldOrigin, + CustomPoint +}; + vertex rotPoint (const vector<LDObject*>& objs); void configRotationPoint ();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui/rotpoint.ui Thu Jul 04 20:08:14 2013 +0300 @@ -0,0 +1,214 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>RotPointUI</class> + <widget class="QDialog" name="RotPointUI"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>178</width> + <height>267</height> + </rect> + </property> + <property name="windowTitle"> + <string>Set Rotation Point</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Rotation Point</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QRadioButton" name="objectPoint"> + <property name="text"> + <string>Object origin</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="worldPoint"> + <property name="text"> + <string>World origin (0, 0, 0)</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="customPoint"> + <property name="text"> + <string>Custom</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="title"> + <string>Custom Point</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="1"> + <widget class="QDoubleSpinBox" name="customX"> + <property name="decimals"> + <number>4</number> + </property> + <property name="minimum"> + <double>-10000.000000000000000</double> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="customY"> + <property name="decimals"> + <number>4</number> + </property> + <property name="minimum"> + <double>-10000.000000000000000</double> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>X:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="customZ"> + <property name="decimals"> + <number>4</number> + </property> + <property name="minimum"> + <double>-10000.000000000000000</double> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Y:</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Z:</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>RotPointUI</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>171</x> + <y>250</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>266</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>RotPointUI</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>171</x> + <y>256</y> + </hint> + <hint type="destinationlabel"> + <x>177</x> + <y>266</y> + </hint> + </hints> + </connection> + <connection> + <sender>customPoint</sender> + <signal>clicked(bool)</signal> + <receiver>groupBox</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>46</x> + <y>85</y> + </hint> + <hint type="destinationlabel"> + <x>136</x> + <y>131</y> + </hint> + </hints> + </connection> + <connection> + <sender>worldPoint</sender> + <signal>clicked(bool)</signal> + <receiver>groupBox</receiver> + <slot>setDisabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>72</x> + <y>66</y> + </hint> + <hint type="destinationlabel"> + <x>90</x> + <y>127</y> + </hint> + </hints> + </connection> + <connection> + <sender>objectPoint</sender> + <signal>clicked(bool)</signal> + <receiver>groupBox</receiver> + <slot>setDisabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>36</x> + <y>45</y> + </hint> + <hint type="destinationlabel"> + <x>23</x> + <y>129</y> + </hint> + </hints> + </connection> + </connections> +</ui>