changeset 215:8aaa84d48451

Improve examples.
author SokoL_SD
date Tue, 14 Jul 2009 15:25:45 +0000
parents 11f1760d1700
children 06e7d3219464
files CMakeLists.txt cmake/FindD.cmake demos/interview/CMakeLists.txt examples/desktop/systray/CMakeLists.txt examples/dialogs/classwizard/CMakeLists.txt examples/dialogs/classwizard/classwizard.d examples/dialogs/classwizard/main.d examples/dialogs/standarddialogs/CMakeLists.txt examples/dialogs/standarddialogs/dialog.d examples/dialogs/standarddialogs/main.d examples/draganddrop/dropsite/CMakeLists.txt examples/draganddrop/dropsite/dropsitewindow.d examples/draganddrop/dropsite/main.d examples/itemviews/customsortfiltermodel/CMakeLists.txt examples/itemviews/editabletreemodel/CMakeLists.txt examples/layouts/basiclayouts/CMakeLists.txt examples/layouts/borderlayout/CMakeLists.txt examples/layouts/dynamiclayouts/CMakeLists.txt examples/mainwindows/dockwidgets/CMakeLists.txt examples/mainwindows/dockwidgets/mainwindow.d examples/opengl/hellogl/CMakeLists.txt examples/opengl/hellogl/glwidget.d examples/opengl/hellogl/window.d examples/tutorials/addressbook/part1/CMakeLists.txt examples/widgets/analogclock/CMakeLists.txt examples/widgets/calculator/CMakeLists.txt examples/widgets/calculator/calculator.d examples/widgets/calculator/main.d
diffstat 28 files changed, 98 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -367,7 +367,7 @@
 	else(CMAKE_HOST_WIN32 AND D_IS_MARS)
 	    set(${package}_lib_param Qt${package_big}) ## Paths for QtD libs. Needed by examples.
 	endif(CMAKE_HOST_WIN32 AND D_IS_MARS) 
-	add_d_target(${lib_name} TYPE ${build_type} INCLUDES ${QTD_IMPORT_PATH} SOURCES ${d_sources} OBJECTS ${cpp_objs} ${d_implib}
+	add_d_target(${lib_name} NOT_DETECT_DEPENDS TYPE ${build_type} INCLUDES ${QTD_IMPORT_PATH} SOURCES ${d_sources} OBJECTS ${cpp_objs} ${d_implib}
 	      OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib DEPENDS ${d_implib})
 	install(FILES ${CMAKE_BINARY_DIR}/${lib} COMPONENT qtd DESTINATION lib)
 	
--- a/cmake/FindD.cmake	Tue Jul 14 14:37:23 2009 +0000
+++ b/cmake/FindD.cmake	Tue Jul 14 15:25:45 2009 +0000
@@ -171,19 +171,19 @@
     ## Parse parameters list.
     set(params_tmp SOURCES FLAGS)
     foreach(arg_tmp ${ARGN})
-	set(founded_type_tmp)
-	if(NOT founded_type_tmp)
+	set(found_type_tmp)
+	if(NOT found_type_tmp)
 	    foreach(param_tmp ${params_tmp})
 		if(arg_tmp STREQUAL param_tmp)	
 		    set(type_tmp ${param_tmp})
-		    set(founded_type_tmp 1)
+		    set(found_type_tmp 1)
 		    break(param_tmp ${params_tmp})
 		endif(arg_tmp STREQUAL param_tmp)
 	    endforeach(param_tmp ${params_tmp})	
-	endif(NOT founded_type_tmp)
-	if(NOT founded_type_tmp)
+	endif(NOT found_type_tmp)
+	if(NOT found_type_tmp)
 	    set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp})
-	endif(NOT founded_type_tmp)
+	endif(NOT found_type_tmp)
     endforeach(arg_tmp ${ARGN})
 
     if(NOT SINGLE_D_OBJECT)
@@ -290,28 +290,30 @@
     set(OUTPUT_PATH_tmp )
     set(compile_flags_tmp ${D_FLAGS})
     set(additional_commands_tmp )
+    set(detect_deps_tmp 1)
     set(link_flags_tmp )
 
     ## Parse parameters list.
     set(params_tmp TYPE INCLUDES FLAGS SOURCES NO_DEPS_SOURCES OBJECTS LIBS LIB_PATHS DEPENDS OUTPUT_PATH)
+    
     foreach(arg_tmp ${ARGN})
-	set(founded_type_tmp)
-	if(${arg_tmp} STREQUAL "DETECT_DEPENDS")		
-	    set(auto_detect_depentes_tmp 1)
-	    set(founded_type_tmp 1)
-	endif(${arg_tmp} STREQUAL "DETECT_DEPENDS")
-	if(NOT founded_type_tmp)
+	set(found_type_tmp)
+	if(${arg_tmp} STREQUAL "NOT_DETECT_DEPENDS")		
+	    set(detect_deps_tmp 0)
+	    set(found_type_tmp 1)
+	endif(${arg_tmp} STREQUAL "NOT_DETECT_DEPENDS")
+	if(NOT found_type_tmp)
 	    foreach(param_tmp ${params_tmp})
 		if(arg_tmp STREQUAL param_tmp)	
 		    set(type_tmp ${param_tmp})
-		    set(founded_type_tmp 1)
+		    set(found_type_tmp 1)
 		    break(param_tmp ${params_tmp})
 		endif(arg_tmp STREQUAL param_tmp)
 	    endforeach(param_tmp ${params_tmp})	
-	endif(NOT founded_type_tmp)
-	if(NOT founded_type_tmp)
+	endif(NOT found_type_tmp)
+	if(NOT found_type_tmp)
 	    set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp})
-	endif(NOT founded_type_tmp)
+	endif(NOT found_type_tmp)
     endforeach(arg_tmp ${ARGN})
 
     ## Init target type.
@@ -405,10 +407,11 @@
 	set(compile_flags_tmp ${compile_flags_tmp} ${D_${CMAKE_BUILD_TYPE_UPPER}_FLAGS})
     endif(CMAKE_BUILD_TYPE)
 
-    if(auto_detect_depentes_tmp)	
+    if(detect_deps_tmp)
+	message(STATUS "Getting dependencies for ${name}")
 	get_files_depends(tmp ${SOURCES_tmp})
 	set(SOURCES_tmp ${tmp})
-    endif(auto_detect_depentes_tmp)
+    endif(detect_deps_tmp)
     set(SOURCES_tmp ${SOURCES_tmp} ${NO_DEPS_SOURCES_tmp})
     
     set(used_ar_tmp)
@@ -500,6 +503,7 @@
     execute_process(COMMAND ${DC} -c -o- -v ${compile_flags_tmp} ${ARGN}
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                   OUTPUT_VARIABLE dc_output_tmp
+		  
     )
     string(REGEX MATCHALL "import[^\\(]*([^\\)]*)" dc_output_tmp "${dc_output_tmp}")
     set(${imported})
--- a/demos/interview/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/demos/interview/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(interview DETECT_DEPENDS main.d RESOURCES interview.qrc)
+build_example(interview main.d RESOURCES interview.qrc)
--- a/examples/desktop/systray/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/desktop/systray/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(systray main.d window.d RESOURCES systray.qrc)
\ No newline at end of file
+build_example(systray main.d RESOURCES systray.qrc)
\ No newline at end of file
--- a/examples/dialogs/classwizard/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/dialogs/classwizard/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(classwizard main.d classwizard.d RESOURCES classwizard.qrc)
\ No newline at end of file
+build_example(classwizard main.d RESOURCES classwizard.qrc)
\ No newline at end of file
--- a/examples/dialogs/classwizard/classwizard.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/dialogs/classwizard/classwizard.d	Tue Jul 14 15:25:45 2009 +0000
@@ -54,21 +54,7 @@
 import qt.core.QDir;
 import qt.core.QRegExp;
 
-version(Tango)
-{
-	import tango.text.convert.Format: Format = format;
-	import tango.core.Array;
-	import tango.text.Ascii;
-	alias toUpper toupper;
-	alias toLower tolower;
-	
-	const string cannot_write_file_str = tr("Cannot write file {}:\n{}");
-}
-else { 
-	import std.string; 
-	import std.algorithm;
-	const string cannot_write_file_str = tr("Cannot write file %s:\n%s");
-}
+import std.string; 
 
 
 class ClassWizard : public QWizard
@@ -92,12 +78,6 @@
 
 	void accept()
 	{
-		version(Tango)
-			const string cannot_write_file_str = tr("Cannot write file {}:\n{}");
-		else 
-			const string cannot_write_file_str = tr("Cannot write file %s:\n%s");
-
-	    
 		string className = field("className").toString();
 		string baseClass = field("baseClass").toString();
 		string macroName = field("macroName").toString();
@@ -161,7 +141,7 @@
 		auto headerFile = new QFile(outputDir ~ "/" ~ header);
 		if (!headerFile.open(QFile.WriteOnly | QFile.Text)) {
 			QMessageBox.warning(null, tr("Simple Wizard"),
-					format(cannot_write_file_str,
+					format(tr("Cannot write file %s:\n%s"),
 					headerFile.fileName(),
 					headerFile.errorString()));
 			return;
@@ -215,7 +195,7 @@
 		auto implementationFile = new QFile(outputDir ~ "/" ~ implementation);
 		if (!implementationFile.open(QFile.WriteOnly | QFile.Text)) {
 			QMessageBox.warning(null, tr("Simple Wizard"),
-					format(cannot_write_file_str,
+					format(tr("Cannot write file %s:\n%s"),
 					implementationFile.fileName(),
 					implementationFile.errorString()));
 			return;
@@ -489,17 +469,8 @@
 	void initializePage()
 	{
 		string finishText = wizard().buttonText(QWizard.FinishButton);	
-		version(Tango)
-		{
-			auto pos = remove(finishText, '&');
-			const string str = tr("Click {} to generate the class skeleton.");
-		}
-		else
-		{
-			const string str = tr("Click %s to generate the class skeleton.");
-			// TODO: port to D2.
-		}
-		label.setText(format(str, finishText));
+		// TODO: port to D2: auto pos = remove(finishText, '&');
+		label.setText(format(tr("Click %s to generate the class skeleton."), finishText));
 	}
 
 private:
--- a/examples/dialogs/classwizard/main.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/dialogs/classwizard/main.d	Tue Jul 14 15:25:45 2009 +0000
@@ -40,16 +40,15 @@
 ****************************************************************************/
 module main;
 
-
 import qt.gui.QApplication;
 import qt.core.QTranslator;
 import qt.core.QLocale;
 import qt.core.QLibraryInfo;
 
-
-import classwizard;
-import qrc_classwizard;
-
+version(D_Version2) 
+	import classwizard; 
+else 
+ 	import classwizard_d1; 
 
 int main(string[] args)
 {
--- a/examples/dialogs/standarddialogs/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/dialogs/standarddialogs/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(standarddialogs main.d dialog.d)
\ No newline at end of file
+build_example(standarddialogs main.d)
\ No newline at end of file
--- a/examples/dialogs/standarddialogs/dialog.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/dialogs/standarddialogs/dialog.d	Tue Jul 14 15:25:45 2009 +0000
@@ -55,10 +55,7 @@
 import qt.gui.QFileDialog;
 import qt.core.QFile;
 
-version(Tango)  
-    import tango.text.convert.Format;
-else
-    import std.string;
+import std.string;
 
 
 string MESSAGE = tr("<p>Message boxes have a caption, a text, "
@@ -212,10 +209,7 @@
 		bool ok;
 		int i = QInputDialog.getInt(this, tr("QInputgetInteger()"), tr("Percentage:"), 25, 0, 100, 1, ok);
 		if (ok)
-			version(Tango) 
-				integerLabel.setText(Format("{}", i)); 
-			else
-				integerLabel.setText(format("%d", i)); 
+			integerLabel.setText(format("%d", i)); 
 	}
 
 	void setDouble()
@@ -224,10 +218,7 @@
 		double d = QInputDialog.getDouble(this, tr("QInputgetDouble()"),
 						tr("Amount:"), 37.56, -10000, 10000, 2, ok);
 		if (ok)
-			version(Tango) 
-				doubleLabel.setText(Format("${}", d));
-			else
-				integerLabel.setText(format("%g", d)); 	
+			integerLabel.setText(format("%g", d)); 	
 	}
 
 	void setItem()
@@ -314,12 +305,7 @@
 						options);
 		if (files.length) {
 			openFilesPath = files[0];
-			version(Tango) 
-				openFileNamesLabel.setText(Format("{}", files));
-			else
-			{
-				openFileNamesLabel.setText(join(files, "; "));
-			}
+			openFileNamesLabel.setText(join(files, "; "));
 		}
 	}
 
--- a/examples/dialogs/standarddialogs/main.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/dialogs/standarddialogs/main.d	Tue Jul 14 15:25:45 2009 +0000
@@ -46,7 +46,11 @@
 import qt.core.QLibraryInfo;
 import qt.gui.QApplication;
 
-import dialog;
+version(D_Version2) 
+	import dialog;
+else 
+ 	import dialog_d1; 
+
 
 
 int main(string[] args)
--- a/examples/draganddrop/dropsite/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/draganddrop/dropsite/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(dropsite main.d droparea.d dropsitewindow.d)
\ No newline at end of file
+build_example(dropsite main.d)
\ No newline at end of file
--- a/examples/draganddrop/dropsite/dropsitewindow.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/draganddrop/dropsite/dropsitewindow.d	Tue Jul 14 15:25:45 2009 +0000
@@ -41,14 +41,7 @@
 
 module dropsitewindow;
 
-version(Tango) {
-    import tango.text.Util;
-    import tango.text.Ascii;
-    import tango.text.convert.Format;
-} else {
-    import std.string;
-    alias strip trim;
-}
+import std.string;
 
 import qt.gui.QWidget;
 import qt.gui.QLabel;
@@ -120,9 +113,9 @@
 
 			string text;
 			if (format == "text/plain") {
-				text = trim(mimeData.text());
+				text = strip(mimeData.text());
 			} else if (format == "text/html") {
-				text = trim(mimeData.html());
+				text = strip(mimeData.html());
 			} else if (format == "text/uri-list") {
 				QUrl[] urlList = mimeData.urls();
 				for (int i = 0; i < urlList.length && i < 32; ++i) {
@@ -132,10 +125,7 @@
 			} else {
 				QByteArray data = mimeData.data(format);
 				for (int i = 0; i < data.size() && i < 32; ++i) {
-					version(Tango)
-					    string hex = toUpper(Format("{0:x}", data.at(i)));
-					else
-					    string hex = toupper(std.string.format("%x", data.at(i)));					
+					string hex = toupper(std.string.format("%x", data.at(i)));					
 					text ~= hex ~ " ";
 				}
 			}
--- a/examples/draganddrop/dropsite/main.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/draganddrop/dropsite/main.d	Tue Jul 14 15:25:45 2009 +0000
@@ -40,7 +40,12 @@
 ****************************************************************************/
 
 import qt.gui.QApplication;
-import dropsitewindow;
+
+version(D_Version2) 
+	import dropsitewindow;
+else 
+ 	import dropsitewindow_d1; 
+
 
 int main(string[] args)
 {
--- a/examples/itemviews/customsortfiltermodel/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/itemviews/customsortfiltermodel/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(mysortfilterproxymodel DETECT_DEPENDS main.d)
+build_example(mysortfilterproxymodel main.d)
--- a/examples/itemviews/editabletreemodel/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/itemviews/editabletreemodel/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(editabletreemodel main.d mainwindow.d treeitem.d treemodel.d ui_mainwindow.d qrc_editabletreemodel.d RESOURCES editabletreemodel.qrc FORMS mainwindow.ui)
\ No newline at end of file
+build_example(editabletreemodel main.d RESOURCES editabletreemodel.qrc FORMS mainwindow.ui)
\ No newline at end of file
--- a/examples/layouts/basiclayouts/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/layouts/basiclayouts/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(basiclayouts main.d dialog.d)
\ No newline at end of file
+build_example(basiclayouts main.d)
\ No newline at end of file
--- a/examples/layouts/borderlayout/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/layouts/borderlayout/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(borderlayout DETECT_DEPENDS main.d)
\ No newline at end of file
+build_example(borderlayout main.d)
\ No newline at end of file
--- a/examples/layouts/dynamiclayouts/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/layouts/dynamiclayouts/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(dynamiclayouts main.d dialog.d)
\ No newline at end of file
+build_example(dynamiclayouts main.d)
\ No newline at end of file
--- a/examples/mainwindows/dockwidgets/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/mainwindows/dockwidgets/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(dockwidgets main.d mainwindow.d RESOURCES dockwidgets.qrc)
\ No newline at end of file
+build_example(dockwidgets main.d RESOURCES dockwidgets.qrc)
\ No newline at end of file
--- a/examples/mainwindows/dockwidgets/mainwindow.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/mainwindows/dockwidgets/mainwindow.d	Tue Jul 14 15:25:45 2009 +0000
@@ -54,15 +54,8 @@
 import qt.gui.QStatusBar;
 import qt.gui.QFont;
 import qt.gui.QIcon;
+import qt.core.QDate;
 
-import qt.core.QDate;
-/*import qt.gui.
-import qt.gui.
-import qt.gui.
-import qt.gui.
-import qt.gui.
-import qt.gui.
-*/
 version(Tango)
     import tango.text.Util;
 else
--- a/examples/opengl/hellogl/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/opengl/hellogl/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,2 +1,2 @@
 build_example(hellogl PACKAGES QtCore QtGui QtOpenGL 
-  SOURCES main.d window.d glwidget.d)
\ No newline at end of file
+  SOURCES main.d)
\ No newline at end of file
--- a/examples/opengl/hellogl/glwidget.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/opengl/hellogl/glwidget.d	Tue Jul 14 15:25:45 2009 +0000
@@ -35,23 +35,14 @@
 **
 ****************************************************************************/
 
-version(Tango)
-    import tango.math.Math;
-else
-{
-    import std.math;
-    int rndint(real x)
-    {
-	return cast(int)rndtol(x);
-    }
-}
+import std.math;
+import std.conv;
 
 import qt.core.QPoint;
 import qt.gui.QMouseEvent;
 import qt.opengl.QGLWidget;
 import qt.gui.QColor;
 import qt.core.QSize;
-
 import qt.opengl.gl;
 import qt.opengl.glu;
 
@@ -250,7 +241,7 @@
 
         void extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
         {
-            qglColor(trolltechGreen.darker(rndint(250 + (100 * x1))));
+            qglColor(trolltechGreen.darker(to!(int)(rndtol(250 + (100 * x1)))));
 
             glVertex3d(x1, y1, +0.05);
             glVertex3d(x2, y2, +0.05);
--- a/examples/opengl/hellogl/window.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/opengl/hellogl/window.d	Tue Jul 14 15:25:45 2009 +0000
@@ -39,7 +39,10 @@
 import qt.gui.QSlider;
 import qt.gui.QHBoxLayout;
 
-import glwidget;
+version(D_Version2)
+    import glwidget;
+else
+    import glwidget_d1;
 
 class Window : public QWidget
 {
--- a/examples/tutorials/addressbook/part1/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/tutorials/addressbook/part1/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(addressbook main.d addressbook.d)
\ No newline at end of file
+build_example(addressbook main.d)
\ No newline at end of file
--- a/examples/widgets/analogclock/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/widgets/analogclock/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(analogclock main.d AnalogClock.d)
+build_example(analogclock main.d)
--- a/examples/widgets/calculator/CMakeLists.txt	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/widgets/calculator/CMakeLists.txt	Tue Jul 14 15:25:45 2009 +0000
@@ -1,1 +1,1 @@
-build_example(calculator main.d calculator.d button.d)
+build_example(calculator main.d)
--- a/examples/widgets/calculator/calculator.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/widgets/calculator/calculator.d	Tue Jul 14 15:25:45 2009 +0000
@@ -47,56 +47,9 @@
 import qt.gui.QLineEdit;
 import qt.gui.QFont;
 
-version(Tango) 
-{
-    import tango.math.Math;     
-    import tango.math.Math : pow, sqrt;
-    import Float = tango.text.convert.Float;
-    import Integer = tango.text.convert.Integer;
-    import tango.core.Array;    
-    string ToString(int x)
-    {
-	return Integer.toString(x);
-    }
-    string ToString(double x, int c = 0)
-    {
-	return Float.toString(x, c);
-    }
-    int ToInt(string s)
-    {
-	return Integer.toInt(s);
-    }
-    float ToFloat(string s)
-    {
-	return Float.toFloat(s);
-    }
-}
-else 
-{ 
-    import std.math; 
-    import std.conv;
-    import std.string; 
-    string ToString(int x)
-    {
-	return std.string.format("%d", x);
-    }
-    string ToString(double x, int c = 0)
-    {
-	return std.string.format("%g", x);
-    }
-    int ToInt(string s)
-    {
-	return to!(int)(s);
-    }
-    float ToFloat(string s)
-    {
-	return to!(float)(s);
-    }
-    int find(string s, dchar c)
-    {
-	return indexOf(s,c);
-    }
-}
+import std.math; 
+import std.conv;
+import std.string; 
 
 class Calculator : public QDialog
 {
@@ -122,7 +75,7 @@
                 display.setFont(font);
 
                 for (int i = 0; i < NumDigitButtons; ++i) {
-                        digitButtons[i] = createButton(ToString(i), &digitClicked);
+                        digitButtons[i] = createButton(format("%d", i), &digitClicked);
                 }
 
                 Button pointButton = createButton(tr("."), &pointClicked);
@@ -189,7 +142,7 @@
         void digitClicked()
         {
                 Button clickedButton = cast(Button) signalSender();
-                int digitValue = ToInt(clickedButton.text);
+                int digitValue = to!int(clickedButton.text);
                 if (display.text() == "0" && digitValue == 0.0)
                         return;
 
@@ -197,14 +150,14 @@
                         display.clear();
                         waitingForOperand = false;
                 }
-                display.setText(display.text() ~ ToString(digitValue));
+                display.setText(display.text() ~ format("%g", digitValue));
         }
 
         void unaryOperatorClicked()
         {
                 Button clickedButton = cast(Button) signalSender();
                 string clickedOperator = clickedButton.text();
-                double operand = ToFloat(display.text);
+                double operand = to!float(display.text);
                 double result = 0.0;
 
                 if (clickedOperator == tr("Sqrt")) {
@@ -222,7 +175,7 @@
                         }
                         result = 1.0 / operand;
                 }
-                display.setText(ToString(result, 4));
+                display.setText(format("%g", result));
                 waitingForOperand = true;
         }
 
@@ -230,14 +183,14 @@
         {
                 Button clickedButton = cast(Button) signalSender();
                 string clickedOperator = clickedButton.text();
-                double operand = ToFloat(display.text);
+                double operand = to!float(display.text);
 
                 if (pendingMultiplicativeOperator.length) {
                         if (!calculate(operand, pendingMultiplicativeOperator)) {
                                 abortOperation();
                                 return;
                         }
-                        display.setText(ToString(factorSoFar, 4));
+                        display.setText(format("%g", factorSoFar));
                         operand = factorSoFar;
                         factorSoFar = 0.0;
                         pendingMultiplicativeOperator = null;
@@ -248,7 +201,7 @@
                                 abortOperation();
                                 return;
                         }
-                        display.setText(ToString(sumSoFar, 4));
+                        display.setText(format("%g", sumSoFar));
                 } else {
                         sumSoFar = operand;
                 }
@@ -261,14 +214,14 @@
         {
                 Button clickedButton = cast(Button) signalSender();
                 string clickedOperator = clickedButton.text();
-                double operand = ToFloat(display.text);
+                double operand = to!float(display.text);
 
                 if (pendingMultiplicativeOperator.length) {
                         if (!calculate(operand, pendingMultiplicativeOperator)) {
                                 abortOperation();
                                 return;
                         }
-                        display.setText(ToString(factorSoFar/*, 4*/));
+                        display.setText(format("%g", factorSoFar));
                 } else {
                         factorSoFar = operand;
                 }
@@ -279,7 +232,7 @@
 
         void equalClicked()
         {
-                double operand = ToFloat(display.text);
+                double operand = to!float(display.text);
 
                 if (pendingMultiplicativeOperator.length) {
                         if (!calculate(operand, pendingMultiplicativeOperator)) {
@@ -300,7 +253,7 @@
                         sumSoFar = operand;
                 }
 
-                display.setText(ToString(sumSoFar, 4));
+                display.setText(format("%g", sumSoFar));
                 sumSoFar = 0.0;
                 waitingForOperand = true;
         }
@@ -312,7 +265,7 @@
                 if (waitingForOperand)
                         display.setText("0");
 
-                if (find(text, '.') >= text.length)
+                if (indexOf(text, '.') >= text.length)
                         display.setText(text ~ tr("."));
                 
                 waitingForOperand = false;
@@ -321,7 +274,7 @@
         void changeSignClicked()
         {
                 string text = display.text();
-                double value = ToFloat(text);
+                double value = to!float(text);
 
                 if (value > 0.0) {
                         text = "-" ~ text;
@@ -372,20 +325,20 @@
 
         void readMemory()
         {
-                display.setText(ToString(sumInMemory, 4));
+                display.setText(format("%g", sumInMemory));
                 waitingForOperand = true;
         }
 
         void setMemory()
         {
                 equalClicked();
-                sumInMemory = ToFloat(display.text);
+                sumInMemory = to!float(display.text);
         }
 
         void addToMemory()
         {
                 equalClicked();
-                sumInMemory += ToFloat(display.text);
+                sumInMemory += to!float(display.text);
         }
 
 private:
--- a/examples/widgets/calculator/main.d	Tue Jul 14 14:37:23 2009 +0000
+++ b/examples/widgets/calculator/main.d	Tue Jul 14 15:25:45 2009 +0000
@@ -43,8 +43,10 @@
 
 import qt.gui.QApplication;
 
-import calculator;
-
+version(D_Version2) 
+	import calculator; 
+else 
+ 	import calculator_d1; 
 
 int main(string[] args)
 {