src/dialogs.cpp

changeset 421
7d26db0be944
parent 410
a5aebcf4a1c8
child 431
ec1e2059319b
equal deleted inserted replaced
420:8d6af951b611 421:7d26db0be944
1 /* 1 /*
2 * LDForge: LDraw parts authoring CAD 2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 Santeri Piippo 3 * Copyright (C) 2013 Santeri Piippo
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or 7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <QDialog> 19 #include <QDialog>
40 #include "ui_openprogress.h" 40 #include "ui_openprogress.h"
41 41
42 extern_cfg (str, io_ldpath); 42 extern_cfg (str, io_ldpath);
43 43
44 // ============================================================================= 44 // =============================================================================
45 OverlayDialog::OverlayDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) 45 OverlayDialog::OverlayDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
46 {
47 ui = new Ui_OverlayUI; 46 ui = new Ui_OverlayUI;
48 ui->setupUi( this ); 47 ui->setupUi (this);
49 48
50 m_cameraArgs = { 49 m_cameraArgs = {
51 { ui->top, GL::Top }, 50 { ui->top, GL::Top },
52 { ui->bottom, GL::Bottom }, 51 { ui->bottom, GL::Bottom },
53 { ui->front, GL::Front }, 52 { ui->front, GL::Front },
56 { ui->right, GL::Right } 55 { ui->right, GL::Right }
57 }; 56 };
58 57
59 GL::Camera cam = g_win->R()->camera(); 58 GL::Camera cam = g_win->R()->camera();
60 59
61 if( cam == GL::Free ) 60 if (cam == GL::Free)
62 cam = GL::Top; 61 cam = GL::Top;
63 62
64 connect( ui->width, SIGNAL( valueChanged( double )), this, SLOT( slot_dimensionsChanged() )); 63 connect (ui->width, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged()));
65 connect( ui->height, SIGNAL( valueChanged( double )), this, SLOT( slot_dimensionsChanged() )); 64 connect (ui->height, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged()));
66 connect( ui->buttonBox, SIGNAL( helpRequested() ), this, SLOT( slot_help() )); 65 connect (ui->buttonBox, SIGNAL (helpRequested()), this, SLOT (slot_help()));
67 connect( ui->fileSearchButton, SIGNAL( clicked( bool )), this, SLOT( slot_fpath() )); 66 connect (ui->fileSearchButton, SIGNAL (clicked (bool)), this, SLOT (slot_fpath()));
68 67
69 slot_dimensionsChanged(); 68 slot_dimensionsChanged();
70 fillDefaults( cam ); 69 fillDefaults (cam);
71 } 70 }
72 71
73 OverlayDialog::~OverlayDialog() 72 OverlayDialog::~OverlayDialog() {
74 {
75 delete ui; 73 delete ui;
76 } 74 }
77 75
78 void OverlayDialog::fillDefaults( int newcam ) 76 void OverlayDialog::fillDefaults (int newcam) {
79 { 77 overlayMeta& info = g_win->R()->getOverlay (newcam);
80 overlayMeta& info = g_win->R()->getOverlay( newcam ); 78 radioDefault<int> (newcam, m_cameraArgs);
81 79
82 radioDefault<int>( newcam, m_cameraArgs ); 80 if (info.img != null) {
83 81 ui->filename->setText (info.fname);
84 if( info.img != null ) 82 ui->originX->setValue (info.ox);
85 { 83 ui->originY->setValue (info.oy);
86 ui->filename->setText( info.fname ); 84 ui->width->setValue (info.lw);
87 ui->originX->setValue( info.ox ); 85 ui->height->setValue (info.lh);
88 ui->originY->setValue( info.oy ); 86 } else {
89 ui->width->setValue( info.lw ); 87 ui->filename->setText ("");
90 ui->height->setValue( info.lh ); 88 ui->originX->setValue (0);
91 } 89 ui->originY->setValue (0);
92 else 90 ui->width->setValue (0.0f);
93 { 91 ui->height->setValue (0.0f);
94 ui->filename->setText( "" ); 92 }
95 ui->originX->setValue( 0 ); 93 }
96 ui->originY->setValue( 0 ); 94
97 ui->width->setValue( 0.0f ); 95 str OverlayDialog::fpath() const {
98 ui->height->setValue( 0.0f );
99 }
100 }
101
102 str OverlayDialog::fpath() const
103 {
104 return ui->filename->text(); 96 return ui->filename->text();
105 } 97 }
106 98
107 ushort OverlayDialog::ofsx() const 99 ushort OverlayDialog::ofsx() const {
108 {
109 return ui->originX->value(); 100 return ui->originX->value();
110 } 101 }
111 102
112 ushort OverlayDialog::ofsy() const 103 ushort OverlayDialog::ofsy() const {
113 {
114 return ui->originY->value(); 104 return ui->originY->value();
115 } 105 }
116 106
117 double OverlayDialog::lwidth() const 107 double OverlayDialog::lwidth() const {
118 {
119 return ui->width->value(); 108 return ui->width->value();
120 } 109 }
121 110
122 double OverlayDialog::lheight() const 111 double OverlayDialog::lheight() const {
123 {
124 return ui->height->value(); 112 return ui->height->value();
125 } 113 }
126 114
127 int OverlayDialog::camera() const 115 int OverlayDialog::camera() const {
128 { 116 return radioSwitch<int> (GL::Top, m_cameraArgs);
129 return radioSwitch<int>( GL::Top, m_cameraArgs ); 117 }
130 } 118
131 119 void OverlayDialog::slot_fpath() {
132 void OverlayDialog::slot_fpath() 120 ui->filename->setText (QFileDialog::getOpenFileName (null, "Overlay image"));
133 { 121 }
134 ui->filename->setText( QFileDialog::getOpenFileName( null, "Overlay image" )); 122
135 } 123 void OverlayDialog::slot_help() {
136 124 showDocumentation (g_docs_overlays);
137 void OverlayDialog::slot_help() 125 }
138 { 126
139 showDocumentation( g_docs_overlays ); 127 void OverlayDialog::slot_dimensionsChanged() {
140 } 128 bool enable = (ui->width->value() != 0) || (ui->height->value() != 0);
141 129 ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (enable);
142 void OverlayDialog::slot_dimensionsChanged()
143 {
144 bool enable = ( ui->width->value() != 0 ) || ( ui->height->value() != 0 );
145 ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enable );
146 } 130 }
147 131
148 // ================================================================================================= 132 // =================================================================================================
149 LDrawPathDialog::LDrawPathDialog( const bool validDefault, QWidget* parent, Qt::WindowFlags f ) 133 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f) :
150 : QDialog( parent, f ), m_validDefault( validDefault ) 134 QDialog (parent, f),
151 { 135 m_validDefault (validDefault) {
136
152 ui = new Ui_LDPathUI; 137 ui = new Ui_LDPathUI;
153 ui->setupUi( this ); 138 ui->setupUi (this);
154 ui->status->setText( "---" ); 139 ui->status->setText ("---");
155 140
156 if( validDefault ) 141 if (validDefault)
157 ui->heading->hide(); 142 ui->heading->hide();
158 else 143 else {
159 { 144 cancelButton()->setText ("Exit");
160 cancelButton()->setText( "Exit" ); 145 cancelButton()->setIcon (getIcon ("exit"));
161 cancelButton()->setIcon( getIcon( "exit" )); 146 }
162 } 147
163 148 okButton()->setEnabled (false);
164 okButton()->setEnabled( false ); 149
165 150 connect (ui->path, SIGNAL (textEdited (QString)), this, SLOT (slot_tryConfigure()));
166 connect( ui->path, SIGNAL( textEdited( QString ) ), this, SLOT( slot_tryConfigure() ) ); 151 connect (ui->searchButton, SIGNAL (clicked()), this, SLOT (slot_findPath()));
167 connect( ui->searchButton, SIGNAL( clicked() ), this, SLOT( slot_findPath() ) ); 152 connect (ui->buttonBox, SIGNAL (rejected()), this, validDefault ? SLOT (reject()) : SLOT (slot_exit()));
168 connect( ui->buttonBox, SIGNAL( rejected() ), this, validDefault ? SLOT( reject() ) : SLOT( slot_exit() )); 153
169 154 setPath (io_ldpath);
170 setPath( io_ldpath ); 155
171 156 if (validDefault)
172 if( validDefault )
173 slot_tryConfigure(); 157 slot_tryConfigure();
174 } 158 }
175 159
176 LDrawPathDialog::~LDrawPathDialog() 160 LDrawPathDialog::~LDrawPathDialog() {
177 {
178 delete ui; 161 delete ui;
179 } 162 }
180 163
181 QPushButton* LDrawPathDialog::okButton() 164 QPushButton* LDrawPathDialog::okButton() {
182 { 165 return ui->buttonBox->button (QDialogButtonBox::Ok);
183 return ui->buttonBox->button( QDialogButtonBox::Ok ); 166 }
184 } 167
185 168 QPushButton* LDrawPathDialog::cancelButton() {
186 QPushButton* LDrawPathDialog::cancelButton() 169 return ui->buttonBox->button (QDialogButtonBox::Cancel);
187 { 170 }
188 return ui->buttonBox->button( QDialogButtonBox::Cancel ); 171
189 } 172 void LDrawPathDialog::setPath (str path) {
190 173 ui->path->setText (path);
191 void LDrawPathDialog::setPath( str path ) 174 }
192 { 175
193 ui->path->setText( path ); 176 str LDrawPathDialog::filename() const {
194 }
195
196 str LDrawPathDialog::filename() const
197 {
198 return ui->path->text(); 177 return ui->path->text();
199 } 178 }
200 179
201 void LDrawPathDialog::slot_findPath() 180 void LDrawPathDialog::slot_findPath() {
202 { 181 str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path");
203 str newpath = QFileDialog::getExistingDirectory( this, "Find LDraw Path" ); 182
204 183 if (newpath.length() > 0 && newpath != filename()) {
205 if( newpath.length() > 0 && newpath != filename() ) 184 setPath (newpath);
206 {
207 setPath( newpath );
208 slot_tryConfigure(); 185 slot_tryConfigure();
209 } 186 }
210 } 187 }
211 188
212 void LDrawPathDialog::slot_exit() 189 void LDrawPathDialog::slot_exit() {
213 { 190 exit (1);
214 exit( 1 ); 191 }
215 } 192
216 193 void LDrawPathDialog::slot_tryConfigure() {
217 void LDrawPathDialog::slot_tryConfigure() 194 if (LDPaths::tryConfigure (filename()) == false) {
218 { 195 ui->status->setText (fmt ("<span style=\"color:#700; \">%1</span>", LDPaths::getError()));
219 if( LDPaths::tryConfigure( filename() ) == false ) 196 okButton()->setEnabled (false);
220 {
221 ui->status->setText( fmt( "<span style=\"color:#700; \">%1</span>", LDPaths::getError() ) );
222 okButton()->setEnabled( false );
223 return; 197 return;
224 } 198 }
225 199
226 ui->status->setText( "<span style=\"color: #270; \">OK!</span>" ); 200 ui->status->setText ("<span style=\"color: #270; \">OK!</span>");
227 okButton()->setEnabled( true ); 201 okButton()->setEnabled (true);
228 } 202 }
229 203
230 // ============================================================================= 204 // =============================================================================
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
232 // ============================================================================= 206 // =============================================================================
233 OpenProgressDialog::OpenProgressDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) 207 OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
234 {
235 ui = new Ui_OpenProgressUI; 208 ui = new Ui_OpenProgressUI;
236 ui->setupUi( this ); 209 ui->setupUi (this);
237 ui->progressText->setText( "Parsing..." ); 210 ui->progressText->setText ("Parsing...");
238 211
239 setNumLines( 0 ); 212 setNumLines (0);
240 m_progress = 0; 213 m_progress = 0;
241 } 214 }
242 215
243 OpenProgressDialog::~OpenProgressDialog() 216 OpenProgressDialog::~OpenProgressDialog() {
244 {
245 delete ui; 217 delete ui;
246 } 218 }
247 219
248 READ_ACCESSOR( ulong, OpenProgressDialog::numLines ) 220 READ_ACCESSOR (ulong, OpenProgressDialog::numLines) {
249 {
250 return m_numLines; 221 return m_numLines;
251 } 222 }
252 223
253 SET_ACCESSOR( ulong, OpenProgressDialog::setNumLines ) 224 SET_ACCESSOR (ulong, OpenProgressDialog::setNumLines) {
254 {
255 m_numLines = val; 225 m_numLines = val;
256 ui->progressBar->setRange (0, numLines ()); 226 ui->progressBar->setRange (0, numLines());
257 updateValues(); 227 updateValues();
258 } 228 }
259 229
260 void OpenProgressDialog::updateValues() 230 void OpenProgressDialog::updateValues() {
261 { 231 ui->progressText->setText (fmt ("Parsing... %1 / %2", progress(), numLines()));
262 ui->progressText->setText( fmt( "Parsing... %1 / %2", progress(), numLines() )); 232 ui->progressBar->setValue (progress());
263 ui->progressBar->setValue( progress() ); 233 }
264 } 234
265 235 void OpenProgressDialog::updateProgress (int progress) {
266 void OpenProgressDialog::updateProgress( int progress )
267 {
268 m_progress = progress; 236 m_progress = progress;
269 updateValues (); 237 updateValues();
270 } 238 }
271 239
272 #include "build/moc_dialogs.cpp" 240 #include "build/moc_dialogs.cpp"
241 // kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4;

mercurial