77QRect
QStyle::itemTextRect(
const QFontMetrics &metrics,
const QRect &rect,
int alignment,
bool enabled,
78 const QString &text)
const
82 rect.getRect(&x, &y, &w, &h);
83 if (!text.isEmpty()) {
84 result = metrics.boundingRect(x, y, w, h, alignment, text);
85 if (!enabled &&
proxy()->styleHint(SH_EtchDisabledText)) {
86 result.setWidth(result.width()+1);
87 result.setHeight(result.height()+1);
90 result = QRect(x, y, w, h);
105 rect.getRect(&x, &y, &w, &h);
107 const int pixmapWidth = pixmap.width()/pixmap.devicePixelRatio();
108 const int pixmapHeight = pixmap.height()/pixmap.devicePixelRatio();
110 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
111 y += h/2 - pixmapHeight/2;
112 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
113 y += h - pixmapHeight;
114 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
115 x += w - pixmapWidth;
116 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
117 x += w/2 - pixmapWidth/2;
118 else if ((alignment & Qt::AlignLeft) != Qt::AlignLeft && QGuiApplication::isRightToLeft())
119 x += w - pixmapWidth;
120 result = QRect(x, y, pixmapWidth, pixmapHeight);
141 bool enabled,
const QString& text, QPalette::ColorRole textRole)
const
146 if (textRole != QPalette::NoRole) {
147 savedPen = painter->pen();
148 painter->setPen(QPen(pal.brush(textRole), savedPen.widthF()));
151 if (
proxy()->styleHint(SH_DitherDisabledText)) {
153 painter->drawText(rect, alignment, text, &br);
154 painter->fillRect(br, QBrush(painter->background().color(), Qt::Dense5Pattern));
156 }
else if (
proxy()->styleHint(SH_EtchDisabledText)) {
157 QPen pen = painter->pen();
158 painter->setPen(pal.light().color());
159 painter->drawText(rect.adjusted(1, 1, 1, 1), alignment, text);
160 painter->setPen(pen);
163 painter->drawText(rect, alignment, text);
164 if (textRole != QPalette::NoRole)
165 painter->setPen(savedPen);
178 const QPixmap &pixmap)
const
180 qreal scale = pixmap.devicePixelRatio();
181 QRect aligned = alignedRect(QGuiApplication::layoutDirection(), QFlag(alignment), pixmap.size() / scale, rect);
182 QRect inter = aligned.intersected(rect);
184 painter->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width() * scale, inter.height() *scale);
200QRect
QStyle::visualRect(Qt::LayoutDirection direction,
const QRect &boundingRect,
const QRect &logicalRect)
202 if (direction == Qt::LeftToRight)
204 QRect rect = logicalRect;
205 rect.translate(2 * (boundingRect.right() - logicalRect.right()) +
206 logicalRect.width() - boundingRect.width(), 0);
231QRect
QStyle::alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment,
const QSize &size,
const QRect &rectangle)
233 alignment = visualAlignment(direction, alignment);
234 int x = rectangle.x();
235 int y = rectangle.y();
236 int w = size.width();
237 int h = size.height();
238 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
239 y += rectangle.size().height()/2 - h/2;
240 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
241 y += rectangle.size().height() - h;
242 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
243 x += rectangle.size().width() - w;
244 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
245 x += rectangle.size().width()/2 - w/2;
246 return QRect(x, y, w, h);
286 if (span <= 0 || logicalValue < min || max <= min)
288 if (logicalValue > max)
289 return upsideDown ? span : min;
291 uint range = max - min;
292 uint p = upsideDown ? max - logicalValue : logicalValue - min;
294 if (range > (uint)INT_MAX/4096) {
295 double dpos = (
double(p))/(
double(range)/span);
297 }
else if (range > (uint)span) {
298 return (2 * p * span + range) / (2*range);
300 uint div = span / range;
301 uint mod = span % range;
302 return p * div + (2 * p * mod + range) / (2 * range);
365 QColor background = QColor(0xd4, 0xd0, 0xc8);
367 QColor light(background.lighter());
368 QColor dark(background.darker());
369 QColor mid(Qt::gray);
370 QPalette palette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
371 palette.setBrush(QPalette::Disabled, QPalette::WindowText, dark);
372 palette.setBrush(QPalette::Disabled, QPalette::Text, dark);
373 palette.setBrush(QPalette::Disabled, QPalette::ButtonText, dark);
374 palette.setBrush(QPalette::Disabled, QPalette::Base, background);
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const