176 int width = dial->rect.width();
177 int height = dial->rect.height();
178 qreal r = qMin(width, height) / 2;
181 qreal xc = width / 2 + 0.5;
182 qreal yc = height / 2 + 0.5;
183 const int ns = dial->tickInterval;
186 int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
189 if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
190 int maximum = dial->minimum + 1000;
191 notches = (maximum + ns - 1 - dial->minimum) / ns;
194 poly.resize(2 + 2 * notches);
195 int smallLineSize = bigLineSize / 2;
196 for (
int i = 0; i <= notches; ++i) {
197 qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
198 : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
199 qreal s = qSin(angle);
200 qreal c = qCos(angle);
201 if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
202 poly[2 * i] = QPointF(xc + (r - bigLineSize) * c,
203 yc - (r - bigLineSize) * s);
204 poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s);
206 poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c,
207 yc - (r - 1 - smallLineSize) * s);
208 poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s);
219 QPalette pal = option->palette;
220 const int width = option->rect.width();
221 const int height = option->rect.height();
222 const bool enabled = option->state & QStyle::State_Enabled;
223 qreal r = qMin(width, height) / 2;
225 const qreal penSize = r/20.0;
228 painter->setRenderHint(QPainter::Antialiasing);
231 if (option->subControls & QStyle::SC_DialTickmarks) {
232 painter->setPen(option->palette.dark().color().darker(120));
233 painter->drawLines(QStyleHelper::calcLines(option));
238 QColor buttonColor = pal.button().color().toHsv();
239 buttonColor.setHsv(buttonColor .hue(),
240 qMin(140, buttonColor .saturation()),
241 qMax(180, buttonColor.value()));
244 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1(
"qdial"))
245 p->setRenderHint(QPainter::Antialiasing);
247 const qreal d_ = r / 6;
248 const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1;
249 const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1;
251 QRectF br = QRectF(dx + 0.5, dy + 0.5,
252 int(r * 2 - 2 * d_ - 2),
253 int(r * 2 - 2 * d_ - 2));
257 qreal shadowSize = qMax(1.0, penSize/2.0);
258 QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
259 2*shadowSize, 2*shadowSize);
260 QRadialGradient shadowGradient(shadowRect.center().x(),
261 shadowRect.center().y(), shadowRect.width()/2.0,
262 shadowRect.center().x(), shadowRect.center().y());
263 shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40));
264 shadowGradient.setColorAt(qreal(1.0), Qt::transparent);
265 p->setBrush(shadowGradient);
266 p->setPen(Qt::NoPen);
267 p->translate(shadowSize, shadowSize);
268 p->drawEllipse(shadowRect);
269 p->translate(-shadowSize, -shadowSize);
272 QRadialGradient gradient(br.center().x() - br.width()/3, dy,
273 br.width()*1.3, br.center().x(),
274 br.center().y() - br.height()/2);
275 gradient.setColorAt(0, buttonColor.lighter(110));
276 gradient.setColorAt(qreal(0.5), buttonColor);
277 gradient.setColorAt(qreal(0.501), buttonColor.darker(102));
278 gradient.setColorAt(1, buttonColor.darker(115));
279 p->setBrush(gradient);
281 p->setBrush(Qt::NoBrush);
284 p->setPen(QPen(buttonColor.darker(280)));
286 p->setBrush(Qt::NoBrush);
287 p->setPen(buttonColor.lighter(110));
288 p->drawEllipse(br.adjusted(1, 1, -1, -1));
290 if (option->state & QStyle::State_HasFocus) {
291 QColor highlight = pal.highlight().color().toHsv();
292 highlight.setHsv(highlight.hue(),
293 qMin(160, highlight.saturation()),
294 qMax(230, highlight.value()));
295 highlight.setAlpha(127);
296 p->setPen(QPen(highlight, 2.0));
297 p->setBrush(Qt::NoBrush);
298 p->drawEllipse(br.adjusted(-1, -1, 1, 1));
301 END_STYLE_PIXMAPCACHE
303 QPointF dp = calcRadialPos(option, qreal(0.70));
304 buttonColor = buttonColor.lighter(104);
305 buttonColor.setAlphaF(0.8f);
306 const qreal ds = r/qreal(7.0);
307 QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds);
308 QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2,
309 dialRect.center().y() + dialRect.width(),
311 dialRect.center().x(), dialRect.center().y());
312 dialGradient.setColorAt(1, buttonColor.darker(140));
313 dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120));
314 dialGradient.setColorAt(0, buttonColor.darker(110));
316 painter->setPen(QPen(QColor(0, 0, 0, 25), penSize));
317 painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96)));
320 painter->setBrush(dialGradient);
321 painter->setPen(QColor(255, 255, 255, 150));
322 painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1));
323 painter->setPen(QColor(0, 0, 0, 80));
324 painter->drawEllipse(dialRect);
329 int left,
int top,
int right,
332 QSize size = pixmap.size();
337 painter->drawPixmap(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), pixmap,
338 QRect(left, 0, size.width() -right - left, top));
342 painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap,
343 QRect(0, 0, left, top));
347 painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap,
348 QRect(size.width() - right, 0, right, top));
353 painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap,
354 QRect(0, top, left, size.height() - bottom - top));
357 painter->drawPixmap(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
358 rect.height() - bottom - top), pixmap,
359 QRect(left, top, size.width() -right -left,
360 size.height() - bottom - top));
363 painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap,
364 QRect(size.width() - right, top, right, size.height() - bottom - top));
368 painter->drawPixmap(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
369 rect.width() - right - left, bottom), pixmap,
370 QRect(left, size.height() - bottom,
371 size.width() - right - left, bottom));
374 painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap,
375 QRect(0, size.height() - bottom, left, bottom));
379 painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap,
380 QRect(size.width() - right, size.height() - bottom, right, bottom));