1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/*
* This file is part of the xTuple ERP: PostBooks Edition, a free and
* open source Enterprise Resource Planning software suite,
* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
#include "filecluster.h"
#include <QHBoxLayout>
FileCluster::FileCluster(QWidget* pParent, const char* pName) :
QWidget(pParent)
{
setObjectName(pName);
_caption = tr("Open File");
_dir = "";
_fileMode = QFileDialog::AnyFile;
_filter = "";
QHBoxLayout *hbox = new QHBoxLayout(this);
hbox->setContentsMargins(0, 0, 0, 0); // prevent double margins
_file = new FileLineEdit();
_list = new QPushButton(tr("..."), this);
_list->setObjectName("_list");
_list->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
#ifndef Q_OS_MAC
_list->setMaximumWidth(25);
#endif
hbox->addWidget(_file);
hbox->addWidget(_list);
connect(_file, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
connect(_file, SIGNAL(requestList()), this, SLOT(sEllipses()));
connect(_file, SIGNAL(requestSearch()), this, SLOT(sEllipses()));
connect(_file, SIGNAL(textChanged(const QString&)), this, SIGNAL(textChanged(const QString&)));
connect(_list, SIGNAL(clicked()), this, SLOT(sEllipses()));
}
FileCluster::~FileCluster()
{
}
void FileCluster::sEllipses()
{
QFileDialog newdlg(this, _caption, _dir);
newdlg.setFileMode(_fileMode);
if (! _filter.isEmpty())
{
QStringList filters;
filters << _filter << tr("Any Files (*)");
newdlg.setNameFilters(filters);
}
if (newdlg.exec())
{
_file->setText(newdlg.selectedFiles().join(", "));
emit editingFinished();
}
}
FileLineEdit::FileLineEdit(QWidget *parent)
: QLineEdit(parent)
{
}
void FileLineEdit::keyPressEvent(QKeyEvent *event)
{
bool handled = false;
if (event->modifiers() & Qt::ControlModifier)
{
if (event->key() == Qt::Key_L)
{
emit (requestList());
handled = true;
}
else if (event->key() == Qt::Key_S)
{
emit (requestSearch());
handled = true;
}
}
if (handled)
event->accept();
else
QLineEdit::keyPressEvent(event);
}
|