summaryrefslogtreecommitdiffstats
path: root/examples/iconview/simple_dd
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-07-10 15:24:15 -0500
committerTimothy Pearson <[email protected]>2011-07-10 15:24:15 -0500
commitbd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch)
tree7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/iconview/simple_dd
downloadqt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz
qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip
Add Qt3 development HEAD version
Diffstat (limited to 'examples/iconview/simple_dd')
-rw-r--r--examples/iconview/simple_dd/main.cpp187
-rw-r--r--examples/iconview/simple_dd/main.h60
-rw-r--r--examples/iconview/simple_dd/simple_dd.doc29
-rw-r--r--examples/iconview/simple_dd/simple_dd.pro10
4 files changed, 286 insertions, 0 deletions
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
+
+