]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiDialog.h
No need (any longer?) to create a new view for lyxfiles-open
[lyx.git] / src / frontends / qt / GuiDialog.h
1 // -*- C++ -*-
2 /**
3  * \file GuiDialog.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUIDIALOG_H
13 #define GUIDIALOG_H
14
15 #include "Dialog.h"
16 #include "ButtonController.h"
17
18 #include <QAbstractButton>
19 #include <QDialog>
20
21
22 namespace lyx {
23 namespace frontend {
24
25 /// Base class for historical LyX dialogs.
26 /**
27   * \warning New dialogs should use the leaner classes \c DialogView or
28   * \c DockView depending on the intent. Eventually, old dialogs should be
29   * converted to \c DialogView too.
30   */
31 class GuiDialog : public QDialog, public Dialog
32 {
33         Q_OBJECT
34
35 public:
36         /// \param lv is the access point for the dialog to the LyX kernel.
37         /// \param name is the identifier given to the dialog by its parent
38         /// container.
39         /// \param title is the window title used for decoration.
40         GuiDialog(GuiView & lv, QString const & name, QString const & title);
41
42         QWidget * asQWidget() override { return this; }
43         QWidget const * asQWidget() const override { return this; }
44
45 public Q_SLOTS:
46         /** \name Buttons
47          *  These methods are publicly accessible because they are invoked
48          *  by the View when the user presses... guess what ;-)
49          */
50         // Restore button clicked
51         void slotRestore();
52         // Restore Defaults button clicked
53         virtual void slotRestoreDefaults() {}
54         // OK button clicked
55         void slotOK();
56         // Apply button clicked
57         void slotApply();
58         // AutoApply checkbox clicked
59         void slotAutoApply();
60         // Close button clicked or closed from WindowManager
61         void slotClose();
62         // A collectiong slot for QDialogButtonBox
63         void slotButtonBox(QAbstractButton *);
64         ///
65         void closeEvent(QCloseEvent * e) override;
66
67 protected Q_SLOTS:
68         void onBufferViewChanged() override {}
69
70 public:
71         /** Check whether we may apply our data.
72          *
73          *  The buttons are disabled if not and (re-)enabled if yes.
74          */
75         void setButtonsValid(bool valid);
76
77         // Set whether to stop the apply process
78         void setApplyStopped(bool stop) { apply_stopped_ = stop; };
79
80         /** \name Dialog Components
81          *  Methods to access the various components making up a dialog.
82          */
83         //@{
84         ButtonController const & bc() const { return bc_; }
85         ButtonController & bc() { return bc_; }
86         //@}
87
88         /// the dialog has changed contents
89         virtual void changed();
90
91         void enableView(bool enable) override;
92
93         /// default: do nothing
94         void applyView() override {}
95         /// default: do nothing
96         virtual void updateContents() {}
97
98 public:
99         /// is the dialog currently valid ?
100         virtual bool isValid() { return true; }
101
102 public:
103
104         /** When applying, it's useful to know whether the dialog is about
105          *  to close or not (no point refreshing the display for example).
106          */
107         bool isClosing() const override { return is_closing_; }
108
109         ///
110         bool needBufferOpen() const override { return isBufferDependent(); }
111
112         /// Update the display of the dialog whilst it is still visible.
113         void updateView() override;
114
115
116         /** Launch a file dialog and return the chosen file.
117                 filename: a suggested filename.
118                 title: the title of the dialog.
119                 filters: *.ps etc.
120                 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
121          */
122         QString browseFile(QString const & filename,
123                 QString const & title,
124                 QStringList const & filters,
125                 bool save = false,
126                 QString const & label1 = QString(),
127                 QString const & dir1 = QString(),
128                 QString const & label2 = QString(),
129                 QString const & dir2 = QString(),
130                 QString const & fallback_dir = QString());
131         /** Launch a file dialog and return the chosen directory.
132                 pathname: a suggested pathname.
133                 title: the title of the dialog.
134                 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
135         */
136         QString browseDir(QString const & pathname,
137                 QString const & title,
138                 QString const & label1 = QString(),
139                 QString const & dir1 = QString(),
140                 QString const & label2 = QString(),
141                 QString const & dir2 = QString());
142         /** Wrappers around browseFile which try to provide a filename relative to relpath.
143
144         \param title: title for dialog
145
146         \param filters: *.ps, etc
147
148         \param save: whether to save dialog info (current path, etc) for next use.
149
150         The \param labelN and \param dirN arguments provide for extra buttons
151         in the dialog (e.g., "Templates" and a path to that directory).
152
153         The difference between the functions concerns when we think we have a
154         relative path.
155
156         In \c browseRelToParent, we return a relative path only if it IS NOT of
157                 the form "../../foo.txt".
158
159         In \c browseRelToSub, we return a relative path only if it IS of the
160          form "../../foo.txt".
161          */
162         QString browseRelToParent(QString const & filename,
163                 QString const & relpath,
164                 QString const & title,
165                 QStringList const & filters,
166                 bool save = false,
167                 QString const & label1 = QString(),
168                 QString const & dir1 = QString(),
169                 QString const & label2 = QString(),
170                 QString const & dir2 = QString());
171         QString browseRelToSub(QString const & filename,
172                 QString const & relpath,
173                 QString const & title,
174                 QStringList const & filters,
175                 bool save = false,
176                 QString const & label1 = QString(),
177                 QString const & dir1 = QString(),
178                 QString const & label2 = QString(),
179                 QString const & dir2 = QString());
180
181         static QColor getColor(const QColor &initial, QWidget *parent);
182         QColor getColor(const QColor &initial);
183
184 private:
185         ButtonController bc_;
186         /// are we updating ?
187         bool updating_;
188
189         bool is_closing_;
190
191         /// stop the apply process?
192         bool applyStopped() { return apply_stopped_; };
193         bool apply_stopped_;
194 };
195
196
197 } // namespace frontend
198 } // namespace lyx
199
200 #endif // GUIDIALOG_H