Developer Documentation
FilePicker.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 /*
51  * FilePicker.hh
52  *
53  * Created on: Jan 8, 2013
54  * Author: ebke
55  */
56 
57 #ifndef FILEPICKER_HH_
58 #define FILEPICKER_HH_
59 
60 #include <OpenFlipper/common/RecentFiles.hh>
61 
62 #include <QWidget>
63 #include <QComboBox>
64 #include <QLineEdit>
65 #include <QPushButton>
66 
67 
68 class DLLEXPORT FilePicker : public QWidget {
69  Q_OBJECT
70  Q_PROPERTY(QString recent_files_ini_key
71  READ recent_files_ini_key
72  WRITE set_recent_files_ini_key)
73  Q_PROPERTY(QString dialog_title
74  READ dialog_title
75  WRITE set_dialog_title)
76  Q_PROPERTY(QString file_filter
77  READ file_filter
78  WRITE set_file_filter)
79  Q_PROPERTY(DialogType dialog_type
80  READ dialog_type
81  WRITE set_dialog_type)
82  Q_PROPERTY(QString current_file_name
83  READ current_file_name
84  WRITE set_current_file_name)
85  Q_ENUMS(DialogType)
86 
87  public:
88  enum DialogType {
89  DT_OPEN_FILE = OpenFlipper::Options::DT_OPEN,
90  DT_SAVE_FILE = OpenFlipper::Options::DT_SAVE,
91  DT_CHOOSE_PATH = OpenFlipper::Options::DT_CHOOSE_PATH
92  };
93 
94  explicit FilePicker(QWidget *parent = 0);
95  explicit FilePicker(QString recent_files_ini_key,
96  DialogType dialog_type,
97  QWidget *parent = 0);
98  virtual ~FilePicker();
99 
100  QString current_file_name() {
101  return textBox_->currentText();
102  }
103 
104  void set_current_file_name(QString value) {
105  return textBox_->lineEdit()->setText(value);
106  }
107 
108  // Legacy:
109  QString currentFileName() {
110  return current_file_name();
111  }
112 
113  QString recent_files_ini_key() { return recent_files_ini_key_; }
114  void set_recent_files_ini_key(QString value);
115 
116  QString dialog_title() { return dialog_title_; }
117  void set_dialog_title(QString value) {
118  dialog_title_ = value;
119  }
120 
121  QString file_filter() { return file_filter_; }
122  void set_file_filter(QString value) {
123  file_filter_ = value;
124  }
125 
126  DialogType dialog_type() { return dialog_type_; }
127  void set_dialog_type(DialogType value) {
128  dialog_type_ = value;
129  }
130 
131  bool overwrite_confirmed_by_user() {
132  return overwrite_confirmed_by_user_;
133  }
134 
135  public slots:
136  bool confirm_overwrite_if_necessary();
137 
138  protected slots:
139  void slot_browse();
140  void path_changed();
141 
142  private:
143  void init();
144 
145  protected:
146  QComboBox *textBox_;
147  QPushButton *browseButton_;
148  QString recent_files_ini_key_;
149  QString dialog_title_;
150  QString file_filter_;
151  DialogType dialog_type_;
152  bool overwrite_confirmed_by_user_;
153 };
154 
155 #endif /* FILEPICKER_HH_ */
#define DLLEXPORT