-rw-r--r-- | library/qpedecoration_qws.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp index 222d906..c2eb751 100644 --- a/library/qpedecoration_qws.cpp +++ b/library/qpedecoration_qws.cpp @@ -1,158 +1,159 @@ /********************************************************************** ** 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. ** **********************************************************************/ #ifdef QWS #define QTOPIA_INTERNAL_LANGLIST #include <qapplication.h> #include <qstyle.h> #include <qwidget.h> #include <qpainter.h> #include <qtimer.h> #include <qwhatsthis.h> #include "qcopenvelope_qws.h" #include "qpedecoration_qws.h" #include <qdialog.h> #include <qdrawutil.h> #include <qgfx_qws.h> #include "qpeapplication.h" #include "resource.h" #include "global.h" #include "qlibrary.h" #include "windowdecorationinterface.h" #include <qfile.h> #include <qsignal.h> #include <stdlib.h> -extern QRect qt_maxWindowRect; +extern QRect qt_maxWindowRect; #define WHATSTHIS_MODE #ifndef QT_NO_QWS_QPE_WM_STYLE #ifndef QT_NO_IMAGEIO_XPM /* XPM */ static const char * const qpe_close_xpm[] = { "16 16 3 1", " c None", ". c #FFFFFF", "+ c #000000", " ", " ", " ..... ", " ..+++++.. ", " .+++++++++. ", " .+..+++..+. ", " .++...+...++. ", " .+++.....+++. ", " .++++...++++. ", " .+++.....+++. ", " .++...+...++. ", " .+..+++..+. ", " .+++++++++. ", " ..+++++.. ", " ..... ", " "}; /* XPM */ static const char * const qpe_accept_xpm[] = { "16 16 3 1", " c None", ". c #FFFFFF", "+ c #000000", " ", " ", " ..... ", " ..+++++.. ", " .+++++++++. ", " .+++++++++. ", " .+++++++..++. ", " .++.+++...++. ", " .+...+...+++. ", " .+......++++. ", " .++....+++++. ", " .++..+++++. ", " .+++++++++. ", " ..+++++.. ", " ..... ", " "}; #endif // QT_NO_IMAGEIO_XPM class HackWidget : public QWidget { public: bool needsOk() { return (getWState() & WState_Reserved1 ) || (inherits( "QDialog" ) && !inherits( "QMessageBox" ) ); } }; static QImage scaleButton( const QImage &img, int height ) { - if ( img.height() != height ) { + qWarning("Height %d %d", height, img.height() ); + if ( img.height()!=0 && img.height() != height ) { return img.smoothScale( img.width()*height/img.height(), height ); } else { return img; } } class TLWidget : public QWidget { public: QWSManager *manager() { return topData()->qwsManager; } QTLWExtra *topExtra() { return topData(); } void setWState( uint s ) { QWidget::setWState( s ); } void clearWState( uint s ) { QWidget::clearWState( s ); } }; QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) { wtTimer = new QTimer( this ); connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); } void QPEManager::updateActive() { QWidget *newActive = qApp->activeWindow(); if ( newActive && (QWidget*)active == newActive ) return; if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); } if ( newActive && ((TLWidget *)newActive)->manager() ) { active = newActive; ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); } else if ( !newActive ) { active = 0; } @@ -602,153 +603,153 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor 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; + 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; + 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; + 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; + 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; + 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); @@ -777,128 +778,128 @@ void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, 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; break; case Maximize: b = WindowDecorationInterface::Maximize; break; default: return; } WindowDecorationInterface::WindowData wd; windowData( w, wd ); int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); QRect rect(w->rect()); QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); QRect brect(region(w, w->rect(), type).boundingRect()); const QColorGroup &cg = w->palette().active(); if ( wd.flags & WindowDecorationInterface::WindowData::Active ) painter->setPen( cg.color(QColorGroup::HighlightedText) ); else painter->setPen( cg.color(QColorGroup::Text) ); QRegion oldClip = painter->clipRegion(); painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); painter->setClipRegion( oldClip ); } //#define QPE_DONT_SHOW_TITLEBAR void QPEDecoration::maximize( QWidget *widget ) { -#ifdef QPE_DONT_SHOW_TITLEBAR +#ifdef QPE_DONT_SHOW_TITLEBAR if ( !widget->inherits( "QDialog" ) ) { widget->setGeometry( qt_maxWindowRect ); - } else -#endif + } else +#endif { QWSDecoration::maximize( widget ); } } #ifndef QT_NO_DIALOG class HackDialog : public QDialog { public: void acceptIt() { if ( isA( "QMessageBox" ) ) qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); else accept(); } }; #endif void QPEDecoration::minimize( QWidget *widget ) { #ifndef QT_NO_DIALOG // We use the minimize button as an "accept" button. if ( widget->inherits( "QDialog" ) ) { HackDialog *d = (HackDialog *)widget; d->acceptIt(); - } + } #endif else if ( ((HackWidget *)widget)->needsOk() ) { QSignal s; s.connect( widget, SLOT( accept() ) ); s.activate(); } else { help( widget ); } } void QPEDecoration::help( QWidget *w ) { if ( helpExists ) { Global::execute( "helpbrowser", helpFile ); } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { QWhatsThis::enterWhatsThisMode(); QWhatsThis::leaveWhatsThisMode( qApp->tr( "<Qt>Comprehensive help is not available for this application, " "however there is context-sensitive help.<p>To use context-sensitive help:<p>" "<ol><li>click and hold the help button." "<li>when the title bar shows <b>What's this...</b>, " "click on any control.</ol></Qt>" ) ); } } void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const { wd.rect = w->rect(); if ( qpeManager->whatsThisWidget() == w ) wd.caption = qApp->tr("What's this..." ); else wd.caption = w->caption(); wd.palette = qApp->palette(); wd.flags = 0; wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; const QWidget *active = qpeManager->activeWidget(); wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; wd.reserved = 1; } /* #ifndef QT_NO_POPUPMENU QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) { return 0; } #endif |