Qtopia library API Documentation

qt_override.cpp

00001 
00002 #include <qpe/qpeapplication.h>
00003 #include <qwsdecoration_qws.h>
00004 #include <qcommonstyle.h>
00005 #include <qfontdatabase.h>
00006 
00007 #include <unistd.h>
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <limits.h>
00011 #include <sys/param.h> // for toolchains with old libc headers
00012 
00013 #include "qt_override_p.h"
00014 
00015 #if QT_VERSION > 233
00016 
00017 struct color_fix_t {
00018     char *m_app;
00019     char *m_class;
00020     char *m_name;
00021     QColorGroup::ColorRole m_set;
00022     QColorGroup::ColorRole m_get;
00023 };
00024 
00025 #ifndef OPIE_NO_OVERRIDE_QT
00026 
00027 static const color_fix_t apps_that_need_special_colors [] = {
00028     { "HancomMobileWord", "HTextEdit", 0, QColorGroup::Background, QColorGroup::Base },
00029     { "neocal", "Display", 0, QColorGroup::Background, QColorGroup::Base },
00030 
00031     { 0, 0, 0, QColorGroup::Base, QColorGroup::Base }
00032 };
00033 
00034 static const char * const apps_that_need_pointsizes_times_10 [] = {
00035     "HancomMobileWord",
00036     "hancomsheet",
00037     "HancomPresenterViewer",
00038 
00039     0
00040 };
00041 
00042 
00043 
00044 
00045 int Opie::force_appearance = 0;
00046 
00047 
00048 // Return the *real* name of the binary - not just a quick guess
00049 // by looking at argv [0] (which could be anything)
00050 
00051 static void binaryNameFree ( )
00052 {
00053     ::free ((void *) Opie::binaryName ( )); // we need to cast away the const here
00054 }
00055 
00056 const char *Opie::binaryName ( )
00057 {
00058     static const char *appname = 0;
00059 
00060     if ( !appname ) {
00061         char dst [PATH_MAX + 1];
00062         int l = ::readlink ( "/proc/self/exe", dst, PATH_MAX );
00063 
00064         if ( l <= 0 )
00065             l = 0;
00066 
00067         dst [l] = 0;
00068         const char *b = ::strrchr ( dst, '/' );
00069         appname = ::strdup ( b ? b + 1 : dst );
00070 
00071         ::atexit ( binaryNameFree );
00072     }
00073     return appname;
00074 }
00075 
00076 #else
00077 int Opie::force_appearance = 0;
00078 #endif
00079 
00080 // Fix for a toolchain incompatibility (binaries compiled with
00081 // old tcs using shared libs compiled with newer tcs)
00082 
00083 extern "C" {
00084 
00085 extern void __gmon_start__ ( ) __attribute__(( weak ));
00086 
00087 extern void __gmon_start__ ( )
00088 {
00089 }
00090 
00091 }
00092 
00093 
00094 // Fix for apps, that use QPainter::eraseRect() which doesn't work with styles
00095 // that set a background pixmap (it would be easier to fix eraseRect(), but
00096 // TT made it an inline ...)
00097 
00098 void QPEApplication::polish ( QWidget *w )
00099 {
00100 #ifndef OPIE_NO_OVERRIDE_QT
00101 //  qDebug ( "QPEApplication::polish()" );
00102 
00103     for ( const color_fix_t *ptr = apps_that_need_special_colors; ptr-> m_app; ptr++ ) {
00104         if (( ::strcmp ( Opie::binaryName ( ), ptr-> m_app ) == 0 ) &&
00105             ( ptr-> m_class ? w-> inherits ( ptr-> m_class ) : true ) &&
00106             ( ptr-> m_name ? ( ::strcmp ( w-> name ( ), ptr-> m_name ) == 0 ) : true )) {
00107             QPalette pal = w-> palette ( );
00108             pal. setColor ( ptr-> m_set, pal. color ( QPalette::Active, ptr-> m_get ));
00109             w-> setPalette ( pal );
00110         }
00111     }
00112 #endif
00113     QApplication::polish ( w );
00114 }
00115 
00116 
00117 #ifndef OPIE_NO_OVERRIDE_QT
00118 // Fix for the binary incompatibility that TT introduced in Qt/E 2.3.4 -- point sizes
00119 // were multiplied by 10 (which was incorrect)
00120 
00121 QValueList <int> QFontDatabase::pointSizes ( QString const &family, QString const &style, QString const &charset )
00122 {
00123 //  qDebug ( "QFontDatabase::pointSizes()" );
00124 
00125     QValueList <int> sl = pointSizes_NonWeak ( family, style, charset );
00126 
00127     for ( const char * const *ptr = apps_that_need_pointsizes_times_10; *ptr; ptr++ ) {
00128         if ( ::strcmp ( Opie::binaryName ( ), *ptr ) == 0 ) {
00129             for ( QValueList <int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
00130                 *it *= 10;
00131         }
00132     }
00133     return sl;
00134 }
00135 
00136 
00137 // Various style/font/color related overrides for weak symbols in Qt/E,
00138 // which allows us to force the usage of the global Opie appearance.
00139 
00140 void QApplication::setStyle ( QStyle *style )
00141 {
00142 //  qDebug ( "QApplication::setStyle()" );
00143 
00144     if ( Opie::force_appearance & Opie::Force_Style )
00145         delete style;
00146     else
00147         QApplication::setStyle_NonWeak ( style );
00148 }
00149 
00150 void QApplication::setPalette ( const QPalette &pal, bool informWidgets, const char *className )
00151 {
00152 //  qDebug ( "QApplication::setPalette()" );
00153 
00154     if (!( Opie::force_appearance & Opie::Force_Style ))
00155         QApplication::setPalette_NonWeak ( pal, informWidgets, className );
00156 }
00157 
00158 void QApplication::setFont ( const QFont &fnt, bool informWidgets, const char *className )
00159 {
00160 //  qDebug ( "QApplication::setFont()" );
00161 
00162     if (!( Opie::force_appearance & Opie::Force_Font ))
00163         QApplication::setFont_NonWeak ( fnt, informWidgets, className );
00164 }
00165 
00166 
00167 void QApplication::qwsSetDecoration ( QWSDecoration *deco )
00168 {
00169 //  qDebug ( "QApplication::qwsSetDecoration()" );
00170 
00171     if ( Opie::force_appearance & Opie::Force_Decoration )
00172         delete deco;
00173     else
00174         QApplication::qwsSetDecoration_NonWeak ( deco );
00175 }
00176 #endif
00177 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001