void QFrame::drawFrame( QPainter *p ) { QPoint p1, p2; QRect r = frameRect(); int type = fstyle & MShape; int cstyle = fstyle & MShadow; #ifdef QT_NO_DRAWUTIL p->setPen( black ); // #### p->drawRect( r ); //### a bit too simple #else const QColorGroup & g = colorGroup(); #ifndef QT_NO_STYLE QStyleOption opt(lineWidth(),midLineWidth()); QStyle::SFlags flags = QStyle::Style_Default; if (isEnabled()) flags |= QStyle::Style_Enabled; if (cstyle == Sunken) flags |= QStyle::Style_Sunken; else if (cstyle == Raised) flags |= QStyle::Style_Raised; if (hasFocus()) flags |= QStyle::Style_HasFocus; if (hasMouse()) flags |= QStyle::Style_MouseOver; #endif // QT_NO_STYLE switch ( type ) { case Box: if ( cstyle == Plain ) qDrawPlainRect( p, r, g.foreground(), lwidth ); else qDrawShadeRect( p, r, g, cstyle == Sunken, lwidth, midLineWidth() ); break; case LineEditPanel: style().drawPrimitive( QStyle::PE_PanelLineEdit, p, r, g, flags, opt ); break; case GroupBoxPanel: style().drawPrimitive( QStyle::PE_PanelGroupBox, p, r, g, flags, opt ); break; case TabWidgetPanel: style().drawPrimitive( QStyle::PE_PanelTabWidget, p, r, g, flags, opt ); break; case MenuBarPanel: #ifndef QT_NO_STYLE style().drawPrimitive(QStyle::PE_PanelMenuBar, p, r, g, flags, opt); break; #endif // fall through to Panel if QT_NO_STYLE case ToolBarPanel: #ifndef QT_NO_STYLE style().drawPrimitive( QStyle::PE_PanelDockWindow, p, rect(), g, flags, opt); break; #endif // fall through to Panel if QT_NO_STYLE case StyledPanel: #ifndef QT_NO_STYLE if ( cstyle == Plain ) qDrawPlainRect( p, r, g.foreground(), lwidth ); else style().drawPrimitive(QStyle::PE_Panel, p, r, g, flags, opt); break; #endif // fall through to Panel if QT_NO_STYLE case PopupPanel: #ifndef QT_NO_STYLE { int vextra = style().pixelMetric(QStyle::PM_PopupMenuFrameVerticalExtra, this), hextra = style().pixelMetric(QStyle::PM_PopupMenuFrameHorizontalExtra, this); if(vextra > 0 || hextra > 0) { QRect fr = frameRect(); int fw = frameWidth(); if(vextra > 0) { style().drawControl(QStyle::CE_PopupMenuVerticalExtra, p, this, QRect(fr.x() + fw, fr.y() + fw, fr.width() - (fw*2), vextra), g, flags, opt); style().drawControl(QStyle::CE_PopupMenuVerticalExtra, p, this, QRect(fr.x() + fw, fr.bottom() - fw - vextra, fr.width() - (fw*2), vextra), g, flags, opt); } if(hextra > 0) { style().drawControl(QStyle::CE_PopupMenuHorizontalExtra, p, this, QRect(fr.x() + fw, fr.y() + fw + vextra, hextra, fr.height() - (fw*2) - vextra), g, flags, opt); style().drawControl(QStyle::CE_PopupMenuHorizontalExtra, p, this, QRect(fr.right() - fw - hextra, fr.y() + fw + vextra, hextra, fr.height() - (fw*2) - vextra), g, flags, opt); } } if ( cstyle == Plain ) qDrawPlainRect( p, r, g.foreground(), lwidth ); else style().drawPrimitive(QStyle::PE_PanelPopup, p, r, g, flags, opt); break; } #endif // fall through to Panel if QT_NO_STYLE case Panel: if ( cstyle == Plain ) qDrawPlainRect( p, r, g.foreground(), lwidth ); else qDrawShadePanel( p, r, g, cstyle == Sunken, lwidth ); break; case WinPanel: if ( cstyle == Plain ) qDrawPlainRect( p, r, g.foreground(), wpwidth ); else qDrawWinPanel( p, r, g, cstyle == Sunken ); break; case HLine: case VLine: if ( type == HLine ) { p1 = QPoint( r.x(), r.height()/2 ); p2 = QPoint( r.x()+r.width(), p1.y() ); } else { p1 = QPoint( r.x()+r.width()/2, 0 ); p2 = QPoint( p1.x(), r.height() ); } if ( cstyle == Plain ) { QPen oldPen = p->pen(); p->setPen( QPen(g.foreground(),lwidth) ); p->drawLine( p1, p2 ); p->setPen( oldPen ); } else qDrawShadeLine( p, p1, p2, g, cstyle == Sunken, lwidth, midLineWidth() ); break; } #endif // QT_NO_DRAWUTIL }
void KDatePicker::drawFrame(QPainter *p) { QPoint p1, p2; QStyleOptionFrame opt; opt.init(this); QList<QWidget*> lst = findChildren<QWidget*>(); foreach ( QWidget *w, lst ) { if ( w->hasFocus() ) { opt.state |= QStyle::State_HasFocus; break; } } int frameShape = frameStyle() & QFrame::Shape_Mask; int frameShadow = frameStyle() & QFrame::Shadow_Mask; int lw = 0; int mlw = 0; opt.rect = frameRect(); switch (frameShape) { case QFrame::Box: case QFrame::HLine: case QFrame::VLine: case QFrame::StyledPanel: lw = lineWidth(); mlw = midLineWidth(); break; default: // most frame styles do not handle customized line and midline widths // (see updateFrameWidth()). lw = frameWidth(); break; } opt.lineWidth = lw; opt.midLineWidth = mlw; if (frameShadow == Sunken) opt.state |= QStyle::State_Sunken; else if (frameShadow == Raised) opt.state |= QStyle::State_Raised; switch (frameShape) { case Box: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawShadeRect(p, opt.rect, opt.palette, frameShadow == Sunken, lw, mlw); break; case StyledPanel: style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this); break; case Panel: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawShadePanel(p, opt.rect, opt.palette, frameShadow == Sunken, lw); break; case WinPanel: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawWinPanel(p, opt.rect, opt.palette, frameShadow == Sunken); break; case HLine: case VLine: if (frameShape == HLine) { p1 = QPoint(opt.rect.x(), opt.rect.height() / 2); p2 = QPoint(opt.rect.x() + opt.rect.width(), p1.y()); } else { p1 = QPoint(opt.rect.x()+opt.rect.width() / 2, 0); p2 = QPoint(p1.x(), opt.rect.height()); } if (frameShadow == Plain) { QPen oldPen = p->pen(); p->setPen(QPen(opt.palette.foreground().color(), lw)); p->drawLine(p1, p2); p->setPen(oldPen); } else { qDrawShadeLine(p, p1, p2, opt.palette, frameShadow == Sunken, lw, mlw); } break; } }