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 #ifndef FILEPICKER_HH_
44 #define FILEPICKER_HH_
45
46 #include <OpenFlipper/common/RecentFiles.hh>
47
48 #include <QWidget>
49 #include <QComboBox>
50 #include <QLineEdit>
51 #include <QPushButton>
52
53
54 class DLLEXPORT FilePicker : public QWidget {
55 Q_OBJECT
56 Q_PROPERTY(QString recent_files_ini_key
57 READ recent_files_ini_key
58 WRITE set_recent_files_ini_key)
59 Q_PROPERTY(QString dialog_title
60 READ dialog_title
61 WRITE set_dialog_title)
62 Q_PROPERTY(QString file_filter
63 READ file_filter
64 WRITE set_file_filter)
65 Q_PROPERTY(DialogType dialog_type
66 READ dialog_type
67 WRITE set_dialog_type)
68 Q_PROPERTY(QString current_file_name
69 READ current_file_name
70 WRITE set_current_file_name)
71 Q_ENUMS(DialogType)
72
73 public:
74 enum DialogType {
75 DT_OPEN_FILE = OpenFlipper::Options::DT_OPEN,
76 DT_SAVE_FILE = OpenFlipper::Options::DT_SAVE,
77 DT_CHOOSE_PATH = OpenFlipper::Options::DT_CHOOSE_PATH
78 };
79
80 explicit FilePicker(QWidget *parent = 0);
81 explicit FilePicker(QString recent_files_ini_key,
82 DialogType dialog_type,
83 QWidget *parent = 0);
84 virtual ~FilePicker();
85
86 QString current_file_name() {
87 return textBox_->currentText();
88 }
89
90 void set_current_file_name(QString value) {
91 return textBox_->lineEdit()->setText(value);
92 }
93
94 // Legacy:
95 QString currentFileName() {
96 return current_file_name();
97 }
98
99 QString recent_files_ini_key() { return recent_files_ini_key_; }
100 void set_recent_files_ini_key(QString value);
101
102 QString dialog_title() { return dialog_title_; }
103 void set_dialog_title(QString value) {
104 dialog_title_ = value;
105 }
106
107 QString file_filter() { return file_filter_; }
108 void set_file_filter(QString value) {
109 file_filter_ = value;
110 }
111
112 DialogType dialog_type() { return dialog_type_; }
113 void set_dialog_type(DialogType value) {
114 dialog_type_ = value;
115 }
116
117 bool overwrite_confirmed_by_user() {
118 return overwrite_confirmed_by_user_;
119 }
120
121 public slots:
122 bool confirm_overwrite_if_necessary();
123
124 protected slots:
125 void slot_browse();
126 void path_changed();
127
128 private:
129 void init();
130
131 protected:
132 QComboBox *textBox_;
133 QPushButton *browseButton_;
134 QString recent_files_ini_key_;
135 QString dialog_title_;
136 QString file_filter_;
137 DialogType dialog_type_;
138 bool overwrite_confirmed_by_user_;
139 };
140
141 #endif /* FILEPICKER_HH_ */
FilePicker
Definition: FilePicker.hh:54
DLLEXPORT
#define DLLEXPORT
Definition: GlobalDefines.hh:95