| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * RTNet GUI
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: t_selWin
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: Widget for File/Directory Selection
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 08-Jan-2013
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include "selwin.h"
|
|---|
| 19 |
|
|---|
| 20 | using namespace std;
|
|---|
| 21 | using namespace GnssCenter;
|
|---|
| 22 |
|
|---|
| 23 | // Constructor
|
|---|
| 24 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 25 | t_selWin::t_selWin(t_selWin::Mode mode, QWidget* parent) : QWidget(parent) {
|
|---|
| 26 |
|
|---|
| 27 | _mode = mode;
|
|---|
| 28 |
|
|---|
| 29 | QHBoxLayout* layout = new QHBoxLayout( this );
|
|---|
| 30 | layout->setMargin(0);
|
|---|
| 31 |
|
|---|
| 32 | _lineEdit = new QLineEdit(this);
|
|---|
| 33 | layout->addWidget(_lineEdit);
|
|---|
| 34 |
|
|---|
| 35 | connect(_lineEdit, SIGNAL(textEdited(const QString &)),
|
|---|
| 36 | this, SLOT(slotTextEdited()));
|
|---|
| 37 |
|
|---|
| 38 | _button = new QPushButton("...", this);
|
|---|
| 39 | _button->setFixedWidth(_button->fontMetrics().width(" ... "));
|
|---|
| 40 | layout->addWidget(_button);
|
|---|
| 41 |
|
|---|
| 42 | connect(_button, SIGNAL(clicked()), this, SLOT(slotChooseFile()));
|
|---|
| 43 | setFocusProxy(_lineEdit);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | // Destructor
|
|---|
| 47 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 48 | t_selWin::~t_selWin() {
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | //
|
|---|
| 52 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 53 | void t_selWin::setFileNames(const QStringList& fileNames) {
|
|---|
| 54 | _fileNames = fileNames;
|
|---|
| 55 | setLineEditText();
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | //
|
|---|
| 59 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 60 | void t_selWin::setLineEditText() {
|
|---|
| 61 | if (_fileNames.size() == 0) {
|
|---|
| 62 | _lineEdit->setText("");
|
|---|
| 63 | }
|
|---|
| 64 | else if (_fileNames.size() == 1) {
|
|---|
| 65 | _lineEdit->setText(_fileNames[0]);
|
|---|
| 66 | }
|
|---|
| 67 | else if (_fileNames.size() > 1) {
|
|---|
| 68 | _lineEdit->setText(QString("SELECTED (%1 FILES)").arg(_fileNames.size()));
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | //
|
|---|
| 73 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 74 | const QStringList& t_selWin::fileNames() const {
|
|---|
| 75 | return _fileNames;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | //
|
|---|
| 79 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 80 | void t_selWin::slotTextEdited() {
|
|---|
| 81 | _fileNames.clear();
|
|---|
| 82 | if (!_lineEdit->text().isEmpty()) {
|
|---|
| 83 | _fileNames << _lineEdit->text();
|
|---|
| 84 | }
|
|---|
| 85 | emit fileNamesChanged();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | //
|
|---|
| 89 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 90 | void t_selWin::slotChooseFile() {
|
|---|
| 91 | if (mode() == File) {
|
|---|
| 92 | QString fileName = QFileDialog::getOpenFileName(this);
|
|---|
| 93 | if (!fileName.isEmpty()) {
|
|---|
| 94 | _fileNames.clear();
|
|---|
| 95 | _fileNames << fileName;
|
|---|
| 96 | emit fileNamesChanged();
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | else if (mode() == Files) {
|
|---|
| 100 | QStringList fileNames = QFileDialog::getOpenFileNames(this);
|
|---|
| 101 | if (fileNames.size()) {
|
|---|
| 102 | _fileNames = fileNames;
|
|---|
| 103 | emit fileNamesChanged();
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 | else {
|
|---|
| 107 | QString dirName = QFileDialog::getExistingDirectory(this);
|
|---|
| 108 | if (!dirName.isEmpty()) {
|
|---|
| 109 | _fileNames.clear();
|
|---|
| 110 | _fileNames << dirName;
|
|---|
| 111 | emit fileNamesChanged();
|
|---|
| 112 | }
|
|---|
| 113 | }
|
|---|
| 114 | setLineEditText();
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|