📄 qdrawutil.cpp
字号:
QVector<QLineF> lines; lines.reserve(2*lineWidth); if (sunken) p->setPen(shade); else p->setPen(light); int x1, y1, x2, y2; int i; x1 = x; y1 = y2 = y; x2 = x+w-2; for (i=0; i<lineWidth; i++) { // top shadow lines << QLineF(x1, y1++, x2--, y2++); } x2 = x1; y1 = y+h-2; for (i=0; i<lineWidth; i++) { // left shado lines << QLineF(x1++, y1, x2++, y2--); } p->drawLines(lines); lines.clear(); if (sunken) p->setPen(light); else p->setPen(shade); x1 = x; y1 = y2 = y+h-1; x2 = x+w-1; for (i=0; i<lineWidth; i++) { // bottom shadow lines << QLineF(x1++, y1--, x2, y2--); } x1 = x2; y1 = y; y2 = y+h-lineWidth-1; for (i=0; i<lineWidth; i++) { // right shadow lines << QLineF(x1--, y1++, x2--, y2); } p->drawLines(lines); if (fill) // fill with fill color p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill); p->setPen(oldPen); // restore pen}/*! \internal This function draws a rectangle with two pixel line width. It is called from qDrawWinButton() and qDrawWinPanel(). c1..c4 and fill are used: 1 1 1 1 1 2 1 3 3 3 4 2 1 3 F F 4 2 1 3 F F 4 2 1 4 4 4 4 2 2 2 2 2 2 2*/static void qDrawWinShades(QPainter *p, int x, int y, int w, int h, const QColor &c1, const QColor &c2, const QColor &c3, const QColor &c4, const QBrush *fill){ if (w < 2 || h < 2) // can't do anything with that return; QPen oldPen = p->pen(); QPoint a[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) }; p->setPen(c1); p->drawPolyline(a, 3); QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) }; p->setPen(c2); p->drawPolyline(b, 3); if (w > 4 && h > 4) { QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) }; p->setPen(c3); p->drawPolyline(c, 3); QPoint d[3] = { QPoint(x+1, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y+1) }; p->setPen(c4); p->drawPolyline(d, 3); if (fill) p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill); } p->setPen(oldPen);}/*! \fn void qDrawWinButton(QPainter *painter, int x, int y, int width, int height, const QPalette &palette, bool sunken, const QBrush *fill) \relates QPainter Draws the Windows-style button specified by the given point (\a x, \a y}, \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the \a{fill} brush unless \a fill is 0. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The button appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style()-> Use the drawing functions in QStyle to make widgets that follow the current GUI style. \sa qDrawWinPanel(), QStyle*/void qDrawWinButton(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill){ if (sunken) qDrawWinShades(p, x, y, w, h, pal.shadow().color(), pal.light().color(), pal.dark().color(), pal.button().color(), fill); else qDrawWinShades(p, x, y, w, h, pal.light().color(), pal.shadow().color(), pal.button().color(), pal.dark().color(), fill);}/*! \fn void qDrawWinPanel(QPainter *painter, int x, int y, int width, int height, const QPalette &palette, bool sunken, const QBrush *fill) \relates QPainter Draws the Windows-style panel specified by the given point(\a x, \a y), \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the \a fill brush unless \a fill is 0. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a shaded panel: \code QFrame frame: frame.setFrameStyle(QFrame::WinPanel | QFrame::Raised); \endcode \sa qDrawShadePanel(), qDrawWinButton(), QStyle*/void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill){ if (sunken) qDrawWinShades(p, x, y, w, h, pal.dark().color(), pal.light().color(), pal.shadow().color(), pal.midlight().color(), fill); else qDrawWinShades(p, x, y, w, h, pal.light().color(), pal.shadow().color(), pal.midlight().color(), pal.dark().color(), fill);}/*! \fn void qDrawPlainRect(QPainter *painter, int x, int y, int width, int height, const QColor &lineColor, int lineWidth, const QBrush *fill) \relates QPainter Draws the plain rectangle beginning at (\a x, \a y) with the given \a width and \a height, using the provided \a painter, \a lineColor and \a lineWidth . The rectangle's interior is filled with the \a fill brush unless \a fill is 0. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a plain rectangle: \code QFrame frame: frame.setFrameStyle(QFrame::Box | QFrame::Plain); \endcode \sa qDrawShadeRect(), QStyle*/void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, int lineWidth, const QBrush *fill){ if (w == 0 || h == 0) return; if (!(w > 0 && h > 0 && lineWidth >= 0)) { qWarning("qDrawPlainRect() Invalid parameters."); } QPen oldPen = p->pen(); QBrush oldBrush = p->brush(); p->setPen(c); p->setBrush(Qt::NoBrush); for (int i=0; i<lineWidth; i++) p->drawRect(x+i, y+i, w-i*2 - 1, h-i*2 - 1); if (fill) { // fill with fill color p->setPen(Qt::NoPen); p->setBrush(*fill); p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2); } p->setPen(oldPen); p->setBrush(oldBrush);}/***************************************************************************** Overloaded functions. *****************************************************************************//*! \fn void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth) \overload*/void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth){ qDrawShadeLine(p, p1.x(), p1.y(), p2.x(), p2.y(), pal, sunken, lineWidth, midLineWidth);}/*! \fn void qDrawShadeRect(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill) \overload*/void qDrawShadeRect(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill){ qDrawShadeRect(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, lineWidth, midLineWidth, fill);}/*! \fn void qDrawShadePanel(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill) \overload*/void qDrawShadePanel(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill){ qDrawShadePanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, lineWidth, fill);}/*! \fn void qDrawWinButton(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill) \overload*/void qDrawWinButton(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill){ qDrawWinButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);}/*! \fn void qDrawWinPanel(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill) \overload*/void qDrawWinPanel(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill){ qDrawWinPanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);}/*! \fn void qDrawPlainRect(QPainter *p, const QRect &r, const QColor &c, int lineWidth, const QBrush *fill) \overload*/void qDrawPlainRect(QPainter *p, const QRect &r, const QColor &c, int lineWidth, const QBrush *fill){ qDrawPlainRect(p, r.x(), r.y(), r.width(), r.height(), c, lineWidth, fill);}#ifdef QT3_SUPPORTstatic void qDrawWinArrow(QPainter *p, Qt::ArrowType type, bool down, int x, int y, int w, int h, const QPalette &pal, bool enabled)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -