2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2012 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "dialoglineedit.h"
26 #include <QHBoxLayout>
30 #include "utilities.h"
32 DialogLineEdit::DialogLineEdit(QWidget
*parent
)
38 DialogLineEdit::DialogLineEdit(bool openfile
, QWidget
*parent
)
42 m_openfile
= openfile
;
45 void DialogLineEdit::build()
47 setWindowTitle(tr("lineedit with file/directory selection dialog"));
48 // this->setHeight(25);
49 QHBoxLayout
* layout
= new QHBoxLayout();
50 layout
->setSpacing(-1);
51 this->setContentsMargins(0, 0, 0, 0);
52 layout
->setContentsMargins(0, 0, 0, 0);
53 this->setLayout(layout
);
54 m_button
= new QPushButton(tr("..."));
55 m_lineedit
= new QLineEdit();
56 m_button
->setSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Fixed
);
57 m_lineedit
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
58 layout
->addWidget(m_lineedit
);
59 layout
->addWidget(m_button
);
61 connect(m_button
, SIGNAL(clicked()), this, SLOT(openDialog()));
63 m_button
->setMaximumWidth(16);
64 this->resize(180, 25);
65 // this->resize(0, 0);
66 // setGeometry(10, 40, 180, 40);
68 // by default, open directory and use file dialog
70 m_UseFileDialog
= true;
73 void DialogLineEdit::openDialog()
77 if (m_UseFileDialog
) {
79 // qDebug() << "m_dir=" << m_dir;
80 if (m_openfile
) name
= QFileDialog::getOpenFileName(NULL
, m_caption
, m_dir
, m_filter
);
81 else name
= getDirectory(NULL
, m_caption
, m_dir
);
84 m_lineedit
->setText(name
);
85 m_dir
= name
;//getDir(name);
90 QString
DialogLineEdit::text()
92 return(m_lineedit
->text());
95 void DialogLineEdit::setText(QString str
)
97 m_lineedit
->setText(str
);
98 m_dir
= str
;//getDir(str);
101 bool DialogLineEdit::getMode()
106 void DialogLineEdit::setMode(bool mode
)
111 void DialogLineEdit::setCaption(QString str
)
116 void DialogLineEdit::setDir(QString str
)
121 void DialogLineEdit::setFilter(QString str
)
126 QString
DialogLineEdit::getCaption()
131 QString
DialogLineEdit::getDir()
136 QString
DialogLineEdit::getFilter()
141 // QString DialogLineEdit::getDir(QString str)
147 // QFileInfo fileinfo(str);
148 // return fileinfo.absolutePath();
152 void DialogLineEdit::useFileDialog(bool arg
)
154 m_UseFileDialog
= arg
;