Skip to content

Commit

Permalink
Shell|GUI: Folder selector can have an extra descriptive label
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 13, 2013
1 parent 7662887 commit 73f3a30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 18 additions & 3 deletions doomsday/tools/shell/shell-gui/src/folderselection.cpp
Expand Up @@ -21,14 +21,15 @@
#include <QPushButton>
#include <QHBoxLayout>
#include <QFileDialog>
#include <QLabel>

DENG2_PIMPL(FolderSelection)
{
QString prompt;
QLineEdit *edit;
QPushButton *button;

Instance(Public &i) : Base(i),
Instance(Public &i, QString extraLabel) : Base(i),
edit(0),
button(0)
{
Expand All @@ -44,6 +45,12 @@ DENG2_PIMPL(FolderSelection)
layout->setContentsMargins(0, 0, 0, 0);
self.setLayout(layout);

if(!extraLabel.isEmpty())
{
QLabel *lab = new QLabel(extraLabel);
layout->addWidget(lab, 0);
}

edit = new QLineEdit;
edit->setMinimumWidth(280);
button = new QPushButton(tr("..."));
Expand All @@ -54,10 +61,16 @@ DENG2_PIMPL(FolderSelection)
};

FolderSelection::FolderSelection(QString const &prompt, QWidget *parent)
: QWidget(parent), d(new Instance(*this))
: QWidget(parent), d(new Instance(*this, ""))
{
d->prompt = prompt;
connect(d->button, SIGNAL(clicked()), this, SLOT(selectFolder()));
}

FolderSelection::FolderSelection(QString const &prompt, QString const &extraLabel, QWidget *parent)
: QWidget(parent), d(new Instance(*this, extraLabel))
{
d->prompt = prompt;
connect(d->button, SIGNAL(clicked()), this, SLOT(selectFolder()));
}

Expand All @@ -78,7 +91,9 @@ de::NativePath FolderSelection::path() const

void FolderSelection::selectFolder()
{
QString dir = QFileDialog::getExistingDirectory(0, d->prompt, d->edit->text());
QString initial = d->edit->text();
if(initial.isEmpty()) initial = QDir::homePath();
QString dir = QFileDialog::getExistingDirectory(0, d->prompt, initial);
if(!dir.isEmpty())
{
d->edit->setText(dir);
Expand Down
1 change: 1 addition & 0 deletions doomsday/tools/shell/shell-gui/src/folderselection.h
Expand Up @@ -32,6 +32,7 @@ class FolderSelection : public QWidget

public:
explicit FolderSelection(QString const &prompt, QWidget *parent = 0);
explicit FolderSelection(QString const &prompt, QString const &extraLabel, QWidget *parent = 0);
virtual ~FolderSelection();

void setPath(de::NativePath const &path);
Expand Down

0 comments on commit 73f3a30

Please sign in to comment.