[Kst] branches/work/kst/portto4/kst/src/widgets
Mike Fenton
mike at staikos.net
Tue Jan 29 22:47:19 CET 2008
SVN commit 768363 by fenton:
Update fileRequester to do autocompletion of the path.
M +17 -15 filerequester.cpp
M +2 -0 filerequester.h
--- branches/work/kst/portto4/kst/src/widgets/filerequester.cpp #768362:768363
@@ -16,6 +16,8 @@
#include <QToolButton>
#include <QHBoxLayout>
#include <QFileDialog>
+#include <QDirModel>
+#include <QCompleter>
#include <QDebug>
@@ -23,31 +25,27 @@
FileRequester::FileRequester(QWidget *parent)
: QWidget(parent) {
+ setup();
+}
- _fileEdit = new QLineEdit(this);
- _fileButton = new QToolButton(this);
- QHBoxLayout * layout = new QHBoxLayout(this);
- layout->setMargin(0);
- layout->addWidget(_fileEdit);
- layout->addWidget(_fileButton);
- setLayout(layout);
+FileRequester::FileRequester(const QString &file, QWidget *parent)
+ : QWidget(parent), _file(file) {
+ setup();
+}
- _fileButton->setIcon(QPixmap(":kst_changefile.png"));
- setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
- connect (_fileEdit, SIGNAL(textChanged(const QString &)), this, SLOT(setFile(const QString &)));
- connect (_fileButton, SIGNAL(clicked()), this, SLOT(chooseFile()));
+FileRequester::~FileRequester() {
}
-FileRequester::FileRequester(const QString &file, QWidget *parent)
- : QWidget(parent), _file(file) {
+void FileRequester::setup() {
_fileEdit = new QLineEdit(this);
_fileButton = new QToolButton(this);
QHBoxLayout * layout = new QHBoxLayout(this);
+ layout->setMargin(0);
layout->addWidget(_fileEdit);
layout->addWidget(_fileButton);
setLayout(layout);
@@ -59,10 +57,14 @@
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
connect (_fileEdit, SIGNAL(textEdited(const QString &)), this, SLOT(setFile(const QString &)));
connect (_fileButton, SIGNAL(clicked()), this, SLOT(chooseFile()));
-}
+ QDirModel *dirModel = new QDirModel(this);
+ dirModel->setFilter(QDir::AllEntries);
-FileRequester::~FileRequester() {
+ QCompleter *completer = new QCompleter(this);
+ completer->setModel(dirModel);
+
+ _fileEdit->setCompleter(completer);
}
--- branches/work/kst/portto4/kst/src/widgets/filerequester.h #768362:768363
@@ -41,6 +41,8 @@
void chooseFile();
private:
+ void setup();
+
QLineEdit *_fileEdit;
QToolButton *_fileButton;
QString _file;
More information about the Kst
mailing list