1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/iconview/qiconview.cpp:2258 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>iconview/simple_dd/main.cpp Example File</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>iconview/simple_dd/main.cpp Example File</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <pre>/****************************************************************************
|
---|
36 | ** $Id: iconview-simple_dd-main-cpp.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
37 | **
|
---|
38 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
39 | **
|
---|
40 | ** This file is part of an example program for Qt. This example
|
---|
41 | ** program may be used, distributed and modified without limitation.
|
---|
42 | **
|
---|
43 | *****************************************************************************/
|
---|
44 |
|
---|
45 | #include "main.h"
|
---|
46 |
|
---|
47 | const char* red_icon[]={
|
---|
48 | "16 16 2 1",
|
---|
49 | "r c red",
|
---|
50 | ". c None",
|
---|
51 | "................",
|
---|
52 | "................",
|
---|
53 | "..rrrrrrrrrrrr..",
|
---|
54 | "..rrrrrrrrrrrr..",
|
---|
55 | "..rrrrrrrrrrrr..",
|
---|
56 | "..rrr......rrr..",
|
---|
57 | "..rrr......rrr..",
|
---|
58 | "..rrr......rrr..",
|
---|
59 | "..rrr......rrr..",
|
---|
60 | "..rrr......rrr..",
|
---|
61 | "..rrr......rrr..",
|
---|
62 | "..rrrrrrrrrrrr..",
|
---|
63 | "..rrrrrrrrrrrr..",
|
---|
64 | "..rrrrrrrrrrrr..",
|
---|
65 | "................",
|
---|
66 | "................"};
|
---|
67 |
|
---|
68 | const char* blue_icon[]={
|
---|
69 | "16 16 2 1",
|
---|
70 | "b c blue",
|
---|
71 | ". c None",
|
---|
72 | "................",
|
---|
73 | "................",
|
---|
74 | "..bbbbbbbbbbbb..",
|
---|
75 | "..bbbbbbbbbbbb..",
|
---|
76 | "..bbbbbbbbbbbb..",
|
---|
77 | "..bbb......bbb..",
|
---|
78 | "..bbb......bbb..",
|
---|
79 | "..bbb......bbb..",
|
---|
80 | "..bbb......bbb..",
|
---|
81 | "..bbb......bbb..",
|
---|
82 | "..bbb......bbb..",
|
---|
83 | "..bbbbbbbbbbbb..",
|
---|
84 | "..bbbbbbbbbbbb..",
|
---|
85 | "..bbbbbbbbbbbb..",
|
---|
86 | "................",
|
---|
87 | "................"};
|
---|
88 |
|
---|
89 | const char* green_icon[]={
|
---|
90 | "16 16 2 1",
|
---|
91 | "g c green",
|
---|
92 | ". c None",
|
---|
93 | "................",
|
---|
94 | "................",
|
---|
95 | "..gggggggggggg..",
|
---|
96 | "..gggggggggggg..",
|
---|
97 | "..gggggggggggg..",
|
---|
98 | "..ggg......ggg..",
|
---|
99 | "..ggg......ggg..",
|
---|
100 | "..ggg......ggg..",
|
---|
101 | "..ggg......ggg..",
|
---|
102 | "..ggg......ggg..",
|
---|
103 | "..ggg......ggg..",
|
---|
104 | "..gggggggggggg..",
|
---|
105 | "..gggggggggggg..",
|
---|
106 | "..gggggggggggg..",
|
---|
107 | "................",
|
---|
108 | "................"};
|
---|
109 |
|
---|
110 |
|
---|
111 | // ListBox -- low level drag and drop
|
---|
112 |
|
---|
113 | <a name="f2"></a>DDListBox::DDListBox( <a href="qwidget.html">QWidget</a> * parent, const char * name, WFlags f ) :
|
---|
114 | <a href="qlistbox.html">QListBox</a>( parent, name, f )
|
---|
115 | {
|
---|
116 | <a href="qwidget.html#setAcceptDrops">setAcceptDrops</a>( TRUE );
|
---|
117 | dragging = FALSE;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | <a name="x2829"></a>void DDListBox::<a href="qwidget.html#dragEnterEvent">dragEnterEvent</a>( <a href="qdragenterevent.html">QDragEnterEvent</a> *evt )
|
---|
122 | {
|
---|
123 | <a name="x2827"></a> if ( QTextDrag::<a href="qtextdrag.html#canDecode">canDecode</a>( evt ) )
|
---|
124 | <a name="x2819"></a> evt-><a href="qdragmoveevent.html#accept">accept</a>();
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | <a name="x2830"></a>void DDListBox::<a href="qwidget.html#dropEvent">dropEvent</a>( <a href="qdropevent.html">QDropEvent</a> *evt )
|
---|
129 | {
|
---|
130 | <a href="qstring.html">QString</a> text;
|
---|
131 |
|
---|
132 | <a name="x2828"></a> if ( QTextDrag::<a href="qtextdrag.html#decode">decode</a>( evt, text ) )
|
---|
133 | <a href="qlistbox.html#insertItem">insertItem</a>( text );
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | <a name="x2832"></a>void DDListBox::<a href="qwidget.html#mousePressEvent">mousePressEvent</a>( <a href="qmouseevent.html">QMouseEvent</a> *evt )
|
---|
138 | {
|
---|
139 | QListBox::<a href="qwidget.html#mousePressEvent">mousePressEvent</a>( evt );
|
---|
140 | dragging = TRUE;
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | <a name="x2831"></a>void DDListBox::<a href="qwidget.html#mouseMoveEvent">mouseMoveEvent</a>( <a href="qmouseevent.html">QMouseEvent</a> * )
|
---|
145 | {
|
---|
146 | if ( dragging ) {
|
---|
147 | <a href="qdragobject.html">QDragObject</a> *d = new <a href="qtextdrag.html">QTextDrag</a>( currentText(), this );
|
---|
148 | <a name="x2818"></a> d-><a href="qdragobject.html#dragCopy">dragCopy</a>(); // do NOT delete d.
|
---|
149 | dragging = FALSE;
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | // IconViewIcon -- high level drag and drop
|
---|
155 |
|
---|
156 |
|
---|
157 | <a name="x2822"></a>bool DDIconViewItem::<a href="qiconviewitem.html#acceptDrop">acceptDrop</a>( const <a href="qmimesource.html">QMimeSource</a> *mime ) const
|
---|
158 | {
|
---|
159 | <a name="x2825"></a> if ( mime-><a href="qmimesource.html#provides">provides</a>( "text/plain" ) )
|
---|
160 | return TRUE;
|
---|
161 | return FALSE;
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | <a name="x2823"></a>void DDIconViewItem::<a href="qiconviewitem.html#dropped">dropped</a>( <a href="qdropevent.html">QDropEvent</a> *evt, const <a href="qvaluelist.html">QValueList</a><QIconDragItem>& )
|
---|
166 | {
|
---|
167 | <a href="qstring.html">QString</a> label;
|
---|
168 |
|
---|
169 | if ( QTextDrag::<a href="qtextdrag.html#decode">decode</a>( evt, label ) )
|
---|
170 | setText( label );
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | // IconView -- high level drag and drop
|
---|
175 |
|
---|
176 | <a name="x2820"></a>QDragObject *DDIconView::<a href="qiconview.html#dragObject">dragObject</a>()
|
---|
177 | {
|
---|
178 | return new <a href="qtextdrag.html">QTextDrag</a>( <a href="qiconview.html#currentItem">currentItem</a>()->text(), this );
|
---|
179 | }
|
---|
180 |
|
---|
181 | void <a name="f1"></a>DDIconView::slotNewItem( <a href="qdropevent.html">QDropEvent</a> *evt, const <a href="qvaluelist.html">QValueList</a><QIconDragItem>& )
|
---|
182 | {
|
---|
183 | <a href="qstring.html">QString</a> label;
|
---|
184 |
|
---|
185 | if ( QTextDrag::<a href="qtextdrag.html#decode">decode</a>( evt, label ) ) {
|
---|
186 | DDIconViewItem *item = new DDIconViewItem( this, label );
|
---|
187 | <a name="x2824"></a> item-><a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( TRUE );
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 | int main( int argc, char *argv[] )
|
---|
194 | {
|
---|
195 | <a href="qapplication.html">QApplication</a> app( argc, argv );
|
---|
196 |
|
---|
197 | // Create and show the widgets
|
---|
198 | <a href="qsplitter.html">QSplitter</a> *split = new <a href="qsplitter.html">QSplitter</a>();
|
---|
199 | DDIconView *iv = new DDIconView( split );
|
---|
200 | (void) new DDListBox( split );
|
---|
201 | app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( split );
|
---|
202 | split-><a href="qwidget.html#resize">resize</a>( 600, 400 );
|
---|
203 | split-><a href="qwidget.html#show">show</a>();
|
---|
204 |
|
---|
205 | // Set up the connection so that we can drop items into the icon view
|
---|
206 | QObject::<a href="qobject.html#connect">connect</a>(
|
---|
207 | <a name="x2821"></a> iv, SIGNAL(<a href="qiconview.html#dropped">dropped</a>(QDropEvent*, const <a href="qvaluelist.html">QValueList</a><QIconDragItem>&)),
|
---|
208 | iv, SLOT(slotNewItem(QDropEvent*, const <a href="qvaluelist.html">QValueList</a><QIconDragItem>&)));
|
---|
209 |
|
---|
210 | // Populate the QIconView with icons
|
---|
211 | DDIconViewItem *item;
|
---|
212 | item = new DDIconViewItem( iv, "Red", QPixmap( red_icon ) );
|
---|
213 | item-><a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( TRUE );
|
---|
214 | item = new DDIconViewItem( iv, "Green", QPixmap( green_icon ) );
|
---|
215 | item-><a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( TRUE );
|
---|
216 | item = new DDIconViewItem( iv, "Blue", QPixmap( blue_icon ) );
|
---|
217 | item-><a href="qiconviewitem.html#setRenameEnabled">setRenameEnabled</a>( TRUE );
|
---|
218 |
|
---|
219 | return app.<a href="qapplication.html#exec">exec</a>();
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | </pre><!-- eof -->
|
---|
224 | <p><address><hr><div align=center>
|
---|
225 | <table width=100% cellspacing=0 border=0><tr>
|
---|
226 | <td>Copyright © 2007
|
---|
227 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
228 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
229 | </table></div></address></body>
|
---|
230 | </html>
|
---|