From 628b0bb74c3fc327efff8add9c73ada04b1cbea2 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 7 Jul 2024 13:06:00 +0900 Subject: Rename drag-n-drop nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- examples/demo/dnd/dnd.cpp | 2 +- examples/demo/dnd/iconview.cpp | 2 +- examples/demo/dnd/listview.cpp | 2 +- examples/demo/dnd/styledbutton.cpp | 2 +- examples/desktop/desktop.cpp | 4 +- examples/dirview/dirview.cpp | 4 +- examples/dragdrop/dropsite.cpp | 2 +- examples/dragdrop/dropsite.h | 2 +- examples/dragdrop/secret.h | 2 +- examples/fileiconview/qfileiconview.cpp | 4 +- examples/iconview/main.cpp | 4 +- examples/tetrix/README | 2 +- examples/tetrix/qdragapp.cpp | 502 -------------------------------- examples/tetrix/qdragapp.h | 31 -- examples/tetrix/tetrix.cpp | 2 +- examples/tetrix/tetrix.pro | 4 +- examples/tetrix/tqdragapp.cpp | 502 ++++++++++++++++++++++++++++++++ examples/tetrix/tqdragapp.h | 31 ++ 18 files changed, 552 insertions(+), 552 deletions(-) delete mode 100644 examples/tetrix/qdragapp.cpp delete mode 100644 examples/tetrix/qdragapp.h create mode 100644 examples/tetrix/tqdragapp.cpp create mode 100644 examples/tetrix/tqdragapp.h (limited to 'examples') diff --git a/examples/demo/dnd/dnd.cpp b/examples/demo/dnd/dnd.cpp index 43100b721..34e9540ed 100644 --- a/examples/demo/dnd/dnd.cpp +++ b/examples/demo/dnd/dnd.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/examples/demo/dnd/iconview.cpp b/examples/demo/dnd/iconview.cpp index 89cac969a..51bfff304 100644 --- a/examples/demo/dnd/iconview.cpp +++ b/examples/demo/dnd/iconview.cpp @@ -1,4 +1,4 @@ -#include +#include #include "dnd.h" #include "iconview.h" diff --git a/examples/demo/dnd/listview.cpp b/examples/demo/dnd/listview.cpp index 0cb86d2c4..e97a03ea0 100644 --- a/examples/demo/dnd/listview.cpp +++ b/examples/demo/dnd/listview.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "listview.h" #include "dnd.h" diff --git a/examples/demo/dnd/styledbutton.cpp b/examples/demo/dnd/styledbutton.cpp index 44d58ee38..ec377d030 100644 --- a/examples/demo/dnd/styledbutton.cpp +++ b/examples/demo/dnd/styledbutton.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include StyledButton::StyledButton(TQWidget* parent, const char* name) diff --git a/examples/desktop/desktop.cpp b/examples/desktop/desktop.cpp index 0e5782889..9997595a3 100644 --- a/examples/desktop/desktop.cpp +++ b/examples/desktop/desktop.cpp @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include diff --git a/examples/dirview/dirview.cpp b/examples/dirview/dirview.cpp index 3183f7213..846eb6289 100644 --- a/examples/dirview/dirview.cpp +++ b/examples/dirview/dirview.cpp @@ -16,8 +16,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/examples/dragdrop/dropsite.cpp b/examples/dragdrop/dropsite.cpp index 98188b19a..214b4d0dd 100644 --- a/examples/dragdrop/dropsite.cpp +++ b/examples/dragdrop/dropsite.cpp @@ -15,7 +15,7 @@ #include "secret.h" #include #include -#include +#include #include #include diff --git a/examples/dragdrop/dropsite.h b/examples/dragdrop/dropsite.h index 7f23f1b36..020aaeaad 100644 --- a/examples/dragdrop/dropsite.h +++ b/examples/dragdrop/dropsite.h @@ -16,7 +16,7 @@ #include #include -#include "ntqdropsite.h" +#include "tqdropsite.h" class TQDragObject; diff --git a/examples/dragdrop/secret.h b/examples/dragdrop/secret.h index 573ea1442..b05547944 100644 --- a/examples/dragdrop/secret.h +++ b/examples/dragdrop/secret.h @@ -14,7 +14,7 @@ #ifndef SECRETDRAG_H #define SECRETDRAG_H -#include +#include #include class SecretDrag: public TQStoredDrag { diff --git a/examples/fileiconview/qfileiconview.cpp b/examples/fileiconview/qfileiconview.cpp index 5a800ff53..acdc8f4c5 100644 --- a/examples/fileiconview/qfileiconview.cpp +++ b/examples/fileiconview/qfileiconview.cpp @@ -11,9 +11,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include diff --git a/examples/iconview/main.cpp b/examples/iconview/main.cpp index 7dc8f04d3..ba6d509ad 100644 --- a/examples/iconview/main.cpp +++ b/examples/iconview/main.cpp @@ -9,11 +9,11 @@ #include #include -#include +#include #include #include -#include +#include #include class ListenDND : public TQObject diff --git a/examples/tetrix/README b/examples/tetrix/README index fc9e74e99..148260a71 100644 --- a/examples/tetrix/README +++ b/examples/tetrix/README @@ -22,7 +22,7 @@ Enjoy! P.S. Tetrix has later been updated to show new versions of Qt. P.P.S The tetrix program uses a special application object called - QDragApplication. Try to guess what it does. + TQDragApplication. Try to guess what it does. Hint: Try pressing the right mouse button somewhere in the tetrix window and start dragging.... diff --git a/examples/tetrix/qdragapp.cpp b/examples/tetrix/qdragapp.cpp deleted file mode 100644 index b11a54505..000000000 --- a/examples/tetrix/qdragapp.cpp +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** -** -** 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 "qdragapp.h" -#include "tqptrlist.h" -#include "ntqintdict.h" -#include "tqpopupmenu.h" -#include "ntqguardedptr.h" -#include "ntqcolor.h" -#include "tqwidget.h" -#include "ntqfontmetrics.h" -#include "ntqcursor.h" -#include "tqobjectlist.h" - -TQWidget *cursorWidget( TQPoint * = 0 ); - -class TQDragger; - - -class DropWindow : public TQWidget -{ - TQ_OBJECT -public: - void paintEvent( TQPaintEvent * ); - void closeEvent( TQCloseEvent * ); - - TQDragger *master; -}; - - -struct DropInfo { - DropInfo() { w=0; } - ~DropInfo() { delete w; } - DropWindow *w; - bool userOpened; -}; - -struct DraggedInfo { - TQWidget *w; - TQWidget *mother; - TQPoint pos; -}; - - -class TQDragger : public TQObject -{ - TQ_OBJECT -public: - TQDragger(); - ~TQDragger(); - - bool notify( TQObject *, TQEvent * ); // event filter - void closeDropWindow( DropWindow * ); -public slots: - void openDropWindow(); - void killDropWindow(); - void killAllDropWindows(); - void sendChildHome(); - void sendAllChildrenHome(); -private: - bool isParentToDragged( TQWidget * ); - bool noWidgets( TQWidget * ); - void killDropWindow( DropInfo * ); - void killAllDropWindows( bool ); - void sendChildHome( DraggedInfo * ); - void sendAllChildrenHome( TQWidget * ); - TQWidget *openDropWindow( const TQRect&, bool ); - - bool startGrab(); - void grabFinished(); - bool dragEvent( TQWidget *, TQMouseEvent * ); - bool killDropEvent( TQMouseEvent * ); - bool sendChildEvent( TQMouseEvent * ); - - bool killingDrop; - bool sendingChild; - TQWidget *clickedWidget; - TQGuardedPtr hostWidget; - TQCursor cursor; - - TQPopupMenu* menu; - TQPoint clickOffset; - TQColor dragBackground; - TQColor dragForeground; - DraggedInfo dragInfo; - TQIntDict draggedDict; - TQIntDict dropDict; -}; - - -TQDragApplication::TQDragApplication( int &argc, char **argv ) - : TQApplication( argc, argv ), dragger( 0 ) -{ - dragger = new TQDragger; -} - -TQDragApplication::~TQDragApplication() -{ - delete dragger; -} - -bool TQDragApplication::notify( TQObject *o, TQEvent *e ) -{ - if ( dragger && !dragger->notify( o, e ) ) - return TQApplication::notify( o, e ); - else - return FALSE; -} - -void DropWindow::paintEvent( TQPaintEvent * ) -{ - const char *msg = "Drag widgets and drop them here or anywhere!"; - int startX = ( width() - fontMetrics().width( msg ) )/2; - startX = startX < 0 ? 0 : startX; - - drawText( startX, height()/2, msg ); -} - -void DropWindow::closeEvent( TQCloseEvent *e ) -{ - master->closeDropWindow( this ); - e->ignore(); -} - -TQDragger::TQDragger() -{ - dragInfo.w = 0; - killingDrop = FALSE; - sendingChild = FALSE; - draggedDict.setAutoDelete( TRUE ); - dropDict .setAutoDelete( TRUE ); - - menu = new TQPopupMenu; - menu->insertItem( "Open drop window", 1 ); - menu->insertItem( "Kill drop window", 2 ); - menu->insertItem( "Kill all drop windows", 3 ); - menu->insertSeparator(); -// menu->insertItem( "Send child home", 4 ); - menu->insertItem( "Send all children home", 5 ); - - menu->connectItem( 1, this, TQ_SLOT(openDropWindow()) ); - menu->connectItem( 2, this, TQ_SLOT(killDropWindow()) ); - menu->connectItem( 3, this, TQ_SLOT(killAllDropWindows()) ); -// menu->connectItem( 4, this, TQ_SLOT(sendChildHome()) ); - menu->connectItem( 5, this, TQ_SLOT(sendAllChildrenHome()) ); -} - -TQDragger::~TQDragger() -{ - delete menu; -} - - -bool TQDragger::notify( TQObject *o, TQEvent *e ) -{ - if ( !o->isWidgetType() || o == menu ) - return FALSE; - switch( e->type() ) { - case TQEvent::MouseMove: - { - TQMouseEvent *tmp = (TQMouseEvent*) e; - if ( killingDrop ) - return killDropEvent( tmp ); - if ( sendingChild ) - return sendChildEvent( tmp ); - if ( tmp->state() & TQMouseEvent::RightButton ) - return dragEvent( (TQWidget*) o, tmp ); - break; - } - case TQEvent::MouseButtonPress: - case TQEvent::MouseButtonRelease: - case TQEvent::MouseButtonDblClick: - { - TQMouseEvent *tmp = (TQMouseEvent*) e; - if ( killingDrop ) - return killDropEvent( tmp ); - if ( sendingChild ) - return sendChildEvent( tmp ); - if ( tmp->button() == TQMouseEvent::RightButton ) - return dragEvent( (TQWidget*) o, tmp ); - } - break; - default: - break; - } - return FALSE; -} - -bool TQDragger::isParentToDragged( TQWidget *w ) -{ - TQIntDictIterator iter( draggedDict ); - - DraggedInfo *tmp; - while( (tmp = iter.current()) ) { - ++iter; - if ( tmp->mother == w ) - return TRUE; - } - return FALSE; -} - -bool TQDragger::noWidgets( TQWidget *w ) -{ - const TQObjectList *l = w->children(); - if ( !l ) - return TRUE; - TQObjectListIt iter( *l ); - TQObject *tmp; - while( (tmp = iter.current()) ) { - ++iter; - if ( tmp->isWidgetType() ) - return FALSE; - } - return TRUE; -} - -void TQDragger::sendAllChildrenHome( TQWidget *w ) -{ - const TQObjectList *l = w->children(); - if ( !l ) - return; - TQObjectListIt iter( *l ); - TQObject *tmp; - while( (tmp = iter.current()) ) { - ++iter; - if ( tmp->isWidgetType() ) { - sendAllChildrenHome( (TQWidget*) tmp ); - DraggedInfo *di = draggedDict.find( (long) tmp ); - if ( di ) - sendChildHome( di ); - } - } -} - -bool TQDragger::dragEvent( TQWidget *w, TQMouseEvent *e ) -{ - switch( e->type() ) { - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseButtonPress: { - if ( !noWidgets( w ) || // has widget children - isParentToDragged( w ) || // has had widget children - w->parentWidget() == 0 ) { // is top level window - hostWidget = w; - menu->popup( w->mapToGlobal( e->pos() ) ); - return TRUE; - } - if ( !draggedDict.find( (long) w ) ) { - DraggedInfo *tmp = new DraggedInfo; - tmp->w = w; - tmp->mother = w->parentWidget(); - tmp->pos = w->frameGeometry().topLeft(); - draggedDict.insert( (long) w, tmp ); - } - dragBackground = w->backgroundColor(); - dragForeground = w->foregroundColor(); - dragInfo.w = w; - dragInfo.mother = w->parentWidget(); - dragInfo.pos = w->frameGeometry().topLeft(); - clickOffset = e->pos(); - dragInfo.w = w; - TQPoint p = w->mapToGlobal(TQPoint(0,0)); - w->reparent( 0, WType_Popup, p, TRUE ); - - return TRUE; - } - case TQEvent::MouseButtonRelease: - case TQEvent::MouseMove: { - if ( dragInfo.w != 0 ) { - TQPoint p = TQCursor::pos() - clickOffset; - dragInfo.w->move( p ); - if ( e->type() == TQEvent::MouseMove ) - return TRUE; - } else { - return FALSE; - } - if ( !dragInfo.w ) - return FALSE; - if ( w != dragInfo.w ) - w = dragInfo.w; - dragInfo.w = 0; - w->hide(); - TQPoint pos; - TQWidget *target = cursorWidget( &pos ); - pos = pos - clickOffset; - TQPoint p; - if ( !target ) { - target = openDropWindow( TQRect( pos, w->size() ), - FALSE); - p = TQPoint( 0, 0 ); - } - else - p = target->mapFromGlobal( pos ); - w->reparent( target, 0, p, TRUE ); - DropInfo *tmp = dropDict.find( (long) dragInfo.mother ); - if ( tmp ) { - if ( !tmp->userOpened && noWidgets( tmp->w ) ) - dropDict.remove( (long) tmp->w ); - } - if ( !target->isVisible() ) - target->show(); - } - return TRUE; - default: - return FALSE; - } -} - -bool TQDragger::killDropEvent( TQMouseEvent *e ) -{ - switch( e->type() ) { - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseButtonPress: - clickedWidget = cursorWidget(); - return TRUE; - case TQEvent::MouseButtonRelease: - hostWidget->releaseMouse(); - if ( clickedWidget ) { - DropInfo *tmp = dropDict.find( (long) clickedWidget ); - if( tmp ) { - killDropWindow( tmp ); - dropDict.remove( (long) tmp->w ); - } - } - grabFinished(); - return TRUE; - case TQEvent::MouseMove: - return TRUE; - default: - break; - } - return FALSE; -} - -bool TQDragger::sendChildEvent( TQMouseEvent *e ) -{ - switch( e->type() ) { - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseButtonPress: - clickedWidget = cursorWidget(); - return TRUE; - case TQEvent::MouseButtonRelease: - hostWidget->releaseMouse(); - if ( clickedWidget ) { - DraggedInfo *tmp = draggedDict.find((long) clickedWidget); - if( tmp ) { - TQWidget *parent = tmp->w->parentWidget(); - sendChildHome( tmp ); - DropInfo *dri = dropDict.find( (long) parent ); - if ( dri && noWidgets(dri->w) && !dri->userOpened ) { - killDropWindow( dri ); - dropDict.remove( (long) dri ); - } - } - grabFinished(); - } - return TRUE; - case TQEvent::MouseMove: - return TRUE; - default: - break; - } - return FALSE; -} - -bool TQDragger::startGrab() -{ - if ( !hostWidget ) - return FALSE; - clickedWidget = 0; - cursor = hostWidget->cursor(); - hostWidget->grabMouse(); - hostWidget->setCursor( TQCursor( CrossCursor ) ); - return TRUE; -} - -void TQDragger::grabFinished() -{ - killingDrop = FALSE; - sendingChild = FALSE; - if(hostWidget) - hostWidget->setCursor( cursor ); -} - -void TQDragger::closeDropWindow( DropWindow *w ) -{ - DropInfo *tmp = dropDict.find( (long) w); - if( tmp ) - killDropWindow( tmp ); -} - -void TQDragger::openDropWindow() -{ - TQWidget *tmp = openDropWindow( TQRect(100, 100, 300, 200), TRUE ); - tmp->show(); -} - -TQWidget *TQDragger::openDropWindow( const TQRect &r, bool user ) -{ - DropInfo *tmp = new DropInfo; - DropWindow *w = new DropWindow; - if ( user ) { - tmp->userOpened = TRUE; - w->setCaption( "Drop window" ); - } else { - tmp->userOpened = FALSE; - w->setCaption( "Auto drop window" ); - } - tmp->w = w; - w->master = this; - w->setGeometry( r ); - dropDict.insert( (long) w, tmp ); - w->show(); - return w; -} - -void TQDragger::killDropWindow() -{ - if ( startGrab() ) - killingDrop = TRUE; -} - -void TQDragger::killDropWindow( DropInfo *di ) -{ - const TQObjectList *l = di->w->children(); - if ( !l ) - return; - TQObjectListIt iter( *l ); - TQObject *tmp; - while( (tmp = iter.current()) ) { - ++iter; - if ( tmp->isWidgetType() ) { - DraggedInfo *dri = draggedDict.find( (long) tmp ); - if ( dri ) { - sendChildHome( dri ); - draggedDict.remove( (long) tmp ); - } - } - } - di->w->hide(); -} - -void TQDragger::killAllDropWindows() -{ - killAllDropWindows( FALSE ); -} - -void TQDragger::killAllDropWindows( bool autoOnly ) -{ - TQIntDictIterator iter( dropDict ); - - DropInfo *tmp; - while( (tmp = iter.current()) ) { - ++iter; - if( !autoOnly || !tmp->userOpened ) { - killDropWindow( tmp ); - dropDict.remove( (long) tmp->w ); - } - } -} - -void TQDragger::sendChildHome( DraggedInfo *i ) -{ - i->w->reparent( i->mother, 0, i->pos, TRUE ); -} - -void TQDragger::sendChildHome() -{ - if ( startGrab() ) - sendingChild = TRUE; -} - -void TQDragger::sendAllChildrenHome() -{ - TQIntDictIterator iter( draggedDict ); - - DraggedInfo *tmp; - while( (tmp = iter.current()) ) { - ++iter; - sendChildHome( tmp ); - draggedDict.remove( (long) tmp->w ); - } - killAllDropWindows( TRUE ); - draggedDict.clear(); -} - - -TQWidget *cursorWidget( TQPoint *p ) -{ - TQPoint curpos = TQCursor::pos(); - if ( p ) - *p = curpos; - return TQApplication::widgetAt( curpos ); -} - - -#include "qdragapp.moc" diff --git a/examples/tetrix/qdragapp.h b/examples/tetrix/qdragapp.h deleted file mode 100644 index c710bd974..000000000 --- a/examples/tetrix/qdragapp.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** -** -** 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. -** -*****************************************************************************/ - -#ifndef TQDRAGAPP_H -#define TQDRAGAPP_H - -#include "ntqapplication.h" - -class TQDragger; - -class TQDragApplication : public TQApplication -{ - TQ_OBJECT -public: - TQDragApplication( int &argc, char **argv ); - virtual ~TQDragApplication(); - - virtual bool notify( TQObject *, TQEvent * ); // event filter - -private: - TQDragger *dragger; -}; - - -#endif // TQDRAGAPP_H diff --git a/examples/tetrix/tetrix.cpp b/examples/tetrix/tetrix.cpp index 2d8c2d5fd..7cb623240 100644 --- a/examples/tetrix/tetrix.cpp +++ b/examples/tetrix/tetrix.cpp @@ -8,7 +8,7 @@ *****************************************************************************/ #include "qtetrix.h" -#include "qdragapp.h" +#include "tqdragapp.h" #include "ntqfont.h" int main( int argc, char **argv ) diff --git a/examples/tetrix/tetrix.pro b/examples/tetrix/tetrix.pro index ad8ad831a..a9f80f011 100644 --- a/examples/tetrix/tetrix.pro +++ b/examples/tetrix/tetrix.pro @@ -7,12 +7,12 @@ DEPENDPATH = ../../include REQUIRES = small-config HEADERS = gtetrix.h \ - qdragapp.h \ + tqdragapp.h \ qtetrix.h \ qtetrixb.h \ tpiece.h SOURCES = gtetrix.cpp \ - qdragapp.cpp \ + tqdragapp.cpp \ qtetrix.cpp \ qtetrixb.cpp \ tetrix.cpp \ diff --git a/examples/tetrix/tqdragapp.cpp b/examples/tetrix/tqdragapp.cpp new file mode 100644 index 000000000..014583a29 --- /dev/null +++ b/examples/tetrix/tqdragapp.cpp @@ -0,0 +1,502 @@ +/**************************************************************************** +** +** 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 "tqdragapp.h" +#include "tqptrlist.h" +#include "ntqintdict.h" +#include "tqpopupmenu.h" +#include "ntqguardedptr.h" +#include "ntqcolor.h" +#include "tqwidget.h" +#include "ntqfontmetrics.h" +#include "ntqcursor.h" +#include "tqobjectlist.h" + +TQWidget *cursorWidget( TQPoint * = 0 ); + +class TQDragger; + + +class DropWindow : public TQWidget +{ + TQ_OBJECT +public: + void paintEvent( TQPaintEvent * ); + void closeEvent( TQCloseEvent * ); + + TQDragger *master; +}; + + +struct DropInfo { + DropInfo() { w=0; } + ~DropInfo() { delete w; } + DropWindow *w; + bool userOpened; +}; + +struct DraggedInfo { + TQWidget *w; + TQWidget *mother; + TQPoint pos; +}; + + +class TQDragger : public TQObject +{ + TQ_OBJECT +public: + TQDragger(); + ~TQDragger(); + + bool notify( TQObject *, TQEvent * ); // event filter + void closeDropWindow( DropWindow * ); +public slots: + void openDropWindow(); + void killDropWindow(); + void killAllDropWindows(); + void sendChildHome(); + void sendAllChildrenHome(); +private: + bool isParentToDragged( TQWidget * ); + bool noWidgets( TQWidget * ); + void killDropWindow( DropInfo * ); + void killAllDropWindows( bool ); + void sendChildHome( DraggedInfo * ); + void sendAllChildrenHome( TQWidget * ); + TQWidget *openDropWindow( const TQRect&, bool ); + + bool startGrab(); + void grabFinished(); + bool dragEvent( TQWidget *, TQMouseEvent * ); + bool killDropEvent( TQMouseEvent * ); + bool sendChildEvent( TQMouseEvent * ); + + bool killingDrop; + bool sendingChild; + TQWidget *clickedWidget; + TQGuardedPtr hostWidget; + TQCursor cursor; + + TQPopupMenu* menu; + TQPoint clickOffset; + TQColor dragBackground; + TQColor dragForeground; + DraggedInfo dragInfo; + TQIntDict draggedDict; + TQIntDict dropDict; +}; + + +TQDragApplication::TQDragApplication( int &argc, char **argv ) + : TQApplication( argc, argv ), dragger( 0 ) +{ + dragger = new TQDragger; +} + +TQDragApplication::~TQDragApplication() +{ + delete dragger; +} + +bool TQDragApplication::notify( TQObject *o, TQEvent *e ) +{ + if ( dragger && !dragger->notify( o, e ) ) + return TQApplication::notify( o, e ); + else + return FALSE; +} + +void DropWindow::paintEvent( TQPaintEvent * ) +{ + const char *msg = "Drag widgets and drop them here or anywhere!"; + int startX = ( width() - fontMetrics().width( msg ) )/2; + startX = startX < 0 ? 0 : startX; + + drawText( startX, height()/2, msg ); +} + +void DropWindow::closeEvent( TQCloseEvent *e ) +{ + master->closeDropWindow( this ); + e->ignore(); +} + +TQDragger::TQDragger() +{ + dragInfo.w = 0; + killingDrop = FALSE; + sendingChild = FALSE; + draggedDict.setAutoDelete( TRUE ); + dropDict .setAutoDelete( TRUE ); + + menu = new TQPopupMenu; + menu->insertItem( "Open drop window", 1 ); + menu->insertItem( "Kill drop window", 2 ); + menu->insertItem( "Kill all drop windows", 3 ); + menu->insertSeparator(); +// menu->insertItem( "Send child home", 4 ); + menu->insertItem( "Send all children home", 5 ); + + menu->connectItem( 1, this, TQ_SLOT(openDropWindow()) ); + menu->connectItem( 2, this, TQ_SLOT(killDropWindow()) ); + menu->connectItem( 3, this, TQ_SLOT(killAllDropWindows()) ); +// menu->connectItem( 4, this, TQ_SLOT(sendChildHome()) ); + menu->connectItem( 5, this, TQ_SLOT(sendAllChildrenHome()) ); +} + +TQDragger::~TQDragger() +{ + delete menu; +} + + +bool TQDragger::notify( TQObject *o, TQEvent *e ) +{ + if ( !o->isWidgetType() || o == menu ) + return FALSE; + switch( e->type() ) { + case TQEvent::MouseMove: + { + TQMouseEvent *tmp = (TQMouseEvent*) e; + if ( killingDrop ) + return killDropEvent( tmp ); + if ( sendingChild ) + return sendChildEvent( tmp ); + if ( tmp->state() & TQMouseEvent::RightButton ) + return dragEvent( (TQWidget*) o, tmp ); + break; + } + case TQEvent::MouseButtonPress: + case TQEvent::MouseButtonRelease: + case TQEvent::MouseButtonDblClick: + { + TQMouseEvent *tmp = (TQMouseEvent*) e; + if ( killingDrop ) + return killDropEvent( tmp ); + if ( sendingChild ) + return sendChildEvent( tmp ); + if ( tmp->button() == TQMouseEvent::RightButton ) + return dragEvent( (TQWidget*) o, tmp ); + } + break; + default: + break; + } + return FALSE; +} + +bool TQDragger::isParentToDragged( TQWidget *w ) +{ + TQIntDictIterator iter( draggedDict ); + + DraggedInfo *tmp; + while( (tmp = iter.current()) ) { + ++iter; + if ( tmp->mother == w ) + return TRUE; + } + return FALSE; +} + +bool TQDragger::noWidgets( TQWidget *w ) +{ + const TQObjectList *l = w->children(); + if ( !l ) + return TRUE; + TQObjectListIt iter( *l ); + TQObject *tmp; + while( (tmp = iter.current()) ) { + ++iter; + if ( tmp->isWidgetType() ) + return FALSE; + } + return TRUE; +} + +void TQDragger::sendAllChildrenHome( TQWidget *w ) +{ + const TQObjectList *l = w->children(); + if ( !l ) + return; + TQObjectListIt iter( *l ); + TQObject *tmp; + while( (tmp = iter.current()) ) { + ++iter; + if ( tmp->isWidgetType() ) { + sendAllChildrenHome( (TQWidget*) tmp ); + DraggedInfo *di = draggedDict.find( (long) tmp ); + if ( di ) + sendChildHome( di ); + } + } +} + +bool TQDragger::dragEvent( TQWidget *w, TQMouseEvent *e ) +{ + switch( e->type() ) { + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseButtonPress: { + if ( !noWidgets( w ) || // has widget children + isParentToDragged( w ) || // has had widget children + w->parentWidget() == 0 ) { // is top level window + hostWidget = w; + menu->popup( w->mapToGlobal( e->pos() ) ); + return TRUE; + } + if ( !draggedDict.find( (long) w ) ) { + DraggedInfo *tmp = new DraggedInfo; + tmp->w = w; + tmp->mother = w->parentWidget(); + tmp->pos = w->frameGeometry().topLeft(); + draggedDict.insert( (long) w, tmp ); + } + dragBackground = w->backgroundColor(); + dragForeground = w->foregroundColor(); + dragInfo.w = w; + dragInfo.mother = w->parentWidget(); + dragInfo.pos = w->frameGeometry().topLeft(); + clickOffset = e->pos(); + dragInfo.w = w; + TQPoint p = w->mapToGlobal(TQPoint(0,0)); + w->reparent( 0, WType_Popup, p, TRUE ); + + return TRUE; + } + case TQEvent::MouseButtonRelease: + case TQEvent::MouseMove: { + if ( dragInfo.w != 0 ) { + TQPoint p = TQCursor::pos() - clickOffset; + dragInfo.w->move( p ); + if ( e->type() == TQEvent::MouseMove ) + return TRUE; + } else { + return FALSE; + } + if ( !dragInfo.w ) + return FALSE; + if ( w != dragInfo.w ) + w = dragInfo.w; + dragInfo.w = 0; + w->hide(); + TQPoint pos; + TQWidget *target = cursorWidget( &pos ); + pos = pos - clickOffset; + TQPoint p; + if ( !target ) { + target = openDropWindow( TQRect( pos, w->size() ), + FALSE); + p = TQPoint( 0, 0 ); + } + else + p = target->mapFromGlobal( pos ); + w->reparent( target, 0, p, TRUE ); + DropInfo *tmp = dropDict.find( (long) dragInfo.mother ); + if ( tmp ) { + if ( !tmp->userOpened && noWidgets( tmp->w ) ) + dropDict.remove( (long) tmp->w ); + } + if ( !target->isVisible() ) + target->show(); + } + return TRUE; + default: + return FALSE; + } +} + +bool TQDragger::killDropEvent( TQMouseEvent *e ) +{ + switch( e->type() ) { + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseButtonPress: + clickedWidget = cursorWidget(); + return TRUE; + case TQEvent::MouseButtonRelease: + hostWidget->releaseMouse(); + if ( clickedWidget ) { + DropInfo *tmp = dropDict.find( (long) clickedWidget ); + if( tmp ) { + killDropWindow( tmp ); + dropDict.remove( (long) tmp->w ); + } + } + grabFinished(); + return TRUE; + case TQEvent::MouseMove: + return TRUE; + default: + break; + } + return FALSE; +} + +bool TQDragger::sendChildEvent( TQMouseEvent *e ) +{ + switch( e->type() ) { + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseButtonPress: + clickedWidget = cursorWidget(); + return TRUE; + case TQEvent::MouseButtonRelease: + hostWidget->releaseMouse(); + if ( clickedWidget ) { + DraggedInfo *tmp = draggedDict.find((long) clickedWidget); + if( tmp ) { + TQWidget *parent = tmp->w->parentWidget(); + sendChildHome( tmp ); + DropInfo *dri = dropDict.find( (long) parent ); + if ( dri && noWidgets(dri->w) && !dri->userOpened ) { + killDropWindow( dri ); + dropDict.remove( (long) dri ); + } + } + grabFinished(); + } + return TRUE; + case TQEvent::MouseMove: + return TRUE; + default: + break; + } + return FALSE; +} + +bool TQDragger::startGrab() +{ + if ( !hostWidget ) + return FALSE; + clickedWidget = 0; + cursor = hostWidget->cursor(); + hostWidget->grabMouse(); + hostWidget->setCursor( TQCursor( CrossCursor ) ); + return TRUE; +} + +void TQDragger::grabFinished() +{ + killingDrop = FALSE; + sendingChild = FALSE; + if(hostWidget) + hostWidget->setCursor( cursor ); +} + +void TQDragger::closeDropWindow( DropWindow *w ) +{ + DropInfo *tmp = dropDict.find( (long) w); + if( tmp ) + killDropWindow( tmp ); +} + +void TQDragger::openDropWindow() +{ + TQWidget *tmp = openDropWindow( TQRect(100, 100, 300, 200), TRUE ); + tmp->show(); +} + +TQWidget *TQDragger::openDropWindow( const TQRect &r, bool user ) +{ + DropInfo *tmp = new DropInfo; + DropWindow *w = new DropWindow; + if ( user ) { + tmp->userOpened = TRUE; + w->setCaption( "Drop window" ); + } else { + tmp->userOpened = FALSE; + w->setCaption( "Auto drop window" ); + } + tmp->w = w; + w->master = this; + w->setGeometry( r ); + dropDict.insert( (long) w, tmp ); + w->show(); + return w; +} + +void TQDragger::killDropWindow() +{ + if ( startGrab() ) + killingDrop = TRUE; +} + +void TQDragger::killDropWindow( DropInfo *di ) +{ + const TQObjectList *l = di->w->children(); + if ( !l ) + return; + TQObjectListIt iter( *l ); + TQObject *tmp; + while( (tmp = iter.current()) ) { + ++iter; + if ( tmp->isWidgetType() ) { + DraggedInfo *dri = draggedDict.find( (long) tmp ); + if ( dri ) { + sendChildHome( dri ); + draggedDict.remove( (long) tmp ); + } + } + } + di->w->hide(); +} + +void TQDragger::killAllDropWindows() +{ + killAllDropWindows( FALSE ); +} + +void TQDragger::killAllDropWindows( bool autoOnly ) +{ + TQIntDictIterator iter( dropDict ); + + DropInfo *tmp; + while( (tmp = iter.current()) ) { + ++iter; + if( !autoOnly || !tmp->userOpened ) { + killDropWindow( tmp ); + dropDict.remove( (long) tmp->w ); + } + } +} + +void TQDragger::sendChildHome( DraggedInfo *i ) +{ + i->w->reparent( i->mother, 0, i->pos, TRUE ); +} + +void TQDragger::sendChildHome() +{ + if ( startGrab() ) + sendingChild = TRUE; +} + +void TQDragger::sendAllChildrenHome() +{ + TQIntDictIterator iter( draggedDict ); + + DraggedInfo *tmp; + while( (tmp = iter.current()) ) { + ++iter; + sendChildHome( tmp ); + draggedDict.remove( (long) tmp->w ); + } + killAllDropWindows( TRUE ); + draggedDict.clear(); +} + + +TQWidget *cursorWidget( TQPoint *p ) +{ + TQPoint curpos = TQCursor::pos(); + if ( p ) + *p = curpos; + return TQApplication::widgetAt( curpos ); +} + + +#include "tqdragapp.moc" diff --git a/examples/tetrix/tqdragapp.h b/examples/tetrix/tqdragapp.h new file mode 100644 index 000000000..c710bd974 --- /dev/null +++ b/examples/tetrix/tqdragapp.h @@ -0,0 +1,31 @@ +/**************************************************************************** +** +** 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. +** +*****************************************************************************/ + +#ifndef TQDRAGAPP_H +#define TQDRAGAPP_H + +#include "ntqapplication.h" + +class TQDragger; + +class TQDragApplication : public TQApplication +{ + TQ_OBJECT +public: + TQDragApplication( int &argc, char **argv ); + virtual ~TQDragApplication(); + + virtual bool notify( TQObject *, TQEvent * ); // event filter + +private: + TQDragger *dragger; +}; + + +#endif // TQDRAGAPP_H -- cgit v1.2.3