src/MainWindow.cc

changeset 644
93dcd1a0e4bd
parent 642
751a8df42842
child 646
1ccb092cebed
equal deleted inserted replaced
643:a79277000830 644:93dcd1a0e4bd
113 113
114 // ============================================================================= 114 // =============================================================================
115 // 115 //
116 KeySequenceConfig* MainWindow::shortcutForAction (QAction* act) 116 KeySequenceConfig* MainWindow::shortcutForAction (QAction* act)
117 { 117 {
118 QString keycfgname = fmt ("key_%1", act->objectName()); 118 QString keycfgname = format ("key_%1", act->objectName());
119 return KeySequenceConfig::getByName (keycfgname); 119 return KeySequenceConfig::getByName (keycfgname);
120 } 120 }
121 121
122 // ============================================================================= 122 // =============================================================================
123 // 123 //
134 134
135 // ============================================================================= 135 // =============================================================================
136 // 136 //
137 void MainWindow::slot_action() 137 void MainWindow::slot_action()
138 { 138 {
139 // Get the name of the sender object and use it to compose the slot name. 139 // Get the name of the sender object and use it to compose the slot name,
140 QString methodName = fmt ("slot_%1", sender()->objectName()); 140 // then invoke this slot to call the action.
141 141 QMetaObject::invokeMethod (this,
142 #ifdef DEBUG 142 qPrintable (format ("slot_%1", sender()->objectName())), Qt::DirectConnection);
143 log ("Action %1 triggered", sender()->objectName());
144 #endif
145
146 // Now invoke this slot to call the action.
147 QMetaObject::invokeMethod (this, methodName.toAscii().constData(), Qt::DirectConnection);
148 endAction(); 143 endAction();
149 } 144 }
150 145
151 // ============================================================================= 146 // =============================================================================
152 // 147 //
255 250
256 // ============================================================================= 251 // =============================================================================
257 // 252 //
258 void MainWindow::updateTitle() 253 void MainWindow::updateTitle()
259 { 254 {
260 QString title = fmt (APPNAME " %1", fullVersionString()); 255 QString title = format (APPNAME " %1", fullVersionString());
261 256
262 // Append our current file if we have one 257 // Append our current file if we have one
263 if (getCurrentDocument()) 258 if (getCurrentDocument())
264 { 259 {
265 if (getCurrentDocument()->name().length() > 0) 260 if (getCurrentDocument()->name().length() > 0)
266 title += fmt (": %1", basename (getCurrentDocument()->name())); 261 title += format (": %1", basename (getCurrentDocument()->name()));
267 else 262 else
268 title += fmt (": <anonymous>"); 263 title += format (": <anonymous>");
269 264
270 if (getCurrentDocument()->getObjectCount() > 0 && 265 if (getCurrentDocument()->getObjectCount() > 0 &&
271 getCurrentDocument()->getObject (0)->type() == LDObject::EComment) 266 getCurrentDocument()->getObject (0)->type() == LDObject::EComment)
272 { 267 {
273 // Append title 268 // Append title
274 LDComment* comm = static_cast<LDComment*> (getCurrentDocument()->getObject (0)); 269 LDComment* comm = static_cast<LDComment*> (getCurrentDocument()->getObject (0));
275 title += fmt (": %1", comm->text()); 270 title += format (": %1", comm->text());
276 } 271 }
277 272
278 if (getCurrentDocument()->hasUnsavedChanges()) 273 if (getCurrentDocument()->hasUnsavedChanges())
279 title += '*'; 274 title += '*';
280 } 275 }
361 break; 356 break;
362 } 357 }
363 358
364 case LDObject::EError: 359 case LDObject::EError:
365 { 360 {
366 descr = fmt ("ERROR: %1", obj->asText()); 361 descr = format ("ERROR: %1", obj->asText());
367 break; 362 break;
368 } 363 }
369 364
370 case LDObject::EVertex: 365 case LDObject::EVertex:
371 { 366 {
375 370
376 case LDObject::ESubfile: 371 case LDObject::ESubfile:
377 { 372 {
378 LDSubfile* ref = static_cast<LDSubfile*> (obj); 373 LDSubfile* ref = static_cast<LDSubfile*> (obj);
379 374
380 descr = fmt ("%1 %2, (", ref->fileInfo()->getDisplayName(), ref->position().toString (true)); 375 descr = format ("%1 %2, (", ref->fileInfo()->getDisplayName(), ref->position().toString (true));
381 376
382 for (int i = 0; i < 9; ++i) 377 for (int i = 0; i < 9; ++i)
383 descr += fmt ("%1%2", ref->transform()[i], (i != 8) ? " " : ""); 378 descr += format ("%1%2", ref->transform()[i], (i != 8) ? " " : "");
384 379
385 descr += ')'; 380 descr += ')';
386 break; 381 break;
387 } 382 }
388 383
393 } 388 }
394 389
395 case LDObject::EOverlay: 390 case LDObject::EOverlay:
396 { 391 {
397 LDOverlay* ovl = static_cast<LDOverlay*> (obj); 392 LDOverlay* ovl = static_cast<LDOverlay*> (obj);
398 descr = fmt ("[%1] %2 (%3, %4), %5 x %6", g_CameraNames[ovl->camera()], 393 descr = format ("[%1] %2 (%3, %4), %5 x %6", g_CameraNames[ovl->camera()],
399 basename (ovl->fileName()), ovl->x(), ovl->y(), 394 basename (ovl->fileName()), ovl->x(), ovl->y(),
400 ovl->width(), ovl->height()); 395 ovl->width(), ovl->height());
401 break; 396 break;
402 } 397 }
403 398
769 if (f->save (path)) 764 if (f->save (path))
770 { 765 {
771 if (f == getCurrentDocument()) 766 if (f == getCurrentDocument())
772 updateTitle(); 767 updateTitle();
773 768
774 log ("Saved to %1.", path); 769 print ("Saved to %1.", path);
775 770
776 // Add it to recent files 771 // Add it to recent files
777 addRecentFile (path); 772 addRecentFile (path);
778 return true; 773 return true;
779 } 774 }
780 775
781 QString message = fmt (tr ("Failed to save to %1: %2"), path, strerror (errno)); 776 QString message = format (tr ("Failed to save to %1: %2"), path, strerror (errno));
782 777
783 // Tell the user the save failed, and give the option for saving as with it. 778 // Tell the user the save failed, and give the option for saving as with it.
784 QMessageBox dlg (QMessageBox::Critical, tr ("Save Failure"), message, QMessageBox::Close, g_win); 779 QMessageBox dlg (QMessageBox::Critical, tr ("Save Failure"), message, QMessageBox::Close, g_win);
785 780
786 // Add a save-as button 781 // Add a save-as button
809 804
810 // ============================================================================= 805 // =============================================================================
811 // 806 //
812 QPixmap getIcon (QString iconName) 807 QPixmap getIcon (QString iconName)
813 { 808 {
814 return (QPixmap (fmt (":/icons/%1.png", iconName))); 809 return (QPixmap (format (":/icons/%1.png", iconName)));
815 } 810 }
816 811
817 // ============================================================================= 812 // =============================================================================
818 bool confirm (QString msg) 813 bool confirm (QString msg)
819 { 814 {
882 { 877 {
883 LDColor* col = getColor (pair.first); 878 LDColor* col = getColor (pair.first);
884 assert (col != null); 879 assert (col != null);
885 880
886 QIcon ico = makeColorIcon (col, 16); 881 QIcon ico = makeColorIcon (col, 16);
887 box->addItem (ico, fmt ("[%1] %2 (%3 object%4)", 882 box->addItem (ico, format ("[%1] %2 (%3 object%4)",
888 pair.first, col->name, pair.second, plural (pair.second))); 883 pair.first, col->name, pair.second, plural (pair.second)));
889 box->setItemData (row, pair.first); 884 box->setItemData (row, pair.first);
890 885
891 ++row; 886 ++row;
892 } 887 }

mercurial