fixed edge display for volume cells
[engrid-github.git] / src / libengrid / dialoglineedit.cpp
blob6a9ae4b6d5da5e7007a8cd71fb9998a3d622779c
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "dialoglineedit.h"
23 #include <QtGui>
24 #include <QHBoxLayout>
25 #include <QtDebug>
26 #include <QFileInfo>
28 #include "utilities.h"
30 DialogLineEdit::DialogLineEdit(QWidget *parent)
31 : QWidget(parent)
33 build();
36 DialogLineEdit::DialogLineEdit(bool openfile, QWidget *parent)
37 : QWidget(parent)
39 build();
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
67 m_openfile = false;
68 m_UseFileDialog = true;
71 void DialogLineEdit::openDialog()
73 emit clicked();
75 if (m_UseFileDialog) {
76 QString name;
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);
81 if (!name.isNull()) {
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()
101 return m_openfile;
104 void DialogLineEdit::setMode(bool mode)
106 m_openfile = mode;
109 void DialogLineEdit::setCaption(QString str)
111 m_caption = str;
114 void DialogLineEdit::setDir(QString str)
116 m_dir = str;
119 void DialogLineEdit::setFilter(QString str)
121 m_filter = str;
124 QString DialogLineEdit::getCaption()
126 return m_caption;
129 QString DialogLineEdit::getDir()
131 return m_dir;
134 QString DialogLineEdit::getFilter()
136 return m_filter;
139 // QString DialogLineEdit::getDir(QString str)
140 // {
141 // if (m_openfile) {
142 // return str;
143 // }
144 // else {
145 // QFileInfo fileinfo(str);
146 // return fileinfo.absolutePath();
147 // }
148 // }
150 void DialogLineEdit::useFileDialog(bool arg)
152 m_UseFileDialog = arg;