void TabBarWidget::mouseMoveEvent(QMouseEvent *event) { QTabBar::mouseMoveEvent(event); if (event->buttons() == Qt::NoButton) { tabHovered(tabAt(event->pos())); } }
void YaTabBarBase::drawTab(QPainter* painter, int index, const QRect& tabRect) { QStyleOptionTabV2 tab = getStyleOption(index); if (!(tab.state & QStyle::State_Enabled)) { tab.palette.setCurrentColorGroup(QPalette::Disabled); } // Don't bother drawing a tab if the entire tab is outside of the visible tab bar. if (tabRect.right() < 0 || tabRect.left() > width() || tabRect.bottom() < 0 || tabRect.top() > height() || tabRect.width() < 3) { return; } bool isCurrent = index == currentIndex(); bool isHovered = tabHovered(index); bool isHighlighted = tabData(index).toBool(); QColor backgroundColor = this->tabBackgroundColor(); if (isCurrent) { #ifndef WIDGET_PLUGIN backgroundColor = Ya::VisualUtil::editAreaColor(); #else backgroundColor = Qt::white; #endif } else if (isHovered) { #ifndef WIDGET_PLUGIN backgroundColor = Ya::VisualUtil::tabHighlightColor(); #else backgroundColor = Qt::gray; #endif } else if (isHighlighted) { backgroundColor = highlightColor(); } if (backgroundColor.isValid()) { painter->fillRect(tabRect, backgroundColor); } painter->save(); #ifndef WIDGET_PLUGIN painter->setPen(Ya::VisualUtil::rosterTabBorderColor()); #endif bool drawLeftLine = tabRect.left() != rect().left(); bool drawRightLine = true; // tabRect.right() != rect().right() || rect().width() < maximumWidth(); switch (shape()) { case YaTabBarBase::RoundedSouth: case YaTabBarBase::TriangularSouth: if (isMultiLine()) drawRightLine = tabRect.right() + 1 < maximumWidth(); if (!isCurrent || isMultiLine()) painter->drawLine(tabRect.topLeft(), tabRect.topRight()); if (isCurrent) { if (drawLeftLine && !isMultiLine()) painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft()); if (drawRightLine) painter->drawLine(tabRect.topRight(), tabRect.bottomRight()); } else { if (isHovered || isMultiLine()) { if (currentIndex() != (index - 1) && !isMultiLine()) if (drawLeftLine) painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft()); if (currentIndex() != (index + 1) || isMultiLine()) if (drawRightLine) painter->drawLine(tabRect.topRight(), tabRect.bottomRight()); } } break; default: Q_ASSERT(false); break; } painter->restore(); tabIcon(index).paint(painter, tabIconRect(index)); QRect textRect = tabTextRect(index); QString text = tabText(index); if (drawTabNumbers_ && index < 10) { int numberToDraw = index + 1; if (numberToDraw > 9) { numberToDraw = 0; } painter->save(); painter->setPen(Qt::gray); QString numberToDrawText = QString::number(numberToDraw) + " "; painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, numberToDrawText); textRect.adjust(fontMetrics().width(numberToDrawText), 0, 0, 0); painter->restore(); } painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, text); #ifndef WIDGET_PLUGIN if (textWidth(text) > textRect.width() && backgroundColor.isValid()) { Ya::VisualUtil::drawTextFadeOut(painter, textRect.adjusted(1, 0, 1, 0), backgroundColor, 15); } #endif if (isMultiLine()) { QPixmap shadow(tabShadow(isCurrent)); QRect r(tabRect); r.setHeight(shadow.height()); painter->drawTiledPixmap(r, shadow); } }