⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appearance.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ 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.************************************************************************/#include "appearance.h"#include <qtopia/global.h>#include <qtopia/fontdatabase.h>#include <qtopia/config.h>#include <qtopia/applnk.h>#include <qtopia/qpeapplication.h>#include <qtopia/pluginloader.h>#include <qtopia/qpestyle.h>#include <qtopia/styleinterface.h>#include <qtopia/windowdecorationinterface.h>#if defined(Q_WS_QWS) && !defined(QT_NO_COP)#include <qtopia/qcopenvelope_qws.h>#endif#include <qlabel.h>#include <qcheckbox.h>#include <qradiobutton.h>#include <qtabwidget.h>#include <qslider.h>#include <qfile.h>#include <qtextstream.h>#include <qdatastream.h>#include <qmessagebox.h>#include <qcombobox.h>#include <qlistbox.h>#include <qdir.h>#include <qgroupbox.h>#include <qwindowsstyle.h>#include <qobjectlist.h>#include <qlayout.h>#include <qvbox.h>#include <qmenubar.h>#include <qpushbutton.h>#include <qcheckbox.h>#include <qwhatsthis.h>#include <qpixmapcache.h>#if QT_VERSION >= 0x030000#include <qstylefactory.h>#endif//#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX)//#include <unistd.h>//#include <linux/fb.h>//#include <sys/types.h>//#include <sys/stat.h>//#include <fcntl.h>//#include <sys/ioctl.h>//#endif#include <stdlib.h>#define SAMPLE_HEIGHT	115class PluginItem : public QListBoxText{public:    PluginItem( QListBox *lb, const QString &t ) : QListBoxText( lb, t ) {}    void setFilename( const QString fn ) { file = fn; }    const QString &filename() const { return file; }private:    QString file;};class SampleText : public QWidget{public:    SampleText( const QString &t, bool h, QWidget *parent )	: QWidget( parent ), hl(h), text(t)    {	if ( hl )	    setBackgroundMode( PaletteHighlight );	else	    setBackgroundMode( PaletteBase );    }    QSize sizeHint() const    {	QFontMetrics fm(font());	return QSize( fm.width(text)+10, fm.height()+4 );    }    void paintEvent( QPaintEvent * )    {	QPainter p(this);	if ( hl )	    p.setPen( colorGroup().highlightedText() );	else	    p.setPen( colorGroup().text() );	p.drawText( rect(), AlignCenter, text );    }private:    bool hl;    QString text;};class SampleWindow : public QWidget{    Q_OBJECTpublic:    SampleWindow( QWidget *parent ) : QWidget(parent), iface(0)    {	setSizePolicy( QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum) );	init();    }    QSize sizeHint() const    {	int w = container->sizeHint().width() + 10;	int h = container->sizeHint().height() + 30;	return QSize( w, QMAX(SAMPLE_HEIGHT,h) );    }    void setFont( const QFont &f )    {	QWidget::setFont( f );	popup->setFont( f );    }    void setDecoration( WindowDecorationInterface *i )    {	iface = i;	wd.rect = QRect( 0, 0, 150, 75 );	wd.caption = tr("Sample");	wd.palette = palette();	wd.flags = WindowDecorationInterface::WindowData::Dialog |		   WindowDecorationInterface::WindowData::Active;	wd.reserved = 1;	th = iface->metric(WindowDecorationInterface::TitleHeight, &wd);	tb = iface->metric(WindowDecorationInterface::TopBorder, &wd);	lb = iface->metric(WindowDecorationInterface::LeftBorder, &wd);	rb = iface->metric(WindowDecorationInterface::RightBorder, &wd);	bb = iface->metric(WindowDecorationInterface::BottomBorder, &wd);	int yoff = th + tb;	int xoff = lb;	wd.rect.setX( 0 );	wd.rect.setWidth( width() - lb - rb );	wd.rect.setY( 0 );	wd.rect.setHeight( height() - yoff - bb );	container->setGeometry( xoff, yoff, wd.rect.width(), wd.rect.height() );	setMinimumSize( container->sizeHint().width()+lb+rb,			QMAX(SAMPLE_HEIGHT,container->sizeHint().height()+tb+th+bb) );    }    void paintEvent( QPaintEvent * )    {	if ( !iface )	    return;	QPainter p( this );	p.translate( lb, th+tb );	iface->drawArea(WindowDecorationInterface::Border, &p, &wd);	iface->drawArea(WindowDecorationInterface::Title, &p, &wd);	p.setPen(palette().active().color(QColorGroup::HighlightedText));	QFont f( font() );	f.setWeight( QFont::Bold );	p.setFont(f);	iface->drawArea(WindowDecorationInterface::TitleText, &p, &wd);	QRect brect( 0, -th, iface->metric(WindowDecorationInterface::HelpWidth,&wd), th );	iface->drawButton( WindowDecorationInterface::Help, &p, &wd,	    brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 );	brect.moveBy( wd.rect.width() -	    iface->metric(WindowDecorationInterface::OKWidth,&wd) -	    iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 );	iface->drawButton( WindowDecorationInterface::Close, &p, &wd,	    brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 );	brect.moveBy( iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 );	iface->drawButton( WindowDecorationInterface::OK, &p, &wd,	    brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 );    }    void init()    {	container = new QVBox( this );	popup = new QPopupMenu( this );	popup->insertItem( tr("Normal Item"), 1 );	popup->insertItem( tr("Disabled Item"), 2 );	popup->setItemEnabled(2, FALSE);	QMenuBar *mb = new QMenuBar( container );	mb->insertItem( tr("Menu"), popup );	QHBox *hb = new QHBox( container );	QWidget *w = new QWidget( hb );	(void)new QScrollBar( 0, 0, 0, 0, 0, Vertical, hb );	QGridLayout *gl = new QGridLayout( w, 2, 2, 4 );	SampleText *l = new SampleText( tr("Normal Text"), FALSE, w );	gl->addWidget( l, 0, 0 );	l = new SampleText( tr("Highlighted Text"), TRUE, w );	gl->addWidget( l, 1, 0 );	QPushButton *pb = new QPushButton( tr("Button"), w );	gl->addWidget( pb, 0, 1 );	pb->setFocusPolicy( NoFocus );	QCheckBox *cb = new QCheckBox( tr("Check Box"), w );	gl->addWidget( cb, 1, 1 );	cb->setFocusPolicy( NoFocus );	cb->setChecked( TRUE );	QWhatsThis::add( this, tr("Sample window using the selected settings.") );    }    bool eventFilter( QObject *, QEvent *e )    {	switch ( e->type() ) {	    case QEvent::MouseButtonPress:	    case QEvent::MouseButtonRelease:	    case QEvent::MouseButtonDblClick:	    case QEvent::MouseMove:	    case QEvent::KeyPress:	    case QEvent::KeyRelease:		return TRUE;	    default:		break;	}	return FALSE;    }    void paletteChange( const QPalette &old )    {	QWidget::paletteChange( old );	wd.palette = palette();	popup->setPalette( palette() );    }    void resizeEvent( QResizeEvent *re )    {	wd.rect.setX( 0 );	wd.rect.setWidth( width() - lb - rb );	wd.rect.setY( 0 );	wd.rect.setHeight( height() - th - tb - bb );	container->setGeometry( lb, th+tb, wd.rect.width(), wd.rect.height() );	QWidget::resizeEvent( re );    }    void setUpdatesEnabled( bool e ) {	QWidget::setUpdatesEnabled( e );	const QObjectList *ol = children();	if ( ol) {	    QObjectListIt it( *ol );	    for ( ; it.current(); ++it ) {		QObject *o = *it;		if( o->isWidgetType() ) {		    ((QWidget *)o)->setUpdatesEnabled( e );		}	    }	}    }public:    void fixGeometry()    {	int w = container->sizeHint().width()+lb+rb;	int h = container->sizeHint().height()+tb+th+bb;	setMinimumSize( w, QMAX(SAMPLE_HEIGHT,h) );    }protected:    WindowDecorationInterface *iface;    WindowDecorationInterface::WindowData wd;    QVBox *container;    QPopupMenu *popup;    int th;    int tb;    int lb;    int rb;    int bb;};//===========================================================================class DefaultWindowDecoration : public WindowDecorationInterface{public:    DefaultWindowDecoration() : ref(0) {}    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;	if ( *iface )	    (*iface)->addRef();	return QS_OK;    }    Q_REFCOUNTprivate:	ulong ref;};//===========================================================================AppearanceSettings::AppearanceSettings( QWidget* parent,  const char* name, WFlags fl )    : AppearanceSettingsBase( parent, name, TRUE, fl ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -