122 |
122 |
123 // ============================================================================= |
123 // ============================================================================= |
124 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
125 KeySequenceConfig* ForgeWindow::shortcutForAction (QAction* act) |
125 KeySequenceConfig* ForgeWindow::shortcutForAction (QAction* act) |
126 { |
126 { |
127 str keycfgname = fmt ("key_%1", act->objectName()); |
127 QString keycfgname = fmt ("key_%1", act->objectName()); |
128 return KeySequenceConfig::getByName (keycfgname); |
128 return KeySequenceConfig::getByName (keycfgname); |
129 } |
129 } |
130 |
130 |
131 // ============================================================================= |
131 // ============================================================================= |
132 // ----------------------------------------------------------------------------- |
132 // ----------------------------------------------------------------------------- |
144 // ============================================================================= |
144 // ============================================================================= |
145 // ----------------------------------------------------------------------------- |
145 // ----------------------------------------------------------------------------- |
146 void ForgeWindow::slot_action() |
146 void ForgeWindow::slot_action() |
147 { |
147 { |
148 // Get the name of the sender object and use it to compose the slot name. |
148 // Get the name of the sender object and use it to compose the slot name. |
149 str methodName = fmt ("slot_%1", sender()->objectName()); |
149 QString methodName = fmt ("slot_%1", sender()->objectName()); |
150 |
150 |
151 #ifdef DEBUG |
151 #ifdef DEBUG |
152 log ("Action %1 triggered", sender()->objectName()); |
152 log ("Action %1 triggered", sender()->objectName()); |
153 #endif |
153 #endif |
154 |
154 |
189 |
189 |
190 QAction* first = null; |
190 QAction* first = null; |
191 |
191 |
192 for (const QVariant& it : io_recentfiles) |
192 for (const QVariant& it : io_recentfiles) |
193 { |
193 { |
194 str file = it.toString(); |
194 QString file = it.toString(); |
195 QAction* recent = new QAction (getIcon ("open-recent"), file, this); |
195 QAction* recent = new QAction (getIcon ("open-recent"), file, this); |
196 |
196 |
197 connect (recent, SIGNAL (triggered()), this, SLOT (slot_recentFile())); |
197 connect (recent, SIGNAL (triggered()), this, SLOT (slot_recentFile())); |
198 ui->menuOpenRecent->insertAction (first, recent); |
198 ui->menuOpenRecent->insertAction (first, recent); |
199 m_recentFiles << recent; |
199 m_recentFiles << recent; |
205 // ----------------------------------------------------------------------------- |
205 // ----------------------------------------------------------------------------- |
206 QList<LDQuickColor> quickColorsFromConfig() |
206 QList<LDQuickColor> quickColorsFromConfig() |
207 { |
207 { |
208 QList<LDQuickColor> colors; |
208 QList<LDQuickColor> colors; |
209 |
209 |
210 for (str colorname : gui_colortoolbar.split (":")) |
210 for (QString colorname : gui_colortoolbar.split (":")) |
211 { |
211 { |
212 if (colorname == "|") |
212 if (colorname == "|") |
213 colors << LDQuickColor::getSeparator(); |
213 colors << LDQuickColor::getSeparator(); |
214 else |
214 else |
215 { |
215 { |
264 |
264 |
265 // ============================================================================= |
265 // ============================================================================= |
266 // ----------------------------------------------------------------------------- |
266 // ----------------------------------------------------------------------------- |
267 void ForgeWindow::updateTitle() |
267 void ForgeWindow::updateTitle() |
268 { |
268 { |
269 str title = fmt (APPNAME " %1", fullVersionString()); |
269 QString title = fmt (APPNAME " %1", fullVersionString()); |
270 |
270 |
271 // Append our current file if we have one |
271 // Append our current file if we have one |
272 if (getCurrentDocument()) |
272 if (getCurrentDocument()) |
273 { |
273 { |
274 if (getCurrentDocument()->getName().length() > 0) |
274 if (getCurrentDocument()->getName().length() > 0) |
778 |
778 |
779 // ============================================================================= |
779 // ============================================================================= |
780 // ----------------------------------------------------------------------------- |
780 // ----------------------------------------------------------------------------- |
781 bool ForgeWindow::save (LDDocument* f, bool saveAs) |
781 bool ForgeWindow::save (LDDocument* f, bool saveAs) |
782 { |
782 { |
783 str path = f->getFullPath(); |
783 QString path = f->getFullPath(); |
784 |
784 |
785 if (saveAs || path.isEmpty()) |
785 if (saveAs || path.isEmpty()) |
786 { |
786 { |
787 str name = f->getDefaultName(); |
787 QString name = f->getDefaultName(); |
788 |
788 |
789 if (!f->getFullPath().isEmpty()) |
789 if (!f->getFullPath().isEmpty()) |
790 name = f->getFullPath(); |
790 name = f->getFullPath(); |
791 elif (!f->getName().isEmpty()) |
791 elif (!f->getName().isEmpty()) |
792 name = f->getName(); |
792 name = f->getName(); |
812 // Add it to recent files |
812 // Add it to recent files |
813 addRecentFile (path); |
813 addRecentFile (path); |
814 return true; |
814 return true; |
815 } |
815 } |
816 |
816 |
817 str message = fmt (tr ("Failed to save to %1: %2"), path, strerror (errno)); |
817 QString message = fmt (tr ("Failed to save to %1: %2"), path, strerror (errno)); |
818 |
818 |
819 // Tell the user the save failed, and give the option for saving as with it. |
819 // Tell the user the save failed, and give the option for saving as with it. |
820 QMessageBox dlg (QMessageBox::Critical, tr ("Save Failure"), message, QMessageBox::Close, g_win); |
820 QMessageBox dlg (QMessageBox::Critical, tr ("Save Failure"), message, QMessageBox::Close, g_win); |
821 |
821 |
822 // Add a save-as button |
822 // Add a save-as button |
843 g_win->spawnContextMenu (ev->globalPos()); |
843 g_win->spawnContextMenu (ev->globalPos()); |
844 } |
844 } |
845 |
845 |
846 // ============================================================================= |
846 // ============================================================================= |
847 // ----------------------------------------------------------------------------- |
847 // ----------------------------------------------------------------------------- |
848 QPixmap getIcon (str iconName) |
848 QPixmap getIcon (QString iconName) |
849 { |
849 { |
850 return (QPixmap (fmt (":/icons/%1.png", iconName))); |
850 return (QPixmap (fmt (":/icons/%1.png", iconName))); |
851 } |
851 } |
852 |
852 |
853 // ============================================================================= |
853 // ============================================================================= |
854 bool confirm (str msg) |
854 bool confirm (QString msg) |
855 { |
855 { |
856 return confirm (ForgeWindow::tr ("Confirm"), msg); |
856 return confirm (ForgeWindow::tr ("Confirm"), msg); |
857 } |
857 } |
858 |
858 |
859 bool confirm (str title, str msg) |
859 bool confirm (QString title, QString msg) |
860 { |
860 { |
861 return QMessageBox::question (g_win, title, msg, |
861 return QMessageBox::question (g_win, title, msg, |
862 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes; |
862 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes; |
863 } |
863 } |
864 |
864 |
865 // ============================================================================= |
865 // ============================================================================= |
866 void critical (str msg) |
866 void critical (QString msg) |
867 { |
867 { |
868 QMessageBox::critical (g_win, ForgeWindow::tr ("Error"), msg, |
868 QMessageBox::critical (g_win, ForgeWindow::tr ("Error"), msg, |
869 (QMessageBox::Close), QMessageBox::Close); |
869 (QMessageBox::Close), QMessageBox::Close); |
870 } |
870 } |
871 |
871 |