summaryrefslogtreecommitdiff
path: root/src/frontend/displaywindow/cdisplaywindow.h
blob: b23d856125366383156740b1aecce67cbf996e20 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2009 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#ifndef CDISPLAYWINDOW_H
#define CDISPLAYWINDOW_H

#include <QMainWindow>
#include "util/cpointers.h"

#include <QStringList>
#include "backend/managers/cswordbackend.h"
#include "frontend/profile/cprofilewindow.h"


class BtActionCollection;
class CDisplay;
class BtDisplaySettingsButton;
class CKeyChooser;
class CMDIArea;
//class CModuleChooserBar;
class BtModuleChooserBar;
class CReadWindow;
class CSwordModuleInfo;
class CWriteWindow;
class QCloseEvent;
class QMenu;
class QToolBar;

/** The base class for all display windows of BibleTime.
  * @author The BibleTime team
  */
class CDisplayWindow : public QMainWindow, public CPointers {
        Q_OBJECT
    public:
        enum WriteWindowType {
            HTMLWindow = 1,
            PlainTextWindow = 2
        };

        /** Insert the keyboard accelerators of this window into the given actioncollection.*/
        static void insertKeyboardActions( BtActionCollection* const a );

        inline CMDIArea *mdi() const {
            return m_mdi;
        }

        /** Returns the correct window caption.*/
        const QString windowCaption();

        /** Returns the used modules as a pointer list.*/
        QList<CSwordModuleInfo*> modules();

        /** Returns the used modules as a string list. */
        inline const QStringList &getModuleList() const {
            return m_modules;
        }

        /** Store the settings of this window in the given CProfileWindow object.*/
        virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ) = 0;

        /** Store the settings of this window in the given profile window.*/
        virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ) = 0;

        /** Returns the display options used by this display window. */
        inline const CSwordBackend::DisplayOptions &displayOptions() const {
            return m_displayOptions;
        }

        /** Returns the filter options used by this window. */
        inline const CSwordBackend::FilterOptions &filterOptions() const {
            return m_filterOptions;
        }

        /** Set the ready status. */
        void setReady(bool ready);

        /** Returns true if the widget is ready for use. */
        inline bool isReady() const {
            return m_isReady;
        }

        /** Returns true if the window may be closed.*/
        virtual bool queryClose();

        /** Returns the keychooser widget of this display window. */
        inline CKeyChooser *keyChooser() const {
            return m_keyChooser;
        }

        /** Sets the new sword key.*/
        void setKey( CSwordKey* key );

        /** Returns the key of this display window. */
        inline CSwordKey *key() const {
            Q_ASSERT(m_swordKey != 0);
            return m_swordKey;
        }

        /**
        * Initialize the window. Call this method from the outside,
        * because calling this in the constructor is not possible!
        */
        virtual bool init();

        /** Sets and inits the properties of the main navigation toolbar.*/
        void setMainToolBar( QToolBar* bar );

        /** Sets and inits the properties of the tool buttons toolbar.*/
        void setButtonsToolBar( QToolBar* bar );

        /** Returns the main navigation toolbar. */
        inline QToolBar *mainToolBar() const {
            return m_mainToolBar;
        }

        /** Returns the tool buttons toolbar. */
        inline QToolBar *buttonsToolBar() const {
            return m_buttonsToolBar;
        }

        /** Initialize the toolbars.*/
        virtual void initToolbars() = 0;

        /** Returns the display settings button. */
        inline BtDisplaySettingsButton *displaySettingsButton() const {
            return m_displaySettingsButton;
        }

        /** Sets the display settings button.*/
        void setDisplaySettingsButton( BtDisplaySettingsButton* button );

        virtual void setupPopupMenu() = 0;

        /** Returns the display widget used by this implementation of CDisplayWindow. */
        virtual inline CDisplay *displayWidget() const {
            Q_ASSERT(m_displayWidget != 0);
            return m_displayWidget;
        }

        /** Sets the display widget used by this display window.*/
        virtual void setDisplayWidget( CDisplay* newDisplay );

        /**
        * Returns whether syncs to the active window are allowed at this time for this display window
        * @return boolean value whether sync is allowed
        */
        virtual bool syncAllowed() const {
            return false;
        };

        inline BtActionCollection *actionCollection() const {
            return m_actionCollection;
        }

    signals:
        /** The module list was set because backend was reloaded.*/
        void sigModuleListSet(QStringList modules);
        /** A module was added to this window.*/
        void sigModuleAdded(int index, QString module);
        void sigModuleReplaced(int index, QString newModule);
        void sigModuleRemoved(int index);
        /** The module list of window changed but backend list didn't.*/
        void sigModuleListChanged();
    public slots:
        /** Receives a signal telling that a module should be added.*/
        void slotAddModule(int index, QString module);
        void slotReplaceModule(int index, QString newModule);
        void slotRemoveModule(int index);

        /**
        * Lookup the specified key in the given module. If the module is not chosen withing
        * this display window create a new displaywindow with the right module in it.
        */
        virtual void lookupModKey( const QString& module, const QString& key );

        /** Lookup the key in the chosen modules.*/
        virtual void lookupKey( const QString& key );

        /** Refresh the settings of this window.*/
        virtual void reload(CSwordBackend::SetupChangedReason reason);

        void slotShowNavigator(bool show);
        void slotShowToolButtons(bool show);
        void slotShowModuleChooser(bool show);
        void slotShowHeader(bool show);

    protected:
        friend class CMDIArea;
        friend class CBibleReadWindow;

        CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
        virtual ~CDisplayWindow();

        /** Returns the display options used by this display window. */
        inline CSwordBackend::DisplayOptions &displayOptions() {
            return m_displayOptions;
        }

        /** Returns the filter options used by this window. */
        inline CSwordBackend::FilterOptions &filterOptions() {
            return m_filterOptions;
        }

        /** Initializes the internel keyboard actions.*/
        virtual void initActions();

        /** Sets the keychooser widget for this display window.*/
        void setKeyChooser( CKeyChooser* ck );

        /** Returns the module chooser bar. */
        inline BtModuleChooserBar *moduleChooserBar() const {
            return m_moduleChooserBar;
        }

        /** Lookup the given key.*/
        virtual void lookupSwordKey( CSwordKey* ) = 0;

        /** Sets the module chooser bar.*/
        void setModuleChooserBar( BtModuleChooserBar* bar );

        void setHeaderBar(QToolBar* header);

        inline QToolBar *headerBar() const {
            return m_headerBar;
        }

        /** Sets the modules. */
        void setModules( const QList<CSwordModuleInfo*>& modules );

        /** Initializes the signal / slot connections of this display window.*/
        virtual void initConnections() = 0;

        /** Initialize the view of this display window.*/
        virtual void initView() = 0;

        /** Returns the installed RMB popup menu.*/
        QMenu* popup();

        virtual void closeEvent(QCloseEvent* e);

    protected slots:
        /** Sets the new filter options of this window.*/
        void setFilterOptions(const CSwordBackend::FilterOptions &filterOptions);

        /** Sets the new display options for this window.*/
        void setDisplayOptions(const CSwordBackend::DisplayOptions &displayOptions);

        virtual void modulesChanged();

        /** Lookup the current key. Used to refresh the display.*/
        void lookup();

        virtual void updatePopupMenu();

        void slotSearchInModules();

        void printAll();

        void printAnchorWithText();

        void setFocusKeyChooser();

    private:
        BtActionCollection* m_actionCollection;
        CMDIArea* m_mdi;

        //we may only cache the module names bacause after a backend relaod the pointers are invalid!
        QStringList m_modules;

        CSwordBackend::FilterOptions m_filterOptions;
        CSwordBackend::DisplayOptions m_displayOptions;

        BtDisplaySettingsButton* m_displaySettingsButton;
        CKeyChooser* m_keyChooser;
        CSwordKey* m_swordKey;
        bool m_isReady;
        BtModuleChooserBar* m_moduleChooserBar;
        QToolBar* m_mainToolBar;
        QToolBar* m_buttonsToolBar;
        QToolBar* m_headerBar;
        QMenu* m_popupMenu;
        CDisplay* m_displayWidget;
};

#endif