diff options
author | Alessio Treglia <alessio@debian.org> | 2012-02-16 11:08:45 +0100 |
---|---|---|
committer | Alessio Treglia <alessio@debian.org> | 2012-02-16 11:08:45 +0100 |
commit | 65a64d260e05c7bf8d3bdf82e796637dc820e574 (patch) | |
tree | 600c2becea7f28fdefff51200bb3ed33514e4cc7 /src/filechooser.cpp | |
parent | 1d323e54ee434609cf035598486075c9a918a2d3 (diff) |
Imported Upstream version 0.7.0
Diffstat (limited to 'src/filechooser.cpp')
-rw-r--r-- | src/filechooser.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/src/filechooser.cpp b/src/filechooser.cpp index 8de459d..85d4954 100644 --- a/src/filechooser.cpp +++ b/src/filechooser.cpp @@ -1,5 +1,5 @@ /* smplayer, GUI front-end for mplayer. - Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org> + Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,6 +17,8 @@ */ #include "filechooser.h" +#include <QToolButton> +#include <QStyle> //#define NO_SMPLAYER_SUPPORT @@ -27,40 +29,34 @@ #include <QFileDialog> #endif -FileChooser::FileChooser(QWidget * parent) : QWidget(parent) -{ - setupUi(this); - -#ifndef NO_SMPLAYER_SUPPORT - button->setIcon(Images::icon("find")); -#else - button->setIcon(QIcon(":/find")); -#endif +QString FileChooser::last_dir; +FileChooser::FileChooser(QWidget * parent) : LineEditWithIcon(parent) +{ setDialogType(GetFileName); setOptions(0); -} -FileChooser::~FileChooser() { -} + setupButton(); + button->setCursor( Qt::PointingHandCursor ); -QLineEdit * FileChooser::lineEdit() { - return line_edit; + connect(button, SIGNAL(clicked()), this, SLOT(openFileDialog())); } -QToolButton * FileChooser::toolButton() { - return button; +FileChooser::~FileChooser() { } -QString FileChooser::text() const { - return line_edit->text(); +void FileChooser::setupButton() { +#ifdef NO_SMPLAYER_SUPPORT + setIcon( QPixmap(":/folder_open") ); +#else + setIcon( Images::icon("folder_open") ); +#endif + button->setToolTip( tr("Click to select a file or folder") ); } -void FileChooser::setText(const QString & text) { - line_edit->setText(text); -} +void FileChooser::openFileDialog() { + qDebug("FileChooser::openFileDialog"); -void FileChooser::on_button_clicked() { QString result; QString f; @@ -68,35 +64,42 @@ void FileChooser::on_button_clicked() { QFileDialog::Options opts = options(); if (opts == 0) opts = QFileDialog::DontResolveSymlinks; + QString dir = QFileInfo(text()).absolutePath(); + if (dir.isEmpty()) dir = last_dir; + #ifndef NO_SMPLAYER_SUPPORT result = MyFileDialog::getOpenFileName( #else result = QFileDialog::getOpenFileName( #endif this, caption(), - line_edit->text(), + dir, filter(), &f, opts ); + if (!result.isEmpty()) last_dir = QFileInfo(result).absolutePath(); } else if (dialogType() == GetDirectory) { QFileDialog::Options opts = options(); if (opts == 0) opts = QFileDialog::ShowDirsOnly; + QString dir = text(); + if (dir.isEmpty()) dir = last_dir; + #ifndef NO_SMPLAYER_SUPPORT result = MyFileDialog::getExistingDirectory( #else result = QFileDialog::getExistingDirectory( #endif this, caption(), - line_edit->text(), opts ); + dir, opts ); + if (!result.isEmpty()) last_dir = result; } if (!result.isEmpty()) { - QString old_file = line_edit->text(); - line_edit->setText(result); + QString old_file = text(); + setText(result); if (old_file != result) emit fileChanged(result); } } #include "moc_filechooser.cpp" - |