Commit 4409e66b authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Moved file picker widget from ACG to OpenFlipper. (It has OpenFlipper dependencies, that's why.)


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17652 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c9c06f26
......@@ -68,6 +68,7 @@ set (directories
../widgets/stereoSettingsWidget
../widgets/postProcessorWidget
../widgets/rendererWidget
../widgets/filePicker
${WIN_EXTRA_DIRS}
)
......
/*
* FilePicker.cc
*
* Created on: Jan 8, 2013
* Author: ebke
*/
#include "FilePicker.hh"
#include <QHBoxLayout>
#include <QMessageBox>
FilePicker::FilePicker(QWidget *parent) :
QWidget(parent),
textBox_(new QComboBox),
browseButton_(new QPushButton(trUtf8("Browse…"))),
recent_files_ini_key_("GenericFilePickerRecents"),
dialog_type_(DT_OPEN_FILE),
overwrite_confirmed_by_user_(false) {
init();
}
FilePicker::FilePicker(QString recent_files_ini_key,
DialogType dialog_type,
QWidget *parent) :
QWidget(parent),
textBox_(new QComboBox),
browseButton_(new QPushButton(trUtf8("Browse…"))),
recent_files_ini_key_(recent_files_ini_key),
dialog_type_(dialog_type),
overwrite_confirmed_by_user_(false) {
init();
}
void FilePicker::init() {
/*
* Do layout stuff.
*/
textBox_->setSizePolicy(QSizePolicy::MinimumExpanding,
textBox_->sizePolicy().verticalPolicy());
textBox_->setEditable(true);
textBox_->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(textBox_);
layout->addWidget(browseButton_);
/*
* Do functional stuff.
*/
textBox_->insertItems(
0,
OpenFlipper::Options::getRecentItems(recent_files_ini_key()));
connect(browseButton_, SIGNAL( clicked() ), this, SLOT( slot_browse() ));
//editTextChanged(const QString &);
connect(textBox_, SIGNAL( editTextChanged(const QString &) ),
this, SLOT( path_changed() ));
}
void FilePicker::set_recent_files_ini_key(QString value) {
recent_files_ini_key_ = value;
textBox_->clear();
textBox_->insertItems(
0,
OpenFlipper::Options::getRecentItems(recent_files_ini_key_));
}
void FilePicker::path_changed() {
overwrite_confirmed_by_user_ = false;
}
bool FilePicker::confirm_overwrite_if_necessary() {
if (overwrite_confirmed_by_user()) return true;
if (dialog_type() != DT_SAVE_FILE) return true;
if (!QFile::exists(currentFileName())) return true;
const QString file_name = QFileInfo(currentFileName()).fileName();
const QMessageBox::StandardButton result =
QMessageBox::question(
this, trUtf8("Overwrite File?"),
trUtf8("The file \"%1\" exists. "
"Do you want to overwrite?")
.arg(file_name),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (result == QMessageBox::Yes) {
overwrite_confirmed_by_user_ = true;
return true;
} else {
return false;
}
}
void FilePicker::slot_browse() {
OpenFlipper::Options::obtainPathName(
textBox_,
dialog_title().toUtf8().constData(),
file_filter().toUtf8().constData(),
recent_files_ini_key().toUtf8().constData(),
static_cast<OpenFlipper::Options::DialogType>(dialog_type()));
std::cout << "overwrite confirmed." << std::endl;
overwrite_confirmed_by_user_ = true;
}
FilePicker::~FilePicker() {
}
/*
* FilePicker.hh
*
* Created on: Jan 8, 2013
* Author: ebke
*/
#ifndef FILEPICKER_HH_
#define FILEPICKER_HH_
#include <QWidget>
#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <OpenFlipper/common/RecentFiles.hh>
class FilePicker : public QWidget {
Q_OBJECT
Q_PROPERTY(QString recent_files_ini_key
READ recent_files_ini_key
WRITE set_recent_files_ini_key)
Q_PROPERTY(QString dialog_title
READ dialog_title
WRITE set_dialog_title)
Q_PROPERTY(QString file_filter
READ file_filter
WRITE set_file_filter)
Q_PROPERTY(DialogType dialog_type
READ dialog_type
WRITE set_dialog_type)
Q_PROPERTY(QString current_file_name
READ current_file_name
WRITE set_current_file_name)
Q_ENUMS(DialogType)
public:
enum DialogType {
DT_OPEN_FILE = OpenFlipper::Options::DT_OPEN,
DT_SAVE_FILE = OpenFlipper::Options::DT_SAVE,
DT_CHOOSE_PATH = OpenFlipper::Options::DT_CHOOSE_PATH
};
explicit FilePicker(QWidget *parent = 0);
explicit FilePicker(QString recent_files_ini_key,
DialogType dialog_type,
QWidget *parent = 0);
virtual ~FilePicker();
QString current_file_name() {
return textBox_->currentText();
}
void set_current_file_name(QString value) {
return textBox_->lineEdit()->setText(value);
}
// Legacy:
QString currentFileName() {
return current_file_name();
}
QString recent_files_ini_key() { return recent_files_ini_key_; }
void set_recent_files_ini_key(QString value);
QString dialog_title() { return dialog_title_; }
void set_dialog_title(QString value) {
dialog_title_ = value;
}
QString file_filter() { return file_filter_; }
void set_file_filter(QString value) {
file_filter_ = value;
}
DialogType dialog_type() { return dialog_type_; }
void set_dialog_type(DialogType value) {
dialog_type_ = value;
}
bool overwrite_confirmed_by_user() {
return overwrite_confirmed_by_user_;
}
public slots:
bool confirm_overwrite_if_necessary();
protected slots:
void slot_browse();
void path_changed();
private:
void init();
protected:
QComboBox *textBox_;
QPushButton *browseButton_;
QString recent_files_ini_key_;
QString dialog_title_;
QString file_filter_;
DialogType dialog_type_;
bool overwrite_confirmed_by_user_;
};
#endif /* FILEPICKER_HH_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment