QPixmap StylePainterMobile::findLineEdit(const QSize & size, bool focused) const { QPixmap result; KeyIdentifier id; id.type = KeyIdentifier::LineEdit; id.width = size.width(); id.height = size.height(); id.trait1 = focused; if (!findCachedControl(id, &result)) { const int focusFrame = painterScale(painter); result = QPixmap(size); result.fill(Qt::transparent); const QRect rect = result.rect().adjusted(focusFrame, focusFrame, -focusFrame, -focusFrame); QPainter cachePainter(&result); drawControlBackground(&cachePainter, borderPen(painter), rect, Qt::white); if (focused) { QPen focusPen(highlightColor, 1.2 * painterScale(painter), Qt::SolidLine); drawControlBackground(&cachePainter, focusPen, rect, Qt::NoBrush); } insertIntoCache(id, result); } return result; }
QPixmap StylePainterMobile::findComboButton(const QSize& size, bool multiple, bool enabled) const { if (size.isNull()) return QPixmap(); QPixmap result; KeyIdentifier id; id.type = KeyIdentifier::ComboButton; id.width = size.width(); id.height = size.height(); id.trait1 = multiple; id.trait2 = enabled; if (!findCachedControl(id, &result)) { result = QPixmap(size); const qreal border = painterScale(painter); const QSizeF padding(2 * border, 2 * border); const QSizeF innerSize = size - padding; ASSERT(innerSize.isValid()); result.fill(Qt::transparent); QPainter cachePainter(&result); cachePainter.translate(border, border); if (multiple) drawMultipleComboButton(&cachePainter, innerSize, enabled ? darkColor : Qt::lightGray); else drawSimpleComboButton(&cachePainter, innerSize, enabled ? darkColor : Qt::lightGray); insertIntoCache(id, result); } return result; }
QSize StylePainterMobile::sizeForPainterScale(const QRect& rect) const { qreal scale = painterScale(painter); QTransform scaleTransform = QTransform::fromScale(scale, scale); return scaleTransform.mapRect(rect).size(); }
QPixmap StylePainterMobile::findPushButton(const QSize& size, bool sunken, bool enabled) const { QPixmap result; KeyIdentifier id; id.type = KeyIdentifier::PushButton; id.width = size.width(); id.height = size.height(); id.trait1 = sunken; id.trait2 = enabled; if (!findCachedControl(id, &result)) { const qreal dropShadowSize = painterScale(painter); result = QPixmap(size); result.fill(Qt::transparent); const QRect rect = QRect(0, 0, size.width(), size.height() - dropShadowSize); QPainter cachePainter(&result); drawControlBackground(&cachePainter, Qt::NoPen, rect.adjusted(0, dropShadowSize, 0, dropShadowSize), shadowColor); QBrush brush; if (enabled && !sunken) { QLinearGradient linearGradient; linearGradient.setStart(rect.bottomLeft()); linearGradient.setFinalStop(rect.topLeft()); linearGradient.setColorAt(0.0, buttonGradientBottom); linearGradient.setColorAt(1.0, Qt::white); brush = linearGradient; } else if (!enabled) brush = QColor(241, 242, 243); else { // sunken QLinearGradient linearGradient; linearGradient.setStart(rect.bottomLeft()); linearGradient.setFinalStop(rect.topLeft()); linearGradient.setColorAt(0.0, highlightColor); linearGradient.setColorAt(1.0, highlightColor.lighter()); brush = linearGradient; } drawControlBackground(&cachePainter, borderPen(painter), rect, brush); insertIntoCache(id, result); } return result; }
static inline QPen borderPen(QPainter* painter = 0) { return QPen(darkColor, 0.4 * painterScale(painter), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); }
static inline QPen borderPen(QPainter* painter = 0) { return QPen(darkColor, qMin(1.0, 0.4 * painterScale(painter))); }