00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "qdirlineedit.h"
00021
00022
#include <qlineedit.h>
00023
#include <qlayout.h>
00024
#include <kpushbutton.h>
00025
#include <kfiledialog.h>
00026
#include <kiconloader.h>
00027
00028 QDirLineEdit::QDirLineEdit(
QWidget *parent,
const char *name)
00029 :
QWidget(parent, name)
00030 {
00031 edit_ =
new QLineEdit(
this);
00032
00033 button_ =
new KPushButton(
this);
00034 button_->setPixmap(SmallIcon(
"fileopen"));
00035 connect(button_,SIGNAL(clicked()),SLOT(buttonClicked()));
00036
00037
QHBoxLayout *main_ =
new QHBoxLayout(
this, 0, 10);
00038 main_->addWidget(edit_);
00039 main_->addWidget(button_);
00040
00041 fileedit_ =
false;
00042 }
00043
00044 QDirLineEdit::~QDirLineEdit()
00045 {
00046 }
00047
00048
void QDirLineEdit::setText(
const QString& txt)
00049 {
00050 edit_->setText(txt);
00051 }
00052
00053
void QDirLineEdit::setButtonText(
const QString& txt)
00054 {
00055 button_->setText(txt);
00056 }
00057
00058
QString QDirLineEdit::text()
00059 {
00060
return edit_->text();
00061 }
00062
00063
QSize QDirLineEdit::sizeHint()
const
00064
{
00065
QSize s1(edit_->sizeHint()), s2(button_->sizeHint());
00066
return QSize(s1.
width()+s2.width()+10,s1.
height());
00067 }
00068
00069
void QDirLineEdit::buttonClicked()
00070 {
00071
QString dirname;
00072
if (!fileedit_) dirname = KFileDialog::getExistingDirectory(edit_->text(),
this);
00073
else dirname = KFileDialog::getOpenFileName(edit_->text(), QString::null,
this);
00074
if (!dirname.
isEmpty()) edit_->setText(dirname);
00075 }
00076
00077
void QDirLineEdit::setFileEdit(
bool on)
00078 {
00079 fileedit_ = on;
00080 }
00081
#include "qdirlineedit.moc"