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

📄 drawparams.cpp

📁 LINUX 下以 QT/KDE 写的 SVN 客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* This file is part of KCachegrind.   Copyright (C) 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>   Adapted for the needs of kdesvn  by Rajko Albrecht <ral@alwins-world.de>   KCachegrind 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, version 2.   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.   You should have received a copy of the GNU General Public License   along with this program; see the file COPYING.  If not, write to   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.*//* * A Widget for visualizing hierarchical metrics as areas. * The API is similar to QListView. */#include <math.h>#include <qpainter.h>#include <qtooltip.h>#include <qregexp.h>#include <qstyle.h>#include <qpopupmenu.h>#include <klocale.h>#include <kconfig.h>#include <kdebug.h>#include "drawparams.h"// set this to 1 to enable debug output#define DEBUG_DRAWING 0#define MAX_FIELD 12//// StoredDrawParams//StoredDrawParams::StoredDrawParams(){  _selected = false;  _current = false;  _shaded = true;  _rotated = false;  _backColor = Qt::white;  // field array has size 0}StoredDrawParams::StoredDrawParams(QColor c,                                   bool selected, bool current){  _backColor = c;  _selected = selected;  _current = current;  _shaded = true;  _rotated = false;  _drawFrame = true;  // field array has size 0}QString StoredDrawParams::text(int f) const{  if ((f<0) || (f >= (int)_field.size()))    return QString::null;  return _field[f].text;}QPixmap StoredDrawParams::pixmap(int f) const{  if ((f<0) || (f >= (int)_field.size()))    return QPixmap();  return _field[f].pix;}DrawParams::Position StoredDrawParams::position(int f) const{  if ((f<0) || (f >= (int)_field.size()))    return Default;  return _field[f].pos;}int StoredDrawParams::maxLines(int f) const{  if ((f<0) || (f >= (int)_field.size()))    return 0;  return _field[f].maxLines;}const QFont& StoredDrawParams::font() const{  static QFont* f = 0;  if (!f) f = new QFont(QApplication::font());  return *f;}void StoredDrawParams::ensureField(int f){  static Field* def = 0;  if (!def) {    def = new Field();    def->pos = Default;    def->maxLines = 0;  }  if (f<0 || f>=MAX_FIELD) return;  if ((int)_field.size() < f+1) _field.resize(f+1, *def);}void StoredDrawParams::setField(int f, QString t, QPixmap pm,                           Position p, int maxLines){  if (f<0 || f>=MAX_FIELD) return;  ensureField(f);  _field[f].text = t;  _field[f].pix  = pm;  _field[f].pos  = p;  _field[f].maxLines = maxLines;}void StoredDrawParams::setText(int f, QString t){  if (f<0 || f>=MAX_FIELD) return;  ensureField(f);  _field[f].text = t;}void StoredDrawParams::setPixmap(int f, QPixmap pm){  if (f<0 || f>=MAX_FIELD) return;  ensureField(f);  _field[f].pix = pm;}void StoredDrawParams::setPosition(int f, Position p){  if (f<0 || f>=MAX_FIELD) return;  ensureField(f);  _field[f].pos = p;}void StoredDrawParams::setMaxLines(int f, int m){  if (f<0 || f>=MAX_FIELD) return;  ensureField(f);  _field[f].maxLines = m;}//// RectDrawing//RectDrawing::RectDrawing(QRect r){  _fm = 0;  _dp = 0;  setRect(r);}RectDrawing::~RectDrawing(){  delete _fm;  delete _dp;}DrawParams* RectDrawing::drawParams(){  if (!_dp)    _dp = new StoredDrawParams();  return _dp;}void RectDrawing::setDrawParams(DrawParams* dp){  if (_dp) delete _dp;  _dp = dp;}void RectDrawing::setRect(QRect r){  _rect = r;  _usedTopLeft = 0;  _usedTopCenter = 0;  _usedTopRight = 0;  _usedBottomLeft = 0;  _usedBottomCenter = 0;  _usedBottomRight = 0;  _fontHeight = 0;}QRect RectDrawing::remainingRect(DrawParams* dp){  if (!dp) dp = drawParams();  if ((_usedTopLeft >0) ||      (_usedTopCenter >0) ||      (_usedTopRight >0)) {    if (dp->rotated())      _rect.setLeft(_rect.left() + _fontHeight);    else      _rect.setTop(_rect.top() + _fontHeight);  }  if ((_usedBottomLeft >0) ||      (_usedBottomCenter >0) ||      (_usedBottomRight >0)) {    if (dp->rotated())      _rect.setRight(_rect.right() - _fontHeight);    else      _rect.setBottom(_rect.bottom() - _fontHeight);  }  return _rect;}void RectDrawing::drawBack(QPainter* p, DrawParams* dp){  if (!dp) dp = drawParams();  if (_rect.width()<=0 || _rect.height()<=0) return;  QRect r = _rect;  QColor normal = dp->backColor();  if (dp->selected()) normal = normal.light();  bool isCurrent = dp->current();  if (dp->drawFrame() || isCurrent) {    // 3D raised/sunken frame effect...    QColor high = normal.light();    QColor low = normal.dark();    p->setPen( isCurrent ? low:high);    p->drawLine(r.left(), r.top(), r.right(), r.top());    p->drawLine(r.left(), r.top(), r.left(), r.bottom());    p->setPen( isCurrent ? high:low);    p->drawLine(r.right(), r.top(), r.right(), r.bottom());    p->drawLine(r.left(), r.bottom(), r.right(), r.bottom());    r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);  }  if (r.width()<=0 || r.height()<=0) return;  if (dp->shaded()) {    // some shading    bool goDark = qGray(normal.rgb())>128;    int rBase, gBase, bBase;    normal.rgb(&rBase, &gBase, &bBase);    p->setBrush(QBrush::NoBrush);    // shade parameters:    int d = 7;    float factor = 0.1, forth=0.7, back1 =0.9, toBack2 = .7, back2 = 0.97;    // coefficient corrections because of rectangle size    int s = r.width();    if (s > r.height()) s = r.height();    if (s<100) {      forth -= .3  * (100-s)/100;      back1 -= .2  * (100-s)/100;      back2 -= .02 * (100-s)/100;    }    // maximal color difference    int rDiff = goDark ? -rBase/d : (255-rBase)/d;    int gDiff = goDark ? -gBase/d : (255-gBase)/d;    int bDiff = goDark ? -bBase/d : (255-bBase)/d;    QColor shadeColor;    while (factor<.95) {      shadeColor.setRgb((int)(rBase+factor*rDiff+.5),                        (int)(gBase+factor*gDiff+.5),                        (int)(bBase+factor*bDiff+.5));      p->setPen(shadeColor);      p->drawRect(r);      r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);      if (r.width()<=0 || r.height()<=0) return;      factor = 1.0 - ((1.0 - factor) * forth);    }    // and back (1st half)    while (factor>toBack2) {      shadeColor.setRgb((int)(rBase+factor*rDiff+.5),                        (int)(gBase+factor*gDiff+.5),                        (int)(bBase+factor*bDiff+.5));      p->setPen(shadeColor);      p->drawRect(r);      r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);      if (r.width()<=0 || r.height()<=0) return;      factor = 1.0 - ((1.0 - factor) / back1);    }    // and back (2nd half)    while ( factor>.01) {      shadeColor.setRgb((int)(rBase+factor*rDiff+.5),                        (int)(gBase+factor*gDiff+.5),                        (int)(bBase+factor*bDiff+.5));      p->setPen(shadeColor);      p->drawRect(r);      r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);      if (r.width()<=0 || r.height()<=0) return;      factor = factor * back2;    }  }  // fill inside  p->setPen(QPen::NoPen);  p->setBrush(normal);  p->drawRect(r);}bool RectDrawing::drawField(QPainter* p, int f, DrawParams* dp){  if (!dp) dp = drawParams();  if (!_fm) {    _fm = new QFontMetrics(dp->font());    _fontHeight = _fm->height();  }  QRect r = _rect;  if (0) kdDebug(90100) << "DrawField: Rect " << r.x() << "/" << r.y()		   << " - " << r.width() << "x" << r.height() << endl;

⌨️ 快捷键说明

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