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

📄 flat.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** 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 <qtopia/qpeapplication.h>#include <qpushbutton.h>#include <qtoolbutton.h>#include <qpainter.h>#include <qfontmetrics.h>#include <qpalette.h>#include <qdrawutil.h>#include <qscrollbar.h>#include <qbutton.h>#include <qframe.h>#include <qtabbar.h>#include <qspinbox.h>#include <qlineedit.h>#include <qmap.h>#define INCLUDE_MENUITEM_DEF#include <qmenudata.h>#include <qpopupmenu.h>#include "flat.h"#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)class SpinBoxHack : public QSpinBox{public:    void setFlatButtons( bool f ) {	upButton()->setFlat( f );	downButton()->setFlat( f );    }};class FlatStylePrivate : public QObject{    Q_OBJECTpublic:    FlatStylePrivate() : QObject() {}    bool eventFilter( QObject *o, QEvent *e ) {	if ( e->type() == QEvent::ParentPaletteChange ) {	    if ( o->inherits( "QMenuBar" ) ) {		QWidget *w = (QWidget *)o;		if ( w->parentWidget() ) {		    QPalette p = w->parentWidget()->palette();		    QColorGroup a = p.active();		    a.setColor( QColorGroup::Light, a.foreground() );		    a.setColor( QColorGroup::Dark, a.foreground() );		    p.setActive( a );		    p.setInactive( a );		    w->setPalette( p );		}	    } else if ( o->inherits( "QHeader" ) ) {		QWidget *w = (QWidget *)o;		if ( w->parentWidget() ) {		    QPalette p = w->parentWidget()->palette();		    QColorGroup a = p.active();		    a.setColor( QColorGroup::Light, a.button() );		    p.setActive( a );		    p.setInactive( a );		    w->setPalette( p );		}	    }	}	return FALSE;    }    QMap<QFrame *,int> frameStyles;};FlatStyle::FlatStyle() : revItem(FALSE), fillBtnBorder(FALSE){    setButtonMargin(3);    setScrollBarExtent(13,13);    setButtonDefaultIndicatorWidth(0);    d = new FlatStylePrivate;}FlatStyle::~FlatStyle(){    delete d;}int FlatStyle::buttonMargin() const{    return 3;}QSize FlatStyle::scrollBarExtent() const{    return QSize(13,13);}void FlatStyle::polish ( QPalette & ){}class QStyleHackWidget : public QWidget {public:    static void setGlobalBrushOrigin(QWidget *w) {	((QStyleHackWidget*)w)->setWState(WState_GlobalBrushOrigin);    }    static void clearGlobalBrushOrigin(QWidget *w) {	((QStyleHackWidget*)w)->clearWState(WState_GlobalBrushOrigin);    }};void FlatStyle::polish( QWidget *w ){    if ( w->inherits( "QFrame" ) ) {	QFrame *f = (QFrame *)w;	if ( f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine )	    f->setFrameShadow( QFrame::Plain );	else if ( f->frameShape() != QFrame::NoFrame )	    f->setFrameShape( QFrame::StyledPanel );	f->setLineWidth( 1 );    }    if ( w->inherits( "QSpinBox" ) )	((SpinBoxHack*)w)->setFlatButtons( TRUE );    if ( w->inherits( "QMenuBar" ) ) {	// make selected item look flat	QPalette p = w->palette();	QColorGroup a = p.active();	a.setColor( QColorGroup::Light, a.foreground() );	a.setColor( QColorGroup::Dark, a.foreground() );	p.setActive( a );	p.setInactive( a );	w->setPalette( p );	w->installEventFilter( d );    } else if ( w->inherits( "QHeader" ) ) {	// make headers look flat	QPalette p = w->palette();	QColorGroup a = p.active();	a.setColor( QColorGroup::Light, a.button() );	p.setActive( a );	p.setInactive( a );	w->setPalette( p );	w->installEventFilter( d );    }    QStyleHackWidget::setGlobalBrushOrigin(w);}void FlatStyle::unPolish( QWidget *w ){    if ( w->inherits("QFrame") ) {	QFrame *f = (QFrame *)w;	if ( f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine ) {	    f->setFrameShadow( QFrame::Sunken );	} else if ( f->frameShape() != QFrame::NoFrame ) {	    f->setFrameShape( QFrame::StyledPanel );	    f->setLineWidth( 2 );	}    }    if ( w->inherits("QSpinBox") )	((SpinBoxHack*)w)->setFlatButtons( FALSE );    if ( w->inherits("QMenuBar") || w->inherits("QHeader") ) {	w->unsetPalette();	w->removeEventFilter( d );    }    QStyleHackWidget::clearGlobalBrushOrigin(w);}int FlatStyle::defaultFrameWidth() const{    return 1;}void FlatStyle::drawItem( QPainter *p, int x, int y, int w, int h,                    int flags, const QColorGroup &g, bool enabled,		    const QPixmap *pixmap, const QString& text, int len,		    const QColor* penColor ){    QColor pc( penColor ? *penColor : g.foreground() );    QColorGroup cg( g );    if ( !enabled )	cg.setColor( QColorGroup::Light, cg.background() );    if ( revItem ) {	pc = cg.button();	revItem = FALSE;    }    QWindowsStyle::drawItem( p, x, y, w, h, flags, cg, enabled, pixmap, text, len, &pc );}void FlatStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,			    const QColorGroup &g, bool /*sunken*/, int lineWidth, const QBrush * fill ){    if ( fill )	p->setBrush( *fill );    p->setPen( QPen(g.foreground(), lineWidth) );    p->drawRect( x, y, w, h );}void FlatStyle::drawButton( QPainter *p, int x, int y, int w, int h,                                const QColorGroup &cg, bool /*sunken*/, const QBrush* fill ){    QPen oldPen = p->pen();    int x2 = x+w-1;    int y2 = y+h-1;    if ( fillBtnBorder && btnBg != cg.color(QColorGroup::Button) ) {	p->setPen( btnBg );	p->drawLine( x, y, x2, y );	p->drawLine( x, y2, x2, y2 );	p->drawLine( x, y+1, x, y2-1 );	p->drawLine( x2, y+1, x2, y2-1 );	p->fillRect( x+1, y+1, 3, 3, btnBg );	p->fillRect( x+1, y2-3, 3, 3, btnBg );	p->fillRect( x2-3, y2-3, 3, 3, btnBg );	p->fillRect( x2-3, y+1, 3, 3, btnBg );	p->fillRect( x+2, y+2, w-4, h-4, fill?(*fill):cg.brush(QColorGroup::Button) );    } else {	p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):cg.brush(QColorGroup::Button) );    }    if ( h >= 10 ) {	x++; y++;	x2--; y2--;	w -= 2; h -= 2;    }    p->setPen( cg.foreground() );    if ( h < 10 ) {	p->setBrush( NoBrush );	p->drawRect( x, y, w, h );    } else {	p->drawLine( x+3, y, x2-3, y );	p->drawLine( x+3, y2, x2-3, y2 );	p->drawLine( x, y+3, x, y2-3 );	p->drawLine( x2, y+3, x2, y2-3 );	p->drawLine( x+1, y+1, x+2, y+1 );	p->drawPoint( x+1, y+2 );	p->drawLine( x2-2, y+1, x2-1, y+1 );	p->drawPoint( x2-1, y+2 );	p->drawLine( x+1, y2-1, x+2, y2-1 );	p->drawPoint( x+1, y2-2 );	p->drawLine( x2-2, y2-1, x2-1, y2-1 );	p->drawPoint( x2-1, y2-2 );    }    p->setPen( oldPen );}void FlatStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h ){    x++; y++;    x-=2; y-=2;    p->fillRect( x, y, w, h, color1 );}void FlatStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,                                const QColorGroup &g, bool /*sunken*/, const QBrush* fill ){    p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );    p->setPen( g.foreground() );    p->setBrush( NoBrush );    p->drawRect( x, y, w, h );}void FlatStyle::drawToolButton( QPainter *p, int x, int y, int w, int h,                                const QColorGroup &g, bool sunken, const QBrush* fill ){    if ( p->device()->devType() == QInternal::Widget ) {	QWidget *w = (QWidget *)p->device();	if ( w->isA("QToolButton") ) {	    QToolButton *btn = (QToolButton *)w;	    if ( btn->parentWidget() ) {		btnBg = btn->parentWidget()->backgroundColor();		fillBtnBorder = TRUE;	    }	}    }    QBrush fb( fill ? *fill : g.button() );    if ( sunken && fb == g.brush( QColorGroup::Button ) ) {	fb = g.buttonText();	revItem = TRUE;	// ugh    }    drawButton( p, x, y, w, h, g, sunken, &fb );    fillBtnBorder = FALSE;}void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p ){    QColorGroup g = btn->colorGroup();    int x1, y1, x2, y2;    btn->rect().coords( &x1, &y1, &x2, &y2 );	// get coordinates    p->setPen( g.foreground() );    p->setBrush( QBrush(g.button(),NoBrush) );//    int diw = buttonDefaultIndicatorWidth();    /*    if ( btn->isDefault() || btn->autoDefault() ) {	if ( btn->isDefault() ) {	    p->setPen( g.shadow() );	    p->drawRect( x1, y1, x2-x1+1, y2-y1+1 );	}	x1 += diw;	y1 += diw;	x2 -= diw;	y2 -= diw;    }    */    if ( btn->parentWidget() ) {	btnBg = btn->parentWidget()->backgroundColor();	fillBtnBorder = TRUE;    }    bool clearButton = TRUE;    if ( btn->isDown() ) {	drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE,		&g.brush( QColorGroup::Text ) );    } else {	if ( btn->isToggleButton() && btn->isOn() && btn->isEnabled() ) {	    QBrush fill(g.light(), Dense4Pattern );	    drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE, &fill );	    clearButton = FALSE;	} else {	    if ( !btn->isFlat() )		drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn(),			&g.brush( QColorGroup::Button ) );	}    }    /*    if ( clearButton ) {	if (btn->isDown())	    p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));	p->fillRect( x1+2, y1+2, x2-x1-3, y2-y1-3,		     g.brush( QColorGroup::Button ) );	if (btn->isDown())	    p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));    }    */    fillBtnBorder = FALSE;    if ( p->brush().style() != NoBrush )	p->setBrush( NoBrush );}

⌨️ 快捷键说明

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