summaryrefslogtreecommitdiffstats
path: root/examples/popup
diff options
context:
space:
mode:
Diffstat (limited to 'examples/popup')
-rw-r--r--examples/popup/README3
-rw-r--r--examples/popup/popup.cpp132
-rw-r--r--examples/popup/popup.doc23
-rw-r--r--examples/popup/popup.h58
-rw-r--r--examples/popup/popup.pro10
5 files changed, 226 insertions, 0 deletions
diff --git a/examples/popup/README b/examples/popup/README
new file mode 100644
index 000000000..3be117bb2
--- /dev/null
+++ b/examples/popup/README
@@ -0,0 +1,3 @@
+The popup program demonstrates some easy techniques for creating custom
+popup widgets like a fancy color or line-width selection for the
+toolbar of a drawing program or a browsebox for various symbols or ...
diff --git a/examples/popup/popup.cpp b/examples/popup/popup.cpp
new file mode 100644
index 000000000..9a13fc8f9
--- /dev/null
+++ b/examples/popup/popup.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** 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 "popup.h"
+#include <qapplication.h>
+#include <qlayout.h>
+
+FancyPopup::FancyPopup( TQWidget* parent, const char* name ):
+ TQLabel( parent, name, WType_Popup ){
+ setFrameStyle( WinPanel|Raised );
+ setAlignment( AlignCenter );
+ resize(150,100);
+ moves = 0;
+ setMouseTracking( TRUE );
+}
+
+void FancyPopup::mouseMoveEvent( TQMouseEvent * e){
+ moves++;
+ TQString s;
+ s.sprintf("%d/%d", e->pos().x(), e->pos().y());
+ if (e->state() & TQMouseEvent::LeftButton)
+ s += " (down)";
+ setText(s);
+}
+
+void FancyPopup::mouseReleaseEvent( TQMouseEvent * e){
+ if (rect().contains( e->pos() ) || moves > 5)
+ close();
+}
+
+void FancyPopup::closeEvent( TQCloseEvent *e ){
+ e->accept();
+ moves = 0;
+ if (!popupParent)
+ return;
+
+ // remember that we (as a popup) might recieve the mouse release
+ // event instead of the popupParent. This is due to the fact that
+ // the popupParent popped us up in its mousePressEvent handler. To
+ // avoid the button remaining in pressed state we simply send a
+ // faked mouse button release event to it.
+ TQMouseEvent me( TQEvent::MouseButtonRelease, TQPoint(0,0), TQPoint(0,0), TQMouseEvent::LeftButton, TQMouseEvent::NoButton);
+ TQApplication::sendEvent( popupParent, &me );
+}
+
+void FancyPopup::popup( TQWidget* parent) {
+ popupParent = parent;
+ setText("Move the mouse!");
+ if (popupParent)
+ move( popupParent->mapToGlobal( popupParent->rect().bottomLeft() ) );
+ show();
+}
+
+
+
+
+
+
+Frame::Frame(TQWidget* parent, const char* name): TQFrame(parent, name){
+ button1 = new TQPushButton("Simple Popup", this);
+ connect ( button1, SIGNAL( clicked() ), SLOT( button1Clicked() ) );
+ button2 = new TQPushButton("Fancy Popup", this);
+ connect ( button2, SIGNAL( pressed() ), SLOT( button2Pressed() ) );
+
+ TQBoxLayout * l = new TQHBoxLayout( this );
+ button1->setMaximumSize(button1->sizeHint());
+ button2->setMaximumSize(button2->sizeHint());
+ l->addWidget( button1 );
+ l->addWidget( button2 );
+ l->activate();
+
+// button1->setGeometry(20,20,100,30);
+// button2->setGeometry(140,20,100,30);
+ resize(270, 70);
+
+ //create a very simple popup: it is just composed with other
+ //widget and will be shown after clicking on button1
+
+ popup1 = new TQFrame( this ,0, WType_Popup);
+ popup1->setFrameStyle( WinPanel|Raised );
+ popup1->resize(150,100);
+ TQLineEdit *tmpE = new TQLineEdit( popup1 );
+ connect( tmpE, SIGNAL( returnPressed() ), popup1, SLOT( hide() ) );
+ tmpE->setGeometry(10,10, 130, 30);
+ tmpE->setFocus();
+ TQPushButton *tmpB = new TQPushButton("Click me!", popup1);
+ connect( tmpB, SIGNAL( clicked() ), popup1, SLOT( close() ) );
+ tmpB->setGeometry(10, 50, 130, 30);
+
+ // the fancier version uses its own class. It will be shown when
+ // pressing button2, so they behavior is more like a modern menu
+ // or toolbar.
+
+ popup2 = new FancyPopup( this );
+
+ // you might also add new widgets to the popup, just like you do
+ // it with any other widget. The next four lines (if not
+ // commented out) will for instance add a line edit widget.
+
+// tmpE = new TQLineEdit( popup2 );
+// tmpE->setFocus();
+// connect( tmpE, SIGNAL( returnPressed() ), popup2, SLOT( close() ) );
+// tmpE->setGeometry(10, 10, 130, 30);
+}
+
+
+void Frame::button1Clicked(){
+ popup1->move( mapToGlobal( button1->geometry().bottomLeft() ) );
+ popup1->show();
+}
+
+void Frame::button2Pressed(){
+ popup2->popup(button2);
+}
+
+
+int main( int argc, char **argv )
+{
+ TQApplication a(argc,argv);
+
+ Frame frame;
+ frame.setCaption("TQt Example - Custom Popups");
+ a.setMainWidget(&frame);
+ frame.show();
+ return a.exec();
+}
diff --git a/examples/popup/popup.doc b/examples/popup/popup.doc
new file mode 100644
index 000000000..1322fbd5a
--- /dev/null
+++ b/examples/popup/popup.doc
@@ -0,0 +1,23 @@
+/*
+*/
+/*! \page popup-example.html
+
+ \ingroup examples
+ \title Popup Widgets
+
+ This example shows how to implement widgets that should
+ pop up.
+
+ <hr>
+
+ Header file:
+
+ \include popup/popup.h
+
+ <hr>
+
+ Implementation:
+
+ \include popup/popup.cpp
+*/
+
diff --git a/examples/popup/popup.h b/examples/popup/popup.h
new file mode 100644
index 000000000..ef4e8b282
--- /dev/null
+++ b/examples/popup/popup.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Definition of something or other
+**
+** Created : 979899
+**
+** Copyright (C) 1997-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.
+**
+*****************************************************************************/
+
+#ifndef POPUP_H
+#define POPUP_H
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qlineedit.h>
+
+class FancyPopup : public TQLabel
+{
+ Q_OBJECT
+public:
+ FancyPopup( TQWidget* parent = 0, const char* name=0);
+
+ void popup( TQWidget* parent = 0);
+protected:
+ virtual void mouseMoveEvent( TQMouseEvent * );
+ virtual void mouseReleaseEvent( TQMouseEvent * );
+ virtual void closeEvent( TQCloseEvent * );
+
+private:
+ TQWidget* popupParent;
+ int moves;
+};
+
+
+ class Frame : public TQFrame
+ {
+ Q_OBJECT
+ public:
+ Frame( TQWidget *parent=0, const char* name=0);
+
+ protected:
+
+ private slots:
+ void button1Clicked();
+ void button2Pressed();
+
+ private:
+ TQPushButton *button1;
+ TQPushButton *button2;
+
+ TQFrame* popup1;
+ FancyPopup* popup2;
+ };
+
+#endif
diff --git a/examples/popup/popup.pro b/examples/popup/popup.pro
new file mode 100644
index 000000000..9a77d8e8c
--- /dev/null
+++ b/examples/popup/popup.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = popup
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = large-config
+
+HEADERS = popup.h
+SOURCES = popup.cpp