src/gui_actions.cpp

changeset 250
6e80f038e8df
parent 240
bdc9d429cdc2
child 251
c4b96bc41298
equal deleted inserted replaced
249:6b2cc2d82ba6 250:6e80f038e8df
64 64
65 // ============================================================================= 65 // =============================================================================
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
67 // ============================================================================= 67 // =============================================================================
68 void doSave (bool saveAs) { 68 void doSave (bool saveAs) {
69 str path = g_curfile->m_filename; 69 str path = g_curfile->name ();
70 70
71 if (~path == 0 || saveAs) { 71 if (~path == 0 || saveAs) {
72 path = QFileDialog::getSaveFileName (g_win, "Save As", 72 path = QFileDialog::getSaveFileName (g_win, "Save As",
73 g_curfile->m_filename, "LDraw files (*.dat *.ldr)"); 73 g_curfile->name (), "LDraw files (*.dat *.ldr)");
74 74
75 if (~path == 0) { 75 if (~path == 0) {
76 // User didn't give a file name. This happens if the user cancelled 76 // User didn't give a file name. This happens if the user cancelled
77 // saving in the save file dialog. Abort. 77 // saving in the save file dialog. Abort.
78 return; 78 return;
79 } 79 }
80 } 80 }
81 81
82 if (g_curfile->save (path)) { 82 if (g_curfile->save (path)) {
83 g_curfile->m_filename = path; 83 g_curfile->setName (path);
84 g_win->updateTitle (); 84 g_win->updateTitle ();
85 85
86 logf ("Saved successfully to %s\n", path.chars ()); 86 logf ("Saved successfully to %s\n", path.chars ());
87 } else { 87 } else {
88 setlocale (LC_ALL, "C"); 88 setlocale (LC_ALL, "C");
89 89
90 // Tell the user the save failed, and give the option for saving as with it. 90 // Tell the user the save failed, and give the option for saving as with it.
91 QMessageBox dlg (QMessageBox::Critical, "Save Failure", 91 QMessageBox dlg (QMessageBox::Critical, "Save Failure",
92 fmt ("Failed to save to %s\nReason: %s", path.chars(), strerror (g_curfile->lastError)), 92 fmt ("Failed to save to %s\nReason: %s", path.chars(), strerror (errno)),
93 QMessageBox::Close, g_win); 93 QMessageBox::Close, g_win);
94 94
95 QPushButton* saveAsBtn = new QPushButton ("Save As"); 95 QPushButton* saveAsBtn = new QPushButton ("Save As");
96 saveAsBtn->setIcon (getIcon ("file-save-as")); 96 saveAsBtn->setIcon (getIcon ("file-save-as"));
97 dlg.addButton (saveAsBtn, QMessageBox::ActionRole); 97 dlg.addButton (saveAsBtn, QMessageBox::ActionRole);
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
206 // ============================================================================= 206 // =============================================================================
207 MAKE_ACTION (selectAll, "Select All", "select-all", "Selects all objects.", CTRL (A)) { 207 MAKE_ACTION (selectAll, "Select All", "select-all", "Selects all objects.", CTRL (A)) {
208 g_win->sel ().clear (); 208 g_win->sel ().clear ();
209 209
210 for (LDObject* obj : g_curfile->m_objs) 210 for (LDObject* obj : g_curfile->objs ())
211 g_win->sel ().push_back (obj); 211 g_win->sel ().push_back (obj);
212 212
213 g_win->updateSelection (); 213 g_win->updateSelection ();
214 } 214 }
215 215
221 221
222 if (dColor == -1) 222 if (dColor == -1)
223 return; // no consensus on color 223 return; // no consensus on color
224 224
225 g_win->sel ().clear (); 225 g_win->sel ().clear ();
226 for (LDObject* obj : g_curfile->m_objs) 226 for (LDObject* obj : g_curfile->objs ())
227 if (obj->color == dColor) 227 if (obj->color == dColor)
228 g_win->sel ().push_back (obj); 228 g_win->sel ().push_back (obj);
229 229
230 g_win->updateSelection (); 230 g_win->updateSelection ();
231 } 231 }
235 "Select all objects by the given type.", (0)) 235 "Select all objects by the given type.", (0))
236 { 236 {
237 if (g_win->sel ().size () == 0) 237 if (g_win->sel ().size () == 0)
238 return; 238 return;
239 239
240 LDObject::Type eType = g_win->uniformSelectedType (); 240 LDObject::Type type = g_win->uniformSelectedType ();
241 241
242 if (eType == LDObject::Unidentified) 242 if (type == LDObject::Unidentified)
243 return; 243 return;
244 244
245 // If we're selecting subfile references, the reference filename must also 245 // If we're selecting subfile references, the reference filename must also
246 // be uniform. 246 // be uniform.
247 str zRefName; 247 str refName;
248 248
249 if (eType == LDObject::Subfile) { 249 if (type == LDObject::Subfile) {
250 zRefName = static_cast<LDSubfile*> (g_win->sel ()[0])->fileName; 250 refName = static_cast<LDSubfile*> (g_win->sel ()[0])->fileName;
251 251
252 for (LDObject* pObj : g_win->sel ()) 252 for (LDObject* pObj : g_win->sel ())
253 if (static_cast<LDSubfile*> (pObj)->fileName != zRefName) 253 if (static_cast<LDSubfile*> (pObj)->fileName != refName)
254 return; 254 return;
255 } 255 }
256 256
257 g_win->sel ().clear (); 257 g_win->sel ().clear ();
258 for (LDObject* obj : g_curfile->m_objs) { 258 for (LDObject* obj : g_curfile->objs ()) {
259 if (obj->getType() != eType) 259 if (obj->getType() != type)
260 continue; 260 continue;
261 261
262 if (eType == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileName != zRefName) 262 if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileName != refName)
263 continue; 263 continue;
264 264
265 g_win->sel ().push_back (obj); 265 g_win->sel ().push_back (obj);
266 } 266 }
267 267
382 uchar* imagedata = g_win->R ()->screencap (w, h); 382 uchar* imagedata = g_win->R ()->screencap (w, h);
383 383
384 // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. 384 // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well.
385 QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored (); 385 QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored ();
386 386
387 str root = basename (g_curfile->m_filename); 387 str root = basename (g_curfile->name ());
388 if (~root >= 4 && root.substr (~root - 4, -1) == ".dat") 388 if (~root >= 4 && root.substr (~root - 4, -1) == ".dat")
389 root -= 4; 389 root -= 4;
390 390
391 str defaultname = (~root > 0) ? fmt ("%s.png", root.c ()) : ""; 391 str defaultname = (~root > 0) ? fmt ("%s.png", root.c ()) : "";
392 str fname = QFileDialog::getSaveFileName (g_win, "Save Screencap", defaultname, 392 str fname = QFileDialog::getSaveFileName (g_win, "Save Screencap", defaultname,

mercurial