📄 fresh.cpp
字号:
/************************************************************************ 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 <qpainter.h>#include <qimage.h>#include <qfontmetrics.h>#include <qpalette.h>#include <qdrawutil.h>#include <qscrollbar.h>#include <qbutton.h>#include <qframe.h>#include <qtabbar.h>#define INCLUDE_MENUITEM_DEF#include <qmenudata.h>#include <qpopupmenu.h>#include "fresh.h"#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)FreshStyle::FreshStyle(){ setButtonMargin(2); setScrollBarExtent(13,13);}FreshStyle::~FreshStyle(){}int FreshStyle::buttonMargin() const{ return 2;}QSize FreshStyle::scrollBarExtent() const{ return QSize(13,13);}void FreshStyle::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 FreshStyle::polish( QWidget *w ){ if ( w->inherits( "QListBox" ) || w->inherits( "QListView" ) || w->inherits( "QPopupMenu" ) || w->inherits( "QSpinBox" ) ) { QFrame *f = (QFrame *)w; f->setFrameShape( QFrame::StyledPanel ); f->setLineWidth( 1 ); } QStyleHackWidget::setGlobalBrushOrigin(w);}void FreshStyle::unPolish( QWidget *w ){ if ( w->inherits( "QListBox" ) || w->inherits( "QListView" ) || w->inherits( "QPopupMenu" ) || w->inherits( "QSpinBox" ) ) { QFrame *f = (QFrame *)w; f->setFrameShape( QFrame::StyledPanel ); f->setLineWidth( 2 ); } QStyleHackWidget::clearGlobalBrushOrigin(w);}int FreshStyle::defaultFrameWidth() const{ return 2;}void FreshStyle::drawPanel ( QPainter * p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill ){ qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );}void FreshStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &cg, bool sunken, const QBrush* fill ){ QPen oldPen = p->pen(); int off = sunken ? 1 : 0; p->fillRect( x+1+off, y+1+off, w-3, h-3, fill?(*fill):cg.brush(QColorGroup::Button) ); int x2 = x+w-1; int y2 = y+h-1; if ( sunken ) p->setPen( cg.dark() ); else p->setPen( cg.light() ); p->drawLine( x, y, x, y2-1 ); p->drawLine( x, y, x2, y ); if ( sunken ) { p->setPen( white ); p->drawLine( x+1, y+1, x+1, y2-2 ); p->drawLine( x+1, y+1, x2-2, y+1 ); } if ( sunken ) p->setPen( cg.light() ); else p->setPen( cg.dark() ); p->drawLine( x2, y+1, x2, y2 ); p->drawLine( x, y2, x2, y2 ); if ( !sunken ) { p->setPen( white ); p->drawLine( x2-1, y+1, x2-1, y2-1 ); p->drawLine( x+1, y2-1, x2-1, y2-1 ); } p->setPen( oldPen );}void FreshStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h ){ p->fillRect( x, y, w, h, color1 );}void FreshStyle::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 );}QRect FreshStyle::comboButtonRect( int x, int y, int w, int h){ return QRect(x+1, y+1, w-2-14, h-2);} QRect FreshStyle::comboButtonFocusRect( int x, int y, int w, int h){ return QRect(x+2, y+2, w-4-14, h-4);}void FreshStyle::drawComboButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, bool /*editable*/, bool enabled, const QBrush *fill ){ drawBevelButton( p, x, y, w, h, g, FALSE, fill ); drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill ); drawArrow( p, QStyle::DownArrow, sunken, x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled, &g.brush( QColorGroup::Button ) );}void FreshStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w, int h, const QColorGroup &cg, bool on, bool down, bool enabled ){ static const QCOORD pts1[] = { // dark lines 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; static const QCOORD pts4[] = { // white lines 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 11,4, 10,3, 10,2 }; static const QCOORD pts5[] = { // inner fill 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; p->eraseRect( x, y, w, h ); QPointArray a( QCOORDARRLEN(pts1), pts4 ); a.translate( x, y ); p->setPen( cg.dark() ); p->drawPolyline( a ); a.setPoints( QCOORDARRLEN(pts4), pts1 ); a.translate( x, y ); p->setPen( cg.light() ); p->drawPolyline( a ); a.setPoints( QCOORDARRLEN(pts5), pts5 ); a.translate( x, y ); QColor fillColor = ( down || !enabled ) ? cg.button() : cg.base(); p->setPen( fillColor ); p->setBrush( fillColor ) ; p->drawPolygon( a ); if ( on ) { p->setPen( NoPen ); p->setBrush( cg.text() ); p->drawRect( x+5, y+4, 2, 4 ); p->drawRect( x+4, y+5, 4, 2 ); }}void FreshStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h, const QColorGroup &cg, int state, bool down, bool enabled ){ QColorGroup mycg( cg ); mycg.setBrush( QColorGroup::Button, QBrush() ); QBrush fill; drawButton( p, x, y, w, h, mycg, TRUE, 0 ); if ( down ) fill = cg.brush( QColorGroup::Button ); else fill = cg.brush( enabled ? QColorGroup::Base : QColorGroup::Background ); mycg.setBrush( QColorGroup::Button, fill ); p->fillRect( x+1, y+1, w-2, h-2, fill ); if ( state != 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 ( state == QButton::NoChange ) { p->setPen( mycg.dark() ); } else { p->setPen( mycg.text() ); } p->drawLineSegments( a ); }}#define HORIZONTAL (sb->orientation() == QScrollBar::Horizontal)#define VERTICAL !HORIZONTAL#define MOTIF_BORDER 2#define SLIDER_MIN 9 // ### motif says 6 but that's too small/*! \reimp */void FreshStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim ){ int maxLength; int length = HORIZONTAL ? sb->width() : sb->height(); int extent = HORIZONTAL ? sb->height() : sb->width(); if ( length > (extent - 1)*2 ) buttonDim = extent; else buttonDim = length/2 - 1; sliderMin = 0; maxLength = length - buttonDim*2; if ( sb->maxValue() == sb->minValue() ) { sliderLength = maxLength; } else { sliderLength = (sb->pageStep()*maxLength)/ (sb->maxValue()-sb->minValue()+sb->pageStep()); uint range = sb->maxValue()-sb->minValue(); if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 ) sliderLength = SLIDER_MIN; if ( sliderLength > maxLength ) sliderLength = maxLength; } sliderMax = sliderMin + maxLength - sliderLength;}/*!\reimp */QStyle::ScrollControl FreshStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p ){ if ( !sb->rect().contains( p ) ) return NoScroll; int sliderMin, sliderMax, sliderLength, buttonDim, pos; scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); if (sb->orientation() == QScrollBar::Horizontal) pos = p.x(); else pos = p.y(); if (pos < sliderStart) return SubPage; if (pos < sliderStart + sliderLength) return Slider; if (pos < sliderMax + sliderLength) return AddPage; if (pos < sliderMax + sliderLength + buttonDim) return SubLine; return AddLine;}/*! \reimp */void FreshStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl ){#define ADD_LINE_ACTIVE ( activeControl == AddLine )#define SUB_LINE_ACTIVE ( activeControl == SubLine ) QColorGroup g = sb->colorGroup(); int sliderMin, sliderMax, sliderLength, buttonDim; scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) ) p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid )); if (sliderStart > sliderMax) { // sanity check sliderStart = sliderMax; } int dimB = buttonDim; QRect addB; QRect subB; QRect addPageR; QRect subPageR; QRect sliderR; int addX, addY, subX, subY; int length = HORIZONTAL ? sb->width() : sb->height(); int extent = HORIZONTAL ? sb->height() : sb->width(); if ( HORIZONTAL ) { subY = addY = ( extent - dimB ) / 2; subX = length - dimB - dimB; addX = length - dimB; } else { subX = addX = ( extent - dimB ) / 2; subY = length - dimB - dimB; addY = length - dimB; } int sliderEnd = sliderStart + sliderLength; int sliderW = extent; if ( HORIZONTAL ) { subB.setRect( subX,subY+1,dimB,dimB-1 ); addB.setRect( addX,addY+1,dimB,dimB-1 ); subPageR.setRect( 0, 0, sliderStart+1, sliderW ); addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW ); sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 ); } else { subB.setRect( subX+1,subY,dimB-1,dimB ); addB.setRect( addX+1,addY,dimB-1,dimB ); subPageR.setRect( 0, 0, sliderW, sliderStart+1 ); addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 ); sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength ); } bool maxedOut = (sb->maxValue() == sb->minValue()); if ( controls & AddLine ) { drawBevelButton( p, addB.x(), addB.y(), addB.width(), addB.height(), g, ADD_LINE_ACTIVE); p->setPen(g.shadow()); drawArrow( p, VERTICAL ? DownArrow : RightArrow, FALSE, addB.x()+2, addB.y()+2, addB.width()-4, addB.height()-4, g, !maxedOut, &g.brush( QColorGroup::Button )); } if ( controls & SubLine ) { drawBevelButton( p, subB.x(), subB.y(), subB.width(), subB.height(), g, SUB_LINE_ACTIVE ); p->setPen(g.shadow()); drawArrow( p, VERTICAL ? UpArrow : LeftArrow, FALSE, subB.x()+2, subB.y()+2, subB.width()-4, subB.height()-4, g, !maxedOut, &g.brush( QColorGroup::Button )); } if ( controls & SubPage ) p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height(), g.brush( QColorGroup::Mid )); if ( controls & AddPage ) p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height(), g.brush( QColorGroup::Mid )); if ( controls & Slider ) { QPoint bo = p->brushOrigin(); if ( !sb->testWState(WState_GlobalBrushOrigin) ) p->setBrushOrigin(sliderR.topLeft()); drawBevelButton( p, sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height(), g, FALSE, &g.brush( QColorGroup::Button ) ); p->setBrushOrigin(bo); drawRiffles( p, sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height(), g, HORIZONTAL ); } // ### perhaps this should not be able to accept focus if maxedOut? if ( sb->hasFocus() && (controls & Slider) ) p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2, sliderR.width()-5, sliderR.height()-5, sb->backgroundColor() );}void FreshStyle::drawRiffles( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, bool horizontal ){ return; if (!horizontal) { if (h > 20) { y += (h-20)/2 ; h = 20; } if (h > 12) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -