author | sandman <sandman> | 2002-11-25 22:12:18 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-11-25 22:12:18 (UTC) |
commit | 4e6b2585987290f874697cbec7c289b4df29f82b (patch) (side-by-side diff) | |
tree | e19415ef5374ffa3730380813298111e24711590 /library | |
parent | 7bd8ef9197506897d3a5287a013934f89658d60a (diff) | |
download | opie-4e6b2585987290f874697cbec7c289b4df29f82b.zip opie-4e6b2585987290f874697cbec7c289b4df29f82b.tar.gz opie-4e6b2585987290f874697cbec7c289b4df29f82b.tar.bz2 |
Some changes to the QPEDecoration c'tor internals:
Since the current deco plugin is unloaded, when a new Deco is created
via new (even if this new deco is never used or deleted immediatly afer-
wards), we have to remember the plugin name, in case someone calls the
default c'tor (without supplying a plugin name)
-rw-r--r-- | library/qpeapplication.cpp | 9 | ||||
-rw-r--r-- | library/qpedecoration_qws.cpp | 41 | ||||
-rw-r--r-- | library/qpedecoration_qws.h | 2 |
3 files changed, 25 insertions, 27 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index a54fb20..c8e6e74 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp @@ -854,191 +854,194 @@ QString QPEApplication::documentDir() static int deforient = -1; /*! \internal */ int QPEApplication::defaultRotation() { if ( deforient < 0 ) { QString d = getenv( "QWS_DISPLAY" ); if ( d.contains( "Rot90" ) ) { deforient = 90; } else if ( d.contains( "Rot180" ) ) { deforient = 180; } else if ( d.contains( "Rot270" ) ) { deforient = 270; } else { deforient = 0; } } return deforient; } /*! \internal */ void QPEApplication::setDefaultRotation( int r ) { if ( qApp->type() == GuiServer ) { deforient = r; setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); Config config("qpe"); config.setGroup( "Rotation" ); config.writeEntry( "Screen", getenv("QWS_DISPLAY") ); } else { #ifndef QT_NO_COP { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); e << r; } #endif } } // exported to libpreload.so -bool opie_block_style = false; +int opie_block_style = 0; /*! \internal */ void QPEApplication::applyStyle() { Config config( "qpe" ); config.setGroup( "Appearance" ); // don't block ourselves ... - opie_block_style = false; + opie_block_style = 0; static QString appname; if ( appname. isNull ( )) { char src [32]; char dst [PATH_MAX + 1]; ::sprintf ( src, "/proc/%d/exe", ::getpid ( )); int l = ::readlink ( src, dst, PATH_MAX ); if ( l > 0 ) { dst [l] = 0; const char *b = ::strrchr ( dst, '/' ); appname = ( b ? b + 1 : dst ); } else appname = ""; } QStringList ex = config. readListEntry ( "NoStyle", ';' ); int nostyle = 0; for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); break; } } // Widget style QString style = config.readEntry( "Style", "Light" ); // don't set a custom style if ( nostyle & 0x01 ) style = "Light"; internalSetStyle ( style ); // Colors QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); QPalette pal( btncolor, bgcolor ); QString color = config.readEntry( "Highlight", "#800000" ); pal.setColor( QColorGroup::Highlight, QColor( color ) ); color = config.readEntry( "HighlightedText", "#FFFFFF" ); pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); color = config.readEntry( "Text", "#000000" ); pal.setColor( QColorGroup::Text, QColor( color ) ); color = config.readEntry( "ButtonText", "#000000" ); pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); color = config.readEntry( "Base", "#FFFFFF" ); pal.setColor( QColorGroup::Base, QColor( color ) ); pal.setColor( QPalette::Disabled, QColorGroup::Text, pal.color( QPalette::Active, QColorGroup::Background ).dark() ); setPalette( pal, TRUE ); // Window Decoration QString dec = config.readEntry( "Decoration", "Qtopia" ); // don't set a custom deco if ( nostyle & 0x04 ) dec = ""; + //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); + if ( dec != d->decorationName ) { qwsSetDecoration( new QPEDecoration( dec ) ); d->decorationName = dec; } // Font QString ff = config.readEntry( "FontFamily", font().family() ); int fs = config.readNumEntry( "FontSize", font().pointSize() ); // don't set a custom font if ( nostyle & 0x02 ) { ff = "Helvetica"; fs = 10; } setFont( QFont(ff, fs) ); // revert to global blocking policy ... - opie_block_style = config. readBoolEntry ( "ForceStyle", false ); + opie_block_style = config. readBoolEntry ( "ForceStyle", false ) ? 0xff : 0x00; + opie_block_style -= nostyle; } void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) { #ifdef Q_WS_QWS QDataStream stream( data, IO_ReadOnly ); if ( msg == "applyStyle()" ) { applyStyle(); } else if ( msg == "setDefaultRotation(int)" ) { if ( type() == GuiServer ) { int r; stream >> r; setDefaultRotation( r ); } } else if ( msg == "shutdown()" ) { if ( type() == GuiServer ) shutdown(); } else if ( msg == "quit()" ) { if ( type() != GuiServer ) tryQuit(); } else if ( msg == "forceQuit()" ) { if ( type() != GuiServer ) quit(); } else if ( msg == "restart()" ) { if ( type() == GuiServer ) restart(); } else if ( msg == "grabKeyboard(QString)" ) { QString who; stream >> who; if ( who.isEmpty() ) d->kbgrabber = 0; else if ( who != d->appName ) d->kbgrabber = 1; else d->kbgrabber = 2; } else if ( msg == "language(QString)" ) { if ( type() == GuiServer ) { QString l; stream >> l; QString cl = getenv( "LANG" ); if ( cl != l ) { diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp index 6221f5b..5e0c32a 100644 --- a/library/qpedecoration_qws.cpp +++ b/library/qpedecoration_qws.cpp @@ -435,156 +435,149 @@ void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowD if ( img ) { if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) p->drawImage(x+2, y+2, *img); else p->drawImage(x+1, y+1, *img); } } QRegion WindowDecorationInterface::mask( const WindowData *wd ) const { int th = metric(TitleHeight,wd); QRect rect( wd->rect ); QRect r(rect.left() - metric(LeftBorder,wd), rect.top() - th - metric(TopBorder,wd), rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); return QRegion(r) - rect; } class DefaultWindowDecoration : public WindowDecorationInterface { public: DefaultWindowDecoration() : ref(0) {} QString name() const { return "Default"; } QPixmap icon() const { return QPixmap(); } QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_WindowDecoration ) *iface = this; if ( *iface ) (*iface)->addRef(); return QS_OK; } Q_REFCOUNT private: ulong ref; }; static WindowDecorationInterface *wdiface = 0; static QLibrary *wdlib = 0; +static QString libname; //=========================================================================== QPEDecoration::QPEDecoration() : QWSDefaultDecoration() { - if ( wdlib ) { - wdiface->release(); - wdlib->unload(); - delete wdlib; - wdlib = 0; - } else { - delete wdiface; - } - wdiface = new DefaultWindowDecoration; - - helpFile = QString(qApp->argv()[0]) + ".html"; - QStringList helpPath = Global::helpPath(); - helpExists = FALSE; - for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { - helpExists = QFile::exists( *it + "/" + helpFile ); - qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); - } - qpeManager = new QPEManager( this ); - - // for backward compatibility: - imageOk = *okImage ( 15 ); - imageClose = *closeImage ( 15 ); - imageHelp = *helpImage ( 15 ); + init ( libname ); } QPEDecoration::QPEDecoration( const QString &plugin ) : QWSDefaultDecoration() { + init ( plugin ); +} + +void QPEDecoration::init ( const QString &plugin ) +{ + libname = plugin; + if ( wdlib ) { wdiface->release(); wdlib->unload(); delete wdlib; wdlib = 0; } else { delete wdiface; } + WindowDecorationInterface *iface = 0; QString path = QPEApplication::qpeDir() + "/plugins/decorations"; QLibrary *lib = new QLibrary( path + "/" + plugin ); if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { wdiface = iface; wdlib = lib; } else { delete lib; wdiface = new DefaultWindowDecoration; } helpFile = QString(qApp->argv()[0]) + ".html"; QStringList helpPath = Global::helpPath(); helpExists = FALSE; for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { helpExists = QFile::exists( *it + "/" + helpFile ); - qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); } + //qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); + } qpeManager = new QPEManager( this ); + + // Qtopia 1.5 compatibility + imageOk = *okImage ( 15 ); + imageClose = *closeImage ( 15 ); + imageHelp = *helpImage ( 15 ); } QPEDecoration::~QPEDecoration() { delete qpeManager; } const char **QPEDecoration::menuPixmap() { return (const char **)0; } const char **QPEDecoration::closePixmap() { return (const char **)qpe_close_xpm; } const char **QPEDecoration::minimizePixmap() { return (const char **)qpe_accept_xpm; } const char **QPEDecoration::maximizePixmap() { return (const char **)0; } const char **QPEDecoration::normalizePixmap() { return (const char **)0; } int QPEDecoration::getTitleHeight( const QWidget *w ) { WindowDecorationInterface::WindowData wd; windowData( w, wd ); return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); } /* If rect is empty, no frame is added. (a hack, really) */ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) { qpeManager->updateActive(); WindowDecorationInterface::WindowData wd; windowData( widget, wd ); diff --git a/library/qpedecoration_qws.h b/library/qpedecoration_qws.h index 691c6f6..6628ba2 100644 --- a/library/qpedecoration_qws.h +++ b/library/qpedecoration_qws.h @@ -18,94 +18,96 @@ ** **********************************************************************/ #ifndef QPE_DECORATION_QWS_H__ #define QPE_DECORATION_QWS_H__ #ifdef QWS #include <qwsdefaultdecoration_qws.h> #include <qimage.h> #include <qdatetime.h> #include <qguardedptr.h> #include "windowdecorationinterface.h" #ifndef QT_NO_QWS_QPE_WM_STYLE class QPEManager; class QTimer; class QPEDecoration : public QWSDefaultDecoration { public: QPEDecoration(); QPEDecoration( const QString &plugin ); virtual ~QPEDecoration(); virtual QRegion region(const QWidget *, const QRect &rect, Region); virtual void paint(QPainter *, const QWidget *); virtual void paintButton(QPainter *, const QWidget *, Region, int state); void maximize( QWidget * ); void minimize( QWidget * ); virtual void help( QWidget * ); enum QPERegion { Help=LastRegion+1 }; void buttonClicked( QPERegion r ); protected: virtual int getTitleHeight(const QWidget *); virtual const char **menuPixmap(); virtual const char **closePixmap(); virtual const char **minimizePixmap(); virtual const char **maximizePixmap(); virtual const char **normalizePixmap(); private: void windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const; + void init ( const QString & ); + protected: QImage imageOk; QImage imageClose; QImage imageHelp; QString helpFile; bool helpExists; QPEManager *qpeManager; }; class QPEManager : public QObject { Q_OBJECT friend class QPEDecoration; public: QPEManager( QPEDecoration *d, QObject *parent=0 ); void updateActive(); const QWidget *activeWidget() const { return (const QWidget *)active; } const QWidget *whatsThisWidget() const { return (const QWidget *)whatsThis; } protected: int pointInQpeRegion( QWidget *w, const QPoint &p ); virtual bool eventFilter( QObject *, QEvent * ); void drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ); void drawTitle( QWidget *w ); protected slots: void whatsThisTimeout(); protected: QPEDecoration *decoration; QGuardedPtr<QWidget> active; int helpState; QTime pressTime; QTimer *wtTimer; bool inWhatsThis; QGuardedPtr<QWidget> whatsThis; }; #endif // QT_NO_QWS_QPE_WM_STYLE #endif // QPE_DECORATION_QWS_H__ #endif // QWS |