-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbrowse_lineedit.cpp
134 lines (98 loc) · 3.62 KB
/
browse_lineedit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// ---------------------------------------------------------------------
//
// Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#include "browse_lineedit.h"
#include <QHBoxLayout>
namespace dealii
{
namespace ParameterGui
{
BrowseLineEdit::BrowseLineEdit(const BrowseType type, QWidget *parent)
: QFrame(parent, 0),
browse_type(type)
{
line_editor = new QLineEdit;
connect(line_editor, SIGNAL(editingFinished()), this, SLOT(editing_finished()));
browse_button = new QPushButton("&Browse...");
connect(browse_button, SIGNAL(clicked()), this, SLOT(browse()));
setFocusPolicy (Qt::StrongFocus);
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(1,1,1,1);
layout->addWidget(line_editor);
layout->addWidget(browse_button);
setLayout(layout);
setAutoFillBackground(true);
setBackgroundRole(QPalette::Highlight);
}
QSize BrowseLineEdit::sizeHint() const
{
QSize size_line_editor = line_editor->sizeHint(),
size_browse_button = browse_button->sizeHint();
int w = size_line_editor.rwidth() + size_browse_button.rwidth(),
h = qMax(size_line_editor.rheight(), size_browse_button.rheight());
return QSize (w, h);
}
QSize BrowseLineEdit::minimumSizeHint() const
{
QSize size_line_editor = line_editor->minimumSizeHint(),
size_browse_button = browse_button->minimumSizeHint();
int w = size_line_editor.rwidth() + size_browse_button.rwidth(),
h = qMax(size_line_editor.rheight(), size_browse_button.rheight());
return QSize (w, h);
}
QString BrowseLineEdit::text() const
{
return line_editor->text();
}
void BrowseLineEdit::setText(const QString &str)
{
line_editor->setText(str);
}
void BrowseLineEdit::editing_finished()
{
emit editingFinished();
}
void BrowseLineEdit::browse()
{
QString name = "";
switch (browse_type)
{
case file:
{
name = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::currentPath(),
tr("All Files (*.*)"));
break;
};
case files:
{
QStringList names = QFileDialog::getOpenFileNames(this, tr("Open Files"),
QDir::currentPath(),
tr("All Files (*.*)"));
name = names.join(",");
break;
};
case directory:
{
name = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
QDir::homePath(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
break;
};
};
if (!name.isEmpty() && !name.isNull())
line_editor->setText(name);
}
}
}