You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
797 lines
19 KiB
797 lines
19 KiB
15 years ago
|
#include "kdockwidgetdemo.h"
|
||
|
|
||
15 years ago
|
#include <tqheader.h>
|
||
|
#include <tqtoolbutton.h>
|
||
|
#include <tqtooltip.h>
|
||
|
#include <tqtextview.h>
|
||
|
#include <tqfileinfo.h>
|
||
|
#include <tqfile.h>
|
||
|
#include <tqtextstream.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqmultilineedit.h>
|
||
|
#include <tqevent.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqpoint.h>
|
||
|
#include <tqmessagebox.h>
|
||
|
#include <tqmime.h>
|
||
|
#include <tqstrlist.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
|
#include <kconfig.h>
|
||
|
#include <kapplication.h>
|
||
|
//#include <kimgio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
static const char *dir_tree_xpm[] = {
|
||
|
"16 16 8 1",
|
||
|
" c Gray0",
|
||
|
". c #000080",
|
||
|
"X c Cyan",
|
||
|
"o c #808000",
|
||
|
"O c Yellow",
|
||
|
"+ c #808080",
|
||
|
"@ c None",
|
||
|
"# c #c1c1c1",
|
||
|
"@@@@@@@@@@@@@@@@",
|
||
|
"@@@+++++@@@@@@@@",
|
||
|
"@@+@O@O@+@@@@@@@",
|
||
|
"@+@O@O@O@++++++@",
|
||
|
"@+@@@@@@@@@@@@o ",
|
||
|
"@+@O@++ +O@O@Oo ",
|
||
|
"@+@@+@X@ +O@O@o ",
|
||
|
"@+@+@X@X@ +O@Oo ",
|
||
|
"@+@+X@X@X o@O@o ",
|
||
|
"@+@+@X@X@ oO@Oo ",
|
||
|
"@+@@+@X@ +ooO@o ",
|
||
|
"@+@O@+ +@..oOo ",
|
||
|
"@+ooooooo.X..oo ",
|
||
|
"@@ .X.. @",
|
||
|
"@@@@@@@@@@@.X.. ",
|
||
|
"@@@@@@@@@@@@.X. "
|
||
|
};
|
||
|
|
||
|
static const char *preview_xpm[] = {
|
||
|
"16 16 6 1",
|
||
|
" c Gray0",
|
||
|
". c #000080",
|
||
|
"X c Yellow",
|
||
|
"o c #808080",
|
||
|
"O c None",
|
||
|
"+ c Gray100",
|
||
|
"OOOOOOOOOOOOOOOO",
|
||
|
"OOo oOOOOOOO",
|
||
|
"Oo oooo OOOOOO",
|
||
|
"O OOOOoo oOOOOO",
|
||
|
"O OOOO++oo OOOOO",
|
||
|
"O OOOO++Oo OOOOO",
|
||
|
"O O+OOOOOo OOOOO",
|
||
|
"O OO+OOOOo OOOOO",
|
||
|
"OooOO+OOo OOOOO",
|
||
|
"OO oOOOo + OOOO",
|
||
|
"OOOo .X+ OOO",
|
||
|
"OOOOOOOOO .X+ OO",
|
||
|
"OOOOOOOOOO .X+ O",
|
||
|
"OOOOOOOOOOO .X O",
|
||
|
"OOOOOOOOOOOO OO",
|
||
|
"OOOOOOOOOOOOOOOO"
|
||
|
};
|
||
|
|
||
15 years ago
|
SFileDialog::SFileDialog( TQString initially, const TQStringList& filter, const char* name )
|
||
|
:TQDialog(0L,name,true)
|
||
15 years ago
|
{
|
||
|
KConfig* config = kapp->config();
|
||
14 years ago
|
config->setGroup( TQString::tqfromLatin1("SFileDialogData:") + name );
|
||
15 years ago
|
if ( initially.isNull() ){
|
||
15 years ago
|
initially = config->readPathEntry( "InitiallyDir", TQDir::currentDirPath() );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQStringList bookmark;
|
||
15 years ago
|
bookmark = config->readListEntry( "Bookmarks" );
|
||
|
|
||
|
dockManager = new KDockManager(this);
|
||
|
|
||
15 years ago
|
d_dirView = new KDockWidget( dockManager, "Dock_DirView", TQPixmap(dir_tree_xpm) );
|
||
15 years ago
|
d_dirView->setCaption("Tree");
|
||
|
|
||
|
dirView = new DirectoryView( d_dirView, 0 );
|
||
|
dirView->addColumn( "" );
|
||
|
dirView->header()->hide();
|
||
|
d_dirView->setWidget( dirView );
|
||
|
|
||
|
Directory* root = new Directory( dirView, "/" );
|
||
|
root->setOpen(true);
|
||
|
|
||
15 years ago
|
d_preview = new KDockWidget( dockManager, "Dock_Preview", TQPixmap(preview_xpm) );
|
||
15 years ago
|
d_preview->setCaption("Preview");
|
||
|
preview = new Preview( d_preview );
|
||
|
d_preview->setWidget( preview );
|
||
|
|
||
15 years ago
|
d_fd = new KDockWidget( dockManager, "Dock_QFileDialog", TQPixmap(), this );
|
||
15 years ago
|
fd = new CustomFileDialog( d_fd );
|
||
|
fd->setDir( initially );
|
||
|
fd->setFilters( filter );
|
||
|
fd->setBookmark( bookmark );
|
||
15 years ago
|
fd->reparent(d_fd, TQPoint(0,0));
|
||
15 years ago
|
d_fd->setWidget( fd );
|
||
|
|
||
15 years ago
|
connect( dirView, TQT_SIGNAL( folderSelected( const TQString & ) ), fd, TQT_SLOT( setDir2( const TQString & ) ) );
|
||
|
connect( fd, TQT_SIGNAL( dirEntered( const TQString & ) ), dirView, TQT_SLOT( setDir( const TQString & ) ) );
|
||
15 years ago
|
|
||
|
d_fd->setDockSite( KDockWidget::DockTop|KDockWidget::DockLeft|KDockWidget::DockRight|KDockWidget::DockBottom );
|
||
|
d_fd->setEnableDocking(KDockWidget::DockNone);
|
||
|
|
||
|
d_dirView->setEnableDocking(KDockWidget::DockTop|KDockWidget::DockLeft|KDockWidget::DockRight|KDockWidget::DockBottom|KDockWidget::DockCenter);
|
||
|
d_preview->setEnableDocking(KDockWidget::DockTop|KDockWidget::DockLeft|KDockWidget::DockRight|KDockWidget::DockBottom|KDockWidget::DockCenter);
|
||
|
|
||
|
d_dirView->manualDock( d_fd, KDockWidget::DockLeft, 20 );
|
||
|
d_preview->manualDock( d_fd, KDockWidget::DockBottom, 70 );
|
||
|
|
||
15 years ago
|
connect(fd, TQT_SIGNAL(fileHighlighted(const TQString&)), preview, TQT_SLOT(showPreview(const TQString&)));
|
||
|
connect(fd, TQT_SIGNAL(signalDone(int)), this, TQT_SLOT(done(int)));
|
||
15 years ago
|
|
||
15 years ago
|
connect(fd, TQT_SIGNAL(dirEntered(const TQString&)), this, TQT_SLOT(changeDir(const TQString&)));
|
||
|
connect(dirView, TQT_SIGNAL(folderSelected(const TQString&)), this, TQT_SLOT(changeDir(const TQString&)));
|
||
15 years ago
|
|
||
15 years ago
|
b_tree = new TQToolButton( fd );
|
||
|
TQToolTip::add( b_tree, "Show/Hide Tree" );
|
||
|
b_tree->setPixmap( TQPixmap( dir_tree_xpm ) );
|
||
|
connect( b_tree, TQT_SIGNAL(clicked()), d_dirView, TQT_SLOT(changeHideShowState()) );
|
||
15 years ago
|
b_tree->setToggleButton(true);
|
||
|
b_tree->setOn(true);
|
||
|
fd->addToolButton( b_tree, true );
|
||
|
|
||
15 years ago
|
b_preview = new TQToolButton( fd );
|
||
|
TQToolTip::add( b_preview, "Show/Hide Preview" );
|
||
|
b_preview->setPixmap( TQPixmap( preview_xpm ) );
|
||
|
connect( b_preview, TQT_SIGNAL(clicked()), d_preview, TQT_SLOT(changeHideShowState()) );
|
||
15 years ago
|
b_preview->setToggleButton(true);
|
||
|
b_preview->setOn(true);
|
||
|
fd->addToolButton( b_preview );
|
||
|
|
||
15 years ago
|
connect( dockManager, TQT_SIGNAL(change()), this, TQT_SLOT(dockChange()));
|
||
|
connect( dockManager, TQT_SIGNAL(setDockDefaultPos(KDockWidget*)), this, TQT_SLOT(setDockDefaultPos(KDockWidget*)));
|
||
15 years ago
|
setCaption("Open File");
|
||
|
resize(550,450);
|
||
|
qDebug("read config");
|
||
|
dockManager->readConfig( 0L , name );
|
||
|
}
|
||
|
|
||
|
void SFileDialog::dockChange()
|
||
|
{
|
||
|
b_preview->setOn( d_preview->isVisibleToTLW() );
|
||
|
b_tree->setOn( d_dirView->isVisibleToTLW() );
|
||
|
}
|
||
|
|
||
|
SFileDialog::~SFileDialog()
|
||
|
{
|
||
|
KConfig* config = kapp->config();
|
||
15 years ago
|
config->setGroup( TQString("SFileDialogData:") + name() );
|
||
15 years ago
|
config->writeEntry( "Bookmarks", fd->getBookmark() );
|
||
|
|
||
|
qDebug("write config");
|
||
|
dockManager->writeConfig( 0L , name() );
|
||
|
}
|
||
|
|
||
|
void SFileDialog::setDockDefaultPos( KDockWidget* d )
|
||
|
{
|
||
|
if ( d == d_dirView ){
|
||
|
d_dirView->manualDock( d_fd, KDockWidget::DockLeft, 20 );
|
||
|
}
|
||
|
|
||
|
if ( d == d_preview ){
|
||
|
d_preview->manualDock( d_fd, KDockWidget::DockBottom, 70 );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void SFileDialog::changeDir( const TQString& f )
|
||
15 years ago
|
{
|
||
|
if ( !f.isEmpty() ){
|
||
|
KConfig* config = kapp->config();
|
||
15 years ago
|
config->setGroup( TQString("SFileDialogData:") + name() );
|
||
15 years ago
|
config->writePathEntry( "InitiallyDir", f );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString SFileDialog::getOpenFileName( TQString initially,
|
||
|
const TQStringList& filter,
|
||
|
const TQString caption, const char* name )
|
||
15 years ago
|
{
|
||
|
SFileDialog* fd = new SFileDialog( initially, filter, name );
|
||
|
if ( !caption.isNull() ) fd->setCaption( caption );
|
||
15 years ago
|
TQString result = ( fd->exec() == TQDialog::Accepted ) ? fd->fd->selectedFile():TQString::null;
|
||
15 years ago
|
delete fd;
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList SFileDialog::getOpenFileNames( TQString initially,
|
||
|
const TQStringList& filter,
|
||
|
const TQString caption, const char* name )
|
||
15 years ago
|
{
|
||
|
SFileDialog* fd = new SFileDialog( initially, filter, name );
|
||
|
if ( !caption.isNull() ) fd->setCaption( caption );
|
||
|
|
||
15 years ago
|
fd->fd->setMode( TQFileDialog::ExistingFiles );
|
||
15 years ago
|
fd->d_preview->undock();
|
||
|
fd->b_preview->hide();
|
||
|
|
||
|
fd->exec();
|
||
15 years ago
|
TQStringList result = fd->fd->selectedFiles();
|
||
15 years ago
|
delete fd;
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
15 years ago
|
void SFileDialog::showEvent( TQShowEvent *e )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDialog::showEvent( e );
|
||
15 years ago
|
dirView->setDir( fd->dirPath() );
|
||
|
}
|
||
|
|
||
|
/******************************************************************************************************/
|
||
15 years ago
|
PixmapView::PixmapView( TQWidget *parent )
|
||
|
:TQScrollView( parent )
|
||
15 years ago
|
{
|
||
|
// kimgioRegister();
|
||
|
viewport()->setBackgroundMode( PaletteBase );
|
||
|
}
|
||
|
|
||
15 years ago
|
void PixmapView::setPixmap( const TQPixmap &pix )
|
||
15 years ago
|
{
|
||
|
pixmap = pix;
|
||
|
resizeContents( pixmap.size().width(), pixmap.size().height() );
|
||
14 years ago
|
viewport()->tqrepaint( true );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void PixmapView::drawContents( TQPainter *p, int, int, int, int )
|
||
15 years ago
|
{
|
||
|
p->drawPixmap( 0, 0, pixmap );
|
||
|
}
|
||
|
|
||
15 years ago
|
Preview::Preview( TQWidget *parent )
|
||
|
:TQWidgetStack( parent )
|
||
15 years ago
|
{
|
||
15 years ago
|
normalText = new TQMultiLineEdit( this );
|
||
15 years ago
|
normalText->setReadOnly( true );
|
||
15 years ago
|
html = new TQTextView( this );
|
||
15 years ago
|
pixmap = new PixmapView( this );
|
||
|
raiseWidget( normalText );
|
||
|
}
|
||
|
|
||
15 years ago
|
void Preview::showPreview( const TQString &str )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQUrl u(str);
|
||
15 years ago
|
if ( u.isLocalFile() ){
|
||
15 years ago
|
TQString path = u.path();
|
||
|
TQFileInfo fi( path );
|
||
15 years ago
|
if ( fi.isFile() && (int)fi.size() > 400 * 1024 ) {
|
||
|
normalText->setText( tr( "The File\n%1\nis too large, so I don't show it!" ).arg( path ) );
|
||
|
raiseWidget( normalText );
|
||
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPixmap pix( path );
|
||
15 years ago
|
if ( pix.isNull() ) {
|
||
|
if ( fi.isFile() ) {
|
||
15 years ago
|
TQFile f( path );
|
||
15 years ago
|
if ( f.open( IO_ReadOnly ) ) {
|
||
15 years ago
|
TQTextStream ts( &f );
|
||
|
TQString text = ts.read();
|
||
15 years ago
|
f.close();
|
||
14 years ago
|
if ( fi.extension().lower().contains( "htm" ) ) {
|
||
15 years ago
|
TQString url = html->mimeSourceFactory()->makeAbsolute( path, html->context() );
|
||
15 years ago
|
html->setText( text, url );
|
||
|
raiseWidget( html );
|
||
|
return;
|
||
|
} else {
|
||
|
normalText->setText( text );
|
||
|
raiseWidget( normalText );
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
normalText->setText( TQString::null );
|
||
15 years ago
|
raiseWidget( normalText );
|
||
|
} else {
|
||
|
pixmap->setPixmap( pix );
|
||
|
raiseWidget( pixmap );
|
||
|
}
|
||
|
} else {
|
||
|
normalText->setText( "I only show local files!" );
|
||
|
raiseWidget( normalText );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ****************************************************************************************************
|
||
|
static const char* homepage_xpm[] = {
|
||
|
"24 24 9 1",
|
||
|
" c #262660",
|
||
|
". c #383666",
|
||
|
"X c #62639c",
|
||
|
"o c #7e86a5",
|
||
|
"O c #a6a7dd",
|
||
|
"+ c #bbbaed",
|
||
|
"@ c #c4c4f2",
|
||
|
"# c #f8f9f9",
|
||
|
"$ c None",
|
||
|
"$$$$$$$$$$$$$$$$$$$$$$$$",
|
||
|
"$$$$$$$$$$$$$$$$$$$$$$$$",
|
||
|
"$$$$$$$$$$$$$$$$o.X$$$$$",
|
||
|
"$$$$$$$$$$oOOOO$O.X$$$$$",
|
||
|
"$$$$$$$$$$oXXXX+O.X$$$$$",
|
||
|
"$$$$$$$$$X#XXXXXO.X$$$$$",
|
||
|
"$$$$$$$$X #XXXXO.X$$$$$",
|
||
|
"$$$$$$$X XO #XXXO.X$$$$$",
|
||
|
"$$$$$$X XOOO #XXX.XX$$$$",
|
||
|
"$$$$$X XOOOOO #XXXXXX$$$",
|
||
|
"$$$$X XOOOOOOO #XXXXXX$$",
|
||
|
"$$$X XOOOOOOOOO #XXXXXX$",
|
||
|
"$$X XOOOOOOOOOOO #.....$",
|
||
|
"$$$$$OOOOXXXXOOOOX...$$$",
|
||
|
"$$$$$OOOOXXXXOOOOX...$$$",
|
||
|
"$$$$$OOOOXXXXOOOOX..o$$$",
|
||
|
"$$$$$OOOOXXXXOOOOX.oo$$$",
|
||
|
"$$$$$OOOOXXXXOOOOXXoo$$$",
|
||
|
"$$$$$OOOOXXXXOOOOXooo$$$",
|
||
|
"$$$ooOOOOXXXXOOOOXoooo$$",
|
||
|
"$ooooXXXXXXXXXXXXXooooo$",
|
||
|
"$ooooooooooooooooooooooo",
|
||
|
"$$$$$$$$$$$$$$$$$$$$$$$$",
|
||
|
"$$$$$$$$$$$$$$$$$$$$$$$$"
|
||
|
};
|
||
|
|
||
|
static const char* folder_trash[] = {
|
||
|
"16 16 10 1",
|
||
|
" c Gray0",
|
||
|
". c #222222",
|
||
|
"X c #333366",
|
||
|
"o c #6666cc",
|
||
|
"O c Magenta",
|
||
|
"+ c #808080",
|
||
|
"@ c #9999ff",
|
||
|
"# c #c0c0c0",
|
||
|
"$ c Gray100",
|
||
|
"% c None",
|
||
|
"%%%%%%oo%%%%%%%%",
|
||
|
"%%%%%o$$o%%%%%%%",
|
||
|
"%%%%o$$$$o%%%%%%",
|
||
|
"%%%o$+$+$$o o%%%",
|
||
|
"%%oo$$+$+$$o .%%",
|
||
|
"%%.oo$$+$+$$o.%%",
|
||
|
"%% Xoo$$+$$o +%%",
|
||
|
"%%o Xoo$$oo o%%",
|
||
|
"%%%X.XX +X%%%",
|
||
|
"%%%o@X+X#X+X+%%%",
|
||
|
"%%%+.$X#X+X %%%%",
|
||
|
"%%%%.o$o#X+X%%%%",
|
||
|
"%%%%.X@$X+ +%%%%",
|
||
|
"%%%%+Xo.#. %%%%%",
|
||
|
"%%%%%.Xo. o%%%%%",
|
||
|
"%%%%%+. %%%%%%"
|
||
|
};
|
||
|
|
||
|
static const char* globalbookmark_xpm[]={
|
||
|
"12 16 3 1",
|
||
|
". c None",
|
||
|
"a c #000000",
|
||
|
"# c #008080",
|
||
|
"............",
|
||
|
"............",
|
||
|
"........##..",
|
||
|
".......#####",
|
||
|
"......#####a",
|
||
|
".....#####a.",
|
||
|
"....#####a..",
|
||
|
"...#####a...",
|
||
|
"..#####a....",
|
||
|
".#####a.....",
|
||
|
"aaa##a......",
|
||
|
"...#a.......",
|
||
|
"...a........",
|
||
|
"............",
|
||
|
"............",
|
||
|
"............"};
|
||
|
|
||
15 years ago
|
CustomFileDialog::CustomFileDialog( TQWidget* parent )
|
||
|
: TQFileDialog( parent, 0, false )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQToolButton *p = new TQToolButton( this );
|
||
15 years ago
|
|
||
15 years ago
|
p->setPixmap( TQPixmap( globalbookmark_xpm ) );
|
||
|
TQToolTip::add( p, tr( "Bookmarks" ) );
|
||
15 years ago
|
|
||
15 years ago
|
bookmarkMenu = new TQPopupMenu( this );
|
||
|
connect( bookmarkMenu, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( bookmarkChosen( int ) ) );
|
||
15 years ago
|
addId = bookmarkMenu->insertItem( "Add bookmark" );
|
||
15 years ago
|
clearId = bookmarkMenu->insertItem( TQPixmap(folder_trash), "Clear bookmarks" );
|
||
15 years ago
|
bookmarkMenu->insertSeparator();
|
||
|
|
||
|
p->setPopup( bookmarkMenu );
|
||
|
p->setPopupDelay(0);
|
||
|
addToolButton( p, true );
|
||
|
|
||
15 years ago
|
TQToolButton *b = new TQToolButton( this );
|
||
|
TQToolTip::add( b, tr( "Go Home!" ) );
|
||
15 years ago
|
|
||
15 years ago
|
b->setPixmap( TQPixmap( homepage_xpm ) );
|
||
|
connect( b, TQT_SIGNAL( clicked() ), this, TQT_SLOT( goHome() ) );
|
||
15 years ago
|
|
||
|
addToolButton( b );
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CustomFileDialog::setBookmark( TQStringList &s )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList::Iterator it = s.begin();
|
||
15 years ago
|
for ( ; it != s.end(); ++it ){
|
||
|
bookmarkList << (*it);
|
||
|
|
||
|
const char* book_pix[]={
|
||
|
"12 16 3 1",
|
||
|
". c None",
|
||
|
"a c #000000",
|
||
|
"# c #008080",
|
||
|
"............",
|
||
|
"............",
|
||
|
"........##..",
|
||
|
".......#####",
|
||
|
"......#####a",
|
||
|
".....#####a.",
|
||
|
"....#####a..",
|
||
|
"...#####a...",
|
||
|
"..#####a....",
|
||
|
".#####a.....",
|
||
|
"aaa##a......",
|
||
|
"...#a.......",
|
||
|
"...a........",
|
||
|
"............",
|
||
|
"............",
|
||
|
"............"};
|
||
15 years ago
|
bookmarkMenu->insertItem( TQIconSet( book_pix ), (*it) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
CustomFileDialog::~CustomFileDialog()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void CustomFileDialog::setDir2( const TQString &s )
|
||
15 years ago
|
{
|
||
|
blockSignals( true );
|
||
|
setDir( s );
|
||
|
blockSignals( false );
|
||
|
}
|
||
|
|
||
|
void CustomFileDialog::bookmarkChosen( int i )
|
||
|
{
|
||
|
if ( i == clearId ){
|
||
|
bookmarkList.clear();
|
||
|
bookmarkMenu->clear();
|
||
|
addId = bookmarkMenu->insertItem( "Add bookmark" );
|
||
|
clearId = bookmarkMenu->insertItem( "Clear bookmarks" );
|
||
|
bookmarkMenu->insertSeparator();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( i == addId ){
|
||
|
bookmarkList << dirPath();
|
||
|
|
||
|
const char* book_pix[]={
|
||
|
"12 16 3 1",
|
||
|
". c None",
|
||
|
"a c #000000",
|
||
|
"# c #008080",
|
||
|
"............",
|
||
|
"............",
|
||
|
"........##..",
|
||
|
".......#####",
|
||
|
"......#####a",
|
||
|
".....#####a.",
|
||
|
"....#####a..",
|
||
|
"...#####a...",
|
||
|
"..#####a....",
|
||
|
".#####a.....",
|
||
|
"aaa##a......",
|
||
|
"...#a.......",
|
||
|
"...a........",
|
||
|
"............",
|
||
|
"............",
|
||
|
"............"};
|
||
15 years ago
|
bookmarkMenu->insertItem( TQIconSet( book_pix ), dirPath() );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
setDir( bookmarkMenu->text( i ) );
|
||
|
}
|
||
|
|
||
|
void CustomFileDialog::goHome()
|
||
|
{
|
||
|
if ( getenv( "HOME" ) )
|
||
|
setDir( getenv( "HOME" ) );
|
||
|
else
|
||
|
setDir( "/" );
|
||
|
}
|
||
|
|
||
|
void CustomFileDialog::done( int i )
|
||
|
{
|
||
|
emit signalDone(i);
|
||
|
}
|
||
|
/******************************************************************************************************/
|
||
|
static const char* folder_closed_xpm[] = {
|
||
|
"16 16 9 1",
|
||
|
" c Gray0",
|
||
|
". c #222222",
|
||
|
"X c #6666cc",
|
||
|
"o c #9999ff",
|
||
|
"O c #c0c0c0",
|
||
|
"+ c #ccccff",
|
||
|
"@ c #ffffcc",
|
||
|
"# c Gray100",
|
||
|
"$ c None",
|
||
|
"$$$$$$$$$$$$$$$$",
|
||
|
"$$$$$$$$$$$$$$$$",
|
||
|
"$$$$$$$$$$$$$$$$",
|
||
|
"$$$$$$$$$$$$$$$$",
|
||
|
"$$XXXXo$$$$$$$$$",
|
||
|
"$X#++o@XXXXXX$$$",
|
||
|
"X#+++++++++++o$$",
|
||
|
"X#o+o+o+o+o+oX$$",
|
||
|
"X#+o+o+o+o+o+X $",
|
||
|
"X#o+o+o+o+o+oX $",
|
||
|
"X#+o+o+o+o+o+X $",
|
||
|
"X#o+o+o+o+o+oX $",
|
||
|
"X#+o+o+o+o+o+X $",
|
||
|
"X+o+o+o+o+o+oX $",
|
||
|
"XXXXXXXXXXXXXX $",
|
||
|
"$ .. $"
|
||
|
};
|
||
|
|
||
|
static const char* folder_open_xpm[] = {
|
||
|
"16 16 10 1",
|
||
|
" c Gray0",
|
||
|
". c #222222",
|
||
|
"X c #6666cc",
|
||
|
"o c Magenta",
|
||
|
"O c #9999ff",
|
||
|
"+ c #c0c0c0",
|
||
|
"@ c #ccccff",
|
||
|
"# c #ffffcc",
|
||
|
"$ c Gray100",
|
||
|
"% c None",
|
||
|
"%%%%%%%%%%%%%%%%",
|
||
|
"%%%%%%%%%%%%%%%%",
|
||
|
"%%%%%%%%%%%%%%%%",
|
||
|
"%%%%%%%%%%%%%%%%",
|
||
|
"%%XXXX%%%%%%%%%%",
|
||
|
"%X$$$XXXXXXXXX%%",
|
||
|
"%X$O+#######.OX%",
|
||
|
"%X$+#######.O@X%",
|
||
|
"%O$#######.O@OX ",
|
||
|
"XXXXXXXXXX.XO@X ",
|
||
|
"X$$$$$$$$$+ @OX ",
|
||
|
"%XO+O+O+O+O+ @X ",
|
||
|
"%X+O+O+O+O+O. X ",
|
||
|
"%%X+O+O+O+O+O. ",
|
||
|
"%%XXXXXXXXXXXXX ",
|
||
|
"%%% "
|
||
|
};
|
||
|
|
||
|
static const char* folder_locked_xpm[] = {
|
||
|
"16 16 8 1",
|
||
|
" c Gray0",
|
||
|
". c #333366",
|
||
|
"X c #6666cc",
|
||
|
"o c Magenta",
|
||
|
"O c #9999ff",
|
||
|
"+ c #c0c0c0",
|
||
|
"@ c Gray100",
|
||
|
"# c None",
|
||
|
"###O.O##########",
|
||
|
"###...##########",
|
||
|
"###O.O##########",
|
||
|
"##.#X#.#OX######",
|
||
|
"#...X...@@X#####",
|
||
|
"#.......OOOOOOX#",
|
||
|
"#.......@@@@@@X#",
|
||
|
"#@@@@@@@O+O+O+X ",
|
||
|
"#O@O+O+O+O+O+OX ",
|
||
|
"#O@+O+O+O+O+O+X ",
|
||
|
"#O@O+O+O+O+O+OX ",
|
||
|
"#O@+O+O+O+O+O+X ",
|
||
|
"#O@O+O+O+O+O+OX ",
|
||
|
"#OXXXXXXXXXXXXX ",
|
||
|
"## ",
|
||
|
"################"
|
||
|
};
|
||
|
|
||
15 years ago
|
Directory::Directory( Directory * parent, const TQString& filename )
|
||
|
:TQListViewItem( parent ), f(filename)
|
||
15 years ago
|
{
|
||
|
p = parent;
|
||
15 years ago
|
readable = TQDir( fullName() ).isReadable();
|
||
15 years ago
|
|
||
|
if ( !readable )
|
||
15 years ago
|
setPixmap( 0, TQPixmap( folder_locked_xpm ) );
|
||
15 years ago
|
else
|
||
15 years ago
|
setPixmap( 0, TQPixmap( folder_closed_xpm ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
Directory::Directory( TQListView * parent, const TQString& filename )
|
||
|
:TQListViewItem( parent ), f(filename)
|
||
15 years ago
|
{
|
||
|
p = 0;
|
||
15 years ago
|
readable = TQDir( fullName() ).isReadable();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void Directory::setOpen( bool o )
|
||
|
{
|
||
|
if ( o )
|
||
15 years ago
|
setPixmap( 0, TQPixmap( folder_open_xpm ) );
|
||
15 years ago
|
else
|
||
15 years ago
|
setPixmap( 0, TQPixmap( folder_closed_xpm ) );
|
||
15 years ago
|
|
||
|
if ( o && !childCount() ){
|
||
15 years ago
|
TQString s( fullName() );
|
||
|
TQDir thisDir( s );
|
||
15 years ago
|
if ( !thisDir.isReadable() ) {
|
||
|
readable = false;
|
||
|
setExpandable( false );
|
||
|
return;
|
||
|
}
|
||
|
|
||
14 years ago
|
listView()->tqsetUpdatesEnabled( false );
|
||
15 years ago
|
const QFileInfoList * files = thisDir.entryInfoList();
|
||
|
if ( files ){
|
||
|
QFileInfoListIterator it( *files );
|
||
15 years ago
|
TQFileInfo * f;
|
||
15 years ago
|
while( (f=it.current()) != 0 ){
|
||
|
++it;
|
||
|
if ( f->fileName() != "." && f->fileName() != ".." && f->isDir() )
|
||
|
(void)new Directory( this, f->fileName() );
|
||
|
}
|
||
|
}
|
||
14 years ago
|
listView()->tqsetUpdatesEnabled( true );
|
||
15 years ago
|
}
|
||
15 years ago
|
TQListViewItem::setOpen( o );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void Directory::setup()
|
||
|
{
|
||
|
setExpandable( true );
|
||
15 years ago
|
TQListViewItem::setup();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString Directory::fullName()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString s;
|
||
15 years ago
|
if ( p ) {
|
||
|
s = p->fullName();
|
||
|
s.append( f.name() );
|
||
|
s.append( "/" );
|
||
|
} else {
|
||
|
s = f.name();
|
||
|
}
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString Directory::text( int column ) const
|
||
15 years ago
|
{
|
||
|
if ( column == 0 )
|
||
|
return f.name();
|
||
|
else
|
||
|
if ( readable )
|
||
|
return "Directory";
|
||
|
else
|
||
|
return "Unreadable Directory";
|
||
|
}
|
||
|
|
||
15 years ago
|
DirectoryView::DirectoryView( TQWidget *parent, const char *name )
|
||
|
:TQListView( parent, name )
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( this, TQT_SIGNAL( clicked( TQListViewItem * ) ),
|
||
|
this, TQT_SLOT( slotFolderSelected( TQListViewItem * ) ) );
|
||
|
connect( this, TQT_SIGNAL( doubleClicked( TQListViewItem * ) ),
|
||
|
this, TQT_SLOT( slotFolderSelected( TQListViewItem * ) ) );
|
||
|
connect( this, TQT_SIGNAL( returnPressed( TQListViewItem * ) ),
|
||
|
this, TQT_SLOT( slotFolderSelected( TQListViewItem * ) ) );
|
||
15 years ago
|
|
||
|
setAcceptDrops( true );
|
||
|
viewport()->setAcceptDrops( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
void DirectoryView::setOpen( TQListViewItem* i, bool b )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListView::setOpen(i,b);
|
||
15 years ago
|
setCurrentItem(i);
|
||
|
slotFolderSelected(i);
|
||
|
}
|
||
|
|
||
15 years ago
|
void DirectoryView::slotFolderSelected( TQListViewItem *i )
|
||
15 years ago
|
{
|
||
|
if ( !i ) return;
|
||
|
|
||
|
Directory *dir = (Directory*)i;
|
||
|
emit folderSelected( dir->fullName() );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString DirectoryView::fullPath(TQListViewItem* item)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString fullpath = item->text(0);
|
||
15 years ago
|
while ( (item=item->parent()) ) {
|
||
|
if ( item->parent() )
|
||
|
fullpath = item->text(0) + "/" + fullpath;
|
||
|
else
|
||
|
fullpath = item->text(0) + fullpath;
|
||
|
}
|
||
|
return fullpath;
|
||
|
}
|
||
|
|
||
15 years ago
|
void DirectoryView::setDir( const TQString &s )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItemIterator it( this );
|
||
15 years ago
|
++it;
|
||
|
for ( ; it.current(); ++it ) {
|
||
|
it.current()->setOpen( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList lst( TQStringList::split( "/", s ) );
|
||
|
TQListViewItem *item = firstChild();
|
||
|
TQStringList::Iterator it2 = lst.begin();
|
||
15 years ago
|
for ( ; it2 != lst.end(); ++it2 ) {
|
||
|
while ( item ) {
|
||
|
if ( item->text( 0 ) == *it2 ) {
|
||
|
item->setOpen( true );
|
||
|
break;
|
||
|
}
|
||
|
item = item->itemBelow();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( item ){
|
||
|
setSelected( item, true );
|
||
|
setCurrentItem( item );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString DirectoryView::selectedDir()
|
||
15 years ago
|
{
|
||
|
Directory *dir = (Directory*)currentItem();
|
||
|
return dir->fullName();
|
||
|
}
|
||
|
/**********************************************************************************************/
|
||
|
|
||
|
int main(int argc, char* argv[]) {
|
||
|
KApplication app(argc,argv,"kdockwidgetdemo");
|
||
|
|
||
|
#if 0
|
||
|
SFileDialog* openfile = new SFileDialog();
|
||
|
openfile->exec();
|
||
|
qDebug( openfile->fileName() );
|
||
|
#endif
|
||
|
|
||
|
#if 0
|
||
14 years ago
|
qDebug ( SFileDialog::getOpenFileName( TQString::null, TQString::tqfromLatin1("All (*)"),
|
||
|
TQString::tqfromLatin1("DockWidget Demo"), "dialog1" ) );
|
||
15 years ago
|
#endif
|
||
|
|
||
|
#if 1
|
||
14 years ago
|
TQStringList s = SFileDialog::getOpenFileNames( TQString::null, TQString::tqfromLatin1("All (*)"),
|
||
|
TQString::tqfromLatin1("DockWidget Demo"), "dialog1" );
|
||
15 years ago
|
TQStringList::Iterator it = s.begin();
|
||
15 years ago
|
for ( ; it != s.end(); ++it ){
|
||
|
qDebug( "%s", (*it).local8Bit().data() );
|
||
|
}
|
||
|
#endif
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
#include "kdockwidgetdemo.moc"
|
||
|
|