-
Notifications
You must be signed in to change notification settings - Fork 19
/
YQApplication.h
405 lines (336 loc) · 11.1 KB
/
YQApplication.h
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/*
Copyright (C) 2000-2012 Novell, Inc
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) version 3.0 of the License. This library
is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details. You should have received a copy of the GNU
Lesser General Public License along with this library; if not, write
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Floor, Boston, MA 02110-1301 USA
*/
/*-/
File: YQApplication.h
Author: Stefan Hundhammer <shundhammer@suse.de>
/-*/
#ifndef YQApplication_h
#define YQApplication_h
#include <qobject.h>
#include <qtranslator.h>
#include <qfont.h>
#include "YQPackageSelectorPluginStub.h"
#include "YQGraphPluginStub.h"
#include <yui/YApplication.h>
class QSettings;
class YQPackageSelectorPlugin;
class YQGraphPlugin;
class QMenu;
class YQApplication: public QObject, public YApplication
{
Q_OBJECT
protected:
friend class YQUI;
/**
* Constructor.
*
* Use YUI::app() to get the singleton for this class.
**/
YQApplication();
/**
* Destructor.
**/
virtual ~YQApplication();
public:
/**
* Set language and encoding for the locale environment ($LANG).
*
* Load UI-internal translations (e.g. for predefined dialogs like
* file selection) and fonts.
*
* 'language' is the ISO short code ("de_DE", "en_US", ...).
*
* 'encoding' an (optional) encoding ("utf8", ...) that will be appended if
* present.
*
* Reimplemented from YApplication.
**/
virtual void setLanguage( const std::string & language,
const std::string & encoding = std::string() );
/**
* Load translations for Qt's predefined dialogs like file selection box
* etc.
**/
void loadPredefinedQtTranslations();
/**
* Set the layout direction (left-to-right or right-to-left) from
* 'language'.
**/
void setLayoutDirection( const std::string & language );
/**
* Set fonts according to the specified language and encoding.
*
* This is most important for some Asian languages that have overlaps in
* the Unicode table, like Japanese vs. Chinese.
**/
void setLangFonts( const std::string & language,
const std::string & encoding = std::string() );
/**
* Returns the application's default font.
**/
const QFont & currentFont();
/**
* Returns the application's default bold font.
**/
const QFont & boldFont();
/**
* Returns the application's heading font.
**/
const QFont & headingFont();
/**
* Delete the fonts so they will be reloaded upon their next usage.
**/
void deleteFonts();
/**
* Determine good fonts based on defaultsize geometry and set
* _auto_normal_font_size and _auto_heading_font_size accordingly.
* Caches the values, so it's safe to call this repeatedly.
**/
void pickAutoFonts();
/**
* Returns 'true' if the UI automatically picks fonts, disregarding Qt
* standard settings.
*
* This makes sense during system installation system where the display DPI
* cannot reliably be retrieved and thus Qt uses random font sizes based on
* that random DPI.
**/
bool autoFonts() const { return _autoFonts; }
/**
* Set whether or not fonts should automatically be picked.
**/
void setAutoFonts( bool useAutoFonts );
/**
* Return a std::string for a named glyph.
*
* Using this is discouraged in new applications.
*
* Reimplemented from YApplication.
**/
virtual std::string glyph( const std::string & glyphSymbolName );
/**
* Open a directory selection box and prompt the user for an existing
* directory.
*
* 'startDir' is the initial directory that is displayed.
*
* 'headline' is an explanatory text for the directory selection box.
* Graphical UIs may omit that if no window manager is running.
*
* Returns the selected directory name
* or an empty std::string if the user canceled the operation.
*
* Implemented from YApplication.
**/
virtual std::string askForExistingDirectory( const std::string & startDir,
const std::string & headline );
/**
* Open a file selection box and prompt the user for an existing file.
*
* 'startWith' is the initial directory or file.
*
* 'filter' is one or more blank-separated file patterns, e.g.
* "*.png *.jpg"
*
* 'headline' is an explanatory text for the file selection box.
* Graphical UIs may omit that if no window manager is running.
*
* Returns the selected file name
* or an empty std::string if the user canceled the operation.
*
* Implemented from YApplication.
**/
virtual std::string askForExistingFile( const std::string & startWith,
const std::string & filter,
const std::string & headline );
/**
* Open a file selection box and prompt the user for a file to save data
* to. Automatically asks for confirmation if the user selects an existing
* file.
*
* 'startWith' is the initial directory or file.
*
* 'filter' is one or more blank-separated file patterns, e.g.
* "*.png *.jpg"
*
* 'headline' is an explanatory text for the file selection box.
* Graphical UIs may omit that if no window manager is running.
*
* Returns the selected file name
* or an empty std::string if the user canceled the operation.
*
* Implemented from YApplication.
**/
virtual std::string askForSaveFileName( const std::string & startWith,
const std::string & filter,
const std::string & headline );
/**
* Lower-level version that works with QStrings and does not change
* the mouse cursor.
**/
static QString askForSaveFileName( const QString & startWith,
const QString & filter,
const QString & headline );
/**
* Open a context menu for a widget
*
* 'itemCollection' describes the menu structure
*
* Returns true on success (otherwise false).
*
* Implemented from YApplication.
**/
virtual bool openContextMenu ( const YItemCollection & itemCollection );
/**
* Return the package selector plugin singleton or creates it
* (including loading the plugin lib) if it does not exist yet.
**/
static YQPackageSelectorPluginStub * packageSelectorPlugin();
/**
* Return the package selector plugin singleton or creates it
* (including loading the plugin lib) if it does not exist yet.
**/
static YQGraphPluginStub * graphPlugin();
/**
* A mouse click with the wrong mouse button was detected - e.g., a right
* click on a push button. The user might be left-handed, but his mouse
* might not (yet) be configured for left-handed use - e.g., during
* installation. Ask him if he would like his mouse temporarily configured
* as a left-handed mouse.
*
* This status can be queried with YQApplication::leftHandedMouse().
**/
void maybeLeftHandedUser();
/**
* Convert logical layout spacing units into device dependent units.
* A default size dialog is assumed to be 80x25 layout spacing units.
*
* Reimplemented from YApplication.
**/
virtual int deviceUnits( YUIDimension dim, float layoutUnits );
/**
* Convert device dependent units into logical layout spacing units.
* A default size dialog is assumed to be 80x25 layout spacing units.
*
* Reimplemented from YApplication.
**/
virtual float layoutUnits( YUIDimension dim, int deviceUnits );
/**
* Change the (mouse) cursor to indicate busy status.
*
* Reimplemented from YApplication.
**/
virtual void busyCursor();
/**
* Change the (mouse) cursor back from busy status to normal.
*
* Reimplemented from YApplication.
**/
virtual void normalCursor();
/**
* Make a screen shot and save it to the specified file.
*
* Reimplemented from YApplication.
**/
virtual void makeScreenShot( const std::string & fileName );
/**
* Beep.
*
* Reimplemented from YApplication.
**/
virtual void beep();
/**
* Return position of the context menu (in gloabl coordinates)
**/
virtual QPoint contextMenuPos() { return _contextMenuPos; }
/**
* Sets the position of the context menu (in gloabl coordinates)
**/
virtual void setContextMenuPos( QPoint contextMenuPos );
// Display information and UI capabilities.
//
// All implemented from YApplication.
virtual int displayWidth();
virtual int displayHeight();
virtual int displayDepth();
virtual long displayColors();
// Size of main dialogs
virtual int defaultWidth();
virtual int defaultHeight();
//
// UI capabilities
//
virtual bool isTextMode() { return false; }
virtual bool hasImageSupport() { return true; }
virtual bool hasIconSupport() { return true; }
virtual bool hasAnimationSupport() { return true; }
virtual bool hasFullUtf8Support() { return true; }
virtual bool richTextSupportsTable() { return true; }
virtual bool hasWizardDialogSupport() { return true; }
virtual bool leftHandedMouse();
/**
* Set the application title
*
* Reimplemented from YApplication.
**/
virtual void setApplicationTitle(const std::string& title);
/**
* Set the application Icon
*
* Reimplemented from YApplication.
**/
virtual void setApplicationIcon(const std::string& icon);
protected:
/**
* Constructs a key for the language specific font file:
* "font[lang]"
* for
* font[de_DE] = "Sans Serif"
* font[zh] = "ChineseSpecial, something"
* font[ja_JP] = "JapaneseSpecial, something"
* font = "Sans Serif"
**/
QString fontKey( const QString & lang );
//
// Data members
//
// Fonts
QFont * _currentFont;
QFont * _headingFont;
QFont * _boldFont;
/**
* Font family or list of font families to use ("Sans Serif" etc.)
**/
QString _fontFamily;
/**
* Language-specific font settings
**/
QSettings * _langFonts;
/**
* Translator for the predefined Qt dialogs
**/
QTranslator * _qtTranslations;
//
// Misc
//
bool _autoFonts;
int _autoNormalFontSize;
int _autoHeadingFontSize;
bool _leftHandedMouse;
bool _askedForLeftHandedMouse;
QPoint _contextMenuPos;
QMenu* _contextMenu;
};
#endif // YQApplication_h