diff options
| author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:17:53 -0500 |
|---|---|---|
| committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:17:53 -0500 |
| commit | dda8474928bd7276e1fad8fb7a601e7c83ff2bc2 (patch) | |
| tree | 7f83910598b33b12730035f086df20b5a53ab99c /tqtinterface/qt4/tools/designer/examples/filechooser/widget | |
| parent | 6260b6178868c03aab1644bf93b0ef043654bdb0 (diff) | |
| download | experimental-dda8474928bd7276e1fad8fb7a601e7c83ff2bc2.tar.gz experimental-dda8474928bd7276e1fad8fb7a601e7c83ff2bc2.zip | |
Added TQt4 HEAD
Diffstat (limited to 'tqtinterface/qt4/tools/designer/examples/filechooser/widget')
4 files changed, 129 insertions, 0 deletions
diff --git a/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.cpp b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.cpp new file mode 100644 index 0000000..f3f986b --- /dev/null +++ b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.cpp @@ -0,0 +1,62 @@ +#include "filechooser.h" +#include <tqlineedit.h> +#include <tqpushbutton.h> +#include <tqfiledialog.h> +#include <tqlayout.h> + +FileChooser::FileChooser( TQWidget *tqparent, const char *name ) + : TQWidget( tqparent, name ), md( File ) +{ + TQHBoxLayout *tqlayout = new TQHBoxLayout( this ); + tqlayout->setMargin( 0 ); + + lineEdit = new TQLineEdit( this, "filechooser_lineedit" ); + tqlayout->addWidget( lineEdit ); + + connect( lineEdit, TQT_SIGNAL( textChanged( const TQString & ) ), + this, TQT_SIGNAL( fileNameChanged( const TQString & ) ) ); + + button = new TQPushButton( "...", this, "filechooser_button" ); + button->setFixedWidth( button->fontMetrics().width( " ... " ) ); + tqlayout->addWidget( button ); + + connect( button, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( chooseFile() ) ); + + setFocusProxy( lineEdit ); +} + +void FileChooser::setMode( Mode m ) +{ + md = m; +} + +FileChooser::Mode FileChooser::mode() const +{ + return md; +} + +void FileChooser::setFileName( const TQString &fn ) +{ + lineEdit->setText( fn ); +} + +TQString FileChooser::fileName() const +{ + return lineEdit->text(); +} + +void FileChooser::chooseFile() +{ + TQString fn; + if ( mode() == File ) + fn = TQFileDialog::getOpenFileName( lineEdit->text(), TQString(), this ); + else + fn = TQFileDialog::getExistingDirectory( lineEdit->text(),this ); + + if ( !fn.isEmpty() ) { + lineEdit->setText( fn ); + emit fileNameChanged( fn ); + } +} + diff --git a/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.h b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.h new file mode 100644 index 0000000..0062e5b --- /dev/null +++ b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.h @@ -0,0 +1,48 @@ +#ifndef FILECHOOSER_H +#define FILECHOOSER_H + +#include <tqwidget.h> +#include <tqwidgetplugin.h> + +class TQLineEdit; +class TQPushButton; + +#ifdef FILECHOOSER_IS_WIDGET +#undef TQT_WIDGET_PLUGIN_EXPORT +#define TQT_WIDGET_PLUGIN_EXPORT +#endif + +class TQT_WIDGET_PLUGIN_EXPORT FileChooser : public TQWidget +{ + TQ_OBJECT + + TQ_ENUMS( Mode ) + Q_PROPERTY( Mode mode READ mode WRITE setMode ) + Q_PROPERTY( TQString fileName READ fileName WRITE setFileName ) + +public: + FileChooser( TQWidget *tqparent = 0, const char *name = 0); + + enum Mode { File, Directory }; + + TQString fileName() const; + Mode mode() const; + +public Q_SLOTS: + void setFileName( const TQString &fn ); + void setMode( Mode m ); + +Q_SIGNALS: + void fileNameChanged( const TQString & ); + +private Q_SLOTS: + void chooseFile(); + +private: + TQLineEdit *lineEdit; + TQPushButton *button; + Mode md; + +}; + +#endif diff --git a/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.pro b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.pro new file mode 100644 index 0000000..20ea787 --- /dev/null +++ b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/filechooser.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +LANGUAGE = C++ +TARGET = filechooser + +SOURCES += filechooser.cpp main.cpp +HEADERS += filechooser.h +CONFIG += qt warn_on release +DBFILE = filechooser.db +DEFINES += FILECHOOSER_IS_WIDGET diff --git a/tqtinterface/qt4/tools/designer/examples/filechooser/widget/main.cpp b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/main.cpp new file mode 100644 index 0000000..6daaddd --- /dev/null +++ b/tqtinterface/qt4/tools/designer/examples/filechooser/widget/main.cpp @@ -0,0 +1,10 @@ +#include <tqapplication.h> +#include "filechooser.h" + +int main( int argc, char ** argv ) +{ + TQApplication a( argc, argv ); + FileChooser *fc = new FileChooser; + fc->show(); + return a.exec(); +} |
