QCachedPainter: add and use pixmapRect()
Add pixmapRect() to return the rect which can be used for drawing on the pixmap. It's the same as option->rect but translated to 0/0. Task-number: QTBUG-129680 Change-Id: I12af3a71983be54ac6366eba940f9936ada87f6a Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
parent
a4d4d04bbd
commit
75617efe23
@ -775,7 +775,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
|
|||||||
|
|
||||||
QCachedPainter p(painter, u"pushbutton-" + buttonColor.name(QColor::HexArgb), option);
|
QCachedPainter p(painter, u"pushbutton-" + buttonColor.name(QColor::HexArgb), option);
|
||||||
if (p.needsPainting()) {
|
if (p.needsPainting()) {
|
||||||
const QRect rect = QRect(0, 0, option->rect.width(), option->rect.height());
|
const QRect rect = p.pixmapRect();
|
||||||
const QRect r = rect.adjusted(0, 1, -1, 0);
|
const QRect r = rect.adjusted(0, 1, -1, 0);
|
||||||
const QColor &darkOutline = (hasFocus | isDefault) ? highlightedOutline : outline;
|
const QColor &darkOutline = (hasFocus | isDefault) ? highlightedOutline : outline;
|
||||||
|
|
||||||
@ -1120,8 +1120,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
|
|||||||
% QLatin1Char(isSectionDragTarget ? '1' : '0');
|
% QLatin1Char(isSectionDragTarget ? '1' : '0');
|
||||||
QCachedPainter cp(painter, pixmapName, option);
|
QCachedPainter cp(painter, pixmapName, option);
|
||||||
if (cp.needsPainting()) {
|
if (cp.needsPainting()) {
|
||||||
const QRect &rect = option->rect;
|
const QRect pixmapRect = cp.pixmapRect();
|
||||||
QRect pixmapRect(0, 0, rect.width(), rect.height());
|
|
||||||
QColor buttonColor = d->buttonColor(option->palette);
|
QColor buttonColor = d->buttonColor(option->palette);
|
||||||
QColor gradientStartColor = buttonColor.lighter(104);
|
QColor gradientStartColor = buttonColor.lighter(104);
|
||||||
QColor gradientStopColor = buttonColor.darker(102);
|
QColor gradientStopColor = buttonColor.darker(102);
|
||||||
@ -1821,7 +1820,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
||||||
QCachedPainter cp(painter, "spinbox"_L1, option);
|
QCachedPainter cp(painter, "spinbox"_L1, option);
|
||||||
if (cp.needsPainting()) {
|
if (cp.needsPainting()) {
|
||||||
const QRect pixmapRect(0, 0, spinBox->rect.width(), spinBox->rect.height());
|
const QRect pixmapRect = cp.pixmapRect();
|
||||||
const QRect r = pixmapRect.adjusted(0, 1, 0, -1);
|
const QRect r = pixmapRect.adjusted(0, 1, 0, -1);
|
||||||
const QColor buttonColor = d->buttonColor(option->palette);
|
const QColor buttonColor = d->buttonColor(option->palette);
|
||||||
const QColor &gradientStopColor = buttonColor;
|
const QColor &gradientStopColor = buttonColor;
|
||||||
@ -2509,7 +2508,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
% QLatin1StringView(!comboBox->frame ? "-frameless" : "");
|
% QLatin1StringView(!comboBox->frame ? "-frameless" : "");
|
||||||
QCachedPainter cp(painter, "spinbox"_L1, option);
|
QCachedPainter cp(painter, "spinbox"_L1, option);
|
||||||
if (cp.needsPainting()) {
|
if (cp.needsPainting()) {
|
||||||
QRect pixmapRect(0, 0, comboBox->rect.width(), comboBox->rect.height());
|
const QRect pixmapRect = cp.pixmapRect();
|
||||||
QStyleOptionComboBox comboBoxCopy = *comboBox;
|
QStyleOptionComboBox comboBoxCopy = *comboBox;
|
||||||
comboBoxCopy.rect = pixmapRect;
|
comboBoxCopy.rect = pixmapRect;
|
||||||
|
|
||||||
@ -2611,10 +2610,10 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
|
|
||||||
|
|
||||||
if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
|
if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
|
||||||
QRect pixmapRect(0, 0, groove.width(), groove.height());
|
|
||||||
// draw background groove
|
// draw background groove
|
||||||
QCachedPainter cp(painter, "slider_groove"_L1, option, groove.size(), groove);
|
QCachedPainter cp(painter, "slider_groove"_L1, option, groove.size(), groove);
|
||||||
if (cp.needsPainting()) {
|
if (cp.needsPainting()) {
|
||||||
|
const QRect pixmapRect = cp.pixmapRect();
|
||||||
const QColor buttonColor = d->buttonColor(option->palette);
|
const QColor buttonColor = d->buttonColor(option->palette);
|
||||||
const auto grooveColor =
|
const auto grooveColor =
|
||||||
QColor::fromHsv(buttonColor.hue(),
|
QColor::fromHsv(buttonColor.hue(),
|
||||||
@ -2657,6 +2656,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
|
|
||||||
QCachedPainter cpBlue(painter, "slider_groove_blue"_L1, option, groove.size(), groove);
|
QCachedPainter cpBlue(painter, "slider_groove_blue"_L1, option, groove.size(), groove);
|
||||||
if (cpBlue.needsPainting()) {
|
if (cpBlue.needsPainting()) {
|
||||||
|
const QRect pixmapRect = cp.pixmapRect();
|
||||||
QLinearGradient gradient;
|
QLinearGradient gradient;
|
||||||
if (horizontal) {
|
if (horizontal) {
|
||||||
gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
|
gradient.setStart(pixmapRect.center().x(), pixmapRect.top());
|
||||||
@ -2750,7 +2750,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
|
|||||||
if ((option->subControls & SC_SliderHandle) ) {
|
if ((option->subControls & SC_SliderHandle) ) {
|
||||||
QCachedPainter cp(painter, "slider_handle"_L1, option, handle.size(), handle);
|
QCachedPainter cp(painter, "slider_handle"_L1, option, handle.size(), handle);
|
||||||
if (cp.needsPainting()) {
|
if (cp.needsPainting()) {
|
||||||
QRect pixmapRect(0, 0, handle.width(), handle.height());
|
const QRect pixmapRect = cp.pixmapRect();
|
||||||
QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2);
|
QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2);
|
||||||
|
|
||||||
// gradient fill
|
// gradient fill
|
||||||
|
@ -55,6 +55,10 @@ public:
|
|||||||
{
|
{
|
||||||
return !m_alreadyCached;
|
return !m_alreadyCached;
|
||||||
}
|
}
|
||||||
|
QRect pixmapRect() const
|
||||||
|
{
|
||||||
|
return QRect(0, 0, m_pixmap.width(), m_pixmap.height());
|
||||||
|
}
|
||||||
QPainter *operator->()
|
QPainter *operator->()
|
||||||
{
|
{
|
||||||
return painter();
|
return painter();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user