Thu, 04 Jul 2013 21:01:52 +0300
Converted overlay prompt
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.h | file | annotate | diff | comparison | revisions | |
src/gui.h | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions |
--- a/src/dialogs.cpp Thu Jul 04 20:12:03 2013 +0300 +++ b/src/dialogs.cpp Thu Jul 04 21:01:52 2013 +0300 @@ -35,122 +35,112 @@ #include "docs.h" #include "file.h" #include "dialogs.h" +#include "ui_overlay.h" extern_cfg (str, io_ldpath); // ============================================================================= -OverlayDialog::OverlayDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { - rb_camera = new RadioBox ("Camera", {}, 0, Qt::Horizontal, this); - - for (int i = 0; i < 6; ++i) { - if (i == 3) - rb_camera->rowBreak (); - - rb_camera->addButton (g_CameraNames[i]); - } - - GL::Camera cam = g_win->R ()->camera (); - if (cam != GL::Free) - rb_camera->setValue ((int) cam); - - QGroupBox* gb_image = new QGroupBox ("Image", this); +OverlayDialog::OverlayDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) +{ + ui = new Ui_OverlayUI; + ui->setupUi( this ); - QLabel* lb_fpath = new QLabel ("File:"); - le_fpath = new QLineEdit; - le_fpath->setFocus (); + m_cameraArgs = { + { ui->top, GL::Top }, + { ui->bottom, GL::Bottom }, + { ui->front, GL::Front }, + { ui->back, GL::Back }, + { ui->left, GL::Left }, + { ui->right, GL::Right } + }; - QLabel* lb_ofs = new QLabel ("Origin:"); - btn_fpath = new QPushButton; - btn_fpath->setIcon (getIcon ("folder")); - connect (btn_fpath, SIGNAL (clicked ()), this, SLOT (slot_fpath ())); - - sb_ofsx = new QSpinBox; - sb_ofsy = new QSpinBox; - sb_ofsx->setRange (0, 10000); - sb_ofsy->setRange (0, 10000); - sb_ofsx->setSuffix (" px"); - sb_ofsy->setSuffix (" px"); + GL::Camera cam = g_win->R()->camera(); - QLabel* lb_dimens = new QLabel ("Dimensions:"); - dsb_lwidth = new QDoubleSpinBox; - dsb_lheight = new QDoubleSpinBox; - dsb_lwidth->setRange (0.0f, 10000.0f); - dsb_lheight->setRange (0.0f, 10000.0f); - dsb_lwidth->setSuffix (" LDU"); - dsb_lheight->setSuffix (" LDU"); - dsb_lwidth->setSpecialValueText ("Automatic"); - dsb_lheight->setSpecialValueText ("Automatic"); + if( cam == GL::Free ) + cam = GL::Top; - dbb_buttons = makeButtonBox (*this); - dbb_buttons->addButton (QDialogButtonBox::Help); - connect (dbb_buttons, SIGNAL (helpRequested ()), this, SLOT (slot_help())); - - QHBoxLayout* fpathlayout = new QHBoxLayout; - fpathlayout->addWidget (lb_fpath); - fpathlayout->addWidget (le_fpath); - fpathlayout->addWidget (btn_fpath); + connect( ui->width, SIGNAL( valueChanged( double )), this, SLOT( slot_dimensionsChanged() )); + connect( ui->height, SIGNAL( valueChanged( double )), this, SLOT( slot_dimensionsChanged() )); + connect( ui->buttonBox, SIGNAL( helpRequested() ), this, SLOT( slot_help() )); + connect( ui->fileSearchButton, SIGNAL( clicked( bool )), this, SLOT( slot_fpath() )); - QGridLayout* metalayout = new QGridLayout; - metalayout->addWidget (lb_ofs, 0, 0); - metalayout->addWidget (sb_ofsx, 0, 1); - metalayout->addWidget (sb_ofsy, 0, 2); - metalayout->addWidget (lb_dimens, 1, 0); - metalayout->addWidget (dsb_lwidth, 1, 1); - metalayout->addWidget (dsb_lheight, 1, 2); - - QVBoxLayout* imagelayout = new QVBoxLayout (gb_image); - imagelayout->addLayout (fpathlayout); - imagelayout->addLayout (metalayout); - - QVBoxLayout* layout = new QVBoxLayout (this); - layout->addWidget (rb_camera); - layout->addWidget (gb_image); - layout->addWidget (dbb_buttons); - - connect (dsb_lwidth, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged ())); - connect (dsb_lheight, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged ())); - connect (rb_camera, SIGNAL (valueChanged (int)), this, SLOT (fillDefaults (int))); - - slot_dimensionsChanged (); - fillDefaults (cam); + slot_dimensionsChanged(); + fillDefaults( cam ); +} + +OverlayDialog::~OverlayDialog() +{ + delete ui; } -void OverlayDialog::fillDefaults (int newcam) { - overlayMeta& info = g_win->R ()->getOverlay (newcam); +void OverlayDialog::fillDefaults( int newcam ) +{ + overlayMeta& info = g_win->R()->getOverlay( newcam ); + + radioDefault<int>( newcam, m_cameraArgs ); - if (info.img != null) { - le_fpath->setText (info.fname); - sb_ofsx->setValue (info.ox); - sb_ofsy->setValue (info.oy); - dsb_lwidth->setValue (info.lw); - dsb_lheight->setValue (info.lh); - } else { - le_fpath->setText (""); - sb_ofsx->setValue (0); - sb_ofsy->setValue (0); - dsb_lwidth->setValue (0.0f); - dsb_lheight->setValue (0.0f); - } + if( info.img != null ) + { + ui->filename->setText( info.fname ); + ui->originX->setValue( info.ox ); + ui->originY->setValue( info.oy ); + ui->width->setValue( info.lw ); + ui->height->setValue( info.lh ); + } + else + { + ui->filename->setText( "" ); + ui->originX->setValue( 0 ); + ui->originY->setValue( 0 ); + ui->width->setValue( 0.0f ); + ui->height->setValue( 0.0f ); + } +} + +str OverlayDialog::fpath() const +{ + return ui->filename->text(); +} + +ushort OverlayDialog::ofsx() const +{ + return ui->originX->value(); } -str OverlayDialog::fpath () const { return le_fpath->text (); } -ushort OverlayDialog::ofsx () const { return sb_ofsx->value (); } -ushort OverlayDialog::ofsy () const { return sb_ofsy->value (); } -double OverlayDialog::lwidth () const { return dsb_lwidth->value (); } -double OverlayDialog::lheight () const { return dsb_lheight->value (); } -int OverlayDialog::camera () const { return rb_camera->value (); } +ushort OverlayDialog::ofsy() const +{ + return ui->originY->value(); +} -void OverlayDialog::slot_fpath () { - le_fpath->setText (QFileDialog::getOpenFileName (null, "Overlay image")); +double OverlayDialog::lwidth() const +{ + return ui->width->value(); +} + +double OverlayDialog::lheight() const +{ + return ui->height->value(); } -void OverlayDialog::slot_help () { - showDocumentation (g_docs_overlays); +int OverlayDialog::camera() const +{ + return radioSwitch<int>( GL::Top, m_cameraArgs ); +} + +void OverlayDialog::slot_fpath() +{ + ui->filename->setText( QFileDialog::getOpenFileName( null, "Overlay image" )); } -void OverlayDialog::slot_dimensionsChanged () { - bool enable = (dsb_lwidth->value () != 0) || (dsb_lheight->value () != 0); - dbb_buttons->button (QDialogButtonBox::Ok)->setEnabled (enable); +void OverlayDialog::slot_help() +{ + showDocumentation( g_docs_overlays ); +} + +void OverlayDialog::slot_dimensionsChanged() +{ + bool enable = ( ui->width->value() != 0 ) || ( ui->height->value() != 0 ); + ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enable ); } // =================================================================================================
--- a/src/dialogs.h Thu Jul 04 20:12:03 2013 +0300 +++ b/src/dialogs.h Thu Jul 04 21:01:52 2013 +0300 @@ -23,6 +23,7 @@ #include "common.h" #include "types.h" +class QRadioButton; class QCheckBox; class QProgressBar; class QGroupBox; @@ -35,33 +36,32 @@ class CheckBoxGroup; class QLabel; class QAbstractButton; +class Ui_OverlayUI; -class OverlayDialog : public QDialog { +class OverlayDialog : public QDialog +{ Q_OBJECT - + public: - explicit OverlayDialog (QWidget* parent = null, Qt::WindowFlags f = 0); - - str fpath () const; - ushort ofsx () const; - ushort ofsy () const; - double lwidth () const; - double lheight () const; - int camera () const; + explicit OverlayDialog( QWidget* parent = null, Qt::WindowFlags f = 0 ); + virtual ~OverlayDialog(); + str fpath() const; + ushort ofsx() const; + ushort ofsy() const; + double lwidth() const; + double lheight() const; + int camera() const; + private: - RadioBox* rb_camera; - QPushButton* btn_fpath; - QLineEdit* le_fpath; - QSpinBox* sb_ofsx, *sb_ofsy; - QDoubleSpinBox* dsb_lwidth, *dsb_lheight; - QDialogButtonBox* dbb_buttons; - + Ui_OverlayUI* ui; + vector<pair<QRadioButton*, int>> m_cameraArgs; + private slots: - void slot_fpath (); - void slot_help (); - void slot_dimensionsChanged (); - void fillDefaults (int newcam); + void slot_fpath(); + void slot_help(); + void slot_dimensionsChanged(); + void fillDefaults( int newcam ); }; // =============================================================================
--- a/src/gui.h Thu Jul 04 20:12:03 2013 +0300 +++ b/src/gui.h Thu Jul 04 21:01:52 2013 +0300 @@ -22,6 +22,7 @@ #include <QMainWindow> #include <QAction> #include <QListWidget> +#include <QRadioButton> #include "config.h" #include "ldtypes.h" @@ -175,6 +176,10 @@ }; // ----------------------------------------------------------------------------- +// Pointer to the instance of ForgeWindow. +extern ForgeWindow* g_win; + +// ----------------------------------------------------------------------------- // Other GUI-related stuff not directly part of ForgeWindow: QPixmap getIcon (str iconName); vector<quickColor> parseQuickColorMeta (); @@ -188,9 +193,36 @@ CheckBoxGroup* makeAxesBox (); QImage imageFromScreencap (uchar* data, ushort w, ushort h); +// ============================================================================= // ----------------------------------------------------------------------------- -// Pointer to the instance of ForgeWindow. -extern ForgeWindow* g_win; +// Takes in pairs of radio buttons and respective values and returns the value of +// the first found radio button that was checked. +// ============================================================================= +template<class T> T radioSwitch( const T& defval, vector<pair<QRadioButton*, T>> haystack ) +{ + for( pair<QRadioButton*, const T&> i : haystack ) + if( i.first->isChecked() ) + return i.second; + + return defval; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +// Takes in pairs of radio buttons and respective values and checks the first +// found radio button to have the given value. +// ============================================================================= +template<class T> void radioDefault( const T& expr, vector<pair<QRadioButton*, T>> haystack ) +{ + for( pair<QRadioButton*, const T&> i : haystack ) + { + if( i.second == expr ) + { + i.first->setChecked( true ); + return; + } + } +} // ============================================================================= // ActionAdder
--- a/src/gui_actions.cpp Thu Jul 04 20:12:03 2013 +0300 +++ b/src/gui_actions.cpp Thu Jul 04 21:01:52 2013 +0300 @@ -419,7 +419,6 @@ g_win->fullRefresh (); } -// ========================================================================================================================================= MAKE_ACTION (wireframe, "Wireframe", "wireframe", "Toggle wireframe view", (0)) { gl_wireframe = !gl_wireframe; g_win->R ()->refresh (); @@ -433,7 +432,7 @@ return; g_win->R ()->setupOverlay( (GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(), - dlg.ofsy(), dlg.width(), dlg.height() ); + dlg.ofsy(), dlg.lwidth(), dlg.lheight() ); } MAKE_ACTION (clearOverlay, "Clear Overlay Image", "overlay-clear", "Clear the overlay image.", (0)) {