diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/dragdrop | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/dragdrop')
-rw-r--r-- | examples/dragdrop/dragdrop.doc | 14 | ||||
-rw-r--r-- | examples/dragdrop/dragdrop.pro | 13 | ||||
-rw-r--r-- | examples/dragdrop/dropsite.cpp | 158 | ||||
-rw-r--r-- | examples/dragdrop/dropsite.h | 55 | ||||
-rw-r--r-- | examples/dragdrop/main.cpp | 73 | ||||
-rw-r--r-- | examples/dragdrop/secret.cpp | 91 | ||||
-rw-r--r-- | examples/dragdrop/secret.h | 42 | ||||
-rw-r--r-- | examples/dragdrop/trolltech.bmp | bin | 0 -> 30054 bytes | |||
-rw-r--r-- | examples/dragdrop/trolltech.gif | bin | 0 -> 42629 bytes |
9 files changed, 446 insertions, 0 deletions
diff --git a/examples/dragdrop/dragdrop.doc b/examples/dragdrop/dragdrop.doc new file mode 100644 index 000000000..25d3170aa --- /dev/null +++ b/examples/dragdrop/dragdrop.doc @@ -0,0 +1,14 @@ +/*! \page dragdrop-example.html + + \ingroup examples + \title Drag and Drop + + This program demonstrates Qt's drag and drop functionality. + + See $QTDIR/examples/dragdrop for the source code. + +*/ + + + + diff --git a/examples/dragdrop/dragdrop.pro b/examples/dragdrop/dragdrop.pro new file mode 100644 index 000000000..e560fbf96 --- /dev/null +++ b/examples/dragdrop/dragdrop.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = dragdrop + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = dropsite.h \ + secret.h +SOURCES = dropsite.cpp \ + main.cpp \ + secret.cpp diff --git a/examples/dragdrop/dropsite.cpp b/examples/dragdrop/dropsite.cpp new file mode 100644 index 000000000..a1df3de21 --- /dev/null +++ b/examples/dragdrop/dropsite.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Drop site example implementation +** +** 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. +** +*****************************************************************************/ + +#include "dropsite.h" +#include "secret.h" +#include <qevent.h> +#include <qpixmap.h> +#include <qdragobject.h> +#include <qimage.h> +#include <qdir.h> + + +DropSite::DropSite( TQWidget * parent, const char * name ) + : TQLabel( parent, name ) +{ + setAcceptDrops(TRUE); +} + + +DropSite::~DropSite() +{ + // nothing necessary +} + + +void DropSite::dragMoveEvent( TQDragMoveEvent *e ) +{ + // Check if you want the drag at e->pos()... + // Give the user some feedback - only copy is possible + e->acceptAction( e->action() == TQDropEvent::Copy ); +} + + +void DropSite::dragEnterEvent( TQDragEnterEvent *e ) +{ + // Check if you want the drag... + if ( SecretDrag::canDecode( e ) + || TQTextDrag::canDecode( e ) + || TQImageDrag::canDecode( e ) + || TQUriDrag::canDecode( e ) ) + { + e->accept(); + } + + + // Give the user some feedback... + TQString t; + const char *f; + for( int i=0; (f=e->format( i )); i++ ) { + if ( *(f) ) { + if ( !t.isEmpty() ) + t += "\n"; + t += f; + } + } + emit message( t ); + setBackgroundColor(white); +} + +void DropSite::dragLeaveEvent( TQDragLeaveEvent * ) +{ + // Give the user some feedback... + emit message(""); + setBackgroundColor(lightGray); +} + + +void DropSite::dropEvent( TQDropEvent * e ) +{ + setBackgroundColor(lightGray); + + // Try to decode to the data you understand... + TQStrList strings; + if ( TQUriDrag::decode( e, strings ) ) { + TQString m("Full URLs:\n"); + for (const char* u=strings.first(); u; u=strings.next()) + m = m + " " + u + '\n'; + TQStringList files; + if ( TQUriDrag::decodeLocalFiles( e, files ) ) { + m += "Files:\n"; + for (TQStringList::Iterator i=files.begin(); i!=files.end(); ++i) + m = m + " " + TQDir::convertSeparators(*i) + '\n'; + } + setText( m ); + setMinimumSize( minimumSize().expandedTo( sizeHint() ) ); + return; + } + + TQString str; + if ( TQTextDrag::decode( e, str ) ) { + setText( str ); + setMinimumSize( minimumSize().expandedTo( sizeHint() ) ); + return; + } + + TQPixmap pm; + if ( TQImageDrag::decode( e, pm ) ) { + setPixmap( pm ); + setMinimumSize( minimumSize().expandedTo( sizeHint() ) ); + return; + } + + if ( SecretDrag::decode( e, str ) ) { + setText( str ); + setMinimumSize( minimumSize().expandedTo( sizeHint() ) ); + return; + } +} + +DragMoviePlayer::DragMoviePlayer( TQDragObject* p ) : + TQObject(p), + dobj(p), + movie("trolltech.gif" ) +{ + movie.connectUpdate(this,SLOT(updatePixmap(const TQRect&))); +} + +void DragMoviePlayer::updatePixmap( const TQRect& ) +{ + dobj->setPixmap(movie.framePixmap()); +} + +void DropSite::mousePressEvent( TQMouseEvent * /*e*/ ) +{ + TQDragObject *drobj; + if ( pixmap() ) { + drobj = new TQImageDrag( pixmap()->convertToImage(), this ); +#if 1 + TQPixmap pm; + pm.convertFromImage(pixmap()->convertToImage().smoothScale( + pixmap()->width()/3,pixmap()->height()/3)); + drobj->setPixmap(pm,TQPoint(-5,-7)); +#else + // Try it. + (void)new DragMoviePlayer(drobj); +#endif + } else { + drobj = new TQTextDrag( text(), this ); + } + drobj->dragCopy(); +} + + +void DropSite::backgroundColorChange( const TQColor & ) +{ + // Reduce flicker by using repaint() rather than update() + repaint(); +} diff --git a/examples/dragdrop/dropsite.h b/examples/dragdrop/dropsite.h new file mode 100644 index 000000000..0179c5497 --- /dev/null +++ b/examples/dragdrop/dropsite.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Drop site example implementation +** +** 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 DROPSITE_H +#define DROPSITE_H + +#include <qlabel.h> +#include <qmovie.h> +#include "qdropsite.h" + +class TQDragObject; + +class DropSite: public TQLabel +{ + Q_OBJECT +public: + DropSite( TQWidget * parent = 0, const char * name = 0 ); + ~DropSite(); + +signals: + void message( const TQString& ); + +protected: + void dragEnterEvent( TQDragEnterEvent * ); + void dragMoveEvent( TQDragMoveEvent * ); + void dragLeaveEvent( TQDragLeaveEvent * ); + void dropEvent( TQDropEvent * ); + void backgroundColorChange( const TQColor& ); + + // this is a normal even + void mousePressEvent( TQMouseEvent * ); +}; + +class DragMoviePlayer : public TQObject { + Q_OBJECT + TQDragObject* dobj; + TQMovie movie; +public: + DragMoviePlayer(TQDragObject*); +private slots: + void updatePixmap( const TQRect& ); +}; + + +#endif diff --git a/examples/dragdrop/main.cpp b/examples/dragdrop/main.cpp new file mode 100644 index 000000000..539c8251a --- /dev/null +++ b/examples/dragdrop/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Ritual main() for TQt applications +** +** Copyright (C) 1996-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 "dropsite.h" +#include "secret.h" +#include <qlayout.h> +#include <qcombobox.h> +#include <qlabel.h> +#include <qpixmap.h> + +static void addStuff( TQWidget * parent, bool image, bool secret = FALSE ) +{ + TQVBoxLayout * tll = new TQVBoxLayout( parent, 10 ); + DropSite * d = new DropSite( parent ); + d->setFrameStyle( TQFrame::Sunken + TQFrame::WinPanel ); + tll->addWidget( d ); + if ( image ) { + TQPixmap stuff; + if ( !stuff.load( "trolltech.bmp" ) ) { + stuff = TQPixmap(20,20); + stuff.fill(TQt::green); + } + d->setPixmap( stuff ); + } else { + d->setText("Drag and Drop"); + } + d->setFont(TQFont("Helvetica",18)); + if ( secret ) { + SecretSource *s = new SecretSource( 42, parent ); + tll->addWidget( s ); + } + + TQLabel * format = new TQLabel( "\n\n\n\nNone\n\n\n\n", parent ); + tll->addWidget( format ); + tll->activate(); + parent->resize( parent->sizeHint() ); + + TQObject::connect( d, SIGNAL(message(const TQString&)), + format, SLOT(setText(const TQString&)) ); +} + + +int main( int argc, char ** argv ) +{ + TQApplication a( argc, argv ); + + TQWidget mw; + addStuff( &mw, TRUE ); + mw.setCaption( "TQt Example - Drag and Drop" ); + mw.show(); + + TQWidget mw2; + addStuff( &mw2, FALSE ); + mw2.setCaption( "TQt Example - Drag and Drop" ); + mw2.show(); + + TQWidget mw3; + addStuff( &mw3, TRUE, TRUE ); + mw3.setCaption( "TQt Example - Drag and Drop" ); + mw3.show(); + + TQObject::connect(qApp,SIGNAL(lastWindowClosed()),qApp,SLOT(tquit())); + return a.exec(); +} diff --git a/examples/dragdrop/secret.cpp b/examples/dragdrop/secret.cpp new file mode 100644 index 000000000..c90e52816 --- /dev/null +++ b/examples/dragdrop/secret.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Custom MIME type implementation example +** +** 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. +** +*****************************************************************************/ + +#include "secret.h" +#include <qevent.h> + + +//create the object withe the secret byte +SecretDrag::SecretDrag( uchar secret, TQWidget * parent, const char * name ) + : TQStoredDrag( "secret/magic", parent, name ) +{ + TQByteArray data(1); + data[0]= secret; + setEncodedData( data ); +} + + +bool SecretDrag::canDecode( TQDragMoveEvent* e ) +{ + return e->provides( "secret/magic" ); +} + +//decode it into a string +bool SecretDrag::decode( TQDropEvent* e, TQString& str ) +{ + TQByteArray payload = e->data( "secret/magic" ); + if ( payload.size() ) { + e->accept(); + TQString msg; + msg.sprintf("The secret number is %d", payload[0] ); + str = msg; + return TRUE; + } + return FALSE; +} + + +SecretSource::SecretSource( int secret, TQWidget *parent, const char * name ) + : TQLabel( "Secret", parent, name ) +{ + setBackgroundColor( blue.light() ); + setFrameStyle( Box | Sunken ); + setMinimumHeight( sizeHint().height()*2 ); + setAlignment( AlignCenter ); + mySecret = secret; +} + +SecretSource::~SecretSource() +{ +} + +/* XPM */ +static const char * picture_xpm[] = { +"16 16 3 1", +" c None", +". c #000000", +"X c #FFFF00", +" ..... ", +" ..XXXXX.. ", +" .XXXXXXXXX. ", +" .XXXXXXXXXXX. ", +" .XX..XXX..XX. ", +".XXXXXXXXXXXXX. ", +".XX...XXX...XX. ", +".XXX..XXX..XXX. ", +".XXXXXXXXXXXXX. ", +".XXXXXX.XXXXXX. ", +" .XX.XX.XX.XX. ", +" .XXX..X..XXX. ", +" .XXXXXXXXX. ", +" ..XXXXX.. ", +" ..... ", +" "}; + +void SecretSource::mousePressEvent( TQMouseEvent * /*e*/ ) +{ + SecretDrag *sd = new SecretDrag( mySecret, this ); + sd->setPixmap(TQPixmap(picture_xpm),TQPoint(8,8)); + sd->dragCopy(); + mySecret++; +} diff --git a/examples/dragdrop/secret.h b/examples/dragdrop/secret.h new file mode 100644 index 000000000..5b027db81 --- /dev/null +++ b/examples/dragdrop/secret.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Custom MIME type implementation example +** +** 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 SECRETDRAG_H +#define SECRETDRAG_H + +#include <qdragobject.h> +#include <qlabel.h> + +class SecretDrag: public TQStoredDrag { +public: + SecretDrag( uchar, TQWidget * parent = 0, const char * name = 0 ); + ~SecretDrag() {}; + + static bool canDecode( TQDragMoveEvent* e ); + static bool decode( TQDropEvent* e, TQString& s ); +}; + + +class SecretSource: public TQLabel +{ +public: + SecretSource( int secret, TQWidget *parent = 0, const char * name = 0 ); + ~SecretSource(); + +protected: + void mousePressEvent( TQMouseEvent * ); +private: + int mySecret; +}; + +#endif diff --git a/examples/dragdrop/trolltech.bmp b/examples/dragdrop/trolltech.bmp Binary files differnew file mode 100644 index 000000000..220861e2e --- /dev/null +++ b/examples/dragdrop/trolltech.bmp diff --git a/examples/dragdrop/trolltech.gif b/examples/dragdrop/trolltech.gif Binary files differnew file mode 100644 index 000000000..f674369ef --- /dev/null +++ b/examples/dragdrop/trolltech.gif |