diff options
Diffstat (limited to 'qtsharp/src/examples')
24 files changed, 2577 insertions, 0 deletions
diff --git a/qtsharp/src/examples/Makefile.am b/qtsharp/src/examples/Makefile.am new file mode 100644 index 00000000..7905a37d --- /dev/null +++ b/qtsharp/src/examples/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = samples tutorials diff --git a/qtsharp/src/examples/samples/Makefile.am b/qtsharp/src/examples/samples/Makefile.am new file mode 100644 index 00000000..eae1d7cc --- /dev/null +++ b/qtsharp/src/examples/samples/Makefile.am @@ -0,0 +1,24 @@ +all: + csant -D$(CSC_NAME)=$(CSC) -C $(CSC_NAME) + chmod 0755 *.exe + +clean: + rm -rf *.exe + +distclean: clean + +install: + mkdir -p $(DESTDIR)$(datadir)/doc/qtcsharp/samples + cat display.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/display.cs.gz + cat eventhandling.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/eventhandling.cs.gz + cat hello.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/hello.cs.gz + cat scribblewindow.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/scribblewindow.cs.gz + cat mandelbrot.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/mandelbrot.cs.gz + cat quantumfractals.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/quantumfractals.cs.gz + cat mandelbrot2.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/samples/mandelbrot2.cs.gz + +uninstall: + rm -rf $(datadir)/doc/qtcsharp/samples/*.cs.gz + rm -rf $(datadir)/doc/qtcsharp/samples/*.cs + +.PHONY: all clean distclean install diff --git a/qtsharp/src/examples/samples/display.cs b/qtsharp/src/examples/samples/display.cs new file mode 100644 index 00000000..b1c7ca10 --- /dev/null +++ b/qtsharp/src/examples/samples/display.cs @@ -0,0 +1,65 @@ +namespace QtSamples { + + using Qt; + using System; + + public class Display : QMainWindow { + + private TextArea textarea; + private QScrollView scrollview; + private QMenuBar menubar; + private QPopupMenu filemenu, aboutmenu; + + private class TextArea : QTextEdit { + + public TextArea (QWidget parent) : base (parent) + { + QFile file = new QFile ("display.cs"); + if ( file.Open(1) ) { + QTextStream ts = new QTextStream (file); + this.SetText (ts.Read ()); + this.SetTabStopWidth (30); + } + } + } + + public Display () + { + filemenu = new QPopupMenu (null, "filemenu"); + filemenu.InsertItem ("&Quit", qApp, SLOT ("quit()")); + + aboutmenu = new QPopupMenu(null, "aboutmenu"); + aboutmenu.InsertItem("&About Qt-Sharp", this, SLOT("slotAbout()")); + + menubar = new QMenuBar(this, ""); + menubar.InsertItem("&File", filemenu); + menubar.InsertItem("&About", aboutmenu); + + textarea = new TextArea (this); + textarea.SetGeometry(0, menubar.Height(), Width(), Height() - menubar.Height()); + this.SetCentralWidget (textarea); + } + + public void slotAbout () + { + QMessageBox.Information ( + this, "About Qt-Sharp-0.7", + "A Qt (http://www.trolltech.com) to C# language binding.\n" + + "Qt-Sharp is compatible with Mono (http://go-mono.org) and\n" + + "Portable.NET (http://www.southern-storm.com.au/portable_net.html)\n" + + "(c) 2002 Adam Treat. Licensed under the terms of the GNU GPL.\n" + ); + } + + public static void Main (String[] args) + { + QApplication app = new QApplication (args); + Display demo = new Display (); + demo.SetCaption ("Qt-Sharp-0.7!"); + app.SetMainWidget (demo); + demo.Show (); + app.Exec (); + return; + } + } +} diff --git a/qtsharp/src/examples/samples/emit.cs b/qtsharp/src/examples/samples/emit.cs new file mode 100644 index 00000000..e9c3c40a --- /dev/null +++ b/qtsharp/src/examples/samples/emit.cs @@ -0,0 +1,41 @@ +// Illustrates basic usage of custom signals. +// Also see the t7 tutorial. + +namespace QtSamples { + using System; + using Qt; + + [DeclareQtSignal ("MySignal()")] + public class EmitSample: QVBox { + public EmitSample (): this (null, "") {} + + public EmitSample (QWidget parent, string name): base () + { + QPushButton pb = new QPushButton ("Papa Smurf", this); + + Connect (pb, SIGNAL ("clicked ()"), SLOT ("DoEmit ()")); + Connect (this, SIGNAL ("MySignal ()"), SLOT ("PrintStuff ()")); + } + + public void DoEmit () + { + Emit ("MySignal()"); + } + + public void PrintStuff () + { + Console.WriteLine ("Emitted MySignal"); + } + + public static int Main (string[] args) + { + QApplication app = new QApplication (args); + EmitSample es = new EmitSample (); + app.SetMainWidget (es); + es.Show (); + int ret = app.Exec (); + es.Dispose(); + return ret; + } + } +} diff --git a/qtsharp/src/examples/samples/eventhandling.cs b/qtsharp/src/examples/samples/eventhandling.cs new file mode 100644 index 00000000..ee410dd3 --- /dev/null +++ b/qtsharp/src/examples/samples/eventhandling.cs @@ -0,0 +1,52 @@ +// eventhandling.cs - qt-sharp Hello World +// +// Author: Adam Treat <manyoso@yahoo.com> +// +// (c) 2002 Adam Treat +// +// Licensed under the terms of the GNU GPL + +namespace QtSamples { + + using Qt; + using System; + + public class EventHandling : QVBox { + + public static void Main (String[] args) + { + QApplication app = new QApplication (args); + EventHandling evh = new EventHandling (); + app.SetMainWidget (evh); + evh.Show (); + app.Exec (); + } + + public EventHandling () : base (null) + { + // This is the global event handler for QMouseEvents + mouseHandler += new QMouseHandler(mouseEvents); + + MyButton pb = new MyButton (this); + } + + public void mouseEvents (QObject sender, QEventArgs e) + { + Console.WriteLine ("Mouse event: " + e.Name); + } + + class MyButton : QPushButton { + + public MyButton (QWidget parent) : base ("Hello Qt-Sharp-0.7!", parent) + { + // This is the local event handler for mousePressEvents + mousePressEvent += new MousePressEvent (pressEvent); + } + + public void pressEvent (QMouseEvent e) + { + Console.WriteLine ("I've been clicked"); + } + } + } +} diff --git a/qtsharp/src/examples/samples/hello.cs b/qtsharp/src/examples/samples/hello.cs new file mode 100644 index 00000000..db6890e5 --- /dev/null +++ b/qtsharp/src/examples/samples/hello.cs @@ -0,0 +1,36 @@ +// helloworld.cs - qt-sharp Hello World +// +// Author: Adam Treat <manyoso@yahoo.com> +// +// (c) 2002 Adam Treat +// +// Licensed under the terms of the GNU GPL + +namespace QtSamples { + + using Qt; + using System; + + public class HelloWorld : QVBox { + + public static void Main (String[] args) + { + QApplication app = new QApplication (args); + HelloWorld hello = new HelloWorld (); + app.SetMainWidget (hello); + hello.Show (); + app.Exec (); + } + + public HelloWorld () : base (null) + { + QPushButton pb = new QPushButton ("Hello Qt-Sharp-0.7!", this); + QObject.Connect (pb, SIGNAL ("clicked()"), this, SLOT("SlotClicked()")); + } + + public void SlotClicked () + { + Console.WriteLine ("QPushButton Clicked!"); + } + } +} diff --git a/qtsharp/src/examples/samples/mandelbrot.cs b/qtsharp/src/examples/samples/mandelbrot.cs new file mode 100644 index 00000000..5dbd9b85 --- /dev/null +++ b/qtsharp/src/examples/samples/mandelbrot.cs @@ -0,0 +1,264 @@ +// Mandelbrot 0.1: A demonstration of Qt# +// +// Copyright 2002 Marcus Urban +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +// NOTE: +// Variables with names like PlotXMin are in the cartesian coordinate plane. +// Those with names like ImageXMin was in a translated coordinate system +// where (0, 0) is the upper-left corner. + + +using System; +using Qt; + + +// This struct is a simple implementation of complex numbers. +// It was originally in a separate file because it is useful +// in its own right. It is included here file only to make the +// compilation process simpler of new users. + +public struct Complex { + + private double re, im; + //private int x; + + public Complex (double re, double im) + { + this.re = re; + this.im = im; + } + + public static implicit operator Complex (double re) + { + return new Complex (re, 0.0); + } + + public double Re + { + get { return re; } + } + + public double Im + { + get { return im; } + } + + public static double Abs (Complex a) + { + return Math.Abs (a.re) >= Math.Abs (a.im) ? + Math.Abs (a.re) * Math.Sqrt( 1.0 + (a.im/a.re)*(a.im/a.re) ) : + Math.Abs (a.im) * Math.Sqrt( 1.0 + (a.re/a.im)*(a.re/a.im) ); + } + + public static Complex operator + (Complex a, Complex b) + { + return new Complex (a.re + b.re, a.im + b.im); + } + + public static Complex operator - (Complex a, Complex b) + { + return new Complex (a.re - b.re, a.im - b.im); + } + + public static Complex operator * (Complex a, Complex b) + { + return new Complex ( a.re*b.re - a.im*b.im, a.im*b.re + a.re*b.im ); + } + + // Division isn't pretty. Do it later. + + public override string ToString () + { + return this.re.ToString () + "+" + this.im.ToString () + "i"; + } +} + + +public class Mandelbrot { + + public static int Iterations ( Complex c ) + { + const int MaximumIterations = 16; + Complex value = c; + int currentDepth = 1; + + while ( Complex.Abs(value) < 2.0 && currentDepth <= MaximumIterations ) { + ++currentDepth; + value = (value * value) + c; + } + return currentDepth; + } + + + public static void Main (string[] args) + { + QApplication app = new QApplication (args); + + ImageDialog dialog = new ImageDialog (null, "Mandelbrot", false, 0); + dialog.Show (); + app.SetMainWidget (dialog); + app.Exec (); + + } +} + + +public class ImageDialog : QDialog { + + const double DefaultPlotXMin = -2.0; + const double DefaultPlotXMax = 2.0; + const double DefaultPlotYMin = -1.5; + const double DefaultPlotYMax = 1.5; + + QHBoxLayout dialogLayout; + QGridLayout gridLayout; + QVBoxLayout leftLayout; + QHBoxLayout buttonLayout; + QPushButton redrawButton; + QLabel pixmapLabel; + QSizePolicy fixedSizePolicy; + + QLabel XMinLabel, XMaxLabel, YMinLabel, YMaxLabel; + QLineEdit editXMin, editXMax, editYMin, editYMax; + + public ImageDialog (QWidget parent, string name, bool modal, WidgetFlags fl): + base (parent, name, modal, fl) + { + if (name == string.Empty) + SetName ("imageDialog"); + SetCaption ("Mandelbrot Image"); + + dialogLayout = new QHBoxLayout (this, 11, 6); + gridLayout = new QGridLayout (null, 1, 1, 0, 6, "gridLayout"); + leftLayout = new QVBoxLayout (null, 0, 6, "leftLayout"); + + fixedSizePolicy = new QSizePolicy (); + fixedSizePolicy.SetHorData (QSizePolicy.SizeType.Fixed); + fixedSizePolicy.SetVerData (QSizePolicy.SizeType.Fixed); + + XMinLabel = new QLabel ("Xmin", this); + XMinLabel.SetSizePolicy (fixedSizePolicy); + gridLayout.AddWidget (XMinLabel, 0, 0); + + XMaxLabel = new QLabel ("Xmax", this); + XMaxLabel.SetSizePolicy(fixedSizePolicy); + gridLayout.AddWidget (XMaxLabel, 1, 0); + + YMinLabel = new QLabel ("Ymin", this); + YMinLabel.SetSizePolicy (fixedSizePolicy); + gridLayout.AddWidget (YMinLabel, 2, 0); + + YMaxLabel = new QLabel ("Ymax", this); + YMaxLabel.SetSizePolicy (fixedSizePolicy); + gridLayout.AddWidget (YMaxLabel, 3, 0); + + QDoubleValidator validator = new QDoubleValidator (this); + + editXMin = new QLineEdit (this, "editXMin"); + editXMin.SetText (Convert.ToString (DefaultPlotXMin)); + editXMin.SetValidator (validator); + gridLayout.AddWidget (editXMin, 0, 1); + + editXMax = new QLineEdit (this, "editXMax"); + editXMax.SetText (Convert.ToString(DefaultPlotXMax)); + editXMax.SetValidator (validator); + gridLayout.AddWidget (editXMax, 1, 1); + + editYMin = new QLineEdit (this, "editYMin"); + editYMin.SetText (Convert.ToString(DefaultPlotYMin)); + editYMin.SetValidator (validator); + gridLayout.AddWidget (editYMin, 2, 1); + + editYMax = new QLineEdit (this, "editYMax"); + editYMax.SetText (Convert.ToString(DefaultPlotYMax)); + editYMax.SetValidator (validator); + gridLayout.AddWidget (editYMax, 3, 1); + + leftLayout.AddLayout (gridLayout); + QSpacerItem spacer1 = new QSpacerItem (0, 0, 0, 0); + leftLayout.AddItem (spacer1); + + buttonLayout = new QHBoxLayout (null, 0, 6, "buttonLayout"); + QSpacerItem spacer2 = new QSpacerItem (0, 0, 0, 0); + buttonLayout.AddItem (spacer2); + + redrawButton = new QPushButton ("Redraw", this); + redrawButton.SetDefault (true); + buttonLayout.AddWidget (redrawButton); + + QSpacerItem spacer3 = new QSpacerItem (0, 0, 0, 0); + buttonLayout.AddItem (spacer3); + + leftLayout.AddLayout (buttonLayout); + + dialogLayout.AddLayout (leftLayout); + QSpacerItem spacer4 = new QSpacerItem (0, 0, 0, 0); + dialogLayout.AddItem (spacer4); + + pixmapLabel = new QLabel (this, "pixmapLabel", 0); + pixmapLabel.SetScaledContents (true); + dialogLayout.AddWidget (pixmapLabel); + + QObject.Connect (redrawButton, SIGNAL ("clicked()"), this, SLOT ("Redraw()")); + + Redraw (); + } + + + QImage MandelbrotImage () + { + int depth; + double real, imag; + + double PlotXMin = Convert.ToDouble ( editXMin.Text () ); + double PlotXMax = Convert.ToDouble ( editXMax.Text () ); + double PlotYMin = Convert.ToDouble ( editYMin.Text () ); + double PlotYMax = Convert.ToDouble ( editYMax.Text () ); + + int ImageXMax = pixmapLabel.Width (); + int ImageYMax = pixmapLabel.Height (); + + QImage image = new QImage (ImageXMax, ImageYMax, 32, 0); + + for (int x = 0; x <= ImageXMax - 1; x+=1) { + for (int y = 0; y <= ImageYMax - 1; y+=1) { + real = (PlotXMax - PlotXMin)/ImageXMax * x + PlotXMin; + imag = (PlotYMin - PlotYMax)/ImageYMax * y + PlotYMax; + depth = Mandelbrot.Iterations ( new Complex (real, imag) ); + image.SetPixel ( x, y, (uint) depth*16 ); + } + } + + return image; + } + + public void Redraw () + { + QSize s = pixmapLabel.BaseSize (); + pixmapLabel.Resize (400,300); + QApplication.SetOverrideCursor ( new QCursor( (int) CursorShape.WaitCursor )); + QImage image = MandelbrotImage (); + QPixmap pixmap = new QPixmap (image); + pixmapLabel.SetPixmap( pixmap); + image.Dispose (); + pixmap.Dispose (); + this.AdjustSize (); + QApplication.RestoreOverrideCursor (); + } +} + + diff --git a/qtsharp/src/examples/samples/mandelbrot2.cs b/qtsharp/src/examples/samples/mandelbrot2.cs new file mode 100644 index 00000000..bcb0a360 --- /dev/null +++ b/qtsharp/src/examples/samples/mandelbrot2.cs @@ -0,0 +1,309 @@ +// Mandelbrot 0.1: A demonstration of Qt# +// +// Copyright 2002 Marcus Urban +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +// NOTE: +// Variables with names like PlotXMin are in the cartesian coordinate plane. +// Those with names like ImageXMin was in a translated coordinate system +// where (0, 0) is the upper-left corner. + + +using System; +using Qt; + + +// This struct is a simple implementation of complex numbers. +// It was originally in a separate file because it is useful +// in its own right. It is included here file only to make the +// compilation process simpler of new users. + +public struct Complex { + + private double re, im; + //private int x; + + public Complex (double re, double im) + { + this.re = re; + this.im = im; + } + + public static implicit operator Complex (double re) + { + return new Complex (re, 0.0); + } + + public double Re + { + get { return re; } + } + + public double Im + { + get { return im; } + } + + public static double Abs (Complex a) + { + return Math.Abs (a.re) >= Math.Abs (a.im) ? + Math.Abs (a.re) * Math.Sqrt( 1.0 + (a.im/a.re)*(a.im/a.re) ) : + Math.Abs (a.im) * Math.Sqrt( 1.0 + (a.re/a.im)*(a.re/a.im) ); + } + + public static Complex operator + (Complex a, Complex b) + { + return new Complex (a.re + b.re, a.im + b.im); + } + + public static Complex operator - (Complex a, Complex b) + { + return new Complex (a.re - b.re, a.im - b.im); + } + + public static Complex operator * (Complex a, Complex b) + { + return new Complex ( a.re*b.re - a.im*b.im, a.im*b.re + a.re*b.im ); + } + + // Division isn't pretty. Do it later. + + public override string ToString () + { + return this.re.ToString () + "+" + this.im.ToString () + "i"; + } +} + + +public class Mandelbrot +{ + public static ImageDialog dialog; + + public static int Iterations ( Complex c ) + { + const int MaximumIterations = 16; + Complex value = c; + int currentDepth = 1; + + while ( Complex.Abs(value) < 2.0 && currentDepth <= MaximumIterations ) { + ++currentDepth; + value = (value * value) + c; + } + return currentDepth; + } + + + public static void Main (string[] args) + { + QApplication app = new QApplication (args); + + dialog = new ImageDialog (null, "Mandelbrot", false, 0); + dialog.SetGeometry(0, 0, 550, 300 ); + dialog.Show(); + app.SetMainWidget (dialog); + app.Exec (); + + } +} + + +public class PicLabel: QFrame +{ + QPixmap newPixmap; + int newWidth = 400; + int newHeight = 300; + + public PicLabel( QWidget parent, string name, WidgetFlags flags ): + base( parent, name, flags ) + { + SetBackgroundMode (Qt.BackgroundMode.NoBackground); + resizeEvent += new ResizeEvent (PerformResize); + paintEvent += new PaintEvent (PerformPaint); + + } + + protected void PerformResize (QResizeEvent e) + { + Console.WriteLine("Resizing to {0} by {1}", + e.Size().Width(), e.Size().Height() ); + + newWidth = e.Size().Width(); + newHeight = e.Size().Height(); + + } + + + protected void PerformPaint(QPaintEvent e ) + { + Console.WriteLine("Making a new image {0} by {1}", newWidth, newHeight ); + + QImage image = Mandelbrot.dialog.MandelbrotImage( newWidth, newHeight ); + newPixmap = new QPixmap( image ); + + BitBlt(this, 0, 0, newPixmap, + 0, 0, -1, -1, RasterOp.CopyROP, false); + Console.WriteLine("PerformPaint"); + } +} + + + +public class ImageDialog : QDialog { + + const double DefaultPlotXMin = -2.0; + const double DefaultPlotXMax = 2.0; + const double DefaultPlotYMin = -1.5; + const double DefaultPlotYMax = 1.5; + + QHBoxLayout dialogLayout; + QGridLayout gridLayout; + QVBoxLayout leftLayout; + QHBoxLayout buttonLayout; + QPushButton redrawButton; + public PicLabel pixmapLabel; + QSizePolicy fixedSizePolicy; + + QLabel XMinLabel, XMaxLabel, YMinLabel, YMaxLabel; + QLineEdit editXMin, editXMax, editYMin, editYMax; + + + public ImageDialog (QWidget parent, string name, bool modal, WidgetFlags fl): + base (parent, name, modal, fl) + { + if (name == string.Empty) + SetName ("imageDialog"); + SetCaption ("Mandelbrot Image"); + + dialogLayout = new QHBoxLayout (this, 11, 6); + gridLayout = new QGridLayout (null, 1, 1, 0, 6, "gridLayout"); + leftLayout = new QVBoxLayout (null, 0, 6, "leftLayout"); + + fixedSizePolicy = new QSizePolicy ( QSizePolicy.SizeType.Fixed, + QSizePolicy.SizeType.Fixed, false ); + + XMinLabel = new QLabel ("Xmin", this); + XMinLabel.SetSizePolicy (fixedSizePolicy); + gridLayout.AddWidget (XMinLabel, 0, 0); + + XMaxLabel = new QLabel ("Xmax", this); + XMaxLabel.SetSizePolicy(fixedSizePolicy); + gridLayout.AddWidget (XMaxLabel, 1, 0); + + YMinLabel = new QLabel ("Ymin", this); + YMinLabel.SetSizePolicy (fixedSizePolicy); + gridLayout.AddWidget (YMinLabel, 2, 0); + + YMaxLabel = new QLabel ("Ymax", this); + YMaxLabel.SetSizePolicy (fixedSizePolicy); + gridLayout.AddWidget (YMaxLabel, 3, 0); + + QDoubleValidator validator = new QDoubleValidator (this); + + editXMin = new QLineEdit (this, "editXMin"); + editXMin.SetSizePolicy( fixedSizePolicy ); + editXMin.SetText (Convert.ToString (DefaultPlotXMin)); + editXMin.SetValidator (validator); + gridLayout.AddWidget (editXMin, 0, 1); + + editXMax = new QLineEdit (this, "editXMax"); + editXMax.SetSizePolicy( fixedSizePolicy ); + editXMax.SetText (Convert.ToString(DefaultPlotXMax)); + editXMax.SetValidator (validator); + gridLayout.AddWidget (editXMax, 1, 1); + + editYMin = new QLineEdit (this, "editYMin"); + editYMin.SetSizePolicy( fixedSizePolicy ); + editYMin.SetText (Convert.ToString(DefaultPlotYMin)); + editYMin.SetValidator (validator); + gridLayout.AddWidget (editYMin, 2, 1); + + editYMax = new QLineEdit (this, "editYMax"); + editYMax.SetSizePolicy( fixedSizePolicy ); + editYMax.SetText (Convert.ToString(DefaultPlotYMax)); + editYMax.SetValidator (validator); + gridLayout.AddWidget (editYMax, 3, 1); + + leftLayout.AddLayout (gridLayout); + QSpacerItem spacer1 = new QSpacerItem (0, 0, 0, 0); + leftLayout.AddItem (spacer1); + + buttonLayout = new QHBoxLayout (null, 0, 6, "buttonLayout"); + QSpacerItem spacer2 = new QSpacerItem (0, 0, 0, 0); + buttonLayout.AddItem (spacer2); + + redrawButton = new QPushButton ("Redraw", this); + redrawButton.SetSizePolicy ( fixedSizePolicy ); + redrawButton.SetDefault (true); + buttonLayout.AddWidget (redrawButton); + + QSpacerItem spacer3 = new QSpacerItem (0, 0, 0, 0); + buttonLayout.AddItem (spacer3); + + leftLayout.AddLayout (buttonLayout); + + dialogLayout.AddLayout (leftLayout); + QSpacerItem spacer4 = new QSpacerItem (0, 0, 0, 0); + dialogLayout.AddItem (spacer4); + + pixmapLabel = new PicLabel (this, "pixmapLabel", 0); + //pixmapLabel.SetScaledContents (true); + pixmapLabel.SetSizePolicy( QSizePolicy.SizeType.Minimum, + QSizePolicy.SizeType.Minimum, false ); + pixmapLabel.SetGeometry( 0, 0, 400, 300 ); + pixmapLabel.Show(); + pixmapLabel.Resize(400,300); + dialogLayout.AddWidget (pixmapLabel); + + + //QImage image = MandelbrotImage( 400, 300 ); + //pixmapLabel.SetPixmap( new QPixmap( image ) ); + + + QObject.Connect (redrawButton, SIGNAL ("clicked()"), pixmapLabel, SLOT ("Repaint()")); + + //Redraw (); + } + + public QImage MandelbrotImage ( int width, int height) + { + int depth; + double real, imag; + + double PlotXMin = Convert.ToDouble ( editXMin.Text () ); + double PlotXMax = Convert.ToDouble ( editXMax.Text () ); + double PlotYMin = Convert.ToDouble ( editYMin.Text () ); + double PlotYMax = Convert.ToDouble ( editYMax.Text () ); + + int ImageXMax = width; + int ImageYMax = height; + + QImage image = new QImage (ImageXMax, ImageYMax, 32, 0); + + for (int x = 0; x <= ImageXMax - 1; x+=1) { + for (int y = 0; y <= ImageYMax - 1; y+=1) { + real = (PlotXMax - PlotXMin)/ImageXMax * x + PlotXMin; + imag = (PlotYMin - PlotYMax)/ImageYMax * y + PlotYMax; + depth = Mandelbrot.Iterations ( new Complex (real, imag) ); + image.SetPixel ( x, y, (uint) depth*16 ); + } + } + + return image; + } + +} + + diff --git a/qtsharp/src/examples/samples/qstring-slot.cs b/qtsharp/src/examples/samples/qstring-slot.cs new file mode 100644 index 00000000..e6d5110a --- /dev/null +++ b/qtsharp/src/examples/samples/qstring-slot.cs @@ -0,0 +1,38 @@ +// Demo of a QString slot +// Implemented by Marcus Urban + +using System; +using Qt; + +public class MyWidget : QVBox +{ + QLineEdit lineEdit; + QLabel label; + + public MyWidget (QWidget parent, String name) : base (parent, name) + { + lineEdit = new QLineEdit( this, "lineEdit" ); + label = new QLabel( this, "label" ); + label.SetText("Default"); + + QObject.Connect( lineEdit, SIGNAL("textChanged(QString)"), + label, "SetText(QString)" ); + } + + + public MyWidget (QWidget parent) : this (parent, "") {} + public MyWidget () : this (null, "") {} +} + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + MyWidget w = new MyWidget (); + a.SetMainWidget (w); + w.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/samples/quantumfractals.cs b/qtsharp/src/examples/samples/quantumfractals.cs new file mode 100644 index 00000000..56898912 --- /dev/null +++ b/qtsharp/src/examples/samples/quantumfractals.cs @@ -0,0 +1,828 @@ +// quantumfractals.cs - Port of eeqt to Qt# +// Author: Adam Treat <manyoso@yahoo.com> +// (c) 2002 Adam Treat +// Licensed under the terms of the GNU GPL + +namespace Qf { + + using Qt; + using System; + using System.Threading; + + public class FractalViewer : QMainWindow { + + //Menuing + private QMenuBar menubar; + private QPopupMenu filemenu; + private QPopupMenu shapemenu; + private QPopupMenu settingsmenu; + + public static int Main (string[] args) + { + //Initialize and start the main event loop + QApplication app = new QApplication (args); + FractalViewer view = new FractalViewer (); + app.SetMainWidget (view); + view.Show (); + return app.Exec (); + } + + public FractalViewer (): base (null, "main") + { + SetCaption ("Quantum Fractals"); + + //Setup the display + Display display = new Display (this); + SetCentralWidget (display); + + //Setup the filemenu + filemenu = new QPopupMenu (null, "filemenu"); + filemenu.InsertItem ("&Screenshot", display, SLOT ("SlotScreenshot()")); + filemenu.InsertSeparator (); + filemenu.InsertItem ("&Quit", qApp, SLOT ("quit()")); + + //Setup the shapemenu + shapemenu = new QPopupMenu (null, "typemenu"); + shapemenu.InsertItem( "&Tetrahedron", 0); + shapemenu.InsertItem( "&Cube", 1); + shapemenu.InsertItem( "&Octahedron", 2); + shapemenu.InsertItem( "&Icosahedron", 3); + shapemenu.InsertItem( "&Dodecahedron", 4); + shapemenu.InsertItem( "&Double Tetrahedron", 5); + shapemenu.InsertItem( "&Icosidodecahedron", 6); + + //Connect the shapemenu + QObject.Connect (shapemenu, SIGNAL ("activated(int)"), + display, SLOT("SlotShapeMenu(int)")); + + //Setup the settingsmenu + settingsmenu = new QPopupMenu (null, "settingsmenu"); + settingsmenu.InsertItem ("&Alpha", display, SLOT ("SlotSetAlpha()")); + + //Setup the menubar + menubar = new QMenuBar (this, ""); + menubar.InsertItem ("&File", filemenu); + menubar.InsertItem ("&Shape", shapemenu); + menubar.InsertItem ("&Settings", settingsmenu); + } + } + + public class Display: QWidget, IQuantumFractal { + + //Labels + QLabel count; + QLabel shape; + QLabel alpha; + + //Buttons + QPushButton start; + QPushButton stop; + QPushButton reset; + QPushButton gray; + QPushButton intense; + + //Drawable region + QPaintBuffer buffer; + + //Layouts + QVBoxLayout layout; + QHBoxLayout buttons; + QVBoxLayout labels; + + //Engine controller variables + int[] topDensity = new int[0]; + int[] bottomDensity = new int[0]; + int resolution = 400; + int scale = 1; + double centerX = 0; + double centerY = 0; + int i = 0; + bool Grayscale = true; + bool Intense = false; + bool Running = false; + bool WasRunning = false; + + //The engine + QuantumFractals qf; + Thread engine; + + public Display (QWidget parent): base (parent) + { + //Setup the sizes + QSize size = new QSize (resolution, resolution); + parent.SetBaseSize (size); + + //Some nice colors + SetPaletteBackgroundColor (new QColor ("Black")); + SetPaletteForegroundColor (new QColor ("LightBlue")); + + //Setup the buttons + start = new QPushButton ("Start", this); + stop = new QPushButton ("Stop", this); + reset = new QPushButton ("Reset", this); + gray = new QPushButton ("Color", this); + intense = new QPushButton ("Intensity", this); + + //Setup the labels + count = new QLabel (this); + alpha = new QLabel (this); + shape = new QLabel (this); + + //Setup the drawable + buffer = new QPaintBuffer (this); + buffer.SetMinimumSize (size); + + //Create the layouts + layout = new QVBoxLayout (this); + buttons = new QHBoxLayout (layout); + + //Add some buttons + buttons.AddWidget (start); + buttons.AddWidget (stop); + buttons.AddWidget (reset); + buttons.AddWidget (gray); + buttons.AddWidget (intense); + + //Connect the buttons and SlotQuit + QObject.Connect (start, SIGNAL ("clicked()"), + this, SLOT ("SlotStart()")); + QObject.Connect (stop, SIGNAL ("clicked()"), + this, SLOT ("SlotStop()")); + QObject.Connect (reset, SIGNAL ("clicked()"), + this, SLOT ("SlotReset()")); + QObject.Connect (gray, SIGNAL ("clicked()"), + this, SLOT ("SlotGray()")); + QObject.Connect (intense, SIGNAL ("clicked()"), + this, SLOT ("SlotIntense()")); + QObject.Connect (buffer, SIGNAL ("Painted()"), + this, SLOT ("SlotSetLabels()")); + QObject.Connect (qApp, SIGNAL ("lastWindowClosed ()"), + this, SLOT ("SlotQuit ()")); + + //Layout labels + labels = new QVBoxLayout (layout); + labels.AddWidget (count); + labels.AddWidget (shape); + labels.AddWidget (alpha); + + //Layout buffer + layout.AddWidget (buffer, 1); + + //Finally create the data engine + qf = new QuantumFractals (this); + + //Handle resize events + resizeEvent += new ResizeEvent (TouchResize); + } + + //This is where the controller receives data from the engine + public void UpdateData (double[] d) + { + i++; //Keep track of the number of points + + //Set the density arrays to match the resolution + if (resolution * resolution != topDensity.Length) { + topDensity = new int[resolution * resolution]; + bottomDensity = new int[resolution * resolution]; + } + + //setup the sphere + int res = resolution; + int res2 = res / 2; + int x = res / 2 + (int)(res2 * scale * (d[0] - centerX)); + int y = res / 2 + (int)(res2 * scale * (d[1] - centerY)); + double z = d[2]; + + if ((x < res) && (x >= 0) && (y >= 0) && (y < res)) { + + if (z >= 0) + topDensity[y * resolution + x]++; + else + bottomDensity[y * resolution + x]++; + + } + + //Convert the density into a color + int top = topDensity[y * resolution + x]; + //int bot = bottomDensity[y * resolution + x]; + top = Math.Min (top, 255); + //bot = Math.Min (bot, 255); + + //Log color system not working well :( + if (Intense) { + top = (int)(Math.Log (top + 1)); + //bot = (int)(Math.Log (bot + 1)); + } + + int topdepth = RGB (top,top,top); + //int botdepth = RGB (bot,bot,bot); + + //Finally draw the pixel + SetPixel (x, y, topdepth); + //SetPixel (x, y, botdepth); + } + + //Calls the drawable + public void SetPixel (int x, int y, int depth) + { + buffer.PaintPixel (x, y, depth); + } + + //Convert the color into a depth + public int RGB (int r, int g, int b) + { + if (!Grayscale) { + + r = Intensity (r < 128 ? 128 - r : 0); + g = Intensity (128 - Math.Abs (g - 128)); + b = Intensity (b < 128 ? 0 : b - 128); + + } else { + + r = Intensity (r); + g = Intensity (g); + b = Intensity (b); + + } + //Console.WriteLine ("{0} {1} {2}", r,g,b); + return 256 * 256 * r + 256 * g + b; + } + + //This provides more detail + private int Intensity(int val) + { + int ret; + + double bases = 64; + double scale = 256.0 / (256.0 - bases); + ret = (int)(bases + ((double)val) / scale); + + //if gray then black, if color then white + if (val == 0 && Grayscale) + ret = 0; + else if (val == 0) + ret = 255; + return ret; + } + + //Draw the labels + private void SlotSetLabels () + { + count.SetText ("Count: " + i.ToString ()); + shape.SetText ("Shape: " + qf.GetPolytope ()); + alpha.SetText ("Alpha: " + qf.Alpha.ToString ()); + } + + //Start the engine + private void SlotStart () + { + engine = new Thread(new ThreadStart(qf.Start)); + engine.Start (); + Running = true; + } + + //Stop the engine + private void SlotStop () + { + if (engine != null) + if (engine.IsAlive) + engine.Abort (); + Running = false; + } + + //Reset everything + private void SlotReset () + { + SlotStop (); + ResetBuffer (); + SlotStart (); + } + + //Reset the drawable + private void ResetBuffer () + { + i = 0; + SlotSetLabels (); + topDensity = new int[0]; + bottomDensity = new int[0]; + buffer.Reset (); + } + + //Toggles the color scheme + private void SlotGray () + { + Grayscale = !Grayscale; + } + + //Toggles log color scheme + //Not working so well :( + private void SlotIntense () + { + Intense = !Intense; + } + + //Change the platonic shape + private void SlotShapeMenu (int item) + { + WasRunning = Running ? true : false; + + SlotStop (); + ResetBuffer (); + + switch(item) { + + case 0: + qf.SetPolytope (0); + break; + case 1: + qf.SetPolytope (1); + break; + case 2: + qf.SetPolytope (2); + break; + case 3: + qf.SetPolytope (3); + break; + case 4: + qf.SetPolytope (4); + break; + case 5: + qf.SetPolytope (5); + break; + case 6: + qf.SetPolytope (6); + break; + Default: + qf.SetPolytope (0); + break; + } + + if (WasRunning) + SlotStart (); + } + + //Save the drawable as a screenshot + private void SlotScreenshot () + { + WasRunning = Running ? true : false; + + SlotStop (); + string filename = QFileDialog.GetSaveFileName ( + + QDir.HomeDirPath (), "*", this, "save", + "Save Screenshot", "*.png", true + ); + + if (filename != null) + buffer.Save (filename); + + if (WasRunning) + SlotStart (); + } + + //Set the alpha engine variable + private void SlotSetAlpha () + { + WasRunning = Running ? true : false; + + SlotStop (); + qf.Alpha = QInputDialog.GetDouble ( + + "Set Alpha", "Alpha: ", qf.Alpha, 0, 2, 32 + ); + + if (WasRunning) + SlotStart (); + else + SlotSetLabels (); + } + + //Make sure to quit all threads upon exit + private void SlotQuit () + { + SlotStop (); + buffer.Stop (); + } + + //Need to reset the resolution upon resize + private void TouchResize (QResizeEvent e) + { + int height = buffer.Size ().Height (); + int width = buffer.Size ().Width (); + + resolution = height > width ? width : height; + } + } + + [DeclareQtSignal ("Painted()")] + public class QPaintBuffer : QFrame { + + //Drawables + private QPixmap buffer; + private QImage image; + + //Timer + private TimerCallback call; + private Timer timer; + + public QPaintBuffer (QWidget parent) : base (parent) + { + SetBackgroundMode (Qt.BackgroundMode.NoBackground); + + //Create drawables + buffer = new QPixmap (); + image = new QImage (Size (), 32); + + //Setup the event handlers + paintEvent += new PaintEvent (TouchPaint); + resizeEvent += new ResizeEvent (TouchResize); + focusInEvent += new FocusInEvent (TouchFocus); + focusOutEvent += new FocusOutEvent (TouchFocus); + + //Start the timer + call = new TimerCallback(PaintImage); + timer = new Timer(call, null, 1000, 1000); + + } + + //Resets the drawables + public void Reset () + { + buffer = new QPixmap (); + image = new QImage (Size (), 32); + PaintImage (null); + } + + //Paints a pixel to the image + public void PaintPixel (int x, int y, int depth) + { + lock (this) { + if (x < image.Width () && y < image.Height ()) + image.SetPixel (x, y, (uint)depth); + } + } + + //Saves the image to a file + public void Save (string filename) + { + image.Save (filename, "PNG"); + } + + //Paints the image to the screen and emits Painted + private void PaintImage (object state) + { + buffer.ConvertFromImage (image); + PerformPaint (); + Emit ("Painted()"); + } + + //The actual bitblt to the screen + private void PerformPaint () + { + BitBlt(this, 0, 0, buffer, + 0, 0, -1, -1, RasterOp.CopyROP, false); + } + + //Receive focus events + private void TouchFocus (QFocusEvent e) + { + PerformPaint (); + } + + //Receive paint events + private void TouchPaint (QPaintEvent e) + { + PerformPaint (); + } + + //Receive resize events + private void TouchResize (QResizeEvent e) + { + image = new QImage (e.Size (), 32); + buffer.Resize (e.Size()); + buffer.Fill (new QColor("black")); + BitBlt (buffer, 0, 0, new QPixmap (buffer), + 0, 0, -1, -1, RasterOp.CopyROP, false); + } + + //Dispose of the timer + public void Stop () + { + timer.Dispose (); + } + } + + public interface IQuantumFractal { + + void UpdateData (Double [] data); + } + + //Polytope types + public enum Shapes { + TETRAHEDRON = 0, + CUBE = 1, + OCTAHEDRON = 2, + ICOSAHEDRON = 3, + DODECAHEDRON = 4, + DOUBLE_TETRAHEDRON = 5, + ICOSIDODECAHEDRON = 6 + } + + public class QuantumFractals { + + private int t = 0; + private double[] p; //Detector probabilities + private double[] fp; //Fractal point + private double[][] n; //Detector points + private double[] counter; //Detect counter + private double alpha = 0.61803398874989288039384209090709; //Initialize to 1/phi + + private Random random; + private Shapes polytope; + private IQuantumFractal consumer; + + public QuantumFractals (IQuantumFractal consumer) + { + this.consumer = consumer; + SetPolytope (0); + Init (); + } + + public double Alpha + { + get { return alpha; } + set { alpha = value; } + } + + private void Init () + { + random = new Random (); + + //Default values + t = 0; + + counter = new double[n.Length]; //Detect counter + fp = new double[3]; //Fractal point + p = new double[n.Length]; + + //Initial state + fp[0] = random.NextDouble () -0.5; + fp[1] = random.NextDouble () -0.5; + fp[2] = random.NextDouble () -0.5; + + double sum = Math.Sqrt (Product (fp, fp)); + + fp[0] = fp[0] / sum; + fp[1] = fp[1] / sum; + fp[2] = fp[2] / sum; + } + + //Main fractal generator loop + public void Start () + { + Init (); + + //double n1 = (1.0) / n.Length as double; + double n1 = (1.0) / n.Length; + + double alpha12 = 2 * alpha / (n.Length * (1 + alpha * alpha)); + + do { + //Increase t + t++; + + //Calculate detector click probabilities + for (int i = 0; i < p.Length; i++) + p[i] = n1 + alpha12 * Product (n[i], fp); + + //Get next random number + double r = random.NextDouble (); + + //Check which detector that clicked + double ptmp = 0; + double[] detector = null; + + for (int i = 0; i < p.Length; i++) { + + ptmp += p[i]; + + if (r <= ptmp) { + //We found which detector clicked + detector = n[i]; + counter[i]++; + break; + } + } + + if (detector == null) + detector = n[p.Length - 1]; + + //Project + double sc = Product (fp, detector); + + for (int j = 0; j < 3; j++) + fp[j]= (1 - alpha * alpha) * fp[j] + 2 * alpha * (1 + alpha * sc) * detector[j]; + + //Normalize + double norm = Math.Sqrt (Product (fp, fp)); + + for (int j=0; j<3; j++) + fp[j] /= norm; + + consumer.UpdateData (fp); + + } while (true); + } + + + //Calculate the scalar product of two vectors + private double Product (double[] v1, double[] v2) + { + double sc = 0; + for(int i=0; i < v1.Length; i++) + sc += v1[i] * v2[i]; + return sc; + } + + public string GetPolytope () + { + string ret = String.Empty; + switch (polytope) { + case Shapes.TETRAHEDRON: + ret = "Tetrahedron"; + break; + case Shapes.CUBE: + ret = "Cube"; + break; + case Shapes.OCTAHEDRON: + ret = "Octahedron"; + break; + case Shapes.ICOSAHEDRON: + ret = "Icosahedron"; + break; + case Shapes.DODECAHEDRON: + ret = "Dodecahedron"; + break; + case Shapes.DOUBLE_TETRAHEDRON: + ret = "Double Tetrahedron"; + break; + case Shapes.ICOSIDODECAHEDRON: + ret = "Icosidodecahedron"; + break; + Default: + ret = "Unknown"; + break; + } + return ret; + } + + public void SetPolytope (int type) + { + polytope = (Qf.Shapes)type; + + switch (type) { + + case 0: { + + n = new double[4][]; + n[0] = new double[] {0,0,1.0}; + n[1] = new double[] {0.9428090415820634,0,-0.3333333333333333}; + n[2] = new double[] {-0.4714045207910317,0.816496580927726,-0.3333333333333333}; + n[3] = new double[] {-0.4714045207910317, -0.816496580927726, -0.3333333333333333}; + + break; + } + + case 1: { + + n = new double[8][]; + n[0] = new double[] {0, 0, 1.0}; + n[1] = new double[] {0.9428090415820634, 0, 0.3333333333333333}; + n[2] = new double[] {-0.4714045207910317, 0.816496580927726, 0.3333333333333333}; + n[3] = new double[] {-0.4714045207910317, -0.816496580927726, 0.3333333333333333}; + n[4] = new double[] {0.4714045207910317, 0.816496580927726, -0.3333333333333333}; + n[5] = new double[] {0.4714045207910317, -0.816496580927726, -0.3333333333333333}; + n[6] = new double[] {-0.9428090415820634, 0, -0.3333333333333333}; + n[7] = new double[] {0, 0, -1.0}; + break; + } + + case 2: { + + n = new double[6][]; + n[0] = new double[] {0, 0, 1.0}; + n[1] = new double[] {1.0, 0, 0}; + n[2] = new double[] {0, 1.0, 0}; + n[3] = new double[] {-1.0, 0, 0}; + n[4] = new double[] {0, -1.0, 0}; + n[5] = new double[] {0, 0, -1.0}; + + break; + } + + case 3: { + + n = new double[12][]; + n[0] = new double[] {0, 0, 1.0}; + n[1] = new double[] {0.8944271909999159, 0, 0.4472135954999579}; + n[2] = new double[] {0.276393202250021, 0.85065080835204, 0.4472135954999579}; + n[3] = new double[] {-0.723606797749979, 0.5257311121191336, 0.4472135954999579}; + n[4] = new double[] {-0.723606797749979, -0.5257311121191336, 0.4472135954999579}; + n[5] = new double[] {0.276393202250021, -0.85065080835204, 0.4472135954999579}; + n[6] = new double[] {0.723606797749979, 0.5257311121191336, -0.4472135954999579}; + n[7] = new double[] {0.723606797749979, -0.5257311121191336, -0.4472135954999579}; + n[8] = new double[] {-0.276393202250021, 0.85065080835204, -0.4472135954999579}; + n[9] = new double[] {-0.8944271909999159, 0, -0.4472135954999579}; + n[10] = new double[] {-0.276393202250021, -0.85065080835204, -0.4472135954999579}; + n[11] = new double[] {0, 0, -1.0}; + + break; + } + + case 4: { + + n = new double[20][]; + n[0] = new double[] {0, 0, 1.0}; + n[1] = new double[] {0.6666666666666666, 0, 0.7453559924999299}; + n[2] = new double[] {-0.3333333333333333, 0.5773502691896257, 0.7453559924999299}; + n[3] = new double[] {-0.3333333333333333, -0.5773502691896257, 0.7453559924999299}; + n[4] = new double[] {0.7453559924999299, 0.5773502691896257, 0.3333333333333333}; + n[5] = new double[] {0.7453559924999299, -0.5773502691896257, 0.3333333333333333}; + n[6] = new double[] {-0.8726779962499649, 0.35682208977308993, 0.3333333333333333}; + n[7] = new double[] {0.12732200375003502, 0.9341723589627157, 0.3333333333333333}; + n[8] = new double[] {0.12732200375003502, -0.9341723589627157, 0.3333333333333333}; + n[9] = new double[] {-0.8726779962499649, -0.35682208977308993, 0.3333333333333333}; + n[10] = new double[] {0.8726779962499649, 0.35682208977308993, -0.3333333333333333}; + n[11] = new double[] {0.8726779962499649, -0.35682208977308993, -0.3333333333333333}; + n[12] = new double[] {-0.7453559924999299, 0.5773502691896257, -0.3333333333333333}; + n[13] = new double[] {-0.12732200375003502, 0.9341723589627157, -0.3333333333333333}; + n[14] = new double[] {-0.12732200375003502, -0.9341723589627157, -0.3333333333333333}; + n[15] = new double[] {-0.7453559924999299, -0.5773502691896257, -0.3333333333333333}; + n[16] = new double[] {0.3333333333333333, 0.5773502691896257, -0.7453559924999299}; + n[17] = new double[] {0.3333333333333333, -0.5773502691896257, -0.7453559924999299}; + n[18] = new double[] {-0.6666666666666666, 0, -0.7453559924999299}; + n[19] = new double[] {0, 0, -1.0}; + break; + } + + case 5: { + + n = new double[8][]; + n[0] = new double[] {0,0,1.0}; + n[1] = new double[] {0.9428090415820634,0,-0.3333333333333333}; + n[2] = new double[] {-0.4714045207910317,0.816496580927726,-0.3333333333333333}; + n[3] = new double[] {-0.4714045207910317, -0.816496580927726, -0.3333333333333333}; + n[4] = new double[] {0,0,-1.0}; + n[5] = new double[] {-0.9428090415820634,0,0.3333333333333333}; + n[6] = new double[] {0.4714045207910317,-0.816496580927726,0.3333333333333333}; + n[7] = new double[] {0.4714045207910317, 0.816496580927726, 0.3333333333333333}; + + break; + } + + case 6: { + + double u=0.5; + double v=0.8090169943749475; // (1/2)*phi + double w=0.3090169943749474; // (1/2)/phi + + n = new double[30][]; + n[0] = new double[] {1,0,0}; + n[1] = new double[] {-1,0,0}; + n[2] = new double[] {0,1,0}; + n[3] = new double[] {0,-1,0}; + n[4] = new double[] {0,0,1}; + n[5] = new double[] {0,0,-1}; + n[6] = new double[] {u,v,w}; + n[7] = new double[] {-u,v,w}; + n[8] = new double[] {u,-v,w}; + n[9] = new double[] {u,v,-w}; + n[10] = new double[] {-u,-v,w}; + n[11] = new double[] {u,-v,-w}; + n[12] = new double[] {-u,v,-w}; + n[13] = new double[] {-u,-v,-w}; + n[14] = new double[] {v,w,u}; + n[15] = new double[] {v,w,-u}; + n[16] = new double[] {-v,w,u}; + n[17] = new double[] {v,-w,u}; + n[18] = new double[] {-v,w,-u}; + n[19] = new double[] {-v,-w,u}; + n[20] = new double[] {v,-w,-u}; + n[21] = new double[] {-v,-w,-u}; + n[22] = new double[] {w,u,v}; + n[23] = new double[] {w,-u,v}; + n[24] = new double[] {w,u,-v}; + n[25] = new double[] {-w,u,v}; + n[26] = new double[] {w,-u,-v}; + n[27] = new double[] {-w,u,-v}; + n[28] = new double[] {-w,-u,v}; + n[29] = new double[] {-w,-u,-v}; + break; + } + + Default: + break; + } + } + } +} diff --git a/qtsharp/src/examples/samples/samples.build b/qtsharp/src/examples/samples/samples.build new file mode 100644 index 00000000..08a314ab --- /dev/null +++ b/qtsharp/src/examples/samples/samples.build @@ -0,0 +1,86 @@ +<?xml version="1.0"> +<project name="Qt# Samples" default="all"> + <target name="all"> + <compile output="hello.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="hello.cs" /> + </sources> + </compile> + + <compile output="display.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="display.cs" /> + </sources> + </compile> + + <compile output="emit.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="emit.cs" /> + </sources> + </compile> + + <compile output="eventhandling.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="eventhandling.cs" /> + </sources> + </compile> + + <compile output="mandelbrot.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="mandelbrot.cs" /> + </sources> + </compile> + + <compile output="scribblewindow.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="scribblewindow.cs" /> + </sources> + </compile> + + <compile output="qfractals.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="quantumfractals.cs" /> + </sources> + </compile> + + <compile output="mandelbrot2.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="mandelbrot2.cs" /> + </sources> + </compile> + + + </target> +</project> diff --git a/qtsharp/src/examples/samples/scribblewindow.cs b/qtsharp/src/examples/samples/scribblewindow.cs new file mode 100644 index 00000000..6b594eb8 --- /dev/null +++ b/qtsharp/src/examples/samples/scribblewindow.cs @@ -0,0 +1,212 @@ +// scribblewindow.cs - Qt# scribblewindow +// +// Author: Adam Treat <manyoso@yahoo.com> +// (c) 2002 Adam Treat +// Licensed under the terms of the GNU GPL + +namespace QtSamples { + + using Qt; + using System; + + [DeclareQtSignal ("colorChanged(QColor)")] + [DeclareQtSignal ("load(QString)")] + [DeclareQtSignal ("save(QString)")] + public class ScribbleWindow : QMainWindow { + + private QMenuBar menubar; + private QPopupMenu filemenu; + private QPopupMenu aboutmenu; + private QScrollView scrollview; + public ScribbleArea scribblearea; + + enum Color {Black, Red, Blue, Green, Yellow}; + + public static int Main (String[] args) + { + QApplication app = new QApplication (args); + ScribbleWindow demo = new ScribbleWindow (); + demo.SetGeometry (50, 500, 400, 400); + app.SetMainWidget (demo); + demo.SetCaption ("Qt# 0.7!"); + demo.Show (); + return app.Exec (); + } + + ScribbleWindow () : base (null, null) + { + filemenu = new QPopupMenu (null, "filemenu"); + filemenu.InsertItem ("&Load", this, SLOT ("SlotLoad()") ); + filemenu.InsertItem ("&Save", this, SLOT ("SlotSave()") ); + filemenu.InsertSeparator (); + filemenu.InsertItem ("&Quit", qApp, SLOT ("quit()")); + + aboutmenu = new QPopupMenu (null, "helpmenu"); + aboutmenu.InsertItem ("&About Qt-Sharp", this, SLOT ("SlotAboutQtSharp()")); + aboutmenu.InsertItem ("&About Qt", this, SLOT ("SlotAboutQt()")); + + menubar = new QMenuBar (this, ""); + menubar.InsertItem ("&File", filemenu); + menubar.InsertItem ("&Color", this, SLOT("SlotColorChooser()")); + menubar.InsertItem ("&About", aboutmenu); + + scrollview = new QScrollView (this); + scrollview.SetGeometry (0, menubar.Height (), Width (), Height () - menubar.Height ()); + scribblearea = new ScribbleArea (this); + scribblearea.SetGeometry (0, 0, 1000, 1000); + scrollview.AddChild (scribblearea); + this.SetCentralWidget (scrollview); + SetMaximumSize (Width (), Height () - menubar.Height ()); + + QObject.Connect (this, SIGNAL ("colorChanged(QColor)"), + scribblearea, SLOT ("SlotSetColor(QColor)") ); + QObject.Connect (this, SIGNAL ("load(QString)"), + scribblearea, SLOT ("PerformLoad(QString)") ); + QObject.Connect (this, SIGNAL ("save(QString)"), + scribblearea, SLOT ("PerformSave(QString)") ); + } + + public void SlotLoad () + { + string filename = QFileDialog.GetOpenFileName (".", "*.bmp", this, + null, "Load File", QString.Null, true); + + if ( filename != null ) + Emit ("load(QString)", (QString) filename); + } + + public void SlotSave () + { + string filename = QFileDialog.GetSaveFileName (".", "*.bmp", this, + null, "Save File", QString.Null, true); + + if ( filename != null ) + { + if ( ! filename.ToLower().EndsWith(".bmp") ) + filename += ".bmp"; + Emit ("save(QString)", (QString) filename); + } + } + + public void SlotAboutQtSharp () + { + QMessageBox.Information (this, "About Qt# 0.7", + "A Qt (http://www.trolltech.com) to C# language binding. \n" + + "Qt# is compatible with Mono (http://go-mono.org) and\n" + + "Portable.NET (http://www.southern-storm.com.au/portable_net.html)\n" + + "(c) 2002 Adam Treat. Licensed under the terms of the GNU GPL.\n" + ); + } + + public void SlotAboutQt () + { + QMessageBox.AboutQt (this, "About Qt"); + } + + public void SlotColorChooser () + { + QColor chosenColor = QColorDialog.GetColor(); + if (chosenColor.IsValid()) + Emit ("colorChanged(QColor)", chosenColor); + } + + public class ScribbleArea : QFrame { + private QPoint last; + private QPixmap buffer; + private QColor currentcolor = new QColor("Black"); + private QPopupMenu popupmenu; + + public ScribbleArea (QWidget parent) : base (parent) + { + buffer = new QPixmap (); + last = new QPoint (); + SetBackgroundMode (Qt.BackgroundMode.NoBackground); + + popupmenu = new QPopupMenu(); + popupmenu.InsertItem ("&Clear", this, SLOT ("SlotClearArea()") ); + + mouseMoveEvent += new MouseMoveEvent (MouseMoved); + mousePressEvent += new MousePressEvent (MousePressed); + paintEvent += new PaintEvent (PerformPaint); + resizeEvent += new ResizeEvent (PerformResize); + } + + public void PerformLoad (QString filename) + { + if ( ! buffer.Load(filename) ) + QMessageBox.Warning (null, "Load error", "Could not load file"); + Repaint(); + } + + public void PerformSave (QString filename) + { + if ( ! buffer.Save (filename, "BMP") ) + QMessageBox.Warning( null, "Save error", "Could not save file"); + } + + public void SlotClearArea () + { + buffer.Fill( new QColor ("white") ); + BitBlt (this, 0, 0, buffer, 0, 0, -1, -1, Qt.RasterOp.CopyROP, false); + } + + + public void SlotSetColor (QColor color) + { + currentcolor = color; + } + + // Note, Dispose() is called on QPoints here to increase performance + // of the UI. Otherwise, the GC would let dead QPoint instances pile + // up and delete them all at once, causing the UI to pause while it frees + // memory. (This happens because the GC runs in the same thread as the + // application.) + + protected void MousePressed (QMouseEvent e) + { + if (e.Button() == ButtonState.RightButton ) + popupmenu.Exec (QCursor.Pos ()); + else { + last.Dispose (); + last = e.Pos(); + } + } + + protected void MouseMoved (QMouseEvent e) + { + QPainter windowPainter = new QPainter (); + QPainter bufferPainter = new QPainter (); + + windowPainter.Begin (this); + bufferPainter.Begin (buffer); + + windowPainter.SetPen (currentcolor); + bufferPainter.SetPen (currentcolor); + + windowPainter.DrawLine (last, e.Pos()); + bufferPainter.DrawLine (last, e.Pos()); + + windowPainter.End (); + bufferPainter.End (); + + last.Dispose (); + last = e.Pos (); + } + + protected void PerformPaint (QPaintEvent e) + { + BitBlt(this, 0, 0, buffer, + 0, 0, -1, -1, RasterOp.CopyROP, false); + } + + protected void PerformResize (QResizeEvent e) + { + QPixmap save = new QPixmap (buffer); + buffer.Resize (e.Size()); + buffer.Fill (new QColor("white")); + BitBlt (buffer, 0, 0, save, + 0, 0, -1, -1, RasterOp.CopyROP, false); + } + } + } +} diff --git a/qtsharp/src/examples/test-results.html b/qtsharp/src/examples/test-results.html new file mode 100644 index 00000000..43ddae93 --- /dev/null +++ b/qtsharp/src/examples/test-results.html @@ -0,0 +1,203 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> + +<HTML> +<HEAD> + + <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1"> + <TITLE></TITLE> + <META NAME="GENERATOR" CONTENT="OpenOffice.org 1.0.2 (Linux)"> + <META NAME="CREATED" CONTENT="20021229;19061900"> + <META NAME="CHANGED" CONTENT="20030209;3092000"> + + <STYLE> + <!-- + BODY,DIV,TABLE,THEAD,TBODY,TFOOT,TR,TH,TD,P { font-family:"Albany"; font-size:x-small } + --> + </STYLE> + +</HEAD> + +<BODY TEXT="#000000"> +<TABLE FRAME=VOID CELLSPACING=0 COLS=7 RULES=GROUPS BORDER=1> + <COLGROUP><COL WIDTH=86><COL WIDTH=86><COL WIDTH=86><COL WIDTH=86><COL WIDTH=130><COL WIDTH=86><COL WIDTH=86></COLGROUP> + <TBODY> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=RIGHT SDVAL="37661" SDNUM="1033;0;YYYY-MM-DD"><FONT SIZE=3>2003-02-09</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono 0.19</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><BR></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun 0.5.2</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>T3</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mandelbrot</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Csc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Csc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (4)</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Cscc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Cscc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (4)</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mcs</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mcs</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (2)</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>T5</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Quantumfractals</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Csc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Csc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (1)</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Cscc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Cscc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (1)</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mcs</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mcs</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (1)</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>T7</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Scribblewindow</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Ilrun</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mono</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Csc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Csc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (3)</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Cscc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Cscc</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (3)</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mcs</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Mcs</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Fail (3)</FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3>Pass</FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><BR></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><BR></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><BR></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + </TR> + <TR> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=130 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + <TD WIDTH=86 HEIGHT=19 ALIGN=LEFT><FONT SIZE=3><BR></FONT></TD> + </TR> + <TR> + <TD COLSPAN=7 WIDTH=644 HEIGHT=19 ALIGN=LEFT><FONT FACE="Arial" SIZE=3>(1) No crashes, but no drawing</FONT></TD> + </TR> + <TR> + <TD COLSPAN=7 WIDTH=644 HEIGHT=19 ALIGN=LEFT><FONT FACE="Arial" SIZE=3>(2) Closing window results in a double QObject deletion and then application locks up</FONT></TD> + </TR> + <TR> + <TD COLSPAN=7 WIDTH=644 HEIGHT=37 ALIGN=LEFT><FONT FACE="Arial" SIZE=3>(3) Random lockups occur after a large amount of scribbling is performed; background fails to initialized properly sometimes</FONT></TD> + </TR> + <TR> + <TD COLSPAN=7 WIDTH=644 HEIGHT=37 ALIGN=LEFT><FONT FACE="Arial" SIZE=3>(4) Closing window results in application locking up (unlike (2) there is no double deletion message)</FONT></TD> + </TR> + </TBODY> +</TABLE> +<!-- ************************************************************************** --> +</BODY> + +</HTML> diff --git a/qtsharp/src/examples/test-results.sxc b/qtsharp/src/examples/test-results.sxc Binary files differnew file mode 100644 index 00000000..6caab7e0 --- /dev/null +++ b/qtsharp/src/examples/test-results.sxc diff --git a/qtsharp/src/examples/tutorials/Makefile.am b/qtsharp/src/examples/tutorials/Makefile.am new file mode 100644 index 00000000..52d1adce --- /dev/null +++ b/qtsharp/src/examples/tutorials/Makefile.am @@ -0,0 +1,24 @@ +all: + csant -D$(CSC_NAME)=$(CSC) -C $(CSC_NAME) + chmod 0755 *.exe + +clean: + rm -rf *.exe + +distclean: clean + +install: + mkdir -p $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials + cat t1.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t1.cs.gz + cat t2.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t2.cs.gz + cat t3.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t3.cs.gz + cat t4.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t4.cs.gz + cat t5.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t5.cs.gz + cat t6.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t6.cs.gz + cat t7.cs | gzip -9c > $(DESTDIR)$(datadir)/doc/qtcsharp/tutorials/t7.cs.gz + +uninstall: + rm -rf $(datadir)/doc/qtcsharp/tutorials/*.cs.gz + rm -rf $(datadir)/doc/qtcsharp/tutorials/*.cs + +.PHONY: all clean distclean install diff --git a/qtsharp/src/examples/tutorials/README b/qtsharp/src/examples/tutorials/README new file mode 100644 index 00000000..21e302ea --- /dev/null +++ b/qtsharp/src/examples/tutorials/README @@ -0,0 +1,14 @@ +These tutorials are translations of the C++ versions provided with +Qt 3.0.x. Tutorial 7 is included, but it does not yet work properly +because it is not yet possible to create custom signals. + +Assuming that you're using Mono and that Qt.dll has been +installed in /opt/kde/lib you can compile the first tutorial +using + +> mcs -L /opt/kde/lib -r Qt t1.cs + +To run the first tutorial, use + +> mono t1.exe + diff --git a/qtsharp/src/examples/tutorials/t1.cs b/qtsharp/src/examples/tutorials/t1.cs new file mode 100644 index 00000000..3dc075b1 --- /dev/null +++ b/qtsharp/src/examples/tutorials/t1.cs @@ -0,0 +1,23 @@ +// Qt# tutorial 1 +// Based on the Qt tutorial +// Implemented by Marcus Urban + +using System; +using Qt; + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + QPushButton hello = new QPushButton ("Hello world!", null); + // In C++, the second parameter is 0 (null pointer) + + hello.Resize (100, 30); + + a.SetMainWidget (hello); + hello.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/t2.cs b/qtsharp/src/examples/tutorials/t2.cs new file mode 100644 index 00000000..44eb304b --- /dev/null +++ b/qtsharp/src/examples/tutorials/t2.cs @@ -0,0 +1,28 @@ +// Qt# tutorial 2 +// Based on the Qt tutorial +// Implemented by Marcus Urban + +using System; +using Qt; + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + QPushButton quit = new QPushButton ("Quit", null); + // In C++, the second parameter is 0 (null pointer) + + quit.Resize (75, 30); + quit.SetFont (new QFont ("Times", 18, QFont.Weight.Bold)); + // In C++, QFont::Bold is sufficient + + QObject.Connect ( quit, QtSupport.SIGNAL ("clicked()"), a, QtSupport.SLOT ("Quit()") ); + // SIGNAL and SLOT are static functions of QtSupport + + a.SetMainWidget (quit); + quit.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/t3.cs b/qtsharp/src/examples/tutorials/t3.cs new file mode 100644 index 00000000..a1c76ce4 --- /dev/null +++ b/qtsharp/src/examples/tutorials/t3.cs @@ -0,0 +1,29 @@ +// Qt# tutorial 3 +// Based on the Qt tutorial +// Implemented by Marcus Urban + +using System; +using Qt; + + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + QVBox box = new QVBox (); + box.Resize (200, 120); + + QPushButton quit = new QPushButton ("Quit", box); + quit.SetFont (new QFont ("Times", 18, QFont.Weight.Bold)); + // In C++, QFont::Bold is sufficient + + QObject.Connect ( quit, QtSupport.SIGNAL ("clicked()"), a, QtSupport.SLOT ("Quit()") ); + // SIGNAL and SLOT are static functions of QtSupport + + a.SetMainWidget (box); + box.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/t4.cs b/qtsharp/src/examples/tutorials/t4.cs new file mode 100644 index 00000000..5373af19 --- /dev/null +++ b/qtsharp/src/examples/tutorials/t4.cs @@ -0,0 +1,44 @@ +// Qt# tutorial 4 +// Based on the Qt tutorial +// Implemented by Marcus Urban + +using System; +using Qt; + +public class MyWidget : QWidget { + + public MyWidget (QWidget parent, String name) : base (parent, name) + // In C++, parent and name have default values of 0 (null pointer) + { + this.SetMinimumSize (200, 120); + this.SetMaximumSize (200, 120); + + QPushButton quit = new QPushButton ("Quit", this, "quit"); + quit.SetGeometry (62, 40, 75, 30); + quit.SetFont (new QFont ("Times", 18, QFont.Weight.Bold) ); + + Connect ( quit, SIGNAL ("clicked()"), qApp, SLOT ("Quit()") ); + // In C++, qApp is a global variable. Here it's a property of the QObject + // class, which we inherit, giving the same effect. We also inherit the + // static method connect(). + } + + public MyWidget (QWidget parent) : this (parent, "") {} + public MyWidget () : this (null, "") {} + // Note that it was necessary to use an empty string ("") + // in the above. Using null does not work at runtime. +} + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + MyWidget w = new MyWidget (); + w.SetGeometry (100, 100, 200, 120); + a.SetMainWidget (w); + w.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/t5.cs b/qtsharp/src/examples/tutorials/t5.cs new file mode 100644 index 00000000..4feadae5 --- /dev/null +++ b/qtsharp/src/examples/tutorials/t5.cs @@ -0,0 +1,45 @@ +// Qt# tutorial 5 +// Based on the Qt tutorial +// Implemented by Marcus Urban + +using System; +using Qt; + +public class MyWidget : QVBox { + + public MyWidget (QWidget parent, String name) : base (parent, name) + // In C++, parent and name have default values of 0 (null pointer) + { + QPushButton quit = new QPushButton ("Quit", this, "quit"); + quit.SetFont ( new QFont ("Times", 18, QFont.Weight.Bold) ); + + QObject.Connect ( quit, SIGNAL ("clicked()"), qApp, SLOT ("Quit()") ); + + QLCDNumber lcd = new QLCDNumber (2, this, "lcd" ); + + QSlider slider = new QSlider (Orientation.Horizontal, this, "slider"); + // Note that Orientation is defined in the Qt class + slider.SetRange (0, 99); + slider.SetValue (0); + + Connect ( slider, SIGNAL ("valueChanged(int)"), lcd, SLOT ("Display(int)") ); + } + + public MyWidget (QWidget parent) : this (parent, "") {} + public MyWidget () : this (null, "") {} + // Note that it was necessary to use an empty string ("") + // in the above. Using null does not work at runtime. +} + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + MyWidget w = new MyWidget (); + a.SetMainWidget (w); + w.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/t6.cs b/qtsharp/src/examples/tutorials/t6.cs new file mode 100644 index 00000000..223e0ff1 --- /dev/null +++ b/qtsharp/src/examples/tutorials/t6.cs @@ -0,0 +1,58 @@ +// Qt# tutorial 6 +// Based on the Qt tutorial +// Implemented by Marcus Urban + +using System; +using Qt; + +public class LCDRange : QVBox { + + public LCDRange (QWidget parent, String name) : base (parent, name) + // In C++, parent and name have default values of 0 (null pointer) + { + QLCDNumber lcd = new QLCDNumber (2, this, "lcd" ); + QSlider slider = new QSlider (Orientation.Horizontal, this, "slider"); + slider.SetRange (0, 99); + slider.SetValue (0); + + Connect ( slider, SIGNAL ("valueChanged(int)"), lcd, SLOT ("Display(int)") ); + } + + public LCDRange (QWidget parent) : this (parent, "") {} + public LCDRange () : this (null, "") {} + // Note that it was necessary to use an empty string ("") + // in the above. Using null does not work at runtime. +} + +public class MyWidget : QVBox { + + MyWidget (QWidget parent, String name) : base (parent, name) + { + QPushButton quit = new QPushButton ("Quit", this, "quit"); + quit.SetFont ( new QFont ("Times", 18, QFont.Weight.Bold) ); + + Connect ( quit, SIGNAL ("clicked()"), qApp, SLOT ("Quit()") ); + + QGrid grid = new QGrid (4, this); + + for ( int c =0; c < 4; c++ ) + for ( int r = 0; r < 4; r++ ) + new LCDRange (grid); + } + + public MyWidget (QWidget parent) : this (parent, "") {} + public MyWidget () : this (null, "") {} +} + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + MyWidget w = new MyWidget (); + a.SetMainWidget (w); + w.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/t7.cs b/qtsharp/src/examples/tutorials/t7.cs new file mode 100644 index 00000000..de9011f2 --- /dev/null +++ b/qtsharp/src/examples/tutorials/t7.cs @@ -0,0 +1,78 @@ +// Qt# tutorial 7 +// Based on the Qt tutorial +// Implemented by Marcus Urban +// +// This example currently does not funtion properly because custom +// signals are not yet implemented. + +using System; +using Qt; + +[DeclareQtSignal ("valueChanged(int)")] +public class LCDRange : QVBox { + + QSlider slider; + + public LCDRange (QWidget parent, String name) : base (parent, name) + // In C++, parent and name have default values of 0 (null pointer) + { + QLCDNumber lcd = new QLCDNumber (2, this, "lcd" ); + slider = new QSlider (Orientation.Horizontal, this, "slider"); + slider.SetRange (0, 99); + slider.SetValue (0); + + Connect ( slider, SIGNAL ("valueChanged(int)"), lcd, SLOT ("Display(int)") ); + Connect ( slider, SIGNAL ("valueChanged(int)"), SIGNAL ("valueChanged(int)")); + } + + public LCDRange (QWidget parent) : this (parent, "") {} + public LCDRange () : this (null, "") {} + // Note that it was necessary to use an empty string ("") + // in the above. Using null does not work at runtime. + + public void SetValue (int value) + { + slider.SetValue (value); + } +} + +public class MyWidget : QVBox { + + MyWidget (QWidget parent, String name) : base (parent, name) + { + QPushButton quit = new QPushButton ("Quit", this, "quit"); + quit.SetFont ( new QFont ("Times", 18, QFont.Weight.Bold) ); + + Connect ( quit, SIGNAL ("clicked()"), qApp, SLOT ("Quit()") ); + + QGrid grid = new QGrid (4, this); + + LCDRange previous = null; + + for ( int c =0; c < 4; c++ ) { + for ( int r = 0; r < 4; r++ ) { + LCDRange lr = new LCDRange (grid); + if (previous != null) + Connect (lr, SIGNAL ("valueChanged(int)"), + previous, SLOT ("SetValue(int)") ); + previous = lr; + } + } + } + + public MyWidget (QWidget parent) : this (parent, "") {} + public MyWidget () : this (null, "") {} +} + +public class Example { + + public static int Main (String[] args) + { + QApplication a = new QApplication (args); + + MyWidget w = new MyWidget (); + a.SetMainWidget (w); + w.Show (); + return a.Exec (); + } +} diff --git a/qtsharp/src/examples/tutorials/tutorials.build b/qtsharp/src/examples/tutorials/tutorials.build new file mode 100644 index 00000000..f3b211f2 --- /dev/null +++ b/qtsharp/src/examples/tutorials/tutorials.build @@ -0,0 +1,75 @@ +<?xml version="1.0"> +<project name="Qt# Samples" default="all"> + <target name="all"> + <compile output="t1.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t1.cs" /> + </sources> + </compile> + + <compile output="t2.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t2.cs" /> + </sources> + </compile> + + <compile output="t3.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t3.cs" /> + </sources> + </compile> + + <compile output="t4.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t4.cs" /> + </sources> + </compile> + + <compile output="t5.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t5.cs" /> + </sources> + </compile> + + <compile output="t6.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t6.cs" /> + </sources> + </compile> + + <compile output="t7.exe" target="exe" optimize="true"> + <references> + <file name="../../bindings/Qt.dll" /> + </references> + + <sources> + <file name="t7.cs" /> + </sources> + </compile> + + </target> +</project> |