Use system clipboard rather than an internal one

Tue, 09 Jul 2013 03:04:31 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 09 Jul 2013 03:04:31 +0300
changeset 368
436ceec98c4f
parent 367
3745caa5d87d
child 369
0060d11e4991

Use system clipboard rather than an internal one

changelog.txt file | annotate | diff | comparison | revisions
src/gui_editactions.cpp file | annotate | diff | comparison | revisions
--- a/changelog.txt	Tue Jul 09 02:57:11 2013 +0300
+++ b/changelog.txt	Tue Jul 09 03:04:31 2013 +0300
@@ -16,6 +16,8 @@
 - Objects can now be edited by double-clicking on them.
 - When drawing, drawn vertices now display coordinate labels.
 - Added an action to quickly toggle BFC red/green view.
+- Objects are now copied to the system clipboard as LDraw code, rather than to an internal clipboard not
+	accessible outside of LDForge.
 - Changed default keys for Y-axis moving from PgUp/PgDown to Home and End ala MLCAD.
 - Cleaned up the toolbars, removed clutter by removing most of the not-so-often-used items, though of course
 	the functionality is still available through menus and keyboard shortcuts.
--- a/src/gui_editactions.cpp	Tue Jul 09 02:57:11 2013 +0300
+++ b/src/gui_editactions.cpp	Tue Jul 09 03:04:31 2013 +0300
@@ -19,6 +19,7 @@
 #include <QSpinBox>
 #include <QCheckBox>
 #include <QBoxLayout>
+#include <QClipboard>
 
 #include "gui.h"
 #include "common.h"
@@ -34,8 +35,6 @@
 #include "ui_editraw.h"
 #include "ui_flip.h"
 
-vector<str> g_Clipboard;
-
 cfg (bool, edit_schemanticinline, false);
 
 // =============================================================================
@@ -46,15 +45,17 @@
 	int num = 0;
 	
 	// Clear the clipboard first.
-	g_Clipboard.clear ();
+	qApp->clipboard()->clear();
 	
 	// Now, copy the contents into the clipboard.
-	for (LDObject* obj : objs)
-	{
-		g_Clipboard << obj->raw ();
+	str data;
+	for (LDObject* obj : objs) {
+		data += ( obj->raw () + "\n" );
 		++num;
 	}
 	
+	qApp->clipboard()->setText( data );
+	
 	return num;
 }
 
@@ -80,11 +81,13 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.", CTRL (V)) {
+	const str clipboardText = qApp->clipboard()->text();
 	ulong idx = g_win->getInsertionPoint ();
 	g_win->sel ().clear ();
 	int num = 0;
 	
-	for (str line : g_Clipboard) {
+	for( str line : clipboardText.split( "\n", QString::SkipEmptyParts ))
+	{
 		LDObject* pasted = parseLine (line);
 		g_curfile->insertObj (idx++, pasted);
 		g_win->sel () << pasted;

mercurial