]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQApplication.h
- installation summary looks nice
[duncan/yast2-qt4.git] / src / YQApplication.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQApplication.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQApplication_h
21 #define YQApplication_h
22
23 #include <Qt/qobject.h>
24 #include <Qt/qtranslator.h>
25 #include <qfont.h>
26
27 #include "QY2Settings.h"
28 #include "YApplication.h"
29
30
31 class YQApplication: public QObject, public YApplication
32 {
33     Q_OBJECT
34
35 protected:
36
37     friend class YQUI;
38
39     /**
40      * Constructor.
41      *
42      * Use YUI::app() to get the singleton for this class.
43      **/
44     YQApplication();
45
46     /**
47      * Destructor.
48      **/
49     virtual ~YQApplication();
50
51
52 public:
53
54     /**
55      * Set language and encoding for the locale environment ($LANG).
56      *
57      * Load UI-internal translations (e.g. for predefined dialogs like
58      * file selection) and fonts.
59      *
60      * 'language' is the ISO short code ("de_DE", "en_US", ...).
61      *
62      * 'encoding' an (optional) encoding ("utf8", ...) that will be appended if
63      *  present.
64      *
65      * Reimplemented from YApplication.
66      **/
67     virtual void setLanguage( const string & language,
68                               const string & encoding = string() );
69
70     /**
71      * Load translations for Qt's predefined dialogs like file selection box
72      * etc.
73      **/
74     void loadPredefinedQtTranslations();
75
76     /**
77      * Set fonts according to the specified language and encoding.
78      *
79      * This is most important for some Asian languages that have overlaps in
80      * the Unicode table, like Japanese vs. Chinese.
81      **/
82     void setLangFonts( const string & language,
83                        const string & encoding = string() );
84
85     /**
86      * Returns the application's default font.
87      **/
88     const QFont & currentFont();
89
90     /**
91      * Returns the application's default bold font.
92      **/
93     const QFont & boldFont();
94
95     /**
96      * Returns the application's heading font.
97      **/
98     const QFont & headingFont();
99
100     /**
101      * Delete the fonts so they will be reloaded upon their next usage.
102      **/
103     void deleteFonts();
104
105     /**
106      * Determine good fonts based on defaultsize geometry and set
107      * _auto_normal_font_size and _auto_heading_font_size accordingly.
108      * Caches the values, so it's safe to call this repeatedly.
109      **/
110     void pickAutoFonts();
111
112     /**
113      * Returns 'true' if the UI  automatically picks fonts, disregarding Qt
114      * standard settings.
115      *
116      * This makes sense during system installation system where the display DPI
117      * cannot reliably be retrieved and thus Qt uses random font sizes based on
118      * that random DPI.
119      **/
120     bool autoFonts() const { return _autoFonts; }
121
122     /**
123      * Set whether or not fonts should automatically be picked.
124      **/
125     void setAutoFonts( bool useAutoFonts );
126
127     /**
128      * Open a directory selection box and prompt the user for an existing
129      * directory.
130      *
131      * 'startDir' is the initial directory that is displayed.
132      *
133      * 'headline' is an explanatory text for the directory selection box.
134      * Graphical UIs may omit that if no window manager is running.
135      *
136      * Returns the selected directory name
137      * or an empty string if the user canceled the operation.
138      *
139      * Implemented from YApplication.
140      **/
141     virtual string askForExistingDirectory( const string & startDir,
142                                             const string & headline );
143
144     /**
145      * Open a file selection box and prompt the user for an existing file.
146      *
147      * 'startWith' is the initial directory or file.
148      *
149      * 'filter' is one or more blank-separated file patterns, e.g.
150      * "*.png *.jpg"
151      *
152      * 'headline' is an explanatory text for the file selection box.
153      * Graphical UIs may omit that if no window manager is running.
154      *
155      * Returns the selected file name
156      * or an empty string if the user canceled the operation.
157      *
158      * Implemented from YApplication.
159      **/
160     virtual string askForExistingFile( const string & startWith,
161                                        const string & filter,
162                                        const string & headline );
163
164     /**
165      * Open a file selection box and prompt the user for a file to save data
166      * to.  Automatically asks for confirmation if the user selects an existing
167      * file.
168      *
169      * 'startWith' is the initial directory or file.
170      *
171      * 'filter' is one or more blank-separated file patterns, e.g.
172      * "*.png *.jpg"
173      *
174      * 'headline' is an explanatory text for the file selection box.
175      * Graphical UIs may omit that if no window manager is running.
176      *
177      * Returns the selected file name
178      * or an empty string if the user canceled the operation.
179      *
180      * Implemented from YApplication.
181      **/
182     virtual string askForSaveFileName( const string & startWith,
183                                        const string & filter,
184                                        const string & headline );
185     /**
186      * Lower-level version that works with QStrings and does not change
187      * the mouse cursor.
188      **/
189     static QString askForSaveFileName( const QString & startWith,
190                                        const QString & filter,
191                                        const QString & headline );
192
193     
194 protected:
195
196     /**
197      * Constructs a key for the language specific font file:
198      *     "font[lang]"
199      * for
200      *     font[de_DE] = "Sans Serif"
201      *     font[zh] = "ChineseSpecial, something"
202      *     font[ja_JP] = "JapaneseSpecial, something"
203      *     font = "Sans Serif"
204      **/
205     QString fontKey( const QString & lang );
206
207
208     //
209     // Data members
210     //
211
212     // Fonts
213
214     QFont * _currentFont;
215     QFont * _headingFont;
216     QFont * _boldFont;
217
218     /**
219      * Font family or list of font families to use ("Sans Serif" etc.)
220      **/
221     QString _fontFamily;
222
223     /**
224      * Language-specific font settings
225      **/
226     QY2Settings * _langFonts;
227
228     /**
229      * Translator for the predefined Qt dialogs
230      **/
231     QTranslator * _qtTranslations;
232
233     /**
234      * For auto fonts
235      **/
236     bool _autoFonts;
237     int  _autoNormalFontSize;
238     int  _autoHeadingFontSize;
239
240
241 };
242
243
244 #endif // YQApplication_h