summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/hello
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtjava/javalib/examples/hello
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtjava/javalib/examples/hello')
-rw-r--r--qtjava/javalib/examples/hello/Hello.java107
-rw-r--r--qtjava/javalib/examples/hello/Main.java45
-rw-r--r--qtjava/javalib/examples/hello/README3
3 files changed, 155 insertions, 0 deletions
diff --git a/qtjava/javalib/examples/hello/Hello.java b/qtjava/javalib/examples/hello/Hello.java
new file mode 100644
index 00000000..c5e85041
--- /dev/null
+++ b/qtjava/javalib/examples/hello/Hello.java
@@ -0,0 +1,107 @@
+/***************************************************************************
+* $Id$
+**
+* Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+**
+* This file is part of an example program for Qt. This example
+* program may be used, distributed and modified without limitation.
+**
+****************************************************************************/
+import org.kde.qt.*;
+
+class Hello extends QWidget
+{
+private String t;
+private int b = 0;
+
+
+/*
+ Constructs a Hello widget. Starts a 40 ms animation timer.
+*/
+Hello( String text )
+{
+ this(text, null, null);
+}
+
+Hello( String text, QWidget parent, String name )
+{
+ super(parent,name);
+ t = text;
+ QTimer timer = new QTimer(this);
+ connect( timer, SIGNAL("timeout()"), SLOT("animate()") );
+ timer.start( 40 );
+
+ resize( 260, 130 );
+}
+
+
+/*
+ This private slot is called each time the timer fires.
+*/
+
+void animate()
+{
+ b = (b + 1) & 15;
+ repaint( false );
+}
+
+
+/*
+ Handles mouse button release events for the Hello widget.
+
+ We emit the clicked() signal when the mouse is released inside
+ the widget.
+*/
+
+protected void mouseReleaseEvent( QMouseEvent e )
+{
+ if ( rect().contains( e.pos() ) )
+ emit("clicked");
+}
+
+
+ static int sin_tbl[] = {
+ 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38};
+
+/*
+ Handles paint events for the Hello widget.
+
+ Flicker-free update. The text is first drawn in the pixmap and the
+ pixmap is then blt'ed to the screen.
+*/
+protected void paintEvent( QPaintEvent e )
+{
+ if ( t.equals("") )
+ return;
+
+ // 1: Compute some sizes, positions etc.
+ QFontMetrics fm = fontMetrics();
+ int w = fm.width(t) + 20;
+ int h = fm.height() * 2;
+ int pmx = width()/2 - w/2;
+ int pmy = height()/2 - h/2;
+
+ // 2: Create the pixmap and fill it with the widget's background
+ QPixmap pm = new QPixmap( w, h );
+ pm.fill( this, pmx, pmy );
+
+ // 3: Paint the pixmap. Cool wave effect
+ QPainter p = new QPainter();
+ int x = 10;
+ int y = h/2 + fm.descent();
+ int i = 0;
+ p.begin( pm );
+ p.setFont( font() );
+ while ( i < t.length() ) {
+ int i16 = (b+i) & 15;
+ p.setPen( new QColor((15-i16)*16,255,255,QColor.Hsv) );
+ p.drawText( x, y-sin_tbl[i16]*h/800, t.substring(i,i+1), 1 );
+ x += fm.width( t.substring(i,i+1) );
+ i++;
+ }
+ p.end();
+
+ // 4: Copy the pixmap to the Hello widget
+ bitBlt( this, pmx, pmy, pm );
+}
+}
diff --git a/qtjava/javalib/examples/hello/Main.java b/qtjava/javalib/examples/hello/Main.java
new file mode 100644
index 00000000..1313b2cf
--- /dev/null
+++ b/qtjava/javalib/examples/hello/Main.java
@@ -0,0 +1,45 @@
+/***************************************************************************
+* $Id$
+**
+* Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+**
+* This file is part of an example program for Qt. This example
+* program may be used, distributed and modified without limitation.
+**
+****************************************************************************/
+import org.kde.qt.*;
+
+public class Main {
+
+/*
+ The program starts here. It parses the command line and builds a message
+ string to be displayed by the Hello widget.
+*/
+
+public static void main( String[] args )
+{
+ QApplication a = new QApplication(args);
+ String s = "";
+ for ( int i=1; i<args.length; i++ ) {
+ s += args[i];
+ if ( i<args.length-1 )
+ s += " ";
+ }
+ if ( s.equals("") )
+ s = "Hello, World";
+ Hello h = new Hello( s );
+ h.setCaption( "Qt says hello" );
+ QObject.connect( h, Qt.SIGNAL("clicked()"), a, Qt.SLOT("quit()") );
+ h.setFont( new QFont("times",32,QFont.Bold) ); // default font
+ h.setBackgroundColor( Qt.white() ); // default bg color
+ a.setMainWidget( h );
+ h.show();
+ a.exec();
+ return;
+}
+
+static {
+ qtjava.initialize();
+}
+
+}
diff --git a/qtjava/javalib/examples/hello/README b/qtjava/javalib/examples/hello/README
new file mode 100644
index 00000000..1d956010
--- /dev/null
+++ b/qtjava/javalib/examples/hello/README
@@ -0,0 +1,3 @@
+Since the classic "hello world" program is too trivial in Qt, We made
+this one - it draws the words "hello world" moving around and in
+rainbow colors.