added methods to convert between Cartesian and spherical coordinates
[engrid-github.git] / src / libengrid / dialoglineedit.cpp
blobe933222e16e039ffc2dbb3b10fd1becbcdfacb9c
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2012 enGits GmbH +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "dialoglineedit.h"
25 #include <QtGui>
26 #include <QHBoxLayout>
27 #include <QtDebug>
28 #include <QFileInfo>
30 #include "utilities.h"
32 DialogLineEdit::DialogLineEdit(QWidget *parent)
33 : QWidget(parent)
35 build();
38 DialogLineEdit::DialogLineEdit(bool openfile, QWidget *parent)
39 : QWidget(parent)
41 build();
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
69 m_openfile = false;
70 m_UseFileDialog = true;
73 void DialogLineEdit::openDialog()
75 emit clicked();
77 if (m_UseFileDialog) {
78 QString name;
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);
83 if (!name.isNull()) {
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()
103 return m_openfile;
106 void DialogLineEdit::setMode(bool mode)
108 m_openfile = mode;
111 void DialogLineEdit::setCaption(QString str)
113 m_caption = str;
116 void DialogLineEdit::setDir(QString str)
118 m_dir = str;
121 void DialogLineEdit::setFilter(QString str)
123 m_filter = str;
126 QString DialogLineEdit::getCaption()
128 return m_caption;
131 QString DialogLineEdit::getDir()
133 return m_dir;
136 QString DialogLineEdit::getFilter()
138 return m_filter;
141 // QString DialogLineEdit::getDir(QString str)
142 // {
143 // if (m_openfile) {
144 // return str;
145 // }
146 // else {
147 // QFileInfo fileinfo(str);
148 // return fileinfo.absolutePath();
149 // }
150 // }
152 void DialogLineEdit::useFileDialog(bool arg)
154 m_UseFileDialog = arg;