Thu, 04 Jul 2013 18:41:24 +0300
Designerified the replace coordinates action
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.h | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/ui/replcoords.ui | file | annotate | diff | comparison | revisions |
--- a/src/dialogs.cpp Thu Jul 04 18:03:22 2013 +0300 +++ b/src/dialogs.cpp Thu Jul 04 18:41:24 2013 +0300 @@ -153,65 +153,6 @@ dbb_buttons->button (QDialogButtonBox::Ok)->setEnabled (enable); } -ReplaceCoordsDialog::ReplaceCoordsDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { - cbg_axes = makeAxesBox (); - - lb_search = new QLabel ("Search:"); - lb_replacement = new QLabel ("Replacement:"); - - dsb_search = new QDoubleSpinBox; - dsb_search->setRange (-10000.0f, 10000.0f); - dsb_search->setDecimals (6); - - dsb_replacement = new QDoubleSpinBox; - dsb_replacement->setRange (-10000.0f, 10000.0f); - dsb_replacement->setDecimals (6); - - cb_any = new QCheckBox ("Any"); - cb_rel = new QCheckBox ("Relative"); - - connect (cb_any, SIGNAL (stateChanged (int)), this, SLOT (anyChanged (int))); - - QGridLayout* valueLayout = new QGridLayout; - valueLayout->setColumnStretch (1, 1); - valueLayout->addWidget (lb_search, 0, 0); - valueLayout->addWidget (dsb_search, 0, 1); - valueLayout->addWidget (cb_any, 0, 2); - valueLayout->addWidget (lb_replacement, 1, 0); - valueLayout->addWidget (dsb_replacement, 1, 1); - valueLayout->addWidget (cb_rel, 1, 2); - - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget (cbg_axes); - layout->addLayout (valueLayout); - layout->addWidget (makeButtonBox (*this)); - setLayout (layout); -} - -double ReplaceCoordsDialog::searchValue () const { - return dsb_search->value (); -} - -double ReplaceCoordsDialog::replacementValue () const { - return dsb_replacement->value (); -} - -vector<int> ReplaceCoordsDialog::axes () const { - return cbg_axes->checkedValues (); -} - -void ReplaceCoordsDialog::anyChanged (int state) { - dsb_search->setEnabled (state != Qt::Checked); -} - -bool ReplaceCoordsDialog::any () const { - return cb_any->isChecked (); -} - -bool ReplaceCoordsDialog::rel () const { - return cb_rel->isChecked (); -} - // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // =============================================================================
--- a/src/dialogs.h Thu Jul 04 18:03:22 2013 +0300 +++ b/src/dialogs.h Thu Jul 04 18:41:24 2013 +0300 @@ -64,28 +64,6 @@ void fillDefaults (int newcam); }; -class ReplaceCoordsDialog : public QDialog { - Q_OBJECT - -public: - explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0); - - vector<int> axes () const; - double searchValue () const; - double replacementValue () const; - bool any () const; - bool rel () const; - -private: - CheckBoxGroup* cbg_axes; - QLabel* lb_search, *lb_replacement; - QDoubleSpinBox* dsb_search, *dsb_replacement; - QCheckBox* cb_any, *cb_rel; - -private slots: - void anyChanged (int state); -}; - // ============================================================================= // SetContentsDialog //
--- a/src/gui_editactions.cpp Thu Jul 04 18:03:22 2013 +0300 +++ b/src/gui_editactions.cpp Thu Jul 04 18:41:24 2013 +0300 @@ -31,6 +31,7 @@ #include "gldraw.h" #include "dialogs.h" #include "colors.h" +#include "ui_replcoords.h" vector<str> g_Clipboard; @@ -532,37 +533,51 @@ } // ============================================================================= -MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) { - ReplaceCoordsDialog dlg; - - if (!dlg.exec ()) +MAKE_ACTION( replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL( R )) +{ + QDialog* dlg = new QDialog( g_win ); + Ui::ReplaceCoordsUI ui; + ui.setupUi( dlg ); + + if( !dlg->exec() ) return; + + const double search = ui.search->value(), + replacement = ui.replacement->value(); + const bool any = ui.any->isChecked(), + rel = ui.relative->isChecked(); - const double search = dlg.searchValue (), - replacement = dlg.replacementValue (); - const bool any = dlg.any (), - rel = dlg.rel (); + vector<Axis> sel; + int num = 0; - vector<int> sel = dlg.axes (); + if( ui.x->isChecked() ) sel << X; + if( ui.y->isChecked() ) sel << Y; + if( ui.z->isChecked() ) sel << Z; - for (LDObject* obj : g_win->sel ()) - for (short i = 0; i < obj->vertices (); ++i) { - vertex v = obj->getVertex (i); - for (int ax : sel) { - double& coord = v[(Axis) ax]; + for( LDObject * obj : g_win->sel() ) + for( short i = 0; i < obj->vertices(); ++i ) + { + vertex v = obj->getVertex( i ); + + for( Axis ax : sel ) + { + double& coord = v[ax]; - if (any || coord == search) { - if (!rel) + if( any || coord == search ) + { + if( !rel ) coord = 0; coord += replacement; + num++; } } - obj->setVertex (i, v); + obj->setVertex( i, v ); } - g_win->fullRefresh (); + log( ForgeWindow::tr( "Altered %1 values" ), num ); + g_win->fullRefresh(); } // =================================================================================================
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui/replcoords.ui Thu Jul 04 18:41:24 2013 +0300 @@ -0,0 +1,196 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ReplaceCoordsUI</class> + <widget class="QDialog" name="ReplaceCoordsUI"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>239</width> + <height>153</height> + </rect> + </property> + <property name="windowTitle"> + <string>Replace Coordinates</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Axes</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QCheckBox" name="x"> + <property name="whatsThis"> + <string>Replace X coordinates.</string> + </property> + <property name="text"> + <string>X</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="y"> + <property name="whatsThis"> + <string>Replace Y coordinates.</string> + </property> + <property name="text"> + <string>Y</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="z"> + <property name="whatsThis"> + <string>Replace Z coordinates.</string> + </property> + <property name="text"> + <string>Z</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::ExpandingFieldsGrow</enum> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Search:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QDoubleSpinBox" name="search"> + <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> + <widget class="QCheckBox" name="any"> + <property name="whatsThis"> + <string>If this is checked, all of the coordinates of selected objects will be changed. If not, they have to match the search value. + +Use this with the Relative option to offset objects, or without to project or flatten.</string> + </property> + <property name="text"> + <string>Any</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Replace:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QDoubleSpinBox" name="replacement"> + <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> + <widget class="QCheckBox" name="relative"> + <property name="whatsThis"> + <string>If this is set, the replace value is added to the coordinates, rather than replaced with.</string> + </property> + <property name="text"> + <string>Relative</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </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>ReplaceCoordsUI</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>224</x> + <y>128</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>144</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>ReplaceCoordsUI</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>246</x> + <y>134</y> + </hint> + <hint type="destinationlabel"> + <x>252</x> + <y>144</y> + </hint> + </hints> + </connection> + <connection> + <sender>any</sender> + <signal>clicked(bool)</signal> + <receiver>search</receiver> + <slot>setDisabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>207</x> + <y>13</y> + </hint> + <hint type="destinationlabel"> + <x>125</x> + <y>12</y> + </hint> + </hints> + </connection> + </connections> +</ui>