?? qinterlacestyle.cpp
字號(hào):
/****************************************************************************** $Id: qt/src/widgets/qinterlacestyle.cpp 2.3.12 edited 2005-10-27 $**** Implementation of QQInterlaceStyle widget class**** Created : 22 January 2001**** Copyright (C) 1992-2001 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 "qinterlacestyle.h"#ifndef QT_NO_STYLE_INTERLACE#include <qapplication.h>#include <qpainter.h>#include <qdrawutil.h> // for now#include <qpalette.h> // for now#include <qwidget.h>#include <qlabel.h>#include <qpushbutton.h>#include <qwidget.h>#include <qrangecontrol.h>#include <qscrollbar.h>#include <qlistbox.h>#include <limits.h>/*! \class QInterlaceStyle qinterlacestyle.h \brief Look and Feel suitable for interlaced displays \ingroup appearance This class implements a look and feel that reduces flicker as much as possible on interlaced displays (i.e. television). It is an experimental style. In addition to using this style you will need to select a font that does not flicker.*//*! Constructs a QInterlaceStyle*/QInterlaceStyle::QInterlaceStyle() : QMotifStyle(){ setButtonDefaultIndicatorWidth( 0 ); setUseHighlightColors( TRUE ); setSliderThickness(18); setScrollBarExtent(18);}int QInterlaceStyle::defaultFrameWidth() const{ return 2;}/*! \reimp */void QInterlaceStyle::polish( QApplication *app){ oldPalette = app->palette();#if 0 QColor bg( 128, 64, 128 ); QColor btn( 255, 145, 0 ); QColor mid = bg.dark( 120 ); QColor low = mid.dark( 120 ); QColor fg( white );#else QColor bg( 224, 224, 224 ); QColor btn = bg.dark( 105 ); QColor mid = bg.dark( 120 ); QColor low = mid.dark( 120 ); QColor fg( black );#endif QColorGroup cg( fg, btn, low, low, mid, black, black, white, bg ); cg.setColor( QColorGroup::Highlight, QColor( 255, 255, 192 ) ); cg.setColor( QColorGroup::HighlightedText, black ); QColorGroup dcg( cg ); dcg.setColor( QColorGroup::ButtonText, low ); dcg.setColor( QColorGroup::Text, low ); app->setPalette( QPalette( cg, dcg, cg ), TRUE );}/*! \reimp */void QInterlaceStyle::unPolish( QApplication *app){ app->setPalette(oldPalette, TRUE);}/*! \reimp */void QInterlaceStyle::polish( QWidget* w){ // the polish function sets some widgets to transparent mode and // some to translate background mode in order to get the full // benefit from the nice pixmaps in the color group. if ( w->inherits("QLCDNumber") ){ return; } if ( !w->isTopLevel() ) { if ( w->inherits("QGroupBox") || w->inherits("QTabWidget") || w->inherits("QPushButton") ) { w->setAutoMask( TRUE ); return; } if (w->inherits("QLabel") || w->inherits("QSlider") || w->inherits("QButton") || w->inherits("QProgressBar") ){ w->setBackgroundOrigin( QWidget::ParentOrigin ); } } if ( w->inherits( "QFrame" ) ) { QFrame *f = (QFrame *)w; switch ( f->frameShape() ) { case QFrame::WinPanel: f->setFrameShape( QFrame::StyledPanel ); case QFrame::Panel: case QFrame::Box: case QFrame::StyledPanel: case QFrame::PopupPanel: if ( f->frameWidth() == 1 ) f->setLineWidth( 2 ); break; default: break; } } if ( w->inherits( "QListBox" ) ) { // the list box in combos has an ugly border otherwise QFrame *f = (QFrame *)w; if ( f->frameShadow() == QFrame::Plain ) { f->setFrameShadow( QFrame::Raised ); f->setLineWidth( 1 ); } }}/*! \reimp*/void QInterlaceStyle::unPolish( QWidget* w){ // the polish function sets some widgets to transparent mode and // some to translate background mode in order to get the full // benefit from the nice pixmaps in the color group. if ( w->inherits("QLCDNumber") ){ return; } if ( !w->isTopLevel() ) { if ( w->inherits("QGroupBox") || w->inherits("QTabWidget") || w->inherits("QPushButton" ) ) { w->setAutoMask( FALSE ); return; } if (w->inherits("QLabel") || w->inherits("QSlider") || w->inherits("QButton") || w->inherits("QProgressBar") ){ w->setBackgroundOrigin( QWidget::WidgetOrigin ); } }}/*! \reimp*/QRect QInterlaceStyle::pushButtonContentsRect( QPushButton *btn ){ int fw = 0; if ( btn->isDefault() || btn->autoDefault() ) fw = buttonDefaultIndicatorWidth(); return buttonRect( fw+5, fw, btn->width()-2*fw-10, btn->height()-2*fw );}/*! \reimp*/void QInterlaceStyle::drawFocusRect ( QPainter *p, const QRect &/*r*/, const QColorGroup &g, const QColor * bg, bool /*atBorder*/ ){ if (bg ) { int h,s,v; bg->hsv(&h,&s,&v); if (v >= 128) p->setPen( Qt::black ); else p->setPen( Qt::white ); } else p->setPen( g.foreground() );/* p->setBrush( NoBrush ); if ( atBorder ) { p->drawRect( QRect( r.x()+1, r.y()+2, r.width()-2, r.height()-4 ) ); p->drawRect( QRect( r.x()+2, r.y()+1, r.width()-4, r.height()-2 ) ); } else { p->drawRect( QRect( r.x(), r.y()+1, r.width(), r.height()-2 ) ); p->drawRect( QRect( r.x()+1, r.y(), r.width()-2, r.height() ) ); }*/}/*! \reimp*/void QInterlaceStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool /*sunken*/, const QBrush *fill){ const int lineWidth = 2; p->setBrush( g.brush( QColorGroup::Dark ) ); p->setPen( NoPen ); p->drawRect( x+1, y+1, 2, 2 ); p->drawRect( x+w-3, y+1, 2, 2 ); p->drawRect( x+1, y+h-3, 2, 2 ); p->drawRect( x+w-3, y+h-3, 2, 2 ); p->drawRect( x+2, y, w-4, 2 ); p->drawRect( x+2, y+h-lineWidth, w-4, lineWidth ); p->drawRect( x, y+2, lineWidth, h-4 ); p->drawRect( x+w-lineWidth, y+2, lineWidth, h-4 ); if ( fill ) { x += 2; y += 2; w -= 4; h -= 4; p->setBrush( *fill ); p->setPen( NoPen ); p->drawRect( x+1, y, w-2, 1 ); p->drawRect( x, y+1, w, h-2 ); p->drawRect( x+1, y+h-1, w-2, 1 ); }}void QInterlaceStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h ){ QBrush fill( color1 ); QColorGroup cg; cg.setBrush( QColorGroup::Dark, color1 ); drawButton( p, x, y, w, h, cg, FALSE, &fill );}/*! \reimp*/void QInterlaceStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ QInterlaceStyle::drawButton(p, x, y, w, h, g, sunken, fill);}/*! \reimp*/void QInterlaceStyle::drawPushButton( QPushButton* btn, QPainter *p){ QColorGroup g = btn->colorGroup(); int x1, y1, x2, y2; btn->rect().coords( &x1, &y1, &x2, &y2 ); // get coordinates QBrush fill( g.button() ); if ( btn->isDown() || btn->isOn() ) fill = g.mid(); if ( btn->hasFocus() ) g.setBrush( QColorGroup::Dark, black ); drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, FALSE, &fill ); if ( btn->isMenuButton() ) { int dx = (y1-y2-4)/3; drawArrow( p, DownArrow, FALSE, x2 - dx, dx, y1, y2 - y1, g, btn->isEnabled() ); } if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush );}/*! \reimp*/QSize QInterlaceStyle::indicatorSize () const{ return QSize(13,13);}/*! \reimp*/void QInterlaceStyle::drawIndicator( QPainter * p, int x, int y, int w, int h, const QColorGroup &g, int s, bool down, bool enabled ){ p->fillRect( x, y, w, h, g.brush( QColorGroup::Background ) ); QBrush fill; if ( s == QButton::NoChange ) { QBrush b = p->brush(); QColor c = p->backgroundColor(); p->setBackgroundMode( TransparentMode ); p->setBackgroundColor( green ); fill = QBrush(g.base(), Dense4Pattern); p->setBackgroundColor( c ); p->setBrush( b ); } else if ( down ) fill = g.brush( QColorGroup::Button ); else fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background ); drawButton( p, x, y, w, h, g, FALSE, &fill ); if ( s != QButton::Off ) { QPointArray a( 7*2 ); int i, xx, yy; xx = x+3; yy = y+5; for ( i=0; i<3; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy++; } yy -= 2; for ( i=3; i<7; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy--; } if ( s == QButton::NoChange ) { p->setPen( g.dark() ); } else { p->setPen( g.text() ); } p->drawLineSegments( a ); }}/*! \reimp*/void QInterlaceStyle::drawIndicatorMask( QPainter *p, int x, int y, int w, int h, int ){ drawButtonMask( p, x, y, w, h );}/*! \reimp*/QSize QInterlaceStyle::exclusiveIndicatorSize() const{ return QSize(13,13);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -