1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "dialoglineedit.h"
24 #include <QHBoxLayout>
28 #include "utilities.h"
30 DialogLineEdit::DialogLineEdit(QWidget
*parent
)
36 DialogLineEdit::DialogLineEdit(bool openfile
, QWidget
*parent
)
40 m_openfile
= openfile
;
43 void DialogLineEdit::build()
45 setWindowTitle(tr("lineedit with file/directory selection dialog"));
46 // this->setHeight(25);
47 QHBoxLayout
* layout
= new QHBoxLayout();
48 layout
->setSpacing(-1);
49 this->setContentsMargins(0, 0, 0, 0);
50 layout
->setContentsMargins(0, 0, 0, 0);
51 this->setLayout(layout
);
52 m_button
= new QPushButton(tr("..."));
53 m_lineedit
= new QLineEdit();
54 m_button
->setSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Fixed
);
55 m_lineedit
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
56 layout
->addWidget(m_lineedit
);
57 layout
->addWidget(m_button
);
59 connect(m_button
, SIGNAL(clicked()), this, SLOT(openDialog()));
61 m_button
->setMaximumWidth(16);
62 this->resize(180, 25);
63 // this->resize(0, 0);
64 // setGeometry(10, 40, 180, 40);
66 // by default, open directory and use file dialog
68 m_UseFileDialog
= true;
71 void DialogLineEdit::openDialog()
75 if (m_UseFileDialog
) {
77 // qDebug() << "m_dir=" << m_dir;
78 if (m_openfile
) name
= QFileDialog::getOpenFileName(NULL
, m_caption
, m_dir
, m_filter
);
79 else name
= getDirectory(NULL
, m_caption
, m_dir
);
82 m_lineedit
->setText(name
);
83 m_dir
= name
;//getDir(name);
88 QString
DialogLineEdit::text()
90 return(m_lineedit
->text());
93 void DialogLineEdit::setText(QString str
)
95 m_lineedit
->setText(str
);
96 m_dir
= str
;//getDir(str);
99 bool DialogLineEdit::getMode()
104 void DialogLineEdit::setMode(bool mode
)
109 void DialogLineEdit::setCaption(QString str
)
114 void DialogLineEdit::setDir(QString str
)
119 void DialogLineEdit::setFilter(QString str
)
124 QString
DialogLineEdit::getCaption()
129 QString
DialogLineEdit::getDir()
134 QString
DialogLineEdit::getFilter()
139 // QString DialogLineEdit::getDir(QString str)
145 // QFileInfo fileinfo(str);
146 // return fileinfo.absolutePath();
150 void DialogLineEdit::useFileDialog(bool arg
)
152 m_UseFileDialog
= arg
;