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 | |
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 @@ -646,607 +646,610 @@ void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) class HackDialog : public QDialog { public: void acceptIt() { accept(); } void rejectIt() { reject(); } }; void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) { // specialised actions for certain widgets. May want to // add more stuff here. if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) && activePopupWidget() ->parentWidget() && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) key = Qt::Key_Return; if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) key = Qt::Key_Return; #ifdef QWS ke->simpleData.keycode = key; #endif } class HackWidget : public QWidget { public: bool needsOk() { return ( getWState() & WState_Reserved1 ); } }; /*! \internal */ #ifdef QWS bool QPEApplication::qwsEventFilter( QWSEvent * e ) { if ( !d->notbusysent && e->type == QWSEvent::Focus ) { if ( qApp->type() != QApplication::GuiServer ) { QCopEnvelope e( "QPE/System", "notBusy(QString)" ); e << d->appName; } d->notbusysent = TRUE; } if ( type() == GuiServer ) { switch ( e->type ) { case QWSEvent::Mouse: if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) emit clientMoused(); break; default: break; } } if ( e->type == QWSEvent::Key ) { if ( d->kbgrabber == 1 ) return TRUE; QWSKeyEvent *ke = ( QWSKeyEvent * ) e; if ( ke->simpleData.keycode == Qt::Key_F33 ) { // Use special "OK" key to press "OK" on top level widgets QWidget * active = activeWindow(); QWidget *popup = 0; if ( active && active->isPopup() ) { popup = active; active = active->parentWidget(); } if ( active && ( int ) active->winId() == ke->simpleData.window && !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { if ( ke->simpleData.is_press ) { if ( popup ) popup->close(); if ( active->inherits( "QDialog" ) ) { HackDialog * d = ( HackDialog * ) active; d->acceptIt(); return TRUE; } else if ( ( ( HackWidget * ) active ) ->needsOk() ) { QSignal s; s.connect( active, SLOT( accept() ) ); s.activate(); } else { // do the same as with the select key: Map to the default action of the widget: mapToDefaultAction( ke, Qt::Key_Return ); } } } } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { // Use special "select" key to do whatever default action a widget has mapToDefaultAction( ke, Qt::Key_Space ); } else if ( ke->simpleData.keycode == Qt::Key_Escape && ke->simpleData.is_press ) { // Escape key closes app if focus on toplevel QWidget * active = activeWindow(); if ( active && active->testWFlags( WType_TopLevel ) && ( int ) active->winId() == ke->simpleData.window && !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { if ( active->inherits( "QDialog" ) ) { HackDialog * d = ( HackDialog * ) active; d->rejectIt(); return TRUE; } else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { active->close(); } } } #if QT_VERSION < 231 // Filter out the F4/Launcher key from apps // ### The launcher key may not always be F4 on all devices if ( ( ( QWSKeyEvent * ) e ) ->simpleData.keycode == Qt::Key_F4 ) return TRUE; #endif } if ( e->type == QWSEvent::Focus ) { QWSFocusEvent * fe = ( QWSFocusEvent* ) e; QWidget* nfw = QWidget::find( e->window() ); if ( !fe->simpleData.get_focus ) { QWidget * active = activeWindow(); while ( active && active->isPopup() ) { active->close(); active = activeWindow(); } if ( !nfw && d->kbgrabber == 2 ) { ungrabKeyboard(); d->kbregrab = TRUE; // want kb back when we're active } } else { // make sure our modal widget is ALWAYS on top QWidget *topm = activeModalWidget(); if ( topm ) { topm->raise(); } if ( d->kbregrab ) { grabKeyboard(); d->kbregrab = FALSE; } } if ( fe->simpleData.get_focus && inputMethodDict ) { InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); if ( m == AlwaysOff ) Global::hideInputMethod(); if ( m == AlwaysOn ) Global::showInputMethod(); } } return QApplication::qwsEventFilter( e ); } #endif /*! Destroys the QPEApplication. */ QPEApplication::~QPEApplication() { ungrabKeyboard(); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) // Need to delete QCopChannels early, since the display will // be gone by the time we get to ~QObject(). delete sysChannel; delete pidChannel; #endif delete d; } /*! Returns <tt>$OPIEDIR/</tt>. */ QString QPEApplication::qpeDir() { const char * base = getenv( "OPIEDIR" ); if ( base ) return QString( base ) + "/"; return QString( "../" ); } /*! Returns the user's current Document directory. There is a trailing "/". .. well, it does now,, and there's no trailing '/' */ QString QPEApplication::documentDir() { const char* base = getenv( "HOME"); if ( base ) return QString( base ) + "/Documents"; return QString( "../Documents" ); } 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 ) { if ( l.isNull() ) unsetenv( "LANG" ); else setenv( "LANG", l.latin1(), 1 ); restart(); } } } else if ( msg == "timeChange(QString)" ) { QString t; stream >> t; if ( t.isNull() ) unsetenv( "TZ" ); else setenv( "TZ", t.latin1(), 1 ); // emit the signal so everyone else knows... emit timeChanged(); } else if ( msg == "execute(QString)" ) { if ( type() == GuiServer ) { QString t; stream >> t; Global::execute( t ); } } else if ( msg == "execute(QString,QString)" ) { if ( type() == GuiServer ) { QString t, d; stream >> t >> d; Global::execute( t, d ); } } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { if ( type() == GuiServer ) { QDateTime when; QCString channel, message; int data; stream >> when >> channel >> message >> data; AlarmServer::addAlarm( when, channel, message, data ); } } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { if ( type() == GuiServer ) { QDateTime when; QCString channel, message; int data; stream >> when >> channel >> message >> data; AlarmServer::deleteAlarm( when, channel, message, data ); } } else if ( msg == "clockChange(bool)" ) { int tmp; stream >> tmp; emit clockChanged( tmp ); } else if ( msg == "weekChange(bool)" ) { int tmp; stream >> tmp; emit weekChanged( tmp ); } else if ( msg == "setDateFormat(DateFormat)" ) { DateFormat tmp; stream >> tmp; emit dateFormatChanged( tmp ); } else if ( msg == "setVolume(int,int)" ) { int t, v; stream >> t >> v; setVolume( t, v ); emit volumeChanged( muted ); } else if ( msg == "volumeChange(bool)" ) { stream >> muted; setVolume(); emit volumeChanged( muted ); } else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> int t, v; stream >> t >> v; setMic( t, v ); emit micChanged( micMuted ); } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> stream >> micMuted; setMic(); emit micChanged( micMuted ); } #endif } /*! \internal */ bool QPEApplication::raiseAppropriateWindow() { bool r = FALSE; // ########## raise()ing main window should raise and set active // ########## it and then all childen. This belongs in Qt/Embedded QWidget *top = d->qpe_main_widget; if ( !top ) top = mainWidget(); if ( top && d->keep_running ) { if ( top->isVisible() ) r = TRUE; else if (d->preloaded) { // We are preloaded and not visible.. pretend we just started.. QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); e << d->appName; } d->show_mx(top, d->nomaximize); top->raise(); top->setActiveWindow(); } QWidget *topm = activeModalWidget(); if ( topm && topm != top ) { topm->show(); topm->raise(); topm->setActiveWindow(); // If we haven't already handled the fastAppShowing message if (!top && d->preloaded) { QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); e << d->appName; } r = FALSE; } return r; } void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) { #ifdef Q_WS_QWS if ( msg == "quit()" ) { tryQuit(); } else if ( msg == "quitIfInvisible()" ) { if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) quit(); } else if ( msg == "close()" ) { hideOrQuit(); } else if ( msg == "disablePreload()" ) { d->preloaded = FALSE; d->keep_running = TRUE; /* so that quit will quit */ } else if ( msg == "enablePreload()" ) { if (d->qpe_main_widget) d->preloaded = TRUE; d->keep_running = TRUE; /* so next quit won't quit */ } else if ( msg == "raise()" ) { d->keep_running = TRUE; d->notbusysent = FALSE; raiseAppropriateWindow(); // Tell the system we're still chugging along... QCopEnvelope e("QPE/System", "appRaised(QString)"); e << d->appName; } else if ( msg == "flush()" ) { emit flush(); // we need to tell the desktop QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); e << d->appName; } else if ( msg == "reload()" ) { emit reload(); } else if ( msg == "setDocument(QString)" ) { d->keep_running = TRUE; QDataStream stream( data, IO_ReadOnly ); QString doc; stream >> doc; QWidget *mw = mainWidget(); if ( !mw ) mw = d->qpe_main_widget; if ( mw ) Global::setDocument( mw, doc ); } else if ( msg == "nextView()" ) { qDebug("got nextView()"); /* if ( raiseAppropriateWindow() ) */ emit appMessage( msg, data); } else { emit appMessage( msg, data); } #endif } /*! Sets widget \a mw as the mainWidget() and shows it. For small windows, consider passing TRUE for \a nomaximize rather than the default FALSE. \sa showMainDocumentWidget() */ void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) { d->show(mw, nomaximize ); } 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 @@ -227,572 +227,565 @@ bool QPEManager::eventFilter( QObject *o, QEvent *e ) helpState = 0; drawButton( w, QPEDecoration::Help, helpState ); QPoint p = ((QMouseEvent*)e)->globalPos(); if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { decoration->help( w ); } return true; } break; case QEvent::MouseMove: if ( helpState & QWSButton::Clicked ) { int oldState = helpState; QPoint p = ((QMouseEvent*)e)->globalPos(); if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { helpState = QWSButton::Clicked|QWSButton::MouseOver; } else { helpState = 0; } if ( helpState != oldState ) drawButton( w, QPEDecoration::Help, helpState ); } break; default: break; } return QObject::eventFilter( o, e ); } void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) { QPainter painter(w); QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; painter.internalGfx()->setWidgetDeviceRegion( rgn ); painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); } void QPEManager::drawTitle( QWidget *w ) { QPainter painter(w); QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; painter.internalGfx()->setWidgetDeviceRegion( rgn ); painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); decoration->paint( &painter, w ); decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); decoration->paintButton(&painter, w, QWSDecoration::Close, 0); decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); } void QPEManager::whatsThisTimeout() { if ( !QWhatsThis::inWhatsThisMode() ) { if ( inWhatsThis ) { if ( whatsThis ) { QWidget *w = whatsThis; whatsThis = 0; drawTitle( w ); } wtTimer->stop(); } else { QWhatsThis::enterWhatsThisMode(); helpState = 0; updateActive(); if ( active ) { whatsThis = active; drawTitle( active ); // check periodically to see if we've left whats this mode wtTimer->start( 250 ); } } inWhatsThis = !inWhatsThis; } } //=========================================================================== static QImage *okImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); } return i; } static QImage *closeImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); } return i; } static QImage *helpImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); } return i; } static QImage *maximizeImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); } return i; } int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const { switch ( m ) { case TitleHeight: if ( QApplication::desktop()->height() > 320 ) return 19; else return 15; case LeftBorder: case RightBorder: case TopBorder: case BottomBorder: return 4; case OKWidth: return okImage(metric(TitleHeight,wd))->width(); case CloseWidth: return closeImage(metric(TitleHeight,wd))->width(); case HelpWidth: return helpImage(metric(TitleHeight,wd))->width(); case MaximizeWidth: return maximizeImage(metric(TitleHeight,wd))->width(); case CornerGrabSize: return 16; } return 0; } void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const { int th = metric( TitleHeight, wd ); QRect r = wd->rect; switch ( a ) { case Border: { const QColorGroup &cg = wd->palette.active(); qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), r.y()-th-metric(TopBorder,wd), r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), cg, FALSE, &cg.brush(QColorGroup::Background)); } break; case Title: { const QColorGroup &cg = wd->palette.active(); QBrush titleBrush; QPen titleLines; if ( wd->flags & WindowData::Active ) { titleBrush = cg.brush(QColorGroup::Highlight); titleLines = titleBrush.color().dark(); } else { titleBrush = cg.brush(QColorGroup::Background); titleLines = titleBrush.color(); } p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); p->setPen( titleLines ); for ( int i = r.y()-th; i < r.y(); i += 2 ) p->drawLine( r.left(), i, r.right(), i ); } break; case TitleText: p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), th, QPainter::AlignVCenter, wd->caption); break; } } void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const { QImage *img = 0; switch ( b ) { case OK: img = okImage(metric(TitleHeight,wd)); break; case Close: img = closeImage(metric(TitleHeight,wd)); break; case Help: img = helpImage(metric(TitleHeight,wd)); break; case Maximize: img = maximizeImage(metric(TitleHeight,wd)); break; } 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 ); wd.rect = rect; int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); QRegion region; switch ((int)type) { case Menu: break; case Maximize: if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); int left = rect.right() - maximizeWidth - closeWidth; if ( ((HackWidget *)widget)->needsOk() ) left -= okWidth; QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); region = r; } break; case Minimize: if ( ((HackWidget *)widget)->needsOk() ) { QRect r(rect.right() - okWidth, rect.top() - titleHeight, okWidth, titleHeight); if (r.left() > rect.left() + titleHeight) region = r; } break; case Close: { int left = rect.right() - closeWidth; if ( ((HackWidget *)widget)->needsOk() ) left -= okWidth; QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); region = r; } break; case Title: if ( !widget->isMaximized() ) { int width = rect.width() - helpWidth - closeWidth; if ( ((HackWidget *)widget)->needsOk() ) width -= okWidth; QRect r(rect.left()+helpWidth, rect.top() - titleHeight, width, titleHeight); if (r.width() > 0) region = r; } break; case Help: if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) { QRect r(rect.left(), rect.top() - titleHeight, helpWidth, titleHeight); region = r; } break; case Top: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); region = m & QRect( br.left()+grab, br.top(), br.width()-2*grab, b ); } break; case Left: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); region = m & QRect( br.left(), br.top()+grab, b, br.height()-2*grab ); } break; case Right: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); region = m & QRect( rect.right(), br.top()+grab, b, br.height()-2*grab ); } break; case Bottom: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); region = m & QRect( br.left()+grab, rect.bottom(), br.width()-2*grab, b ); } break; case TopLeft: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); QRegion crgn( br.left(), br.top(), grab, tb ); crgn |= QRect( br.left(), br.top(), lb, grab ); region = m & crgn; } break; case TopRight: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); QRegion crgn( br.right()-grab, br.top(), grab, tb ); crgn |= QRect( br.right()-rb, br.top(), rb, grab ); region = m & crgn; } break; case BottomLeft: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); } break; case BottomRight: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); } break; case All: if ( widget->isMaximized() ) region = QWSDefaultDecoration::region(widget, rect, type); else region = wdiface->mask(&wd) - rect; break; default: region = QWSDefaultDecoration::region(widget, rect, type); break; } return region; } void QPEDecoration::paint(QPainter *painter, const QWidget *widget) { WindowDecorationInterface::WindowData wd; windowData( widget, wd ); int titleWidth = getTitleWidth(widget); int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); QRect rect(widget->rect()); // title bar rect QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); #ifndef QT_NO_PALETTE QRegion oldClip = painter->clipRegion(); painter->setClipRegion( oldClip - QRegion( tr ) ); // reduce flicker wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); painter->setClipRegion( oldClip ); if (titleWidth > 0) { const QColorGroup &cg = widget->palette().active(); QBrush titleBrush; QPen titlePen; if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { titleBrush = cg.brush(QColorGroup::Highlight); titlePen = cg.color(QColorGroup::HighlightedText); } else { titleBrush = cg.brush(QColorGroup::Background); titlePen = cg.color(QColorGroup::Text); } wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); // Draw caption painter->setPen(titlePen); QFont f( QApplication::font() ); f.setWeight( QFont::Bold ); painter->setFont(f); wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); } #endif //QT_NO_PALETTE paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); } void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, QWSDecoration::Region type, int state) { WindowDecorationInterface::Button b; switch ((int)type) { case Close: b = WindowDecorationInterface::Close; break; case Minimize: if ( ((HackWidget *)w)->needsOk() ) b = WindowDecorationInterface::OK; else if ( helpExists ) b = WindowDecorationInterface::Help; else return; break; case Help: b = WindowDecorationInterface::Help; 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 @@ -1,111 +1,113 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #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 |