summaryrefslogtreecommitdiffstats
path: root/examples/iconview
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/iconview
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/iconview')
-rw-r--r--examples/iconview/iconview.doc16
-rw-r--r--examples/iconview/iconview.pro10
-rw-r--r--examples/iconview/main.cpp75
-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
7 files changed, 387 insertions, 0 deletions
diff --git a/examples/iconview/iconview.doc b/examples/iconview/iconview.doc
new file mode 100644
index 00000000..5ef16a48
--- /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 00000000..1d38eecf
--- /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 00000000..18daafd0
--- /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 TQt. 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 TQObject
+{
+ Q_OBJECT
+
+public:
+ ListenDND( TQWidget *w )
+ : view( w )
+ {}
+
+public slots:
+ void dropped( TQDropEvent *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:
+ TQWidget *view;
+
+};
+
+int main( int argc, char **argv )
+{
+ TQApplication a( argc, argv );
+
+ TQIconView qiconview;
+ qiconview.setSelectionMode( TQIconView::Extended );
+
+ for ( unsigned int i = 0; i < 3000; i++ ) {
+ TQIconViewItem *item = new TQIconViewItem( &qiconview, TQString( "Item %1" ).arg( i + 1 ) );
+ item->setRenameEnabled( TRUE );
+ }
+
+ qiconview.setCaption( "TQt Example - Iconview" );
+
+ ListenDND listen_dnd( &qiconview );
+ TQObject::connect( &qiconview, SIGNAL( dropped( TQDropEvent *, const TQValueList<TQIconDragItem> & ) ),
+ &listen_dnd, SLOT( dropped( TQDropEvent * ) ) );
+ TQObject::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 00000000..3093e89a
--- /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 TQt. 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( TQWidget * parent, const char * name, WFlags f ) :
+ TQListBox( parent, name, f )
+{
+ setAcceptDrops( TRUE );
+ dragging = FALSE;
+}
+
+
+void DDListBox::dragEnterEvent( TQDragEnterEvent *evt )
+{
+ if ( TQTextDrag::canDecode( evt ) )
+ evt->accept();
+}
+
+
+void DDListBox::dropEvent( TQDropEvent *evt )
+{
+ TQString text;
+
+ if ( TQTextDrag::decode( evt, text ) )
+ insertItem( text );
+}
+
+
+void DDListBox::mousePressEvent( TQMouseEvent *evt )
+{
+ TQListBox::mousePressEvent( evt );
+ dragging = TRUE;
+}
+
+
+void DDListBox::mouseMoveEvent( TQMouseEvent * )
+{
+ if ( dragging ) {
+ TQDragObject *d = new TQTextDrag( currentText(), this );
+ d->dragCopy(); // do NOT delete d.
+ dragging = FALSE;
+ }
+}
+
+
+// IconViewIcon -- high level drag and drop
+
+
+bool DDIconViewItem::acceptDrop( const TQMimeSource *mime ) const
+{
+ if ( mime->provides( "text/plain" ) )
+ return TRUE;
+ return FALSE;
+}
+
+
+void DDIconViewItem::dropped( TQDropEvent *evt, const TQValueList<TQIconDragItem>& )
+{
+ TQString label;
+
+ if ( TQTextDrag::decode( evt, label ) )
+ setText( label );
+}
+
+
+// IconView -- high level drag and drop
+
+TQDragObject *DDIconView::dragObject()
+{
+ return new TQTextDrag( currentItem()->text(), this );
+}
+
+void DDIconView::slotNewItem( TQDropEvent *evt, const TQValueList<TQIconDragItem>& )
+{
+ TQString label;
+
+ if ( TQTextDrag::decode( evt, label ) ) {
+ DDIconViewItem *item = new DDIconViewItem( this, label );
+ item->setRenameEnabled( TRUE );
+ }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+ TQApplication app( argc, argv );
+
+ // Create and show the widgets
+ TQSplitter *split = new TQSplitter();
+ 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
+ TQObject::connect(
+ iv, SIGNAL(dropped(TQDropEvent*, const TQValueList<TQIconDragItem>&)),
+ iv, SLOT(slotNewItem(TQDropEvent*, const TQValueList<TQIconDragItem>&)));
+
+ // Populate the TQIconView with icons
+ DDIconViewItem *item;
+ item = new DDIconViewItem( iv, "Red", TQPixmap( red_icon ) );
+ item->setRenameEnabled( TRUE );
+ item = new DDIconViewItem( iv, "Green", TQPixmap( green_icon ) );
+ item->setRenameEnabled( TRUE );
+ item = new DDIconViewItem( iv, "Blue", TQPixmap( 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 00000000..062d47f7
--- /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 TQt. 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 TQDragEnterEvent;
+class TQDragDropEvent;
+
+
+class DDListBox : public TQListBox
+{
+ Q_OBJECT
+public:
+ DDListBox( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 );
+ // Low-level drag and drop
+ void dragEnterEvent( TQDragEnterEvent *evt );
+ void dropEvent( TQDropEvent *evt );
+ void mousePressEvent( TQMouseEvent *evt );
+ void mouseMoveEvent( TQMouseEvent * );
+private:
+ int dragging;
+};
+
+
+class DDIconViewItem : public TQIconViewItem
+{
+public:
+ DDIconViewItem( TQIconView *parent, const TQString& text, const TQPixmap& icon ) :
+ TQIconViewItem( parent, text, icon ) {}
+ DDIconViewItem( TQIconView *parent, const TQString &text ) :
+ TQIconViewItem( parent, text ) {}
+ // High-level drag and drop
+ bool acceptDrop( const TQMimeSource *mime ) const;
+ void dropped( TQDropEvent *evt, const TQValueList<TQIconDragItem>& );
+};
+
+
+class DDIconView : public TQIconView
+{
+ Q_OBJECT
+public:
+ DDIconView( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 ) :
+ TQIconView( parent, name, f ) {}
+ // High-level drag and drop
+ TQDragObject *dragObject();
+public slots:
+ void slotNewItem( TQDropEvent *evt, const TQValueList<TQIconDragItem>& list );
+};
+
diff --git a/examples/iconview/simple_dd/simple_dd.doc b/examples/iconview/simple_dd/simple_dd.doc
new file mode 100644
index 00000000..25705936
--- /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 00000000..5ccef9c6
--- /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
+
+