libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQApplication.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:       YQApplication.h
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #ifndef YQApplication_h
00027 #define YQApplication_h
00028 
00029 #include <Qt/qobject.h>
00030 #include <Qt/qtranslator.h>
00031 #include <qfont.h>
00032 
00033 #include "YQPackageSelectorPluginStub.h"
00034 #include "YQGraphPluginStub.h"
00035 #include <yui/YApplication.h>
00036 
00037 class QSettings;
00038 class YQPackageSelectorPlugin;
00039 class YQGraphPlugin;
00040 class QMenu;
00041 
00042 
00043 class YQApplication: public QObject, public YApplication
00044 {
00045     Q_OBJECT
00046 
00047 protected:
00048 
00049     friend class YQUI;
00050 
00051     /**
00052      * Constructor.
00053      *
00054      * Use YUI::app() to get the singleton for this class.
00055      **/
00056     YQApplication();
00057 
00058     /**
00059      * Destructor.
00060      **/
00061     virtual ~YQApplication();
00062 
00063 
00064 public:
00065 
00066     /**
00067      * Set language and encoding for the locale environment ($LANG).
00068      *
00069      * Load UI-internal translations (e.g. for predefined dialogs like
00070      * file selection) and fonts.
00071      *
00072      * 'language' is the ISO short code ("de_DE", "en_US", ...).
00073      *
00074      * 'encoding' an (optional) encoding ("utf8", ...) that will be appended if
00075      *  present.
00076      *
00077      * Reimplemented from YApplication.
00078      **/
00079     virtual void setLanguage( const std::string & language,
00080                               const std::string & encoding = std::string() );
00081 
00082     /**
00083      * Load translations for Qt's predefined dialogs like file selection box
00084      * etc.
00085      **/
00086     void loadPredefinedQtTranslations();
00087 
00088     /**
00089      * Set the layout direction (left-to-right or right-to-left) from
00090      * 'language'.
00091      **/
00092     void setLayoutDirection( const std::string & language );
00093 
00094     /**
00095      * Set fonts according to the specified language and encoding.
00096      *
00097      * This is most important for some Asian languages that have overlaps in
00098      * the Unicode table, like Japanese vs. Chinese.
00099      **/
00100     void setLangFonts( const std::string & language,
00101                        const std::string & encoding = std::string() );
00102 
00103     /**
00104      * Returns the application's default font.
00105      **/
00106     const QFont & currentFont();
00107 
00108     /**
00109      * Returns the application's default bold font.
00110      **/
00111     const QFont & boldFont();
00112 
00113     /**
00114      * Returns the application's heading font.
00115      **/
00116     const QFont & headingFont();
00117 
00118     /**
00119      * Delete the fonts so they will be reloaded upon their next usage.
00120      **/
00121     void deleteFonts();
00122 
00123     /**
00124      * Determine good fonts based on defaultsize geometry and set
00125      * _auto_normal_font_size and _auto_heading_font_size accordingly.
00126      * Caches the values, so it's safe to call this repeatedly.
00127      **/
00128     void pickAutoFonts();
00129 
00130     /**
00131      * Returns 'true' if the UI  automatically picks fonts, disregarding Qt
00132      * standard settings.
00133      *
00134      * This makes sense during system installation system where the display DPI
00135      * cannot reliably be retrieved and thus Qt uses random font sizes based on
00136      * that random DPI.
00137      **/
00138     bool autoFonts() const { return _autoFonts; }
00139 
00140     /**
00141      * Set whether or not fonts should automatically be picked.
00142      **/
00143     void setAutoFonts( bool useAutoFonts );
00144 
00145     /**
00146      * Return a std::string for a named glyph.
00147      *
00148      * Using this is discouraged in new applications.
00149      *
00150      * Reimplemented from YApplication.
00151      **/
00152     virtual std::string glyph( const std::string & glyphSymbolName );
00153 
00154     /**
00155      * Open a directory selection box and prompt the user for an existing
00156      * directory.
00157      *
00158      * 'startDir' is the initial directory that is displayed.
00159      *
00160      * 'headline' is an explanatory text for the directory selection box.
00161      * Graphical UIs may omit that if no window manager is running.
00162      *
00163      * Returns the selected directory name
00164      * or an empty std::string if the user canceled the operation.
00165      *
00166      * Implemented from YApplication.
00167      **/
00168     virtual std::string askForExistingDirectory( const std::string & startDir,
00169                                             const std::string & headline );
00170 
00171     /**
00172      * Open a file selection box and prompt the user for an existing file.
00173      *
00174      * 'startWith' is the initial directory or file.
00175      *
00176      * 'filter' is one or more blank-separated file patterns, e.g.
00177      * "*.png *.jpg"
00178      *
00179      * 'headline' is an explanatory text for the file selection box.
00180      * Graphical UIs may omit that if no window manager is running.
00181      *
00182      * Returns the selected file name
00183      * or an empty std::string if the user canceled the operation.
00184      *
00185      * Implemented from YApplication.
00186      **/
00187     virtual std::string askForExistingFile( const std::string & startWith,
00188                                        const std::string & filter,
00189                                        const std::string & headline );
00190 
00191     /**
00192      * Open a file selection box and prompt the user for a file to save data
00193      * to.  Automatically asks for confirmation if the user selects an existing
00194      * file.
00195      *
00196      * 'startWith' is the initial directory or file.
00197      *
00198      * 'filter' is one or more blank-separated file patterns, e.g.
00199      * "*.png *.jpg"
00200      *
00201      * 'headline' is an explanatory text for the file selection box.
00202      * Graphical UIs may omit that if no window manager is running.
00203      *
00204      * Returns the selected file name
00205      * or an empty std::string if the user canceled the operation.
00206      *
00207      * Implemented from YApplication.
00208      **/
00209     virtual std::string askForSaveFileName( const std::string & startWith,
00210                                        const std::string & filter,
00211                                        const std::string & headline );
00212     /**
00213      * Lower-level version that works with QStrings and does not change
00214      * the mouse cursor.
00215      **/
00216     static QString askForSaveFileName( const QString & startWith,
00217                                        const QString & filter,
00218                                        const QString & headline );
00219 
00220     /**
00221      * Open a context menu for a widget
00222      *
00223      * 'itemCollection' describes the menu structure
00224      *
00225      * Returns true on success (otherwise false).
00226      *
00227      * Implemented from YApplication.
00228      **/
00229     virtual bool openContextMenu (  const YItemCollection & itemCollection );
00230 
00231 
00232     /**
00233      * Return the package selector plugin singleton or creates it
00234      * (including loading the plugin lib) if it does not exist yet.
00235      **/
00236     static YQPackageSelectorPluginStub * packageSelectorPlugin();
00237 
00238     /**
00239      * Return the package selector plugin singleton or creates it
00240      * (including loading the plugin lib) if it does not exist yet.
00241      **/
00242     static YQGraphPluginStub * graphPlugin();
00243 
00244     /**
00245      * A mouse click with the wrong mouse button was detected - e.g., a right
00246      * click on a push button. The user might be left-handed, but his mouse
00247      * might not (yet) be configured for left-handed use - e.g., during
00248      * installation. Ask him if he would like his mouse temporarily configured
00249      * as a left-handed mouse.
00250      *
00251      * This status can be queried with YQApplication::leftHandedMouse().
00252      **/
00253     void maybeLeftHandedUser();
00254 
00255     /**
00256      * Convert logical layout spacing units into device dependent units.
00257      * A default size dialog is assumed to be 80x25 layout spacing units.
00258      *
00259      * Reimplemented from YApplication.
00260      **/
00261     virtual int deviceUnits( YUIDimension dim, float layoutUnits );
00262 
00263     /**
00264      * Convert device dependent units into logical layout spacing units.
00265      * A default size dialog is assumed to be 80x25 layout spacing units.
00266      *
00267      * Reimplemented from YApplication.
00268      **/
00269     virtual float layoutUnits( YUIDimension dim, int deviceUnits );
00270 
00271     /**
00272      * Change the (mouse) cursor to indicate busy status.
00273      *
00274      * Reimplemented from YApplication.
00275      **/
00276     virtual void busyCursor();
00277 
00278     /**
00279      * Change the (mouse) cursor back from busy status to normal.
00280      *
00281      * Reimplemented from YApplication.
00282      **/
00283     virtual void normalCursor();
00284 
00285     /**
00286      * Make a screen shot and save it to the specified file.
00287      *
00288      * Reimplemented from YApplication.
00289      **/
00290     virtual void makeScreenShot( const std::string & fileName );
00291 
00292     /**
00293      * Beep.
00294      *
00295      * Reimplemented from YApplication.
00296      **/
00297     virtual void beep();
00298 
00299     /**
00300      * Return position of the context menu (in gloabl coordinates)
00301      **/
00302     virtual QPoint contextMenuPos() { return _contextMenuPos; }
00303 
00304     /**
00305      * Sets the position of the context menu (in gloabl coordinates)
00306      **/
00307     virtual void setContextMenuPos( QPoint contextMenuPos );
00308 
00309     // Display information and UI capabilities.
00310     //
00311     // All implemented from YApplication.
00312 
00313     virtual int  displayWidth();
00314     virtual int  displayHeight();
00315     virtual int  displayDepth();
00316     virtual long displayColors();
00317 
00318     // Size of main dialogs
00319     virtual int  defaultWidth();
00320     virtual int  defaultHeight();
00321 
00322     //
00323     // UI capabilities
00324     //
00325 
00326     virtual bool isTextMode()                   { return false; }
00327     virtual bool hasImageSupport()              { return true; }
00328     virtual bool hasIconSupport()               { return true; }
00329     virtual bool hasAnimationSupport()          { return true; }
00330     virtual bool hasFullUtf8Support()           { return true; }
00331     virtual bool richTextSupportsTable()        { return true; }
00332     virtual bool hasWizardDialogSupport()       { return true; }
00333     virtual bool leftHandedMouse();
00334 
00335     /**
00336      * Set the application title
00337      *
00338      * Reimplemented from YApplication.
00339      **/
00340     virtual void setApplicationTitle(const std::string& title);
00341 
00342     /**
00343      * Set the application Icon
00344      *
00345      * Reimplemented from YApplication.
00346      **/
00347     virtual void setApplicationIcon(const std::string& icon);
00348 protected:
00349 
00350     /**
00351      * Constructs a key for the language specific font file:
00352      *     "font[lang]"
00353      * for
00354      *     font[de_DE] = "Sans Serif"
00355      *     font[zh] = "ChineseSpecial, something"
00356      *     font[ja_JP] = "JapaneseSpecial, something"
00357      *     font = "Sans Serif"
00358      **/
00359     QString fontKey( const QString & lang );
00360 
00361 
00362     //
00363     // Data members
00364     //
00365 
00366     // Fonts
00367 
00368     QFont * _currentFont;
00369     QFont * _headingFont;
00370     QFont * _boldFont;
00371 
00372     /**
00373      * Font family or list of font families to use ("Sans Serif" etc.)
00374      **/
00375     QString _fontFamily;
00376 
00377     /**
00378      * Language-specific font settings
00379      **/
00380     QSettings   * _langFonts;
00381 
00382     /**
00383      * Translator for the predefined Qt dialogs
00384      **/
00385     QTranslator * _qtTranslations;
00386 
00387     //
00388     // Misc
00389     //
00390 
00391     bool _autoFonts;
00392     int  _autoNormalFontSize;
00393     int  _autoHeadingFontSize;
00394 
00395     bool _leftHandedMouse;
00396     bool _askedForLeftHandedMouse;
00397 
00398     QPoint _contextMenuPos;
00399     QMenu*  _contextMenu;
00400 
00401 
00402 };
00403 
00404 
00405 #endif // YQApplication_h
 All Classes Functions Variables