fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kde3support / tests / kdockwidgetdemo.cpp
blobeb9fa7127294c22430f42dcf388b269d34f6849e
1 #include "kdockwidgetdemo.h"
3 #include <Qt3Support/Q3Header>
4 #include <QtGui/QToolButton>
6 #include <Qt3Support/Q3TextView>
7 #include <QtCore/QFileInfo>
8 #include <QtCore/QFile>
9 #include <QtCore/QTextStream>
10 #include <QtGui/QLabel>
11 #include <Qt3Support/Q3MultiLineEdit>
12 #include <QtGui/QKeyEvent>
13 #include <Qt3Support/Q3PopupMenu>
14 #include <QtGui/QPushButton>
15 #include <QtCore/QPoint>
16 #include <QtGui/QMessageBox>
17 #include <QtGui/QMacMime>
18 #include <Qt3Support/Q3StrList>
19 #include <QtGui/QPainter>
20 //Added by qt3to4:
21 #include <QtGui/QPixmap>
23 #include <kconfiggroup.h>
24 #include <kaboutdata.h>
25 #include <kcmdlineargs.h>
26 #include <kapplication.h>
27 //#include <kimgio.h>
28 #include <stdlib.h>
30 static const char *dir_tree_xpm[] = {
31 "16 16 8 1",
32 " c Gray0",
33 ". c #000080",
34 "X c Cyan",
35 "o c #808000",
36 "O c Yellow",
37 "+ c #808080",
38 "@ c None",
39 "# c #c1c1c1",
40 "@@@@@@@@@@@@@@@@",
41 "@@@+++++@@@@@@@@",
42 "@@+@O@O@+@@@@@@@",
43 "@+@O@O@O@++++++@",
44 "@+@@@@@@@@@@@@o ",
45 "@+@O@++ +O@O@Oo ",
46 "@+@@+@X@ +O@O@o ",
47 "@+@+@X@X@ +O@Oo ",
48 "@+@+X@X@X o@O@o ",
49 "@+@+@X@X@ oO@Oo ",
50 "@+@@+@X@ +ooO@o ",
51 "@+@O@+ +@..oOo ",
52 "@+ooooooo.X..oo ",
53 "@@ .X.. @",
54 "@@@@@@@@@@@.X.. ",
55 "@@@@@@@@@@@@.X. "
58 static const char *preview_xpm[] = {
59 "16 16 6 1",
60 " c Gray0",
61 ". c #000080",
62 "X c Yellow",
63 "o c #808080",
64 "O c None",
65 "+ c Gray100",
66 "OOOOOOOOOOOOOOOO",
67 "OOo oOOOOOOO",
68 "Oo oooo OOOOOO",
69 "O OOOOoo oOOOOO",
70 "O OOOO++oo OOOOO",
71 "O OOOO++Oo OOOOO",
72 "O O+OOOOOo OOOOO",
73 "O OO+OOOOo OOOOO",
74 "OooOO+OOo OOOOO",
75 "OO oOOOo + OOOO",
76 "OOOo .X+ OOO",
77 "OOOOOOOOO .X+ OO",
78 "OOOOOOOOOO .X+ O",
79 "OOOOOOOOOOO .X O",
80 "OOOOOOOOOOOO OO",
81 "OOOOOOOOOOOOOOOO"
84 SFileDialog::SFileDialog( QString initially, const QStringList& filter, const char* name )
85 :QDialog(0L)
87 setObjectName(name);
88 setModal(true);
89 KConfigGroup config( KGlobal::config(), QLatin1String("SFileDialogData:") + name );
90 if ( initially.isNull() ){
91 initially = config.readPathEntry( "InitiallyDir", QDir::currentPath() );
94 QStringList bookmark;
95 bookmark = config.readEntry( "Bookmarks",QStringList() );
97 dockManager = new K3DockManager(this);
99 d_dirView = new K3DockWidget( dockManager, "Dock_DirView", QPixmap(dir_tree_xpm) );
100 d_dirView->setWindowTitle("Tree");
102 dirView = new DirectoryView( d_dirView, 0 );
103 dirView->addColumn( "" );
104 dirView->header()->hide();
105 d_dirView->setWidget( dirView );
107 Directory* root = new Directory( dirView, "/" );
108 root->setOpen(true);
110 d_preview = new K3DockWidget( dockManager, "Dock_Preview", QPixmap(preview_xpm) );
111 d_preview->setWindowTitle("Preview");
112 preview = new Preview( d_preview );
113 d_preview->setWidget( preview );
115 d_fd = new K3DockWidget( dockManager, "Dock_QFileDialog", QPixmap(), this );
116 fd = new CustomFileDialog( d_fd );
117 fd->setDir( initially );
118 fd->setFilters( filter );
119 fd->setBookmark( bookmark );
120 fd->setParent( d_fd );
121 d_fd->setWidget( fd );
123 connect( dirView, SIGNAL( folderSelected( const QString & ) ), fd, SLOT( setDir2( const QString & ) ) );
124 connect( fd, SIGNAL( dirEntered( const QString & ) ), dirView, SLOT( setDir( const QString & ) ) );
126 d_fd->setDockSite( K3DockWidget::DockTop|K3DockWidget::DockLeft|K3DockWidget::DockRight|K3DockWidget::DockBottom );
127 d_fd->setEnableDocking(K3DockWidget::DockNone);
129 d_dirView->setEnableDocking(K3DockWidget::DockTop|K3DockWidget::DockLeft|K3DockWidget::DockRight|K3DockWidget::DockBottom|K3DockWidget::DockCenter);
130 d_preview->setEnableDocking(K3DockWidget::DockTop|K3DockWidget::DockLeft|K3DockWidget::DockRight|K3DockWidget::DockBottom|K3DockWidget::DockCenter);
132 d_dirView->manualDock( d_fd, K3DockWidget::DockLeft, 20 );
133 d_preview->manualDock( d_fd, K3DockWidget::DockBottom, 70 );
135 connect(fd, SIGNAL(fileHighlighted(const QString&)), preview, SLOT(showPreview(const QString&)));
136 connect(fd, SIGNAL(signalDone(int)), this, SLOT(done(int)));
138 connect(fd, SIGNAL(dirEntered(const QString&)), this, SLOT(changeDir(const QString&)));
139 connect(dirView, SIGNAL(folderSelected(const QString&)), this, SLOT(changeDir(const QString&)));
141 b_tree = new QToolButton( fd );
142 b_tree->setToolTip( "Show/Hide Tree" );
143 b_tree->setIcon( QIcon( QPixmap( dir_tree_xpm ) ) );
144 connect( b_tree, SIGNAL(clicked()), d_dirView, SLOT(changeHideShowState()) );
145 b_tree->setCheckable(true);
146 b_tree->setChecked(true);
147 fd->addToolButton( b_tree, true );
149 b_preview = new QToolButton( fd );
150 b_preview->setToolTip( "Show/Hide Preview" );
151 b_preview->setIcon( QIcon( QPixmap( preview_xpm ) ) );
152 connect( b_preview, SIGNAL(clicked()), d_preview, SLOT(changeHideShowState()) );
153 b_preview->setCheckable(true);
154 b_preview->setChecked(true);
155 fd->addToolButton( b_preview );
157 connect( dockManager, SIGNAL(change()), this, SLOT(dockChange()));
158 connect( dockManager, SIGNAL(setDockDefaultPos(K3DockWidget*)), this, SLOT(setDockDefaultPos(K3DockWidget*)));
159 setWindowTitle("Open File");
160 resize(550,450);
161 qDebug("read config");
162 dockManager->readConfig( 0L , name );
165 void SFileDialog::dockChange()
167 b_preview->setChecked( d_preview->isVisible() );
168 b_tree->setChecked( d_dirView->isVisible() );
171 SFileDialog::~SFileDialog()
173 KConfigGroup config(KGlobal::config(), QString("SFileDialogData:") + objectName() );
174 config.writeEntry( "Bookmarks", fd->getBookmark() );
176 qDebug("write config");
177 dockManager->writeConfig( 0L , objectName() );
180 void SFileDialog::setDockDefaultPos( K3DockWidget* d )
182 if ( d == d_dirView ){
183 d_dirView->manualDock( d_fd, K3DockWidget::DockLeft, 20 );
186 if ( d == d_preview ){
187 d_preview->manualDock( d_fd, K3DockWidget::DockBottom, 70 );
191 void SFileDialog::changeDir( const QString& f )
193 if ( !f.isEmpty() ){
194 KConfigGroup config( KGlobal::config(), QString("SFileDialogData:") + objectName() );
195 config.writePathEntry( "InitiallyDir", f );
199 QString SFileDialog::getOpenFileName( QString initially,
200 const QStringList& filter,
201 const QString caption, const char* name )
203 SFileDialog* fd = new SFileDialog( initially, filter, name );
204 if ( !caption.isNull() ) fd->setWindowTitle( caption );
205 QString result = ( fd->exec() == QDialog::Accepted ) ? fd->fd->selectedFile():QString();
206 delete fd;
208 return result;
211 QStringList SFileDialog::getOpenFileNames( QString initially,
212 const QStringList& filter,
213 const QString caption, const char* name )
215 SFileDialog* fd = new SFileDialog( initially, filter, name );
216 if ( !caption.isNull() ) fd->setWindowTitle( caption );
218 fd->fd->setMode( Q3FileDialog::ExistingFiles );
219 fd->d_preview->undock();
220 fd->b_preview->hide();
222 fd->exec();
223 QStringList result = fd->fd->selectedFiles();
224 delete fd;
226 return result;
229 void SFileDialog::showEvent( QShowEvent *e )
231 QDialog::showEvent( e );
232 dirView->setDir( fd->dirPath() );
235 /******************************************************************************************************/
236 PixmapView::PixmapView( QWidget *parent )
237 :Q3ScrollView( parent )
239 // kimgioRegister();
242 void PixmapView::setPixmap( const QPixmap &pix )
244 pixmap = pix;
245 resizeContents( pixmap.size().width(), pixmap.size().height() );
246 viewport()->repaint();
249 void PixmapView::drawContents( QPainter *p, int, int, int, int )
251 p->drawPixmap( 0, 0, pixmap );
254 Preview::Preview( QWidget *parent )
255 :Q3WidgetStack( parent )
257 normalText = new Q3MultiLineEdit( this );
258 normalText->setReadOnly( true );
259 html = new Q3TextView( this );
260 pixmap = new PixmapView( this );
261 raiseWidget( normalText );
264 void Preview::showPreview( const QString &str )
266 Q3Url u(str);
267 if ( u.isLocalFile() ){
268 QString path = u.path();
269 QFileInfo fi( path );
270 if ( fi.isFile() && (int)fi.size() > 400 * 1024 ) {
271 normalText->setText( tr( "The File\n%1\nis too large, so I don't show it!" ).arg( path ) );
272 raiseWidget( normalText );
273 return;
276 QPixmap pix( path );
277 if ( pix.isNull() ) {
278 if ( fi.isFile() ) {
279 QFile f( path );
280 if ( f.open( QIODevice::ReadOnly ) ) {
281 QTextStream ts( &f );
282 QString text = ts.readAll();
283 f.close();
284 if ( fi.suffix().toLower().contains( "htm" ) ) {
285 QString url = html->mimeSourceFactory()->makeAbsolute( path, html->context() );
286 html->setText( text, url );
287 raiseWidget( html );
288 return;
289 } else {
290 normalText->setText( text );
291 raiseWidget( normalText );
292 return;
296 normalText->setText( QString() );
297 raiseWidget( normalText );
298 } else {
299 pixmap->setPixmap( pix );
300 raiseWidget( pixmap );
302 } else {
303 normalText->setText( "I only show local files!" );
304 raiseWidget( normalText );
308 // ****************************************************************************************************
309 static const char* homepage_xpm[] = {
310 "24 24 9 1",
311 " c #262660",
312 ". c #383666",
313 "X c #62639c",
314 "o c #7e86a5",
315 "O c #a6a7dd",
316 "+ c #bbbaed",
317 "@ c #c4c4f2",
318 "# c #f8f9f9",
319 "$ c None",
320 "$$$$$$$$$$$$$$$$$$$$$$$$",
321 "$$$$$$$$$$$$$$$$$$$$$$$$",
322 "$$$$$$$$$$$$$$$$o.X$$$$$",
323 "$$$$$$$$$$oOOOO$O.X$$$$$",
324 "$$$$$$$$$$oXXXX+O.X$$$$$",
325 "$$$$$$$$$X#XXXXXO.X$$$$$",
326 "$$$$$$$$X #XXXXO.X$$$$$",
327 "$$$$$$$X XO #XXXO.X$$$$$",
328 "$$$$$$X XOOO #XXX.XX$$$$",
329 "$$$$$X XOOOOO #XXXXXX$$$",
330 "$$$$X XOOOOOOO #XXXXXX$$",
331 "$$$X XOOOOOOOOO #XXXXXX$",
332 "$$X XOOOOOOOOOOO #.....$",
333 "$$$$$OOOOXXXXOOOOX...$$$",
334 "$$$$$OOOOXXXXOOOOX...$$$",
335 "$$$$$OOOOXXXXOOOOX..o$$$",
336 "$$$$$OOOOXXXXOOOOX.oo$$$",
337 "$$$$$OOOOXXXXOOOOXXoo$$$",
338 "$$$$$OOOOXXXXOOOOXooo$$$",
339 "$$$ooOOOOXXXXOOOOXoooo$$",
340 "$ooooXXXXXXXXXXXXXooooo$",
341 "$ooooooooooooooooooooooo",
342 "$$$$$$$$$$$$$$$$$$$$$$$$",
343 "$$$$$$$$$$$$$$$$$$$$$$$$"
346 static const char* folder_trash[] = {
347 "16 16 10 1",
348 " c Gray0",
349 ". c #222222",
350 "X c #333366",
351 "o c #6666cc",
352 "O c Magenta",
353 "+ c #808080",
354 "@ c #9999ff",
355 "# c #c0c0c0",
356 "$ c Gray100",
357 "% c None",
358 "%%%%%%oo%%%%%%%%",
359 "%%%%%o$$o%%%%%%%",
360 "%%%%o$$$$o%%%%%%",
361 "%%%o$+$+$$o o%%%",
362 "%%oo$$+$+$$o .%%",
363 "%%.oo$$+$+$$o.%%",
364 "%% Xoo$$+$$o +%%",
365 "%%o Xoo$$oo o%%",
366 "%%%X.XX +X%%%",
367 "%%%o@X+X#X+X+%%%",
368 "%%%+.$X#X+X %%%%",
369 "%%%%.o$o#X+X%%%%",
370 "%%%%.X@$X+ +%%%%",
371 "%%%%+Xo.#. %%%%%",
372 "%%%%%.Xo. o%%%%%",
373 "%%%%%+. %%%%%%"
376 static const char* globalbookmark_xpm[]={
377 "12 16 3 1",
378 ". c None",
379 "a c #000000",
380 "# c #008080",
381 "............",
382 "............",
383 "........##..",
384 ".......#####",
385 "......#####a",
386 ".....#####a.",
387 "....#####a..",
388 "...#####a...",
389 "..#####a....",
390 ".#####a.....",
391 "aaa##a......",
392 "...#a.......",
393 "...a........",
394 "............",
395 "............",
396 "............"};
398 CustomFileDialog::CustomFileDialog( QWidget* parent )
399 : Q3FileDialog( parent, 0, false )
401 QToolButton *p = new QToolButton( this );
403 p->setIcon( QIcon( QPixmap( globalbookmark_xpm ) ) );
404 p->setToolTip( tr("Bookmarks") );
406 bookmarkMenu = new Q3PopupMenu( this );
407 connect( bookmarkMenu, SIGNAL( activated( int ) ), this, SLOT( bookmarkChosen( int ) ) );
408 addId = bookmarkMenu->insertItem( "Add bookmark" );
409 clearId = bookmarkMenu->insertItem( QPixmap(folder_trash), "Clear bookmarks" );
410 bookmarkMenu->addSeparator();
412 p->setMenu( bookmarkMenu );
413 p->setPopupDelay(0);
414 addToolButton( p, true );
416 QToolButton *b = new QToolButton( this );
417 b->setToolTip( tr("Go Home!") );
419 b->setIcon( QIcon( QPixmap( homepage_xpm ) ) );
420 connect( b, SIGNAL( clicked() ), this, SLOT( goHome() ) );
422 addToolButton( b );
426 void CustomFileDialog::setBookmark( QStringList &s )
428 QStringList::Iterator it = s.begin();
429 for ( ; it != s.end(); ++it ){
430 bookmarkList << (*it);
432 const char* book_pix[]={
433 "12 16 3 1",
434 ". c None",
435 "a c #000000",
436 "# c #008080",
437 "............",
438 "............",
439 "........##..",
440 ".......#####",
441 "......#####a",
442 ".....#####a.",
443 "....#####a..",
444 "...#####a...",
445 "..#####a....",
446 ".#####a.....",
447 "aaa##a......",
448 "...#a.......",
449 "...a........",
450 "............",
451 "............",
452 "............"};
453 bookmarkMenu->insertItem( QIcon( book_pix ), (*it) );
457 CustomFileDialog::~CustomFileDialog()
461 void CustomFileDialog::setDir2( const QString &s )
463 blockSignals( true );
464 setDir( s );
465 blockSignals( false );
468 void CustomFileDialog::bookmarkChosen( int i )
470 if ( i == clearId ){
471 bookmarkList.clear();
472 bookmarkMenu->clear();
473 addId = bookmarkMenu->insertItem( "Add bookmark" );
474 clearId = bookmarkMenu->insertItem( "Clear bookmarks" );
475 bookmarkMenu->addSeparator();
476 return;
479 if ( i == addId ){
480 bookmarkList << dirPath();
482 const char* book_pix[]={
483 "12 16 3 1",
484 ". c None",
485 "a c #000000",
486 "# c #008080",
487 "............",
488 "............",
489 "........##..",
490 ".......#####",
491 "......#####a",
492 ".....#####a.",
493 "....#####a..",
494 "...#####a...",
495 "..#####a....",
496 ".#####a.....",
497 "aaa##a......",
498 "...#a.......",
499 "...a........",
500 "............",
501 "............",
502 "............"};
503 bookmarkMenu->insertItem( QIcon( book_pix ), dirPath() );
504 return;
507 setDir( bookmarkMenu->text( i ) );
510 void CustomFileDialog::goHome()
512 const QByteArray home = qgetenv( "HOME" );
513 setDir( home.isEmpty() ? QLatin1String( "/" ) : QString(home) );
516 void CustomFileDialog::done( int i )
518 emit signalDone(i);
520 /******************************************************************************************************/
521 static const char* folder_closed_xpm[] = {
522 "16 16 9 1",
523 " c Gray0",
524 ". c #222222",
525 "X c #6666cc",
526 "o c #9999ff",
527 "O c #c0c0c0",
528 "+ c #ccccff",
529 "@ c #ffffcc",
530 "# c Gray100",
531 "$ c None",
532 "$$$$$$$$$$$$$$$$",
533 "$$$$$$$$$$$$$$$$",
534 "$$$$$$$$$$$$$$$$",
535 "$$$$$$$$$$$$$$$$",
536 "$$XXXXo$$$$$$$$$",
537 "$X#++o@XXXXXX$$$",
538 "X#+++++++++++o$$",
539 "X#o+o+o+o+o+oX$$",
540 "X#+o+o+o+o+o+X $",
541 "X#o+o+o+o+o+oX $",
542 "X#+o+o+o+o+o+X $",
543 "X#o+o+o+o+o+oX $",
544 "X#+o+o+o+o+o+X $",
545 "X+o+o+o+o+o+oX $",
546 "XXXXXXXXXXXXXX $",
547 "$ .. $"
550 static const char* folder_open_xpm[] = {
551 "16 16 10 1",
552 " c Gray0",
553 ". c #222222",
554 "X c #6666cc",
555 "o c Magenta",
556 "O c #9999ff",
557 "+ c #c0c0c0",
558 "@ c #ccccff",
559 "# c #ffffcc",
560 "$ c Gray100",
561 "% c None",
562 "%%%%%%%%%%%%%%%%",
563 "%%%%%%%%%%%%%%%%",
564 "%%%%%%%%%%%%%%%%",
565 "%%%%%%%%%%%%%%%%",
566 "%%XXXX%%%%%%%%%%",
567 "%X$$$XXXXXXXXX%%",
568 "%X$O+#######.OX%",
569 "%X$+#######.O@X%",
570 "%O$#######.O@OX ",
571 "XXXXXXXXXX.XO@X ",
572 "X$$$$$$$$$+ @OX ",
573 "%XO+O+O+O+O+ @X ",
574 "%X+O+O+O+O+O. X ",
575 "%%X+O+O+O+O+O. ",
576 "%%XXXXXXXXXXXXX ",
577 "%%% "
580 static const char* folder_locked_xpm[] = {
581 "16 16 8 1",
582 " c Gray0",
583 ". c #333366",
584 "X c #6666cc",
585 "o c Magenta",
586 "O c #9999ff",
587 "+ c #c0c0c0",
588 "@ c Gray100",
589 "# c None",
590 "###O.O##########",
591 "###...##########",
592 "###O.O##########",
593 "##.#X#.#OX######",
594 "#...X...@@X#####",
595 "#.......OOOOOOX#",
596 "#.......@@@@@@X#",
597 "#@@@@@@@O+O+O+X ",
598 "#O@O+O+O+O+O+OX ",
599 "#O@+O+O+O+O+O+X ",
600 "#O@O+O+O+O+O+OX ",
601 "#O@+O+O+O+O+O+X ",
602 "#O@O+O+O+O+O+OX ",
603 "#OXXXXXXXXXXXXX ",
604 "## ",
605 "################"
608 Directory::Directory( Directory * parent, const QString& filename )
609 :Q3ListViewItem( parent ), f(filename)
611 p = parent;
612 readable = QDir( fullName() ).isReadable();
614 if ( !readable )
615 setPixmap( 0, QPixmap( folder_locked_xpm ) );
616 else
617 setPixmap( 0, QPixmap( folder_closed_xpm ) );
621 Directory::Directory( Q3ListView * parent, const QString& filename )
622 :Q3ListViewItem( parent ), f(filename)
624 p = 0;
625 readable = QDir( fullName() ).isReadable();
629 void Directory::setOpen( bool o )
631 if ( o )
632 setPixmap( 0, QPixmap( folder_open_xpm ) );
633 else
634 setPixmap( 0, QPixmap( folder_closed_xpm ) );
636 if ( o && !childCount() ){
637 QString s( fullName() );
638 QDir thisDir( s );
639 if ( !thisDir.isReadable() ) {
640 readable = false;
641 setExpandable( false );
642 return;
645 listView()->setUpdatesEnabled( false );
646 QFileInfoList files = thisDir.entryInfoList();
647 foreach ( const QFileInfo &f, files ){
648 if ( f.fileName() != "." && f.fileName() != ".." && f.isDir() )
649 (void)new Directory( this, f.fileName() );
651 listView()->setUpdatesEnabled( true );
653 Q3ListViewItem::setOpen( o );
657 void Directory::setup()
659 setExpandable( true );
660 Q3ListViewItem::setup();
664 QString Directory::fullName()
666 QString s;
667 if ( p ) {
668 s = p->fullName();
669 s.append( f.fileName() );
670 s.append( "/" );
671 } else {
672 s = f.fileName();
674 return s;
678 QString Directory::text( int column ) const
680 if ( column == 0 )
681 return f.fileName();
682 else
683 if ( readable )
684 return "Directory";
685 else
686 return "Unreadable Directory";
689 DirectoryView::DirectoryView( QWidget *parent, const char *name )
690 :Q3ListView( parent, name )
692 connect( this, SIGNAL( clicked( Q3ListViewItem * ) ),
693 this, SLOT( slotFolderSelected( Q3ListViewItem * ) ) );
694 connect( this, SIGNAL( doubleClicked( Q3ListViewItem * ) ),
695 this, SLOT( slotFolderSelected( Q3ListViewItem * ) ) );
696 connect( this, SIGNAL( returnPressed( Q3ListViewItem * ) ),
697 this, SLOT( slotFolderSelected( Q3ListViewItem * ) ) );
699 setAcceptDrops( true );
700 viewport()->setAcceptDrops( true );
703 void DirectoryView::setOpen( Q3ListViewItem* i, bool b )
705 Q3ListView::setOpen(i,b);
706 setCurrentItem(i);
707 slotFolderSelected(i);
710 void DirectoryView::slotFolderSelected( Q3ListViewItem *i )
712 if ( !i ) return;
714 Directory *dir = (Directory*)i;
715 emit folderSelected( dir->fullName() );
718 QString DirectoryView::fullPath(Q3ListViewItem* item)
720 QString fullpath = item->text(0);
721 while ( (item=item->parent()) ) {
722 if ( item->parent() )
723 fullpath = item->text(0) + "/" + fullpath;
724 else
725 fullpath = item->text(0) + fullpath;
727 return fullpath;
730 void DirectoryView::setDir( const QString &s )
732 Q3ListViewItemIterator it( this );
733 ++it;
734 for ( ; it.current(); ++it ) {
735 it.current()->setOpen( false );
738 QStringList lst( s.split( "/", QString::SkipEmptyParts ) );
739 Q3ListViewItem *item = firstChild();
740 QStringList::Iterator it2 = lst.begin();
741 for ( ; it2 != lst.end(); ++it2 ) {
742 while ( item ) {
743 if ( item->text( 0 ) == *it2 ) {
744 item->setOpen( true );
745 break;
747 item = item->itemBelow();
751 if ( item ){
752 setSelected( item, true );
753 setCurrentItem( item );
757 QString DirectoryView::selectedDir()
759 Directory *dir = (Directory*)currentItem();
760 return dir->fullName();
762 /**********************************************************************************************/
764 int main(int argc, char* argv[]) {
765 KAboutData about("kdockwidgetdemo", 0, ki18n("kdockwidgetdemo"), "version");
766 KCmdLineArgs::init(argc, argv, &about);
768 KApplication app;
770 #if 0
771 SFileDialog* openfile = new SFileDialog();
772 openfile->exec();
773 qDebug( openfile->fileName() );
774 #endif
776 #if 0
777 qDebug ( SFileDialog::getOpenFileName( QString(), QLatin1String("All (*)"),
778 QLatin1String("DockWidget Demo"), "dialog1" ) );
779 #endif
781 #if 1
782 QStringList s = SFileDialog::getOpenFileNames( QString(),
783 QStringList(QLatin1String("All (*)")),
784 QLatin1String("DockWidget Demo"), "dialog1" );
785 QStringList::Iterator it = s.begin();
786 for ( ; it != s.end(); ++it ){
787 qDebug( "%s", (*it).toLocal8Bit().data() );
789 #endif
790 return 0;
793 #include "kdockwidgetdemo.moc"