9#include <QtGui/qpainter.h>
10#include <QtGui/qbitmap.h>
11#include <QtGui/qpixmapcache.h>
12#include <QtGui/qpa/qplatformtheme.h>
14#include <QtGui/private/qguiapplication_p.h>
17# include <QtCore/qdebug.h>
28
29
38
39
40
41
50
51
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74QRect
QStyle::itemTextRect(
const QFontMetrics &metrics,
const QRect &rect,
int alignment,
bool enabled,
75 const QString &text)
const
79 rect.getRect(&x, &y, &w, &h);
80 if (!text.isEmpty()) {
81 result = metrics.boundingRect(x, y, w, h, alignment, text);
82 if (!enabled && proxy()->styleHint(SH_EtchDisabledText)) {
83 result.setWidth(result.width()+1);
84 result.setHeight(result.height()+1);
87 result = QRect(x, y, w, h);
93
94
95
96
97
102 rect.getRect(&x, &y, &w, &h);
104 const int pixmapWidth = pixmap.width()/pixmap.devicePixelRatio();
105 const int pixmapHeight = pixmap.height()/pixmap.devicePixelRatio();
107 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
108 y += h/2 - pixmapHeight/2;
109 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
110 y += h - pixmapHeight;
111 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
112 x += w - pixmapWidth;
113 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
114 x += w/2 - pixmapWidth/2;
115 else if ((alignment & Qt::AlignLeft) != Qt::AlignLeft && QGuiApplication::isRightToLeft())
116 x += w - pixmapWidth;
117 result = QRect(x, y, pixmapWidth, pixmapHeight);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
138 bool enabled,
const QString& text, QPalette::ColorRole textRole)
const
143 if (textRole != QPalette::NoRole) {
144 savedPen = painter->pen();
145 painter->setPen(QPen(pal.brush(textRole), savedPen.widthF()));
148 if (proxy()->styleHint(SH_DitherDisabledText)) {
150 painter->drawText(rect, alignment, text, &br);
151 painter->fillRect(br, QBrush(painter->background().color(), Qt::Dense5Pattern));
153 }
else if (proxy()->styleHint(SH_EtchDisabledText)) {
154 QPen pen = painter->pen();
155 painter->setPen(pal.light().color());
156 painter->drawText(rect.adjusted(1, 1, 1, 1), alignment, text);
157 painter->setPen(pen);
160 painter->drawText(rect, alignment, text);
161 if (textRole != QPalette::NoRole)
162 painter->setPen(savedPen);
166
167
168
169
170
171
172
173
176 const QPixmap &pixmap)
const
178 qreal scale = pixmap.devicePixelRatio();
179 QRect aligned = alignedRect(QGuiApplication::layoutDirection(), QFlag(alignment), pixmap.size() / scale, rect);
180 QRect inter = aligned.intersected(rect);
182 painter->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width() * scale, inter.height() *scale);
186
187
188
189
190
191
192
193
194
195
196
197
198QRect
QStyle::visualRect(Qt::LayoutDirection direction,
const QRect &boundingRect,
const QRect &logicalRect)
200 if (direction == Qt::LeftToRight)
202 QRect rect = logicalRect;
203 rect.translate(2 * (boundingRect.right() - logicalRect.right()) +
204 logicalRect.width() - boundingRect.width(), 0);
209
210
211
212
213
214
215
216
217QPoint
QStyle::visualPos(Qt::LayoutDirection direction,
const QRect &boundingRect,
const QPoint &logicalPos)
219 if (direction == Qt::LeftToRight)
221 return QPoint(boundingRect.right() - logicalPos.x(), logicalPos.y());
225
226
227
228QRect
QStyle::alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment,
const QSize &size,
const QRect &rectangle)
230 alignment = visualAlignment(direction, alignment);
231 int x = rectangle.x();
232 int y = rectangle.y();
233 int w = size.width();
234 int h = size.height();
235 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
236 y += rectangle.size().height()/2 - h/2;
237 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
238 y += rectangle.size().height() - h;
239 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
240 x += rectangle.size().width() - w;
241 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
242 x += rectangle.size().width()/2 - w/2;
243 return QRect(x, y, w, h);
247
248
249
250
251
252
253
254
255
256
257Qt::Alignment
QStyle::visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
259 return QGuiApplicationPrivate::visualAlignment(direction, alignment);
263
264
265
266
267
268
269
270
271
272
273
274
275
279 if (span <= 0 || logicalValue < min || max <= min)
281 if (logicalValue > max)
282 return upsideDown ? span : min;
284 uint range = max - min;
285 uint p = upsideDown ? max - logicalValue : logicalValue - min;
287 if (range > (uint)INT_MAX/4096) {
288 double dpos = (
double(p))/(
double(range)/span);
290 }
else if (range > (uint)span) {
291 return (2 * p * span + range) / (2*range);
293 uint div = span / range;
294 uint mod = span % range;
295 return p * div + (2 * p * mod + range) / (2 * range);
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
322 if (span <= 0 || pos <= 0)
323 return upsideDown ? max : min;
325 return upsideDown ? min : max;
327 uint range = max - min;
329 if ((uint)span > range) {
330 int tmp = (2 * pos * range + span) / (2 * span);
331 return upsideDown ? max - tmp : tmp + min;
333 uint div = range / span;
334 uint mod = range % span;
335 int tmp = pos * div + (2 * pos * mod + span) / (2 * span);
336 return upsideDown ? max - tmp : tmp + min;
344
345
346
347
348
349
350
351
352
353
356 QColor background = QColor(0xd4, 0xd0, 0xc8);
358 QColor light(background.lighter());
359 QColor dark(background.darker());
360 QColor mid(Qt::gray);
361 QPalette palette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
362 palette.setBrush(QPalette::Disabled, QPalette::WindowText, dark);
363 palette.setBrush(QPalette::Disabled, QPalette::Text, dark);
364 palette.setBrush(QPalette::Disabled, QPalette::ButtonText, dark);
365 palette.setBrush(QPalette::Disabled, QPalette::Base, background);
372 auto theme = QGuiApplicationPrivate::platformTheme();
373 return theme && theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();
380#include "moc_qquickstyle.cpp"
virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Returns the area within the given rectangle in which to draw the specified pixmap according to the de...
virtual QPalette standardPalette() const
Returns the style's standard palette.
virtual ~QStyle()
Destroys the style object.
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment,...
QStyle()
Constructs a style object.
static int sliderPositionFromValue(int min, int max, int val, int space, bool upsideDown=false)
Converts the given logicalValue to a pixel position.
static int sliderValueFromPosition(int min, int max, int pos, int space, bool upsideDown=false)
Converts the given pixel position to a logical value.
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.