# HG changeset patch # User Santeri Piippo # Date 1372957694 -10800 # Node ID 3013acb1df53ed78e937304bc7caf3daee1ba6cf # Parent bf301f81a0b69f3177bb351652790d24fd847bc6 Converted rotation point prompt diff -r bf301f81a0b6 -r 3013acb1df53 src/dialogs.cpp --- 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 ({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..." ); diff -r bf301f81a0b6 -r 3013acb1df53 src/dialogs.h --- 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) diff -r bf301f81a0b6 -r 3013acb1df53 src/misc.cpp --- 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& objs) { - if (edit_rotpoint == 1) - return vertex (edit_rotpoint_x, edit_rotpoint_y, edit_rotpoint_z); - +vertex rotPoint( const vector& objs ) +{ bbox box; - // Calculate center vertex - for (LDObject* obj : objs) { - if (obj->hasMatrix ()) - box << dynamic_cast (obj)->position (); - else - box << obj; + switch( edit_rotpoint ) + { + case ObjectOrigin: + // Calculate center vertex + for( LDObject * obj : objs ) + { + if( obj->hasMatrix() ) + box << dynamic_cast( 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 vals, str delim) { diff -r bf301f81a0b6 -r 3013acb1df53 src/misc.h --- 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& objs); void configRotationPoint (); diff -r bf301f81a0b6 -r 3013acb1df53 src/ui/rotpoint.ui --- /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 @@ + + + RotPointUI + + + + 0 + 0 + 178 + 267 + + + + Set Rotation Point + + + + + + Rotation Point + + + + + + Object origin + + + + + + + World origin (0, 0, 0) + + + + + + + Custom + + + + + + + + + + false + + + Custom Point + + + + + + 4 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 4 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + X: + + + + + + + 4 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + Y: + + + + + + + Z: + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + RotPointUI + accept() + + + 171 + 250 + + + 157 + 266 + + + + + buttonBox + rejected() + RotPointUI + reject() + + + 171 + 256 + + + 177 + 266 + + + + + customPoint + clicked(bool) + groupBox + setEnabled(bool) + + + 46 + 85 + + + 136 + 131 + + + + + worldPoint + clicked(bool) + groupBox + setDisabled(bool) + + + 72 + 66 + + + 90 + 127 + + + + + objectPoint + clicked(bool) + groupBox + setDisabled(bool) + + + 36 + 45 + + + 23 + 129 + + + + +