summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--library/qpedecoration_qws.cpp55
1 files changed, 15 insertions, 40 deletions
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index fb47c14..1afae88 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -116,424 +116,399 @@ static QImage scaleButton( const QImage &img, int 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;
}
}
int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
{
QRect rect(w->geometry());
if ( decoration->region( w, rect,
(QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
return QPEDecoration::Help;
for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
return (QWSDecoration::Region)i;
}
return QWSDecoration::None;
}
bool QPEManager::eventFilter( QObject *o, QEvent *e )
{
QWSManager *mgr = (QWSManager *)o;
QWidget *w = mgr->widget();
switch ( e->type() ) {
case QEvent::MouseButtonPress:
{
pressTime = QTime::currentTime();
QPoint p = ((QMouseEvent*)e)->globalPos();
int inRegion = pointInQpeRegion( w, p );
#ifdef WHATSTHIS_MODE
if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
QString text;
switch ( inRegion ) {
case QWSDecoration::Close:
if ( ((DecorHackWidget*)w)->needsOk() )
text = tr("Click to close this window, discarding changes.");
else
text = tr("Click to close this window.");
break;
case QWSDecoration::Minimize:
text = tr("Click to close this window and apply changes.");
break;
case QWSDecoration::Maximize:
if ( w->isMaximized() )
text = tr("Click to make this window movable.");
else
text = tr("Click to make this window use all available screen area.");
break;
default:
break;
}
QWhatsThis::leaveWhatsThisMode( text );
whatsThisTimeout();
helpState = 0;
return true;
}
#endif
if ( inRegion == QPEDecoration::Help ) {
#ifdef WHATSTHIS_MODE
wtTimer->start( 400, TRUE );
#endif
helpState = QWSButton::Clicked|QWSButton::MouseOver;
drawButton( w, QPEDecoration::Help, helpState );
return true;
}
}
break;
case QEvent::MouseButtonRelease:
if ( helpState & QWSButton::Clicked ) {
wtTimer->stop();
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 || ::abs( i->height()-th ) > 4 ) {
- delete i;
- i = new QImage(scaleButton(Resource::loadImage("OKButton"),th));
- }
- return i;
-}
-
-static QImage *closeImage( int th )
-{
- static QImage *i = 0;
- if ( !i || ::abs( i->height()-th ) > 4 ) {
- delete i;
- i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
- }
- return i;
-}
-
-static QImage *helpImage( int th )
-{
- static QImage *i = 0;
- if ( !i || ::abs( i->height()-th ) > 4 ) {
- delete i;
- i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
- }
- return i;
-}
-
-static QImage *maximizeImage( int th )
-{
- static QImage *i = 0;
- if ( !i || ::abs( i->height()-th ) > 4 ) {
- delete i;
- i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
- }
- return i;
-}
+#define IMAGE_METHOD( methodName, imageName ) \
+static QImage* methodName( int th ) { \
+ static QImage *i = 0; \
+ if ( !i || ::abs( i->height()-th ) > 4 ) { \
+ delete i; \
+ i = new QImage(scaleButton(Resource::loadImage(#imageName),th)); \
+ } \
+ \
+ return i; \
+}
+
+IMAGE_METHOD(okImage, OKButton );
+IMAGE_METHOD(closeImage, CloseButton );
+IMAGE_METHOD(helpImage, HelpButton );
+IMAGE_METHOD(maximizeImage,MaximizeButton );
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(){}
QString name() const {
return qApp->translate("WindowDecoration", "Default",
"List box text for default window decoration");
}
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;
else
return QS_FALSE;
if ( *iface )
(*iface)->addRef();
return QS_OK;
}
Q_REFCOUNT
};
static WindowDecorationInterface *wdiface = 0;
static QLibrary* wdlib = 0;
static QString libname;
//===========================================================================
bool QPEDecoration::helpExists() const
{
if ( helpFile.isNull() ) {
QStringList helpPath = Global::helpPath();
QString hf = QString(qApp->argv()[0]) + ".html";
bool he = FALSE;
for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !he; ++it)
he = QFile::exists( *it + "/" + hf );
((QPEDecoration*)this)->helpFile = hf;
((QPEDecoration*)this)->helpexists = he;
return he;
}
return helpexists;
}
QPEDecoration::QPEDecoration()
: QWSDefaultDecoration()
{
if ( wdlib ) {
delete wdlib;
wdlib = 0;
} else {
delete wdiface;
}
wdiface = new DefaultWindowDecoration;
helpexists = FALSE; // We don't know (flagged by helpFile being null)
qpeManager = new QPEManager( this );
imageOk = Resource::loadImage( "OKButton" );
imageClose = Resource::loadImage( "CloseButton" );
imageHelp = Resource::loadImage( "HelpButton" );
}
QPEDecoration::QPEDecoration( const QString &plugin )
: QWSDefaultDecoration()
{
libname = plugin;
if ( wdlib ) {
wdiface->release();
wdlib->unload();
delete wdlib;
wdlib = 0;
} else {
delete wdiface;
}
WindowDecorationInterface *iface = 0;