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

📄 qmotifplusstyle.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** $Id: qt/src/widgets/qmotifplusstyle.cpp   2.3.12   edited 2005-10-27 $**** Implementation of QMotifPlusStyle class**** Created : 2000.07.27**** Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of the widgets module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** 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.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** 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/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** 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 "qmotifplusstyle.h"#ifndef QT_NO_STYLE_MOTIFPLUS#define INCLUDE_MENUITEM_DEF#include <qapplication.h>#include <qpainter.h>#include <qpalette.h>#include <qframe.h>#include <qpushbutton.h>#include <qmenubar.h>#include <qdrawutil.h>#include <qscrollbar.h>#include <qtabbar.h>#include <qguardedptr.h>#include <qlayout.h>typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,					      QColorGroup &, bool, bool);QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);struct QMotifPlusStylePrivate{    QMotifPlusStylePrivate()	: hoverWidget(0), hovering(FALSE), sliderActive(FALSE),	  scrollbarElement(0), ref(1), hoverPalette(0)    { ; }    QGuardedPtr<QWidget> hoverWidget;    QPalette oldpalette, prelight_palette;    bool hovering, sliderActive;    int scrollbarElement, ref;    QPoint mousePos;    QPalette *hoverPalette;};static QMotifPlusStylePrivate *d = 0;/*!  \class QMotifPlusStyle qmotifplusstyle.h  \brief More sophisticated Motif-ish look and feel  \ingroup appearance This class implements a Motif-ish look and feel with more sophisticated bevelling as used by the GIMP Toolkit (GTK+) for Unix/X11. *//*!  Constructs a QMotifPlusStyle  If \a hoveringHighlight is FALSE (default value), then the style will not  highlight push buttons, checkboxes, radiobuttons, comboboxes, scrollbars  and sliders. */QMotifPlusStyle::QMotifPlusStyle(bool hoveringHighlight) : QMotifStyle(TRUE){    if (! d) {	d = new QMotifPlusStylePrivate;    } else {	d->ref++;    }    setScrollBarExtent(15, 15);    setButtonDefaultIndicatorWidth(5);    setSliderThickness(15);    setButtonMargin(2);    useHoveringHighlight = hoveringHighlight;}/*!  Destructs the style. */QMotifPlusStyle::~QMotifPlusStyle(){    if (d && d->ref == 0) {	delete d;	d = 0;    }}/*!  \reimp*/void QMotifPlusStyle::polish(QPalette &pal){    d->oldpalette = pal;    QColor bg = pal.color(QPalette::Active, QColorGroup::Background);    if (bg.red()   == 0xc0 &&	bg.green() == 0xc0 &&	bg.blue()  == 0xc0) {	// assume default palette... no -bg arg or color read from RESOURCE_MANAGER	QColor gtkdf(0x75, 0x75, 0x75);	QColor gtksf(0xff, 0xff, 0xff);	QColor gtkbg(0xd6, 0xd6, 0xd6);	QColor gtksl(0x00, 0x00, 0x9c);	pal.setColor(QPalette::Active, QColorGroup::Background, gtkbg);	pal.setColor(QPalette::Inactive, QColorGroup::Background, gtkbg);	pal.setColor(QPalette::Disabled, QColorGroup::Background, gtkbg);	pal.setColor(QPalette::Active, QColorGroup::Button, gtkbg);	pal.setColor(QPalette::Inactive, QColorGroup::Button, gtkbg);	pal.setColor(QPalette::Disabled, QColorGroup::Button, gtkbg);	pal.setColor(QPalette::Active, QColorGroup::Highlight, gtksl);	pal.setColor(QPalette::Inactive, QColorGroup::Highlight, gtksl);	pal.setColor(QPalette::Disabled, QColorGroup::Highlight, gtksl);	pal.setColor(QPalette::Active, QColorGroup::HighlightedText, gtksf);	pal.setColor(QPalette::Inactive, QColorGroup::HighlightedText, gtksf);	pal.setColor(QPalette::Disabled, QColorGroup::HighlightedText, gtkdf);    }    {	QColorGroup active(pal.color(QPalette::Active,				     QColorGroup::Foreground),           // foreground			   pal.color(QPalette::Active,				     QColorGroup::Button),               // button			   pal.color(QPalette::Active,				     QColorGroup::Background).light(),   // light			   pal.color(QPalette::Active,				     QColorGroup::Background).dark(142), // dark			   pal.color(QPalette::Active,				     QColorGroup::Background).dark(110), // mid			   pal.color(QPalette::Active,				     QColorGroup::Text),                 // text			   pal.color(QPalette::Active,				     QColorGroup::BrightText),           // bright text			   pal.color(QPalette::Active,				     QColorGroup::Base),                 // base			   pal.color(QPalette::Active,				     QColorGroup::Background)),          // background	    disabled(pal.color(QPalette::Disabled,			       QColorGroup::Foreground),                 // foreground		     pal.color(QPalette::Disabled,			       QColorGroup::Button),                     // button		     pal.color(QPalette::Disabled,			       QColorGroup::Background).light(),         // light		     pal.color(QPalette::Disabled,			       QColorGroup::Background).dark(156),       // dark		     pal.color(QPalette::Disabled,			       QColorGroup::Background).dark(110),       // mid		     pal.color(QPalette::Disabled,			       QColorGroup::Text),                       // text		     pal.color(QPalette::Disabled,			       QColorGroup::BrightText),                 // bright text		     pal.color(QPalette::Disabled,			       QColorGroup::Base),                       // base		     pal.color(QPalette::Disabled,			       QColorGroup::Background));                // background	active.setColor(QColorGroup::Highlight,			pal.color(QPalette::Active, QColorGroup::Highlight));	disabled.setColor(QColorGroup::Highlight,			  pal.color(QPalette::Disabled, QColorGroup::Highlight));	active.setColor(QColorGroup::HighlightedText,			pal.color(QPalette::Active, QColorGroup::HighlightedText));	disabled.setColor(QColorGroup::HighlightedText,			  pal.color(QPalette::Disabled, QColorGroup::HighlightedText));	pal.setActive(active);	pal.setInactive(active);	pal.setDisabled(disabled);    }    {	QColor prelight;	if ( (bg.red() + bg.green() + bg.blue()) / 3 > 128)	    prelight = pal.color(QPalette::Active,				 QColorGroup::Background).light(110);	else	    prelight = pal.color(QPalette::Active,				 QColorGroup::Background).light(120);	QColorGroup active2(pal.color(QPalette::Active,				      QColorGroup::Foreground), // foreground			    prelight,                           // button			    prelight.light(),                   // light			    prelight.dark(156),                 // dark			    prelight.dark(110),                 // mid			    pal.color(QPalette::Active,				      QColorGroup::Text),       // text			    pal.color(QPalette::Active,				      QColorGroup::BrightText), // bright text			    pal.color(QPalette::Active,				      QColorGroup::Base),       // base			    prelight);                          // background	d->prelight_palette = pal;	d->prelight_palette.setActive(active2);	d->prelight_palette.setInactive(active2);    }}/*!  \reimp*/void QMotifPlusStyle::polish(QWidget *widget){    if (widget->inherits("QFrame") &&	((QFrame *) widget)->frameStyle() == QFrame::Panel)	((QFrame *) widget)->setFrameStyle(QFrame::WinPanel);#ifndef QT_NO_MENUBAR    if (widget->inherits("QMenuBar") &&	((QMenuBar *) widget)->frameStyle() != QFrame::NoFrame)	((QMenuBar *) widget)->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);#endif#ifndef QT_NO_TOOLBAR    if (widget->inherits("QToolBar"))	widget->layout()->setMargin(2);#endif    if (useHoveringHighlight) {	if (widget->inherits("QButton") ||	    widget->inherits("QComboBox"))	    widget->installEventFilter(this);	if (widget->inherits("QScrollBar") ||	    widget->inherits("QSlider")) {	    widget->setMouseTracking(TRUE);	    widget->installEventFilter(this);	}    }    QMotifStyle::polish(widget);}/*!  \reimp*/void QMotifPlusStyle::unPolish(QWidget *widget){    widget->removeEventFilter(this);    QMotifStyle::unPolish(widget);}/*!  \reimp*/void QMotifPlusStyle::polish(QApplication *){    qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &QMotifPlusStyle::drawMenuBarItem);}/*!  \reimp*/void QMotifPlusStyle::unPolish(QApplication *app){    app->setPalette(d->oldpalette);    qt_set_draw_menu_bar_impl(0);}/*!  \reimp*/void QMotifPlusStyle::polishPopupMenu(QPopupMenu *menu){    menu->setMouseTracking(TRUE);}/*!  \reimp*/void QMotifPlusStyle::drawPushButton(QPushButton *button, QPainter *p){    int x1, y1, x2, y2;    button->rect().coords(&x1, &y1, &x2, &y2);    if (button->isDefault())	drawButton(p, x1, y1, x2 - x1 + 1, y2 - y1 + 1,		   qApp->palette().active(), TRUE);    if (button->isDefault() || button->autoDefault()) {	x1 += buttonDefaultIndicatorWidth();	y1 += buttonDefaultIndicatorWidth();	x2 -= buttonDefaultIndicatorWidth();	y2 -= buttonDefaultIndicatorWidth();    }    QBrush fill;    if (button->isDown() || button->isOn())	fill = button->colorGroup().brush(QColorGroup::Mid);    else	fill = button->colorGroup().brush(QColorGroup::Button);    if ( !button->isFlat() || button->isOn() || button->isDown() )	drawButton(p, x1, y1, x2 - x1 + 1, y2 - y1 + 1,		   button->colorGroup(), button->isOn() || button->isDown(), &fill);}/*!  \reimp*/void QMotifPlusStyle::drawButton(QPainter *p, int x, int y, int w, int h,				 const QColorGroup &g, bool sunken, const QBrush *fill){    QPen oldpen = p->pen();    QPointArray a(4);    if (sunken) p->setPen(g.dark());    else p->setPen(g.light());    a.setPoint(0, x, y + h - 1);    a.setPoint(1, x, y);    a.setPoint(2, x, y);    a.setPoint(3, x + w - 1, y);    p->drawLineSegments(a);    if (sunken) p->setPen(black);    else p->setPen(g.button());    a.setPoint(0, x + 1, y + h - 2);    a.setPoint(1, x + 1, y + 1);    a.setPoint(2, x + 1, y + 1);    a.setPoint(3, x + w - 2, y + 1);    p->drawLineSegments(a);    if (sunken) p->setPen(g.button());    else p->setPen(g.dark());    a.setPoint(0, x + 2, y + h - 2);    a.setPoint(1, x + w - 2, y + h - 2);    a.setPoint(2, x + w - 2, y + h - 2);    a.setPoint(3, x + w - 2, y + 2);    p->drawLineSegments(a);    if (sunken) p->setPen(g.light());    else p->setPen(black);    a.setPoint(0, x + 1, y + h - 1);    a.setPoint(1, x + w - 1, y + h - 1);    a.setPoint(2, x + w - 1, y + h - 1);    a.setPoint(3, x + w - 1, y);    p->drawLineSegments(a);    if ( fill )	p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill);    else	p->fillRect(x + 2, y + 2, w - 4, h - 4, QBrush(g.button()));    p->setPen(oldpen);}/*!  \reimp*/void QMotifPlusStyle::drawBevelButton(QPainter *p, int x, int y, int w, int h,				      const QColorGroup &g, bool sunken, const QBrush *fill){    drawButton(p, x, y, w, h, g, sunken, fill);}/*!  \reimp*/void QMotifPlusStyle::getButtonShift(int &x, int &y){    x = y = 0;}/*!  \reimp*/void QMotifPlusStyle::drawComboButton(QPainter *p, int x, int y, int w, int h,				 const QColorGroup &g, bool sunken,				 bool editable, bool,				 const QBrush *fill){    drawButton(p, x, y, w, h, g, sunken, fill);    if (editable) {	QRect r = comboButtonRect(x, y, w, h);	drawButton(p, r.x() - defaultFrameWidth(),		   r.y() - defaultFrameWidth(),		   r.width() + (defaultFrameWidth() * 2),		   r.height() + (defaultFrameWidth() * 2),		   g, TRUE);

⌨️ 快捷键说明

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