From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- examples/qdir/qdir.cpp | 359 +++++++++++++++++++++++++++++++++++++++++++++++++ examples/qdir/qdir.doc | 15 +++ examples/qdir/qdir.h | 98 ++++++++++++++ examples/qdir/qdir.pro | 10 ++ 4 files changed, 482 insertions(+) create mode 100644 examples/qdir/qdir.cpp create mode 100644 examples/qdir/qdir.doc create mode 100644 examples/qdir/qdir.h create mode 100644 examples/qdir/qdir.pro (limited to 'examples/qdir') diff --git a/examples/qdir/qdir.cpp b/examples/qdir/qdir.cpp new file mode 100644 index 0000000..346c3ed --- /dev/null +++ b/examples/qdir/qdir.cpp @@ -0,0 +1,359 @@ +/**************************************************************************** +** +** 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 "../dirview/dirview.h" +#include "qdir.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* XPM */ +static const char *bookmarks[]={ + "22 14 8 1", + "# c #000080", + "a c #585858", + "b c #000000", + "c c #ffffff", + "d c #ffffff", + "e c #ffffff", + "f c #000000", + ". c None", + "...bb.................", + "..bacb....bbb.........", + "..badcb.bbccbab.......", + "..bacccbadccbab.......", + "..baecdbcccdbab.......", + "..bacccbacccbab.......", + "..badcdbcecdfab.......", + "..bacecbacccbab.......", + "..baccdbcccdbab.......", + "...badcbacdbbab.......", + "....bacbcbbccab.......", + ".....babbaaaaab.......", + ".....bbabbbbbbb.......", + "......bb.............." +}; + +/* XPM */ +static const char *home[]={ + "16 15 4 1", + "# c #000000", + "a c #ffffff", + "b c #c0c0c0", + ". c None", + ".......##.......", + "..#...####......", + "..#..#aabb#.....", + "..#.#aaaabb#....", + "..##aaaaaabb#...", + "..#aaaaaaaabb#..", + ".#aaaaaaaaabbb#.", + "###aaaaaaaabb###", + "..#aaaaaaaabb#..", + "..#aaa###aabb#..", + "..#aaa#.#aabb#..", + "..#aaa#.#aabb#..", + "..#aaa#.#aabb#..", + "..#aaa#.#aabb#..", + "..#####.######.." +}; + +// **************************************************************************************************** + +PixmapView::PixmapView( QWidget *parent ) + : QScrollView( parent ) +{ + viewport()->setBackgroundMode( PaletteBase ); +} + +void PixmapView::setPixmap( const QPixmap &pix ) +{ + pixmap = pix; + resizeContents( pixmap.size().width(), pixmap.size().height() ); + viewport()->repaint( FALSE ); +} + +void PixmapView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) +{ + p->fillRect( cx, cy, cw, ch, colorGroup().brush( QColorGroup::Base ) ); + p->drawPixmap( 0, 0, pixmap ); +} + +// **************************************************************************************************** + +Preview::Preview( QWidget *parent ) + : QWidgetStack( parent ) +{ + normalText = new QMultiLineEdit( this ); + normalText->setReadOnly( TRUE ); + html = new QTextView( this ); + pixmap = new PixmapView( this ); + raiseWidget( normalText ); +} + +void Preview::showPreview( const QUrl &u, int size ) +{ + if ( u.isLocalFile() ) { + QString path = u.path(); + QFileInfo fi( path ); + if ( fi.isFile() && (int)fi.size() > size * 1000 ) { + normalText->setText( tr( "The File\n%1\nis too large, so I don't show it!" ).arg( path ) ); + raiseWidget( normalText ); + return; + } + + QPixmap pix( path ); + if ( pix.isNull() ) { + if ( fi.isFile() ) { + QFile f( path ); + if ( f.open( IO_ReadOnly ) ) { + QTextStream ts( &f ); + QString text = ts.read(); + f.close(); + if ( fi.extension().lower().contains( "htm" ) ) { + QString url = html->mimeSourceFactory()->makeAbsolute( path, html->context() ); + html->setText( text, url ); + raiseWidget( html ); + return; + } else { + normalText->setText( text ); + raiseWidget( normalText ); + return; + } + } + } + normalText->setText( QString::null ); + raiseWidget( normalText ); + } else { + pixmap->setPixmap( pix ); + raiseWidget( pixmap ); + } + } else { + normalText->setText( "I only show local files!" ); + raiseWidget( normalText ); + } +} + +// **************************************************************************************************** + +PreviewWidget::PreviewWidget( QWidget *parent ) + : QVBox( parent ), QFilePreview() +{ + setSpacing( 5 ); + setMargin( 5 ); + QHBox *row = new QHBox( this ); + row->setSpacing( 5 ); + (void)new QLabel( tr( "Only show files smaller than: " ), row ); + sizeSpinBox = new QSpinBox( 1, 10000, 1, row ); + sizeSpinBox->setSuffix( " KB" ); + sizeSpinBox->setValue( 64 ); + row->setFixedHeight( 10 + sizeSpinBox->sizeHint().height() ); + preview = new Preview( this ); +} + +void PreviewWidget::previewUrl( const QUrl &u ) +{ + preview->showPreview( u, sizeSpinBox->value() ); +} + +// **************************************************************************************************** + +CustomFileDialog::CustomFileDialog() + : QFileDialog( 0, 0, TRUE ) +{ + setDir( "/" ); + + dirView = new DirectoryView( this, 0, TRUE ); + dirView->addColumn( "" ); + dirView->header()->hide(); + ::Directory *root = new ::Directory( dirView, "/" ); + root->setOpen( TRUE ); + dirView->setFixedWidth( 150 ); + + addLeftWidget( dirView ); + + QPushButton *p = new QPushButton( this ); + p->setPixmap( QPixmap( bookmarks ) ); + QToolTip::add( p, tr( "Bookmarks" ) ); + + bookmarkMenu = new QPopupMenu( this ); + connect( bookmarkMenu, SIGNAL( activated( int ) ), + this, SLOT( bookmarkChosen( int ) ) ); + addId = bookmarkMenu->insertItem( tr( "Add bookmark" ) ); + bookmarkMenu->insertSeparator(); + + QFile f( ".bookmarks" ); + if ( f.open( IO_ReadOnly ) ) { + QDataStream ds( &f ); + ds >> bookmarkList; + f.close(); + + QStringList::Iterator it = bookmarkList.begin(); + for ( ; it != bookmarkList.end(); ++it ) { + bookmarkMenu->insertItem( *it ); + } + } + + p->setPopup( bookmarkMenu ); + + addToolButton( p, TRUE ); + + connect( dirView, SIGNAL( folderSelected( const QString & ) ), + this, SLOT( setDir2( const QString & ) ) ); + connect( this, SIGNAL( dirEntered( const QString & ) ), + dirView, SLOT( setDir( const QString & ) ) ); + + QToolButton *b = new QToolButton( this ); + QToolTip::add( b, tr( "Go Home!" ) ); + b->setPixmap( QPixmap( home ) ); + connect( b, SIGNAL( clicked() ), + this, SLOT( goHome() ) ); + + addToolButton( b ); + + resize( width() + width() / 3, height() ); +} + +CustomFileDialog::~CustomFileDialog() +{ + if ( !bookmarkList.isEmpty() ) { + QFile f( ".bookmarks" ); + if ( f.open( IO_WriteOnly ) ) { + QDataStream ds( &f ); + ds << bookmarkList; + f.close(); + } + } +} + +void CustomFileDialog::setDir2( const QString &s ) +{ + blockSignals( TRUE ); + setDir( s ); + blockSignals( FALSE ); +} + +void CustomFileDialog::showEvent( QShowEvent *e ) +{ + QFileDialog::showEvent( e ); + dirView->setDir( dirPath() ); +} + +void CustomFileDialog::bookmarkChosen( int i ) +{ + if ( i == addId ) { + bookmarkList << dirPath(); + bookmarkMenu->insertItem( dirPath() ); + } else { + setDir( bookmarkMenu->text( i ) ); + } +} + +void CustomFileDialog::goHome() +{ + if ( getenv( "HOME" ) ) + setDir( getenv( "HOME" ) ); + else + setDir( "/" ); +} + +// **************************************************************************************************** + +int main( int argc, char ** argv ) +{ + QFileDialog::Mode mode = QFileDialog::ExistingFile; + QString start; + QString filter; + QString caption; + bool preview = FALSE; + bool custom = FALSE; + QApplication a( argc, argv ); + for (int i=1; i + + Main: + + \include qdir/qdir.cpp +*/ + diff --git a/examples/qdir/qdir.h b/examples/qdir/qdir.h new file mode 100644 index 0000000..a4bee8f --- /dev/null +++ b/examples/qdir/qdir.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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. +** +*****************************************************************************/ + +#ifndef QDIREXAMPLE_H +#define QDIREXAMPLE_H + +#include +#include +#include +#include +#include +#include +#include + +class QMultiLineEdit; +class QTextView; +class DirectoryView; +class QSpinBox; +class QShowEvent; +class QPopupMenu; + +class PixmapView : public QScrollView +{ + Q_OBJECT + +public: + PixmapView( QWidget *parent ); + void setPixmap( const QPixmap &pix ); + void drawContents( QPainter *p, int, int, int, int ); + +private: + QPixmap pixmap; + +}; + +class Preview : public QWidgetStack +{ + Q_OBJECT + +public: + Preview( QWidget *parent ); + void showPreview( const QUrl &u, int size ); + +private: + QMultiLineEdit *normalText; + QTextView *html; + PixmapView *pixmap; + +}; + +class PreviewWidget : public QVBox, + public QFilePreview +{ + Q_OBJECT + +public: + PreviewWidget( QWidget *parent ); + void previewUrl( const QUrl &u ); + +private: + QSpinBox *sizeSpinBox; + Preview *preview; + +}; + +class CustomFileDialog : public QFileDialog +{ + Q_OBJECT + +public: + CustomFileDialog(); + ~CustomFileDialog(); + +protected: + void showEvent( QShowEvent *e ); + +public slots: + void setDir2( const QString & ); + +private slots: + void bookmarkChosen( int i ); + void goHome(); + +private: + DirectoryView *dirView; + QPopupMenu *bookmarkMenu; + QStringList bookmarkList; + int addId; + +}; + +#endif diff --git a/examples/qdir/qdir.pro b/examples/qdir/qdir.pro new file mode 100644 index 0000000..fa7a0f6 --- /dev/null +++ b/examples/qdir/qdir.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = qdir + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = qdir.h ../dirview/dirview.h +SOURCES = qdir.cpp ../dirview/dirview.cpp -- cgit v1.2.3