IbuGuSlider::IbuGuSlider(QWidget* parent) : RangedSlider(parent) { setRange(0,1); setPreferredRange(0,0); setPrecision(2); QLinearGradient bgGrad( QPointF(0,0), QPointF(1,0) ); bgGrad.setCoordinateMode(QGradient::ObjectBoundingMode); //bgGrad.setColorAt( 0, QColor(255,255,255) ); bgGrad.setColorAt( (.28+.36)/2.0, QColor(252,144,48) ); bgGrad.setColorAt( (.36+.44)/2.0, QColor(252,204,4) ); bgGrad.setColorAt( (.44+.53)/2.0, QColor(243,252,4) ); bgGrad.setColorAt( (.53+.64)/2.0, QColor(185,240,120) ); bgGrad.setColorAt( (.64+.85)/2.0, QColor(121,201,121) ); //bgGrad.setColorAt( .85, QColor(255,255,255) ); setBackgroundBrush(bgGrad); setMarkerBrush(QColor(0,0,0)); setTickMarks(0,0); }
void ModeTabBar::paintEvent(QPaintEvent *event) { QPainter p(this); IconManager *iconManager = IconManager::instance(); QLinearGradient bgGrad(rect().topLeft(), rect().topRight()); bgGrad.setColorAt(0.5, palette().color(QPalette::Window)); bgGrad.setColorAt(1.0, palette().color(QPalette::Midlight)); p.fillRect(rect(), bgGrad); p.setPen(palette().color(QPalette::Shadow)); p.drawLine(width() - 1, 0, width() - 1, height()); for(int i = 0; i < count(); ++i) { p.save(); QFont labelFont = font(); labelFont.setBold(true); p.setFont(labelFont); QRect rect = tabRect(i); int textHeight = p.fontMetrics().boundingRect(QRect(0, 0, width(), height()), 0, tabLabel(i)).height(); QRect labelRect(QPoint(rect.left() + tabPadding, rect.bottom() - textHeight - tabPadding), QSize(rect.width() - (tabPadding * 2), textHeight)); int iconSize = rect.height() - textHeight - (3 * tabPadding); QRect iconRect(QPoint((rect.width() - iconSize) / 2, rect.top() + tabPadding), QSize(iconSize, iconSize)); bool isSelected = (i == m_currentIndex); bool isEnabled = isTabEnabled(i); bool isHovered = (i == m_hoverIndex); if(isHovered && isEnabled) { p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 24)); } if(isSelected) { p.save(); p.setPen(palette().color(QPalette::Shadow)); p.drawLine(rect.topLeft(), rect.topRight()); p.drawLine(rect.bottomLeft(), rect.bottomRight()); p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 32)); p.translate(rect.width() - 6, rect.top() + (rect.height() / 2) - 12); QPolygon arrowPoly; arrowPoly.append(QPoint(7, 0)); arrowPoly.append(QPoint(7, 24)); arrowPoly.append(QPoint(0, 12)); p.translate(0, 1); p.setBrush(palette().color(QPalette::Shadow)); p.setPen(palette().color(QPalette::Shadow)); p.setRenderHint(QPainter::Antialiasing); p.drawPolygon(arrowPoly); p.translate(0, -1); p.setBrush(palette().color(QPalette::Light)); p.drawPolygon(arrowPoly); p.restore(); } if(!isEnabled) p.setOpacity(0.6); QIcon icon(iconManager->icon(tabIcon(i))); QPixmap pixmap = icon.pixmap(iconSize, iconSize, isEnabled ? QIcon::Normal : QIcon::Disabled); p.drawPixmap(iconRect, pixmap); p.setPen(palette().color(QPalette::Text)); p.drawText(labelRect, Qt::AlignCenter, tabLabel(i)); p.restore(); } }