Changeset View
Changeset View
Standalone View
Standalone View
kstyle/breezehelper.cpp
Show First 20 Lines • Show All 635 Lines • ▼ Show 20 Line(s) | 629 | { | |||
---|---|---|---|---|---|
636 | frameRect.adjust( 1, 1, -1, -1 ); | 636 | frameRect.adjust( 1, 1, -1, -1 ); | ||
637 | qreal radius( frameRadius() ); | 637 | qreal radius( frameRadius() ); | ||
638 | 638 | | |||
639 | // shadow | 639 | // shadow | ||
640 | if( sunken ) { | 640 | if( sunken ) { | ||
641 | 641 | | |||
642 | frameRect.translate( 1, 1 ); | 642 | frameRect.translate( 1, 1 ); | ||
643 | 643 | | |||
644 | } else if( shadow.isValid() ) { | 644 | } else { | ||
645 | 645 | | |||
646 | const qreal shadowRadius = qMax( radius - 1, qreal( 0.0 ) ); | 646 | renderRoundedRectShadow( painter, frameRect, shadow, radius ); | ||
647 | painter->setPen( QPen( shadow, 2 ) ); | | |||
648 | painter->setBrush( Qt::NoBrush ); | | |||
649 | painter->drawRoundedRect( shadowRect( frameRect ), shadowRadius, shadowRadius ); | | |||
650 | 647 | | |||
651 | } | 648 | } | ||
652 | 649 | | |||
653 | if( outline.isValid() ) | 650 | if( outline.isValid() ) | ||
654 | { | 651 | { | ||
655 | 652 | | |||
656 | QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); | 653 | QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); | ||
657 | gradient.setColorAt( 0, outline.lighter( hasFocus ? 103:101 ) ); | 654 | gradient.setColorAt( 0, outline.lighter( hasFocus ? 103:101 ) ); | ||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Line(s) | 857 | { | |||
870 | // shadow | 867 | // shadow | ||
871 | if( sunken ) | 868 | if( sunken ) | ||
872 | { | 869 | { | ||
873 | 870 | | |||
874 | frameRect.translate(1, 1); | 871 | frameRect.translate(1, 1); | ||
875 | 872 | | |||
876 | } else { | 873 | } else { | ||
877 | 874 | | |||
878 | painter->setPen( QPen( shadow, 1 ) ); | 875 | renderRoundedRectShadow( painter, frameRect, shadow, radius ); | ||
879 | painter->setBrush( Qt::NoBrush ); | | |||
880 | | ||||
881 | const qreal shadowRadius( radius + 0.5 ); | | |||
882 | painter->drawRoundedRect( shadowRect( frameRect ).adjusted( -0.5, -0.5, 0.5, 0.5 ), shadowRadius, shadowRadius ); | | |||
883 | 876 | | |||
884 | } | 877 | } | ||
885 | 878 | | |||
886 | // content | 879 | // content | ||
887 | { | 880 | { | ||
888 | 881 | | |||
889 | painter->setPen( QPen( color, 1 ) ); | 882 | painter->setPen( QPen( color, 1 ) ); | ||
890 | painter->setBrush( Qt::NoBrush ); | 883 | painter->setBrush( Qt::NoBrush ); | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 961 | { | |||
977 | // shadow | 970 | // shadow | ||
978 | if( sunken ) | 971 | if( sunken ) | ||
979 | { | 972 | { | ||
980 | 973 | | |||
981 | frameRect.translate( 1, 1 ); | 974 | frameRect.translate( 1, 1 ); | ||
982 | 975 | | |||
983 | } else { | 976 | } else { | ||
984 | 977 | | |||
985 | painter->setPen( QPen( shadow, 1 ) ); | 978 | renderEllipseShadow( painter, frameRect, shadow ); | ||
986 | painter->setBrush( Qt::NoBrush ); | | |||
987 | painter->drawEllipse( shadowRect( frameRect ).adjusted( -0.5, -0.5, 0.5, 0.5 ) ); | | |||
988 | 979 | | |||
989 | } | 980 | } | ||
990 | 981 | | |||
991 | // content | 982 | // content | ||
992 | { | 983 | { | ||
993 | 984 | | |||
994 | painter->setPen( QPen( color, 1 ) ); | 985 | painter->setPen( QPen( color, 1 ) ); | ||
995 | painter->setBrush( Qt::NoBrush ); | 986 | painter->setBrush( Qt::NoBrush ); | ||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 1125 | { | |||
1136 | // setup painter | 1127 | // setup painter | ||
1137 | painter->setRenderHint( QPainter::Antialiasing, true ); | 1128 | painter->setRenderHint( QPainter::Antialiasing, true ); | ||
1138 | 1129 | | |||
1139 | // copy rect | 1130 | // copy rect | ||
1140 | QRectF frameRect( rect ); | 1131 | QRectF frameRect( rect ); | ||
1141 | frameRect.adjust( 1, 1, -1, -1 ); | 1132 | frameRect.adjust( 1, 1, -1, -1 ); | ||
1142 | 1133 | | |||
1143 | // shadow | 1134 | // shadow | ||
1144 | if( shadow.isValid() && !sunken ) | 1135 | if( !sunken ) | ||
1145 | { | 1136 | { | ||
1146 | 1137 | | |||
1147 | painter->setPen( QPen( shadow, 2 ) ); | 1138 | renderEllipseShadow( painter, frameRect, shadow ); | ||
1148 | painter->setBrush( Qt::NoBrush ); | | |||
1149 | painter->drawEllipse( shadowRect( frameRect ) ); | | |||
1150 | 1139 | | |||
1151 | } | 1140 | } | ||
1152 | 1141 | | |||
1153 | // set pen | 1142 | // set pen | ||
1154 | if( outline.isValid() ) | 1143 | if( outline.isValid() ) | ||
1155 | { | 1144 | { | ||
1156 | 1145 | | |||
1157 | painter->setPen( outline ); | 1146 | painter->setPen( outline ); | ||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Line(s) | 1355 | { | |||
1405 | default: break; | 1394 | default: break; | ||
1406 | } | 1395 | } | ||
1407 | 1396 | | |||
1408 | painter->restore(); | 1397 | painter->restore(); | ||
1409 | 1398 | | |||
1410 | } | 1399 | } | ||
1411 | 1400 | | |||
1412 | //______________________________________________________________________________ | 1401 | //______________________________________________________________________________ | ||
1402 | void Helper::renderRoundedRectShadow( QPainter* painter, const QRectF& rect, const QColor& color, qreal radius ) const | ||||
1403 | { | ||||
1404 | if( !color.isValid() ) return; | ||||
1405 | | ||||
1406 | painter->save(); | ||||
1407 | | ||||
1408 | /* Clipping prevents shadows from being visible inside checkboxes. | ||||
1409 | * Clipping away unneeded parts here also improves performance by 40-60% | ||||
1410 | * versus using just an outline of a rectangle. | ||||
1411 | * Tested by looking at the paint analyser in GammaRay. | ||||
1412 | */ | ||||
1413 | // Right side | ||||
1414 | QRegion clip( rect.right() - std::ceil( radius ), rect.top(), | ||||
1415 | std::ceil( radius ) + 1, rect.height() ); | ||||
1416 | // Bottom side | ||||
1417 | clip = clip.united( QRegion( rect.left(), rect.bottom() - std::ceil( radius ), | ||||
1418 | rect.width(), std::ceil( radius ) + 1 ) ); | ||||
1419 | | ||||
1420 | painter->setClipRegion( clip ); | ||||
1421 | painter->setPen( color ); | ||||
1422 | painter->setBrush( Qt::NoBrush ); | ||||
1423 | painter->drawRoundedRect( rect.translated( 0.5, 0.5 ), radius, radius ); | ||||
1424 | | ||||
1425 | painter->restore(); | ||||
1426 | } | ||||
1427 | | ||||
1428 | //______________________________________________________________________________ | ||||
1429 | void Helper::renderEllipseShadow( QPainter* painter, const QRectF& rect, const QColor& color ) const | ||||
1430 | { | ||||
1431 | if( !color.isValid() ) return; | ||||
1432 | | ||||
1433 | painter->save(); | ||||
1434 | | ||||
1435 | // Clipping does not improve performance here | ||||
1436 | | ||||
1437 | // 0.5 is subtracted because of the pen | ||||
1438 | qreal radius = rect.width() / 2 - 0.5; | ||||
1439 | | ||||
1440 | /* The right side is offset by +0.5 for the visible part of the shadow. | ||||
1441 | * The other sides are offset by +0.5 or -0.5 because of the pen. | ||||
1442 | */ | ||||
1443 | QRectF shadowRect = rect.adjusted( 0.5, 0.5, 0.5, -0.5 ); | ||||
1444 | | ||||
1445 | painter->translate( rect.center() ); | ||||
1446 | painter->rotate( 45 ); | ||||
1447 | painter->translate( -rect.center() ); | ||||
1448 | painter->setPen( color ); | ||||
1449 | painter->setBrush( Qt::NoBrush ); | ||||
1450 | painter->drawRoundedRect( shadowRect, radius, radius ); | ||||
1451 | | ||||
1452 | painter->restore(); | ||||
1453 | } | ||||
1454 | | ||||
1455 | //______________________________________________________________________________ | ||||
1413 | bool Helper::isX11() | 1456 | bool Helper::isX11() | ||
1414 | { | 1457 | { | ||
1415 | #if BREEZE_HAVE_X11 | 1458 | #if BREEZE_HAVE_X11 | ||
1416 | #if QT_VERSION >= 0x050000 | 1459 | #if QT_VERSION >= 0x050000 | ||
1417 | static const bool s_isX11 = KWindowSystem::isPlatformX11(); | 1460 | static const bool s_isX11 = KWindowSystem::isPlatformX11(); | ||
1418 | return s_isX11; | 1461 | return s_isX11; | ||
1419 | #else | 1462 | #else | ||
1420 | return true; | 1463 | return true; | ||
Show All 30 Lines | |||||
1451 | 1494 | | |||
1452 | QRectF Helper::strokedRect( const QRectF &rect, const int penWidth ) const | 1495 | QRectF Helper::strokedRect( const QRectF &rect, const int penWidth ) const | ||
1453 | { | 1496 | { | ||
1454 | qreal adjustment = 0.5 * penWidth; | 1497 | qreal adjustment = 0.5 * penWidth; | ||
1455 | return rect.adjusted( adjustment, adjustment, -adjustment, -adjustment ); | 1498 | return rect.adjusted( adjustment, adjustment, -adjustment, -adjustment ); | ||
1456 | } | 1499 | } | ||
1457 | 1500 | | |||
1458 | //______________________________________________________________________________ | 1501 | //______________________________________________________________________________ | ||
1459 | QRectF Helper::shadowRect( const QRectF& rect ) const | | |||
1460 | { return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( 0.5, 0.5 ); } | | |||
1461 | | ||||
1462 | //______________________________________________________________________________ | | |||
1463 | QPainterPath Helper::roundedPath( const QRectF& rect, Corners corners, qreal radius ) const | 1502 | QPainterPath Helper::roundedPath( const QRectF& rect, Corners corners, qreal radius ) const | ||
1464 | { | 1503 | { | ||
1465 | 1504 | | |||
1466 | QPainterPath path; | 1505 | QPainterPath path; | ||
1467 | 1506 | | |||
1468 | // simple cases | 1507 | // simple cases | ||
1469 | if( corners == 0 ) | 1508 | if( corners == 0 ) | ||
1470 | { | 1509 | { | ||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |