diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/iconview | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/iconview')
-rw-r--r-- | examples/iconview/iconview.doc | 16 | ||||
-rw-r--r-- | examples/iconview/iconview.pro | 10 | ||||
-rw-r--r-- | examples/iconview/main.cpp | 75 | ||||
-rw-r--r-- | examples/iconview/simple_dd/main.cpp | 187 | ||||
-rw-r--r-- | examples/iconview/simple_dd/main.h | 60 | ||||
-rw-r--r-- | examples/iconview/simple_dd/simple_dd.doc | 29 | ||||
-rw-r--r-- | examples/iconview/simple_dd/simple_dd.pro | 10 |
7 files changed, 387 insertions, 0 deletions
diff --git a/examples/iconview/iconview.doc b/examples/iconview/iconview.doc new file mode 100644 index 0000000..5ef16a4 --- /dev/null +++ b/examples/iconview/iconview.doc @@ -0,0 +1,16 @@ +/* +*/ +/*! \page iconview-example.html + + \ingroup examples + \title Iconview + + This example implements a flexible icon view which can store + lots of icon items. It supports Drag&Drop, different selection modes, + view modes, rubberband selection, etc. + + Main: + + \include iconview/main.cpp +*/ + diff --git a/examples/iconview/iconview.pro b/examples/iconview/iconview.pro new file mode 100644 index 0000000..1d38eec --- /dev/null +++ b/examples/iconview/iconview.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = iconview + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = iconview full-config + +HEADERS = +SOURCES = main.cpp diff --git a/examples/iconview/main.cpp b/examples/iconview/main.cpp new file mode 100644 index 0000000..8784e93 --- /dev/null +++ b/examples/iconview/main.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qiconview.h> +#include <qapplication.h> +#include <qdragobject.h> +#include <qpixmap.h> +#include <qiconset.h> + +#include <qmime.h> +#include <stdio.h> + +class ListenDND : public QObject +{ + Q_OBJECT + +public: + ListenDND( QWidget *w ) + : view( w ) + {} + +public slots: + void dropped( QDropEvent *mime ) { + qDebug( "Dropped Mimesource %p into the view %p", mime, view ); + qDebug( " Formats:" ); + int i = 0; + const char *str = mime->format( i ); + qDebug( " %s", str ); + while ( str ) { + qDebug( " %s", str ); + str = mime->format( ++i ); + } + }; + void moved() { + qDebug( "All selected items were moved to another widget" ); + } + +protected: + QWidget *view; + +}; + +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); + + QIconView qiconview; + qiconview.setSelectionMode( QIconView::Extended ); + + for ( unsigned int i = 0; i < 3000; i++ ) { + QIconViewItem *item = new QIconViewItem( &qiconview, QString( "Item %1" ).arg( i + 1 ) ); + item->setRenameEnabled( TRUE ); + } + + qiconview.setCaption( "Qt Example - Iconview" ); + + ListenDND listen_dnd( &qiconview ); + QObject::connect( &qiconview, SIGNAL( dropped( QDropEvent *, const QValueList<QIconDragItem> & ) ), + &listen_dnd, SLOT( dropped( QDropEvent * ) ) ); + QObject::connect( &qiconview, SIGNAL( moved() ), &listen_dnd, SLOT( moved() ) ); + + a.setMainWidget( &qiconview ); + qiconview.show(); + qiconview.resize( qiconview.sizeHint() ); + + return a.exec(); +} + +#include "main.moc" diff --git a/examples/iconview/simple_dd/main.cpp b/examples/iconview/simple_dd/main.cpp new file mode 100644 index 0000000..7435818 --- /dev/null +++ b/examples/iconview/simple_dd/main.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "main.h" + +const char* red_icon[]={ +"16 16 2 1", +"r c red", +". c None", +"................", +"................", +"..rrrrrrrrrrrr..", +"..rrrrrrrrrrrr..", +"..rrrrrrrrrrrr..", +"..rrr......rrr..", +"..rrr......rrr..", +"..rrr......rrr..", +"..rrr......rrr..", +"..rrr......rrr..", +"..rrr......rrr..", +"..rrrrrrrrrrrr..", +"..rrrrrrrrrrrr..", +"..rrrrrrrrrrrr..", +"................", +"................"}; + +const char* blue_icon[]={ +"16 16 2 1", +"b c blue", +". c None", +"................", +"................", +"..bbbbbbbbbbbb..", +"..bbbbbbbbbbbb..", +"..bbbbbbbbbbbb..", +"..bbb......bbb..", +"..bbb......bbb..", +"..bbb......bbb..", +"..bbb......bbb..", +"..bbb......bbb..", +"..bbb......bbb..", +"..bbbbbbbbbbbb..", +"..bbbbbbbbbbbb..", +"..bbbbbbbbbbbb..", +"................", +"................"}; + +const char* green_icon[]={ +"16 16 2 1", +"g c green", +". c None", +"................", +"................", +"..gggggggggggg..", +"..gggggggggggg..", +"..gggggggggggg..", +"..ggg......ggg..", +"..ggg......ggg..", +"..ggg......ggg..", +"..ggg......ggg..", +"..ggg......ggg..", +"..ggg......ggg..", +"..gggggggggggg..", +"..gggggggggggg..", +"..gggggggggggg..", +"................", +"................"}; + + +// ListBox -- low level drag and drop + +DDListBox::DDListBox( QWidget * parent, const char * name, WFlags f ) : + QListBox( parent, name, f ) +{ + setAcceptDrops( TRUE ); + dragging = FALSE; +} + + +void DDListBox::dragEnterEvent( QDragEnterEvent *evt ) +{ + if ( QTextDrag::canDecode( evt ) ) + evt->accept(); +} + + +void DDListBox::dropEvent( QDropEvent *evt ) +{ + QString text; + + if ( QTextDrag::decode( evt, text ) ) + insertItem( text ); +} + + +void DDListBox::mousePressEvent( QMouseEvent *evt ) +{ + QListBox::mousePressEvent( evt ); + dragging = TRUE; +} + + +void DDListBox::mouseMoveEvent( QMouseEvent * ) +{ + if ( dragging ) { + QDragObject *d = new QTextDrag( currentText(), this ); + d->dragCopy(); // do NOT delete d. + dragging = FALSE; + } +} + + +// IconViewIcon -- high level drag and drop + + +bool DDIconViewItem::acceptDrop( const QMimeSource *mime ) const +{ + if ( mime->provides( "text/plain" ) ) + return TRUE; + return FALSE; +} + + +void DDIconViewItem::dropped( QDropEvent *evt, const QValueList<QIconDragItem>& ) +{ + QString label; + + if ( QTextDrag::decode( evt, label ) ) + setText( label ); +} + + +// IconView -- high level drag and drop + +QDragObject *DDIconView::dragObject() +{ + return new QTextDrag( currentItem()->text(), this ); +} + +void DDIconView::slotNewItem( QDropEvent *evt, const QValueList<QIconDragItem>& ) +{ + QString label; + + if ( QTextDrag::decode( evt, label ) ) { + DDIconViewItem *item = new DDIconViewItem( this, label ); + item->setRenameEnabled( TRUE ); + } +} + + + +int main( int argc, char *argv[] ) +{ + QApplication app( argc, argv ); + + // Create and show the widgets + QSplitter *split = new QSplitter(); + DDIconView *iv = new DDIconView( split ); + (void) new DDListBox( split ); + app.setMainWidget( split ); + split->resize( 600, 400 ); + split->show(); + + // Set up the connection so that we can drop items into the icon view + QObject::connect( + iv, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), + iv, SLOT(slotNewItem(QDropEvent*, const QValueList<QIconDragItem>&))); + + // Populate the QIconView with icons + DDIconViewItem *item; + item = new DDIconViewItem( iv, "Red", QPixmap( red_icon ) ); + item->setRenameEnabled( TRUE ); + item = new DDIconViewItem( iv, "Green", QPixmap( green_icon ) ); + item->setRenameEnabled( TRUE ); + item = new DDIconViewItem( iv, "Blue", QPixmap( blue_icon ) ); + item->setRenameEnabled( TRUE ); + + return app.exec(); +} + + diff --git a/examples/iconview/simple_dd/main.h b/examples/iconview/simple_dd/main.h new file mode 100644 index 0000000..38a4685 --- /dev/null +++ b/examples/iconview/simple_dd/main.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qapplication.h> +#include <qcursor.h> +#include <qsplitter.h> +#include <qlistbox.h> +#include <qiconview.h> +#include <qpixmap.h> + +class QDragEnterEvent; +class QDragDropEvent; + + +class DDListBox : public QListBox +{ + Q_OBJECT +public: + DDListBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + // Low-level drag and drop + void dragEnterEvent( QDragEnterEvent *evt ); + void dropEvent( QDropEvent *evt ); + void mousePressEvent( QMouseEvent *evt ); + void mouseMoveEvent( QMouseEvent * ); +private: + int dragging; +}; + + +class DDIconViewItem : public QIconViewItem +{ +public: + DDIconViewItem( QIconView *parent, const QString& text, const QPixmap& icon ) : + QIconViewItem( parent, text, icon ) {} + DDIconViewItem( QIconView *parent, const QString &text ) : + QIconViewItem( parent, text ) {} + // High-level drag and drop + bool acceptDrop( const QMimeSource *mime ) const; + void dropped( QDropEvent *evt, const QValueList<QIconDragItem>& ); +}; + + +class DDIconView : public QIconView +{ + Q_OBJECT +public: + DDIconView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : + QIconView( parent, name, f ) {} + // High-level drag and drop + QDragObject *dragObject(); +public slots: + void slotNewItem( QDropEvent *evt, const QValueList<QIconDragItem>& list ); +}; + diff --git a/examples/iconview/simple_dd/simple_dd.doc b/examples/iconview/simple_dd/simple_dd.doc new file mode 100644 index 0000000..2570593 --- /dev/null +++ b/examples/iconview/simple_dd/simple_dd.doc @@ -0,0 +1,29 @@ +/*! \page simple_dd-example.html + + \ingroup examples + \title Drag and Drop (Simple) + + This provides a very simple example of Qt's drag and drop + functionality. + + For a more complete example see the \link dragdrop-example.html + Drag and Drop example\endlink. + + + <hr> + + Header file: + + \include iconview/simple_dd/main.h + + <hr> + + Implementation: + + \include iconview/simple_dd/main.cpp + +*/ + + + + diff --git a/examples/iconview/simple_dd/simple_dd.pro b/examples/iconview/simple_dd/simple_dd.pro new file mode 100644 index 0000000..5ccef9c --- /dev/null +++ b/examples/iconview/simple_dd/simple_dd.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +CONFIG += qt warn_on release + +REQUIRES = full-config + +HEADERS = main.h +SOURCES = main.cpp + + |