libyui-qt  2.43.3
 All Classes Functions Variables
YQApplication.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQApplication.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQApplication_h
27 #define YQApplication_h
28 
29 #include <Qt/qobject.h>
30 #include <Qt/qtranslator.h>
31 #include <qfont.h>
32 
33 #include "YQPackageSelectorPluginStub.h"
34 #include "YQGraphPluginStub.h"
35 #include <yui/YApplication.h>
36 
37 class QSettings;
38 class YQPackageSelectorPlugin;
39 class YQGraphPlugin;
40 class QMenu;
41 
42 
43 class YQApplication: public QObject, public YApplication
44 {
45  Q_OBJECT
46 
47 protected:
48 
49  friend class YQUI;
50 
51  /**
52  * Constructor.
53  *
54  * Use YUI::app() to get the singleton for this class.
55  **/
56  YQApplication();
57 
58  /**
59  * Destructor.
60  **/
61  virtual ~YQApplication();
62 
63 
64 public:
65 
66  /**
67  * Set language and encoding for the locale environment ($LANG).
68  *
69  * Load UI-internal translations (e.g. for predefined dialogs like
70  * file selection) and fonts.
71  *
72  * 'language' is the ISO short code ("de_DE", "en_US", ...).
73  *
74  * 'encoding' an (optional) encoding ("utf8", ...) that will be appended if
75  * present.
76  *
77  * Reimplemented from YApplication.
78  **/
79  virtual void setLanguage( const std::string & language,
80  const std::string & encoding = std::string() );
81 
82  /**
83  * Load translations for Qt's predefined dialogs like file selection box
84  * etc.
85  **/
87 
88  /**
89  * Set the layout direction (left-to-right or right-to-left) from
90  * 'language'.
91  **/
92  void setLayoutDirection( const std::string & language );
93 
94  /**
95  * Set fonts according to the specified language and encoding.
96  *
97  * This is most important for some Asian languages that have overlaps in
98  * the Unicode table, like Japanese vs. Chinese.
99  **/
100  void setLangFonts( const std::string & language,
101  const std::string & encoding = std::string() );
102 
103  /**
104  * Returns the application's default font.
105  **/
106  const QFont & currentFont();
107 
108  /**
109  * Returns the application's default bold font.
110  **/
111  const QFont & boldFont();
112 
113  /**
114  * Returns the application's heading font.
115  **/
116  const QFont & headingFont();
117 
118  /**
119  * Delete the fonts so they will be reloaded upon their next usage.
120  **/
121  void deleteFonts();
122 
123  /**
124  * Determine good fonts based on defaultsize geometry and set
125  * _auto_normal_font_size and _auto_heading_font_size accordingly.
126  * Caches the values, so it's safe to call this repeatedly.
127  **/
128  void pickAutoFonts();
129 
130  /**
131  * Returns 'true' if the UI automatically picks fonts, disregarding Qt
132  * standard settings.
133  *
134  * This makes sense during system installation system where the display DPI
135  * cannot reliably be retrieved and thus Qt uses random font sizes based on
136  * that random DPI.
137  **/
138  bool autoFonts() const { return _autoFonts; }
139 
140  /**
141  * Set whether or not fonts should automatically be picked.
142  **/
143  void setAutoFonts( bool useAutoFonts );
144 
145  /**
146  * Return a std::string for a named glyph.
147  *
148  * Using this is discouraged in new applications.
149  *
150  * Reimplemented from YApplication.
151  **/
152  virtual std::string glyph( const std::string & glyphSymbolName );
153 
154  /**
155  * Open a directory selection box and prompt the user for an existing
156  * directory.
157  *
158  * 'startDir' is the initial directory that is displayed.
159  *
160  * 'headline' is an explanatory text for the directory selection box.
161  * Graphical UIs may omit that if no window manager is running.
162  *
163  * Returns the selected directory name
164  * or an empty std::string if the user canceled the operation.
165  *
166  * Implemented from YApplication.
167  **/
168  virtual std::string askForExistingDirectory( const std::string & startDir,
169  const std::string & headline );
170 
171  /**
172  * Open a file selection box and prompt the user for an existing file.
173  *
174  * 'startWith' is the initial directory or file.
175  *
176  * 'filter' is one or more blank-separated file patterns, e.g.
177  * "*.png *.jpg"
178  *
179  * 'headline' is an explanatory text for the file selection box.
180  * Graphical UIs may omit that if no window manager is running.
181  *
182  * Returns the selected file name
183  * or an empty std::string if the user canceled the operation.
184  *
185  * Implemented from YApplication.
186  **/
187  virtual std::string askForExistingFile( const std::string & startWith,
188  const std::string & filter,
189  const std::string & headline );
190 
191  /**
192  * Open a file selection box and prompt the user for a file to save data
193  * to. Automatically asks for confirmation if the user selects an existing
194  * file.
195  *
196  * 'startWith' is the initial directory or file.
197  *
198  * 'filter' is one or more blank-separated file patterns, e.g.
199  * "*.png *.jpg"
200  *
201  * 'headline' is an explanatory text for the file selection box.
202  * Graphical UIs may omit that if no window manager is running.
203  *
204  * Returns the selected file name
205  * or an empty std::string if the user canceled the operation.
206  *
207  * Implemented from YApplication.
208  **/
209  virtual std::string askForSaveFileName( const std::string & startWith,
210  const std::string & filter,
211  const std::string & headline );
212  /**
213  * Lower-level version that works with QStrings and does not change
214  * the mouse cursor.
215  **/
216  static QString askForSaveFileName( const QString & startWith,
217  const QString & filter,
218  const QString & headline );
219 
220  /**
221  * Open a context menu for a widget
222  *
223  * 'itemCollection' describes the menu structure
224  *
225  * Returns true on success (otherwise false).
226  *
227  * Implemented from YApplication.
228  **/
229  virtual bool openContextMenu ( const YItemCollection & itemCollection );
230 
231 
232  /**
233  * Return the package selector plugin singleton or creates it
234  * (including loading the plugin lib) if it does not exist yet.
235  **/
237 
238  /**
239  * Return the package selector plugin singleton or creates it
240  * (including loading the plugin lib) if it does not exist yet.
241  **/
242  static YQGraphPluginStub * graphPlugin();
243 
244  /**
245  * A mouse click with the wrong mouse button was detected - e.g., a right
246  * click on a push button. The user might be left-handed, but his mouse
247  * might not (yet) be configured for left-handed use - e.g., during
248  * installation. Ask him if he would like his mouse temporarily configured
249  * as a left-handed mouse.
250  *
251  * This status can be queried with YQApplication::leftHandedMouse().
252  **/
253  void maybeLeftHandedUser();
254 
255  /**
256  * Convert logical layout spacing units into device dependent units.
257  * A default size dialog is assumed to be 80x25 layout spacing units.
258  *
259  * Reimplemented from YApplication.
260  **/
261  virtual int deviceUnits( YUIDimension dim, float layoutUnits );
262 
263  /**
264  * Convert device dependent units into logical layout spacing units.
265  * A default size dialog is assumed to be 80x25 layout spacing units.
266  *
267  * Reimplemented from YApplication.
268  **/
269  virtual float layoutUnits( YUIDimension dim, int deviceUnits );
270 
271  /**
272  * Change the (mouse) cursor to indicate busy status.
273  *
274  * Reimplemented from YApplication.
275  **/
276  virtual void busyCursor();
277 
278  /**
279  * Change the (mouse) cursor back from busy status to normal.
280  *
281  * Reimplemented from YApplication.
282  **/
283  virtual void normalCursor();
284 
285  /**
286  * Make a screen shot and save it to the specified file.
287  *
288  * Reimplemented from YApplication.
289  **/
290  virtual void makeScreenShot( const std::string & fileName );
291 
292  /**
293  * Beep.
294  *
295  * Reimplemented from YApplication.
296  **/
297  virtual void beep();
298 
299  /**
300  * Return position of the context menu (in gloabl coordinates)
301  **/
302  virtual QPoint contextMenuPos() { return _contextMenuPos; }
303 
304  /**
305  * Sets the position of the context menu (in gloabl coordinates)
306  **/
307  virtual void setContextMenuPos( QPoint contextMenuPos );
308 
309  // Display information and UI capabilities.
310  //
311  // All implemented from YApplication.
312 
313  virtual int displayWidth();
314  virtual int displayHeight();
315  virtual int displayDepth();
316  virtual long displayColors();
317 
318  // Size of main dialogs
319  virtual int defaultWidth();
320  virtual int defaultHeight();
321 
322  //
323  // UI capabilities
324  //
325 
326  virtual bool isTextMode() { return false; }
327  virtual bool hasImageSupport() { return true; }
328  virtual bool hasIconSupport() { return true; }
329  virtual bool hasAnimationSupport() { return true; }
330  virtual bool hasFullUtf8Support() { return true; }
331  virtual bool richTextSupportsTable() { return true; }
332  virtual bool hasWizardDialogSupport() { return true; }
333  virtual bool leftHandedMouse();
334 
335  /**
336  * Set the application title
337  *
338  * Reimplemented from YApplication.
339  **/
340  virtual void setApplicationTitle(const std::string& title);
341 
342  /**
343  * Set the application Icon
344  *
345  * Reimplemented from YApplication.
346  **/
347  virtual void setApplicationIcon(const std::string& icon);
348 protected:
349 
350  /**
351  * Constructs a key for the language specific font file:
352  * "font[lang]"
353  * for
354  * font[de_DE] = "Sans Serif"
355  * font[zh] = "ChineseSpecial, something"
356  * font[ja_JP] = "JapaneseSpecial, something"
357  * font = "Sans Serif"
358  **/
359  QString fontKey( const QString & lang );
360 
361 
362  //
363  // Data members
364  //
365 
366  // Fonts
367 
368  QFont * _currentFont;
369  QFont * _headingFont;
370  QFont * _boldFont;
371 
372  /**
373  * Font family or list of font families to use ("Sans Serif" etc.)
374  **/
375  QString _fontFamily;
376 
377  /**
378  * Language-specific font settings
379  **/
380  QSettings * _langFonts;
381 
382  /**
383  * Translator for the predefined Qt dialogs
384  **/
385  QTranslator * _qtTranslations;
386 
387  //
388  // Misc
389  //
390 
391  bool _autoFonts;
392  int _autoNormalFontSize;
393  int _autoHeadingFontSize;
394 
395  bool _leftHandedMouse;
396  bool _askedForLeftHandedMouse;
397 
398  QPoint _contextMenuPos;
399  QMenu* _contextMenu;
400 
401 
402 };
403 
404 
405 #endif // YQApplication_h