summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpedecoration_qws.cpp147
-rw-r--r--library/qpedecoration_qws.h9
2 files changed, 100 insertions, 56 deletions
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index bac1a75..7842ebd 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -12,39 +12,42 @@
** 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 <qpopupmenu.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 <qpe/qlibrary.h>
#include <qfile.h>
#include <qsignal.h>
#include <stdlib.h>
-extern QRect qt_maxWindowRect;
+extern Q_EXPORT QRect qt_maxWindowRect;
#define WHATSTHIS_MODE
#ifndef QT_NO_QWS_QPE_WM_STYLE
#ifndef QT_NO_IMAGEIO_XPM
/* XPM */
@@ -90,22 +93,23 @@ static const char * const qpe_accept_xpm[] = {
" .++..+++++. ",
" .+++++++++. ",
" ..+++++.. ",
" ..... ",
" "};
#endif // QT_NO_IMAGEIO_XPM
-class HackWidget : public QWidget
+class DecorHackWidget : public QWidget
{
public:
bool needsOk() {
return (getWState() & WState_Reserved1 ) ||
- (inherits( "QDialog" ) && !inherits( "QMessageBox" ) );
+ (inherits("QDialog") && !inherits("QMessageBox")
+ && !inherits("QWizard") );
}
};
static QImage scaleButton( const QImage &img, int height )
{
if ( img.height() != 0 && img.height() != height ) {
return img.smoothScale( img.width()*height/img.height(), height );
} else {
@@ -183,29 +187,29 @@ bool QPEManager::eventFilter( QObject *o, QEvent *e )
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 ( ((HackWidget*)w)->needsOk() )
- text = QObject::tr("Click to close this window, discarding changes.");
+ if ( ((DecorHackWidget*)w)->needsOk() )
+ text = tr("Click to close this window, discarding changes.");
else
- text = QObject::tr("Click to close this window.");
+ text = tr("Click to close this window.");
break;
case QWSDecoration::Minimize:
- text = QObject::tr("Click to close this window and apply changes.");
+ text = tr("Click to close this window and apply changes.");
break;
case QWSDecoration::Maximize:
if ( w->isMaximized() )
- text = QObject::tr("Click to make this window moveable.");
+ text = tr("Click to make this window movable.");
else
- text = QObject::tr("Click to make this window use all available screen area.");
+ text = tr("Click to make this window use all available screen area.");
break;
default:
break;
}
QWhatsThis::leaveWhatsThisMode( text );
whatsThisTimeout();
helpState = 0;
return true;
@@ -449,69 +453,91 @@ QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
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) {}
+ DefaultWindowDecoration(){}
QString name() const {
- return "Default";
+ 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
-private:
- ulong ref;
};
static WindowDecorationInterface *wdiface = 0;
-static QLibrary *wdlib = 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()
{
- init ( libname );
+ 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()
{
- init ( plugin );
-}
-
-void QPEDecoration::init ( const QString &plugin )
-{
libname = plugin;
if ( wdlib ) {
- wdiface->release();
- wdlib->unload();
- delete wdlib;
- wdlib = 0;
+ wdiface->release();
+ wdlib->unload();
+ delete wdlib;
+ wdlib = 0;
} else {
- delete wdiface;
+ delete wdiface;
}
WindowDecorationInterface *iface = 0;
QString path = QPEApplication::qpeDir() + "/plugins/decorations/";
#ifdef Q_OS_MACX
if ( plugin.find( ".dylib" ) > 0 ) {
#else
@@ -531,29 +557,20 @@ void QPEDecoration::init ( const QString &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);
- }
- qpeManager = new QPEManager( this );
- // Qtopia 1.5 compatibility
- imageOk = *okImage ( 15 );
- imageClose = *closeImage ( 15 );
- imageHelp = *helpImage ( 15 );
+
+ helpexists = FALSE; // We don't know (flagged by helpFile being null)
+ qpeManager = new QPEManager( this );
}
QPEDecoration::~QPEDecoration()
{
delete qpeManager;
}
const char **QPEDecoration::menuPixmap()
@@ -609,52 +626,52 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor
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() )
+ if ( ((DecorHackWidget *)widget)->needsOk() )
left -= okWidth;
QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
region = r;
}
break;
case Minimize:
- if ( ((HackWidget *)widget)->needsOk() ) {
+ if ( ((DecorHackWidget *)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() )
+ if ( ((DecorHackWidget *)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() )
+ if ( ((DecorHackWidget *)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) ) {
+ 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);
@@ -747,21 +764,21 @@ void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
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 );
+ QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
#ifndef QT_NO_PALETTE
QRegion oldClip = painter->clipRegion();
- painter->setClipRegion( oldClip - QRegion( tr ) ); // reduce flicker
+ painter->setClipRegion( oldClip - QRegion( tbr ) ); // reduce flicker
wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
painter->setClipRegion( oldClip );
if (titleWidth > 0) {
const QColorGroup &cg = widget->palette().active();
QBrush titleBrush;
QPen titlePen;
@@ -791,19 +808,19 @@ 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() )
+ if ( ((DecorHackWidget *)w)->needsOk() )
b = WindowDecorationInterface::OK;
- else if ( helpExists )
+ else if ( helpExists() )
b = WindowDecorationInterface::Help;
else
return;
break;
case Help:
b = WindowDecorationInterface::Help;
break;
case Maximize:
@@ -813,27 +830,27 @@ void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
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 tbr( 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
+ painter->setClipRegion( QRect(brect.x(), tbr.y(), brect.width(), tbr.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 )
@@ -843,16 +860,30 @@ void QPEDecoration::maximize( QWidget *widget )
widget->setGeometry( qt_maxWindowRect );
} else
#endif
{
QWSDecoration::maximize( widget );
}
}
+QPopupMenu *QPEDecoration::menu( const QWidget *, const QPoint & )
+{
+ QPopupMenu *m = new QPopupMenu();
+
+ m->insertItem(QPEManager::tr("Restore"), (int)Normalize);
+ m->insertItem(QPEManager::tr("Move"), (int)Title);
+ m->insertItem(QPEManager::tr("Size"), (int)BottomRight);
+ m->insertItem(QPEManager::tr("Maximize"), (int)Maximize);
+ m->insertSeparator();
+ m->insertItem(QPEManager::tr("Close"), (int)Close);
+
+ return m;
+}
+
#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
@@ -866,45 +897,54 @@ 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() ) {
+ else if ( ((DecorHackWidget *)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 );
+ if ( helpExists() ) {
+ QString hf = helpFile;
+ QString localHelpFile = QString(qApp->argv()[0]) + "-" + w->name() + ".html";
+ QStringList helpPath = Global::helpPath();
+ for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end(); ++it) {
+ if ( QFile::exists( *it + "/" + localHelpFile ) ) {
+ hf = localHelpFile;
+ break;
+ }
+ }
+ Global::execute( "helpbrowser", hf );
} else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
QWhatsThis::enterWhatsThisMode();
- QWhatsThis::leaveWhatsThisMode( QObject::tr(
+ QWhatsThis::leaveWhatsThisMode( QObject::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 = QObject::tr("What's this..." );
+ wd.caption = QObject::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;
@@ -919,8 +959,9 @@ QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
}
#endif
*/
#endif // QT_NO_QWS_QPE_WM_STYLE
+#endif
diff --git a/library/qpedecoration_qws.h b/library/qpedecoration_qws.h
index d0a2005..ca670cd 100644
--- a/library/qpedecoration_qws.h
+++ b/library/qpedecoration_qws.h
@@ -17,65 +17,68 @@
** not clear to you.
**
**********************************************************************/
#ifndef QPE_DECORATION_QWS_H__
#define QPE_DECORATION_QWS_H__
#ifdef QWS
+#include <qpe/global.h>
#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;
+#include <qwidget.h>
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 QPopupMenu *menu( const QWidget *, const QPoint & );
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 & );
+ bool helpExists() const;
protected:
QImage imageOk;
QImage imageClose;
QImage imageHelp;
QString helpFile;
- bool helpExists;
+ bool helpexists : 1;
QPEManager *qpeManager;
};
class QPEManager : public QObject
{
Q_OBJECT
friend class QPEDecoration;
@@ -96,17 +99,17 @@ protected slots:
void whatsThisTimeout();
protected:
QPEDecoration *decoration;
QGuardedPtr<QWidget> active;
int helpState;
QTime pressTime;
QTimer *wtTimer;
- bool inWhatsThis;
+ bool inWhatsThis : 1;
QGuardedPtr<QWidget> whatsThis;
};
#endif // QT_NO_QWS_QPE_WM_STYLE
#endif // QPE_DECORATION_QWS_H__