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