2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file LyXFileDialog.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "LyXFileDialog.h"
|
2006-08-17 08:45:48 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QToolButton>
|
2006-05-07 10:20:43 +00:00
|
|
|
#include <QHBoxLayout>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
namespace lyx {
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// return the Qt form of the label
|
2008-03-05 23:10:53 +00:00
|
|
|
static QString getLabel(QString const & qstr)
|
2007-09-10 19:02:11 +00:00
|
|
|
{
|
2008-03-05 23:10:53 +00:00
|
|
|
// FIXME UNICODE (or "qt-ify")
|
|
|
|
string str = fromqstr(qstr);
|
2006-03-05 17:24:44 +00:00
|
|
|
string label;
|
2007-09-10 19:02:11 +00:00
|
|
|
string sc = split(str, label, '|');
|
2006-03-05 17:24:44 +00:00
|
|
|
if (sc.length() < 2)
|
2008-03-05 23:10:53 +00:00
|
|
|
return toqstr(label);
|
2007-11-23 21:39:51 +00:00
|
|
|
size_t pos = label.find(sc[1]);
|
|
|
|
if (pos != string::npos)
|
|
|
|
label.insert(pos, 1, '&');
|
2008-03-05 23:10:53 +00:00
|
|
|
return toqstr(label);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
LyXFileDialog::LyXFileDialog(QString const & title,
|
|
|
|
QString const & path,
|
2008-04-20 19:56:01 +00:00
|
|
|
QStringList const & filters,
|
2006-03-05 17:24:44 +00:00
|
|
|
FileDialog::Button const & b1,
|
|
|
|
FileDialog::Button const & b2)
|
2007-11-18 20:36:52 +00:00
|
|
|
// FIXME replace that with guiApp->currentView()
|
2008-04-20 19:56:01 +00:00
|
|
|
: QFileDialog(qApp->focusWidget(), title, path)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2013-02-03 11:23:31 +00:00
|
|
|
setNameFilters(filters);
|
2008-03-05 23:10:53 +00:00
|
|
|
setWindowTitle(title);
|
2013-12-24 16:21:56 +00:00
|
|
|
setOption(QFileDialog::DontUseNativeDialog);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-07 10:20:43 +00:00
|
|
|
QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
|
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
if (!b1.first.isEmpty()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
b1_dir_ = b1.second;
|
2007-10-28 16:32:20 +00:00
|
|
|
QToolButton * tb = new QToolButton(this);
|
2007-11-13 00:38:21 +00:00
|
|
|
connect(tb, SIGNAL(clicked()), this, SLOT(button1Clicked()));
|
2008-03-05 23:10:53 +00:00
|
|
|
tb->setText(getLabel(b1.first));
|
2007-10-28 16:32:20 +00:00
|
|
|
layout.at(0)->addWidget(tb);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
if (!b2.first.isEmpty()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
b2_dir_ = b2.second;
|
2007-10-28 16:32:20 +00:00
|
|
|
QToolButton * tb = new QToolButton(this);
|
2007-11-13 00:38:21 +00:00
|
|
|
connect(tb, SIGNAL(clicked()), this, SLOT(button2Clicked()));
|
2008-03-05 23:10:53 +00:00
|
|
|
tb->setText(getLabel(b2.first));
|
2007-10-28 16:32:20 +00:00
|
|
|
layout.at(0)->addWidget(tb);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-28 16:32:20 +00:00
|
|
|
void LyXFileDialog::button1Clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-03-05 23:10:53 +00:00
|
|
|
setDirectory(b1_dir_);
|
2007-10-28 16:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXFileDialog::button2Clicked()
|
|
|
|
{
|
2008-03-05 23:10:53 +00:00
|
|
|
setDirectory(b2_dir_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_LyXFileDialog.cpp"
|