void RRGViz::drawPathOnMap(QPixmap& map) { Path * p = m_PPInfo.mp_found_path; QPainter painter(&map); QPen paintpen(QColor(255,140,0)); paintpen.setWidth(2); painter.setPen(paintpen); int point_num = p->m_way_points.size(); if(point_num > 0) { for(int i=0;i<point_num-1;i++) { painter.drawLine( QPoint(p->m_way_points[i][0], p->m_way_points[i][1]), QPoint(p->m_way_points[i+1][0], p->m_way_points[i+1][1]) ); } } painter.end(); QPainter startPainter(&map); QPen paintpen1(QColor(255,0,0)); paintpen.setWidth(10); startPainter.setPen(paintpen1); startPainter.drawPoint( QPoint(p->m_way_points[0][0], p->m_way_points[0][1]) ); startPainter.end(); int lastIdx = p->m_way_points.size() - 1; QPainter endPainter(&map); QPen paintpen2(QColor(0,0,255)); paintpen.setWidth(10); endPainter.setPen(paintpen2); endPainter.drawPoint( QPoint(p->m_way_points[lastIdx][0], p->m_way_points[lastIdx][1]) ); endPainter.end(); }
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return d->style->drawPrimitive(element, option, painter, widget); bool animating = (option->state & State_Animating); int state = option->state; QRect rect = option->rect; QRect oldRect; QRect newRect; if (widget && (element == PE_PanelButtonTool) && !animating) { QWidget *w = const_cast<QWidget *> (widget); int oldState = w->property("_q_stylestate").toInt(); oldRect = w->property("_q_stylerect").toRect(); newRect = w->rect(); w->setProperty("_q_stylestate", (int)option->state); w->setProperty("_q_stylerect", w->rect()); // Determine the animated transition bool doTransition = ((state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver)); if (oldRect != newRect) { doTransition = false; d->animator.stopAnimation(widget); } if (doTransition) { QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); Animation *anim = d->animator.widgetAnimation(widget); QStyleOption opt = *option; opt.state = (QStyle::State)oldState; opt.state |= (State)State_Animating; startImage.fill(0); Transition *t = new Transition; t->setWidget(w); QPainter startPainter(&startImage); if (!anim) { drawPrimitive(element, &opt, &startPainter, widget); } else { anim->paint(&startPainter, &opt); d->animator.stopAnimation(widget); } QStyleOption endOpt = *option; endOpt.state |= (State)State_Animating; t->setStartImage(startImage); d->animator.startAnimation(t); endImage.fill(0); QPainter endPainter(&endImage); drawPrimitive(element, &endOpt, &endPainter, widget); t->setEndImage(endImage); t->setDuration(130); t->setStartTime(QTime::currentTime()); } } switch (element) { case PE_PanelLineEdit: { painter->save(); if (option->state & State_Enabled) drawCornerImage(d->lineeditImage, painter, option->rect, 2, 2, 2, 2); else drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 2, 2, 2, 2); if (option->state & State_HasFocus || option->state & State_MouseOver) { QColor hover = StyleHelper::baseColor(); if (state & State_HasFocus) hover.setAlpha(100); else hover.setAlpha(50); painter->setPen(QPen(hover, 1)); painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2)); } painter->restore(); } break; case PE_FrameStatusBarItem: break; case PE_PanelButtonTool: { Animation *anim = d->animator.widgetAnimation(widget); if (!animating && anim) { anim->paint(painter, option); } else { bool pressed = option->state & State_Sunken || option->state & State_On; QColor shadow(0, 0, 0, 30); painter->setPen(shadow); if (pressed) { QColor shade(0, 0, 0, 40); painter->fillRect(rect, shade); painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); // painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); QColor highlight(255, 255, 255, 30); painter->setPen(highlight); } else if (option->state & State_Enabled && option->state & State_MouseOver) { QColor lighter(255, 255, 255, 37); painter->fillRect(rect, lighter); } } } break; case PE_PanelStatusBar: { painter->save(); QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom())); QColor startColor = StyleHelper::shadowColor().darker(164); QColor endColor = StyleHelper::baseColor().darker(130); grad.setColorAt(0, endColor); grad.setColorAt(1, endColor); painter->fillRect(option->rect, grad); painter->setPen(QColor(255, 255, 255, 60)); painter->drawLine(rect.topLeft() + QPoint(0,1), rect.topRight()+ QPoint(0,1)); painter->setPen(StyleHelper::borderColor().darker(110)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->restore(); } break; case PE_IndicatorToolBarSeparator: { QColor separatorColor = StyleHelper::borderColor(); separatorColor.setAlpha(100); painter->setPen(separatorColor); const int margin = 3; if (option->state & State_Horizontal) { const int offset = rect.width()/2; painter->drawLine(rect.bottomLeft().x() + offset, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset, rect.topLeft().y() + margin); } else { //Draw vertical separator const int offset = rect.height()/2; painter->setPen(QPen(option->palette.background().color().darker(110))); painter->drawLine(rect.topLeft().x() + margin , rect.topLeft().y() + offset, rect.topRight().x() - margin, rect.topRight().y() + offset); } } break; case PE_IndicatorToolBarHandle: { bool horizontal = option->state & State_Horizontal; painter->save(); QPainterPath path; int x = option->rect.x() + horizontal ? 2 : 6; int y = option->rect.y() + horizontal ? 6 : 2; static const int RectHeight = 2; if (horizontal) { while (y < option->rect.height() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); y += 6; } } else { while (x < option->rect.width() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); x += 6; } } painter->setPen(Qt::NoPen); QColor dark = StyleHelper::borderColor(); dark.setAlphaF(0.4); QColor light = StyleHelper::baseColor(); light.setAlphaF(0.4); painter->fillPath(path, light); painter->save(); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); painter->translate(3, 3); painter->fillPath(path, light); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); } break; case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { // From windowsstyle but modified to enable AA if (option->rect.width() <= 1 || option->rect.height() <= 1) break; QRect r = option->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; QString pixmapName; pixmapName.sprintf("%s-%s-%d-%d-%d-%lld", "$qt_ia", metaObject()->className(), uint(option->state), element, size, option->palette.cacheKey()); if (!QPixmapCache::find(pixmapName, pixmap)) { int border = size/5; int sqsize = 2*(size/2); QImage image(sqsize, sqsize, QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter imagePainter(&image); imagePainter.setRenderHint(QPainter::Antialiasing, true); imagePainter.translate(0.5, 0.5); QPolygon a; switch (element) { case PE_IndicatorArrowUp: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); break; case PE_IndicatorArrowDown: a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); break; case PE_IndicatorArrowRight: a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; case PE_IndicatorArrowLeft: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; default: break; } int bsx = 0; int bsy = 0; if (option->state & State_Sunken) { bsx = pixelMetric(PM_ButtonShiftHorizontal); bsy = pixelMetric(PM_ButtonShiftVertical); } QRect bounds = a.boundingRect(); int sx = sqsize / 2 - bounds.center().x() - 1; int sy = sqsize / 2 - bounds.center().y() - 1; imagePainter.translate(sx + bsx, sy + bsy); if (!(option->state & State_Enabled)) { QColor foreGround(150, 150, 150, 150); imagePainter.setBrush(option->palette.mid().color()); imagePainter.setPen(option->palette.mid().color()); } else { QColor shadow(0, 0, 0, 100); imagePainter.translate(0, 1); imagePainter.setPen(shadow); imagePainter.setBrush(shadow); QColor foreGround(255, 255, 255, 210); imagePainter.drawPolygon(a); imagePainter.translate(0, -1); imagePainter.setPen(foreGround); imagePainter.setBrush(foreGround); } imagePainter.drawPolygon(a); imagePainter.end(); pixmap = QPixmap::fromImage(image); QPixmapCache::insert(pixmapName, pixmap); } int xOffset = r.x() + (r.width() - size)/2; int yOffset = r.y() + (r.height() - size)/2; painter->drawPixmap(xOffset, yOffset, pixmap); } break; default: d->style->drawPrimitive(element, option, painter, widget); break; } }
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawPrimitive(element, option, painter, widget); bool animating = (option->state & State_Animating); int state = option->state; QRect rect = option->rect; QRect oldRect; QRect newRect; if (widget && (element == PE_PanelButtonTool) && !animating) { QWidget *w = const_cast<QWidget *> (widget); int oldState = w->property("_q_stylestate").toInt(); oldRect = w->property("_q_stylerect").toRect(); newRect = w->rect(); w->setProperty("_q_stylestate", (int)option->state); w->setProperty("_q_stylerect", w->rect()); // Determine the animated transition bool doTransition = ((state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver)); if (oldRect != newRect) { doTransition = false; d->animator.stopAnimation(widget); } if (doTransition) { QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); Animation *anim = d->animator.widgetAnimation(widget); QStyleOption opt = *option; opt.state = (QStyle::State)oldState; opt.state |= (State)State_Animating; startImage.fill(0); Transition *t = new Transition; t->setWidget(w); QPainter startPainter(&startImage); if (!anim) { drawPrimitive(element, &opt, &startPainter, widget); } else { anim->paint(&startPainter, &opt); d->animator.stopAnimation(widget); } QStyleOption endOpt = *option; endOpt.state |= (State)State_Animating; t->setStartImage(startImage); d->animator.startAnimation(t); endImage.fill(0); QPainter endPainter(&endImage); drawPrimitive(element, &endOpt, &endPainter, widget); t->setEndImage(endImage); if (oldState & State_MouseOver) t->setDuration(150); else t->setDuration(75); t->setStartTime(QTime::currentTime()); } } switch (element) { case PE_IndicatorDockWidgetResizeHandle: painter->fillRect(option->rect, Utils::StyleHelper::borderColor()); break; case PE_FrameDockWidget: QCommonStyle::drawPrimitive(element, option, painter, widget); break; case PE_PanelLineEdit: { painter->save(); // Fill the line edit background QRect filledRect = option->rect.adjusted(1, 1, -1, -1); painter->setBrushOrigin(filledRect.topLeft()); painter->fillRect(filledRect, option->palette.base()); if (option->state & State_Enabled) Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5); else Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5); if (option->state & State_HasFocus || option->state & State_MouseOver) { QColor hover = Utils::StyleHelper::baseColor(); if (state & State_HasFocus) hover.setAlpha(100); else hover.setAlpha(50); painter->setPen(QPen(hover, 1)); painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2)); } painter->restore(); } break; case PE_FrameStatusBarItem: break; case PE_PanelButtonTool: { Animation *anim = d->animator.widgetAnimation(widget); if (!animating && anim) { anim->paint(painter, option); } else { bool pressed = option->state & State_Sunken || option->state & State_On; QColor shadow(0, 0, 0, 30); painter->setPen(shadow); if (pressed) { QColor shade(0, 0, 0, 40); painter->fillRect(rect, shade); painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); // painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); QColor highlight(255, 255, 255, 30); painter->setPen(highlight); } else if (option->state & State_Enabled && option->state & State_MouseOver) { QColor lighter(255, 255, 255, 37); painter->fillRect(rect, lighter); } if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) { QColor highlight = option->palette.highlight().color(); highlight.setAlphaF(0.4); painter->setPen(QPen(highlight.lighter(), 1)); highlight.setAlphaF(0.3); painter->setBrush(highlight); painter->setRenderHint(QPainter::Antialiasing); QRectF rect = option->rect; rect.translate(0.5, 0.5); painter->drawRoundedRect(rect.adjusted(2, 2, -3, -3), 2, 2); } } } break; case PE_PanelStatusBar: { painter->save(); QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom())); QColor startColor = Utils::StyleHelper::shadowColor().darker(164); QColor endColor = Utils::StyleHelper::baseColor().darker(130); grad.setColorAt(0, startColor); grad.setColorAt(1, endColor); painter->fillRect(option->rect, grad); painter->setPen(QColor(255, 255, 255, 60)); painter->drawLine(rect.topLeft() + QPoint(0,1), rect.topRight()+ QPoint(0,1)); painter->setPen(Utils::StyleHelper::borderColor().darker(110)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->restore(); } break; case PE_IndicatorToolBarSeparator: { QColor separatorColor = Utils::StyleHelper::borderColor(); separatorColor.setAlpha(100); painter->setPen(separatorColor); const int margin = 6; if (option->state & State_Horizontal) { const int offset = rect.width()/2; painter->drawLine(rect.bottomLeft().x() + offset, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset, rect.topLeft().y() + margin); } else { //Draw vertical separator const int offset = rect.height()/2; painter->setPen(QPen(option->palette.background().color().darker(110))); painter->drawLine(rect.topLeft().x() + margin , rect.topLeft().y() + offset, rect.topRight().x() - margin, rect.topRight().y() + offset); } } break; case PE_IndicatorToolBarHandle: { bool horizontal = option->state & State_Horizontal; painter->save(); QPainterPath path; int x = option->rect.x() + (horizontal ? 2 : 6); int y = option->rect.y() + (horizontal ? 6 : 2); static const int RectHeight = 2; if (horizontal) { while (y < option->rect.height() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); y += 6; } } else { while (x < option->rect.width() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); x += 6; } } painter->setPen(Qt::NoPen); QColor dark = Utils::StyleHelper::borderColor(); dark.setAlphaF(0.4); QColor light = Utils::StyleHelper::baseColor(); light.setAlphaF(0.4); painter->fillPath(path, light); painter->save(); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); painter->translate(3, 3); painter->fillPath(path, light); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); } break; case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { Utils::StyleHelper::drawArrow(element, painter, option); } break; default: QProxyStyle::drawPrimitive(element, option, painter, widget); break; } }