summaryrefslogtreecommitdiffstats
path: root/examples/tooltip
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
committerTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/tooltip
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/tooltip')
-rw-r--r--examples/tooltip/README8
-rw-r--r--examples/tooltip/main.cpp23
-rw-r--r--examples/tooltip/tooltip.cpp116
-rw-r--r--examples/tooltip/tooltip.doc33
-rw-r--r--examples/tooltip/tooltip.h43
-rw-r--r--examples/tooltip/tooltip.pro11
6 files changed, 234 insertions, 0 deletions
diff --git a/examples/tooltip/README b/examples/tooltip/README
new file mode 100644
index 000000000..cdfe50cd2
--- /dev/null
+++ b/examples/tooltip/README
@@ -0,0 +1,8 @@
+The tooltip example demonstrates advanced use of tool tips.
+
+There are dynamic tool tips on the blue rectanges - QToolTip asks
+tooltip whether to display anything, and if so, what. The Right Thing
+happens when you click on the rectangles.
+
+There is also a static tool tip on the red rectangle.
+
diff --git a/examples/tooltip/main.cpp b/examples/tooltip/main.cpp
new file mode 100644
index 000000000..fa02f0e86
--- /dev/null
+++ b/examples/tooltip/main.cpp
@@ -0,0 +1,23 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include "tooltip.h"
+
+int main( int argc, char ** argv )
+{
+ TQApplication a( argc, argv );
+
+ TellMe mw;
+ mw.setCaption( "TQt Example - Dynamic Tool Tips" );
+ a.setMainWidget( &mw );
+ mw.show();
+
+ return a.exec();
+}
diff --git a/examples/tooltip/tooltip.cpp b/examples/tooltip/tooltip.cpp
new file mode 100644
index 000000000..628c4d94f
--- /dev/null
+++ b/examples/tooltip/tooltip.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "tooltip.h"
+#include <qapplication.h>
+#include <qpainter.h>
+#include <stdlib.h>
+
+
+DynamicTip::DynamicTip( TQWidget * parent )
+ : TQToolTip( parent )
+{
+ // no explicit initialization needed
+}
+
+
+void DynamicTip::maybeTip( const TQPoint &pos )
+{
+ if ( !parentWidget()->inherits( "TellMe" ) )
+ return;
+
+ TQRect r( ((TellMe*)parentWidget())->tip(pos) );
+ if ( !r.isValid() )
+ return;
+
+ TQString s;
+ s.sprintf( "position: %d,%d", r.center().x(), r.center().y() );
+ tip( r, s );
+}
+
+
+TellMe::TellMe( TQWidget * parent , const char * name )
+ : TQWidget( parent, name )
+{
+ setMinimumSize( 30, 30 );
+ r1 = randomRect();
+ r2 = randomRect();
+ r3 = randomRect();
+
+ t = new DynamicTip( this );
+
+ TQToolTip::add( this, r3, "this color is called red" ); // <- helpful
+}
+
+
+TellMe::~TellMe()
+{
+ delete t;
+ t = 0;
+}
+
+
+void TellMe::paintEvent( TQPaintEvent * e )
+{
+ TQPainter p( this );
+
+ // I try to be efficient here, and repaint only what's needed
+
+ if ( e->rect().intersects( r1 ) ) {
+ p.setBrush( blue );
+ p.drawRect( r1 );
+ }
+
+ if ( e->rect().intersects( r2 ) ) {
+ p.setBrush( blue );
+ p.drawRect( r2 );
+ }
+
+ if ( e->rect().intersects( r3 ) ) {
+ p.setBrush( red );
+ p.drawRect( r3 );
+ }
+}
+
+
+void TellMe::mousePressEvent( TQMouseEvent * e )
+{
+ if ( r1.contains( e->pos() ) )
+ r1 = randomRect();
+ if ( r2.contains( e->pos() ) )
+ r2 = randomRect();
+ repaint();
+}
+
+
+void TellMe::resizeEvent( TQResizeEvent * )
+{
+ if ( !rect().contains( r1 ) )
+ r1 = randomRect();
+ if ( !rect().contains( r2 ) )
+ r2 = randomRect();
+}
+
+
+TQRect TellMe::randomRect()
+{
+ return TQRect( ::rand() % (width() - 20), ::rand() % (height() - 20),
+ 20, 20 );
+}
+
+
+TQRect TellMe::tip( const TQPoint & p )
+{
+ if ( r1.contains( p ) )
+ return r1;
+ else if ( r2.contains( p ) )
+ return r2;
+ else
+ return TQRect( 0,0, -1,-1 );
+}
diff --git a/examples/tooltip/tooltip.doc b/examples/tooltip/tooltip.doc
new file mode 100644
index 000000000..41800ff07
--- /dev/null
+++ b/examples/tooltip/tooltip.doc
@@ -0,0 +1,33 @@
+/*
+*/
+/*! \page tooltip-example.html
+
+ \ingroup examples
+ \title Advanced use of tool tips
+
+ This example widget demonstrates how to use tool tips for static and
+ dynamic regions within a widget.
+
+ It displays two blue and one red rectangle. The blue ones move every
+ time you click on them, the red one is static. There are dynamic
+ tool tips on the blue rectangles and a static tool tip on the red one.
+
+ <hr>
+
+ Header file:
+
+ \include tooltip/tooltip.h
+
+ <hr>
+
+ Implementation:
+
+ \include tooltip/tooltip.cpp
+
+ <hr>
+
+ Main:
+
+ \include tooltip/main.cpp
+*/
+
diff --git a/examples/tooltip/tooltip.h b/examples/tooltip/tooltip.h
new file mode 100644
index 000000000..c9d26d9ac
--- /dev/null
+++ b/examples/tooltip/tooltip.h
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qwidget.h>
+#include <qtooltip.h>
+
+
+class DynamicTip : public TQToolTip
+{
+public:
+ DynamicTip( TQWidget * parent );
+
+protected:
+ void maybeTip( const TQPoint & );
+};
+
+
+class TellMe : public TQWidget
+{
+ Q_OBJECT
+public:
+ TellMe( TQWidget * parent = 0, const char * name = 0 );
+ ~TellMe();
+
+ TQRect tip( const TQPoint & );
+
+protected:
+ void paintEvent( TQPaintEvent * );
+ void mousePressEvent( TQMouseEvent * );
+ void resizeEvent( TQResizeEvent * );
+
+private:
+ TQRect randomRect();
+
+ TQRect r1, r2, r3;
+ DynamicTip * t;
+};
diff --git a/examples/tooltip/tooltip.pro b/examples/tooltip/tooltip.pro
new file mode 100644
index 000000000..d0c2fdb47
--- /dev/null
+++ b/examples/tooltip/tooltip.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = tooltip
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = large-config
+
+HEADERS = tooltip.h
+SOURCES = main.cpp \
+ tooltip.cpp