src/dialogs.cpp

changeset 335
30c11cff511d
parent 333
905027940c51
child 337
4e05207c76c9
equal deleted inserted replaced
334:bb3a0e5ebe53 335:30c11cff511d
33 #include "gui.h" 33 #include "gui.h"
34 #include "gldraw.h" 34 #include "gldraw.h"
35 #include "docs.h" 35 #include "docs.h"
36 #include "file.h" 36 #include "file.h"
37 #include "dialogs.h" 37 #include "dialogs.h"
38 #include "ui_overlay.h"
38 39
39 extern_cfg (str, io_ldpath); 40 extern_cfg (str, io_ldpath);
40 41
41 // ============================================================================= 42 // =============================================================================
42 OverlayDialog::OverlayDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { 43 OverlayDialog::OverlayDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f )
43 rb_camera = new RadioBox ("Camera", {}, 0, Qt::Horizontal, this); 44 {
44 45 ui = new Ui_OverlayUI;
45 for (int i = 0; i < 6; ++i) { 46 ui->setupUi( this );
46 if (i == 3) 47
47 rb_camera->rowBreak (); 48 m_cameraArgs = {
48 49 { ui->top, GL::Top },
49 rb_camera->addButton (g_CameraNames[i]); 50 { ui->bottom, GL::Bottom },
50 } 51 { ui->front, GL::Front },
51 52 { ui->back, GL::Back },
52 GL::Camera cam = g_win->R ()->camera (); 53 { ui->left, GL::Left },
53 if (cam != GL::Free) 54 { ui->right, GL::Right }
54 rb_camera->setValue ((int) cam); 55 };
55 56
56 QGroupBox* gb_image = new QGroupBox ("Image", this); 57 GL::Camera cam = g_win->R()->camera();
57 58
58 QLabel* lb_fpath = new QLabel ("File:"); 59 if( cam == GL::Free )
59 le_fpath = new QLineEdit; 60 cam = GL::Top;
60 le_fpath->setFocus (); 61
61 62 connect( ui->width, SIGNAL( valueChanged( double )), this, SLOT( slot_dimensionsChanged() ));
62 QLabel* lb_ofs = new QLabel ("Origin:"); 63 connect( ui->height, SIGNAL( valueChanged( double )), this, SLOT( slot_dimensionsChanged() ));
63 btn_fpath = new QPushButton; 64 connect( ui->buttonBox, SIGNAL( helpRequested() ), this, SLOT( slot_help() ));
64 btn_fpath->setIcon (getIcon ("folder")); 65 connect( ui->fileSearchButton, SIGNAL( clicked( bool )), this, SLOT( slot_fpath() ));
65 connect (btn_fpath, SIGNAL (clicked ()), this, SLOT (slot_fpath ())); 66
66 67 slot_dimensionsChanged();
67 sb_ofsx = new QSpinBox; 68 fillDefaults( cam );
68 sb_ofsy = new QSpinBox; 69 }
69 sb_ofsx->setRange (0, 10000); 70
70 sb_ofsy->setRange (0, 10000); 71 OverlayDialog::~OverlayDialog()
71 sb_ofsx->setSuffix (" px"); 72 {
72 sb_ofsy->setSuffix (" px"); 73 delete ui;
73 74 }
74 QLabel* lb_dimens = new QLabel ("Dimensions:"); 75
75 dsb_lwidth = new QDoubleSpinBox; 76 void OverlayDialog::fillDefaults( int newcam )
76 dsb_lheight = new QDoubleSpinBox; 77 {
77 dsb_lwidth->setRange (0.0f, 10000.0f); 78 overlayMeta& info = g_win->R()->getOverlay( newcam );
78 dsb_lheight->setRange (0.0f, 10000.0f); 79
79 dsb_lwidth->setSuffix (" LDU"); 80 radioDefault<int>( newcam, m_cameraArgs );
80 dsb_lheight->setSuffix (" LDU"); 81
81 dsb_lwidth->setSpecialValueText ("Automatic"); 82 if( info.img != null )
82 dsb_lheight->setSpecialValueText ("Automatic"); 83 {
83 84 ui->filename->setText( info.fname );
84 dbb_buttons = makeButtonBox (*this); 85 ui->originX->setValue( info.ox );
85 dbb_buttons->addButton (QDialogButtonBox::Help); 86 ui->originY->setValue( info.oy );
86 connect (dbb_buttons, SIGNAL (helpRequested ()), this, SLOT (slot_help())); 87 ui->width->setValue( info.lw );
87 88 ui->height->setValue( info.lh );
88 QHBoxLayout* fpathlayout = new QHBoxLayout; 89 }
89 fpathlayout->addWidget (lb_fpath); 90 else
90 fpathlayout->addWidget (le_fpath); 91 {
91 fpathlayout->addWidget (btn_fpath); 92 ui->filename->setText( "" );
92 93 ui->originX->setValue( 0 );
93 QGridLayout* metalayout = new QGridLayout; 94 ui->originY->setValue( 0 );
94 metalayout->addWidget (lb_ofs, 0, 0); 95 ui->width->setValue( 0.0f );
95 metalayout->addWidget (sb_ofsx, 0, 1); 96 ui->height->setValue( 0.0f );
96 metalayout->addWidget (sb_ofsy, 0, 2); 97 }
97 metalayout->addWidget (lb_dimens, 1, 0); 98 }
98 metalayout->addWidget (dsb_lwidth, 1, 1); 99
99 metalayout->addWidget (dsb_lheight, 1, 2); 100 str OverlayDialog::fpath() const
100 101 {
101 QVBoxLayout* imagelayout = new QVBoxLayout (gb_image); 102 return ui->filename->text();
102 imagelayout->addLayout (fpathlayout); 103 }
103 imagelayout->addLayout (metalayout); 104
104 105 ushort OverlayDialog::ofsx() const
105 QVBoxLayout* layout = new QVBoxLayout (this); 106 {
106 layout->addWidget (rb_camera); 107 return ui->originX->value();
107 layout->addWidget (gb_image); 108 }
108 layout->addWidget (dbb_buttons); 109
109 110 ushort OverlayDialog::ofsy() const
110 connect (dsb_lwidth, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged ())); 111 {
111 connect (dsb_lheight, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged ())); 112 return ui->originY->value();
112 connect (rb_camera, SIGNAL (valueChanged (int)), this, SLOT (fillDefaults (int))); 113 }
113 114
114 slot_dimensionsChanged (); 115 double OverlayDialog::lwidth() const
115 fillDefaults (cam); 116 {
116 } 117 return ui->width->value();
117 118 }
118 void OverlayDialog::fillDefaults (int newcam) { 119
119 overlayMeta& info = g_win->R ()->getOverlay (newcam); 120 double OverlayDialog::lheight() const
120 121 {
121 if (info.img != null) { 122 return ui->height->value();
122 le_fpath->setText (info.fname); 123 }
123 sb_ofsx->setValue (info.ox); 124
124 sb_ofsy->setValue (info.oy); 125 int OverlayDialog::camera() const
125 dsb_lwidth->setValue (info.lw); 126 {
126 dsb_lheight->setValue (info.lh); 127 return radioSwitch<int>( GL::Top, m_cameraArgs );
127 } else { 128 }
128 le_fpath->setText (""); 129
129 sb_ofsx->setValue (0); 130 void OverlayDialog::slot_fpath()
130 sb_ofsy->setValue (0); 131 {
131 dsb_lwidth->setValue (0.0f); 132 ui->filename->setText( QFileDialog::getOpenFileName( null, "Overlay image" ));
132 dsb_lheight->setValue (0.0f); 133 }
133 } 134
134 } 135 void OverlayDialog::slot_help()
135 136 {
136 str OverlayDialog::fpath () const { return le_fpath->text (); } 137 showDocumentation( g_docs_overlays );
137 ushort OverlayDialog::ofsx () const { return sb_ofsx->value (); } 138 }
138 ushort OverlayDialog::ofsy () const { return sb_ofsy->value (); } 139
139 double OverlayDialog::lwidth () const { return dsb_lwidth->value (); } 140 void OverlayDialog::slot_dimensionsChanged()
140 double OverlayDialog::lheight () const { return dsb_lheight->value (); } 141 {
141 int OverlayDialog::camera () const { return rb_camera->value (); } 142 bool enable = ( ui->width->value() != 0 ) || ( ui->height->value() != 0 );
142 143 ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enable );
143 void OverlayDialog::slot_fpath () {
144 le_fpath->setText (QFileDialog::getOpenFileName (null, "Overlay image"));
145 }
146
147 void OverlayDialog::slot_help () {
148 showDocumentation (g_docs_overlays);
149 }
150
151 void OverlayDialog::slot_dimensionsChanged () {
152 bool enable = (dsb_lwidth->value () != 0) || (dsb_lheight->value () != 0);
153 dbb_buttons->button (QDialogButtonBox::Ok)->setEnabled (enable);
154 } 144 }
155 145
156 // ================================================================================================= 146 // =================================================================================================
157 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f) 147 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f)
158 : QDialog (parent, f), m_validDefault (validDefault) 148 : QDialog (parent, f), m_validDefault (validDefault)

mercurial