bool YaTabBarBase::tabTextFits(int index) const { // return tabSizeHint(index).width() >= YaTabBarBase::preferredTabSize(index).width(); return textWidth(tabText(index)) <= tabTextRect(index).width(); }
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const { if (!validIndex(tabIndex)) { qWarning("invalid index"); return; } painter->save(); QRect rect = tabRect(tabIndex); bool selected = (tabIndex == m_currentIndex); bool enabled = isTabEnabled(tabIndex); if (selected) { //jassuncao:if (creatorTheme()->widgetStyle() == Theme::StyleFlat) { if(true) { // background color of a fancy tab that is active painter->fillRect(rect.adjusted(0, 0, 0, -1), QColor(0x90,0x90,0x90,0xFF)); } else { //background painter->save(); QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, QColor(255, 255, 255, 140)); grad.setColorAt(1, QColor(255, 255, 255, 210)); painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); painter->restore(); //shadows painter->setPen(QColor(0, 0, 0, 110)); painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(QColor(0, 0, 0, 40)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); //highlights painter->setPen(QColor(255, 255, 255, 50)); painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); painter->setPen(QColor(255, 255, 255, 40)); painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); } } QString tabText(this->tabText(tabIndex)); QRect tabTextRect(rect); const bool drawIcon = rect.height() > 36; QRect tabIconRect(tabTextRect); tabTextRect.translate(0, drawIcon ? -2 : 1); QFont boldFont(painter->font()); //jassuncao boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); boldFont.setPointSizeF(8); boldFont.setBold(true); painter->setFont(boldFont); painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap; #if defined(Q_OS_MAC) bool isMacHost = true; #else bool isMacHost = false; #endif if (!isMacHost && !selected && enabled) { painter->save(); int fader = int(m_tabs[tabIndex]->fader()); //jassuncaoif (creatorTheme()->widgetStyle() == Theme::StyleFlat) { if(true) { //QColor c = creatorTheme()->color(Theme::BackgroundColorHover); QColor c(0x51,0x51,0x51,0xFF); c.setAlpha(int(255 * fader/40.0)); // FIXME: hardcoded end value 40 painter->fillRect(rect, c); } else { QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, Qt::transparent); grad.setColorAt(0.5, QColor(255, 255, 255, fader)); grad.setColorAt(1, Qt::transparent); painter->fillRect(rect, grad); painter->setPen(QPen(grad, 1.0)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); } painter->restore(); } if (!enabled) painter->setOpacity(0.7); if (drawIcon) { int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); tabIconRect.adjust(0, 4, 0, -textHeight); //jassuncao StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); } painter->setOpacity(1.0); //FIXME: was 0.7 before? /*jassuncao if (enabled) { painter->setPen(selected ? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor) : creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor)); } else { painter->setPen(selected ? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor) : creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor)); } */ if (enabled) { painter->setPen(selected ? QColor(0x3C,0x3C,0x3C,0xFF) : QColor(0xFF,0xFF,0xFF,0xFF)); } else { painter->setPen(selected ? QColor(0xFF,0xFF,0xFF,0xFF) : QColor(0xFF,0xFF,0xFF,0x78)); } painter->translate(0, -1); painter->drawText(tabTextRect, textFlags, tabText); painter->restore(); }
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); } }
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const { if (!validIndex(tabIndex)) { qWarning("invalid index"); return; } painter->save(); QRect rect = tabRect(tabIndex); bool selected = (tabIndex == m_currentIndex); bool enabled = isTabEnabled(tabIndex); if (selected) { //background painter->save(); QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, QColor(255, 255, 255, 140)); grad.setColorAt(1, QColor(255, 255, 255, 210)); painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); painter->restore(); //shadows painter->setPen(QColor(0, 0, 0, 110)); painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(QColor(0, 0, 0, 40)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); //highlights painter->setPen(QColor(255, 255, 255, 50)); painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); painter->setPen(QColor(255, 255, 255, 40)); painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); } QString tabText(this->tabText(tabIndex)); QRect tabTextRect(tabRect(tabIndex)); QRect tabIconRect(tabTextRect); tabTextRect.translate(0, -2); QFont boldFont(painter->font()); boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); boldFont.setBold(true); painter->setFont(boldFont); painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); int textFlags = Qt::AlignCenter | Qt::AlignBottom | Qt::TextWordWrap; if (enabled) { painter->drawText(tabTextRect, textFlags, tabText); painter->setPen(selected ? QColor(60, 60, 60) : StyleHelper::panelTextColor()); } else { painter->setPen(selected ? StyleHelper::panelTextColor() : QColor(255, 255, 255, 120)); } #ifndef Q_WS_MAC if (!selected && enabled) { painter->save(); int fader = int(m_tabs[tabIndex]->fader()); QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, Qt::transparent); grad.setColorAt(0.5, QColor(255, 255, 255, fader)); grad.setColorAt(1, Qt::transparent); painter->fillRect(rect, grad); painter->setPen(QPen(grad, 1.0)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->restore(); } #endif if (!enabled) painter->setOpacity(0.7); int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); tabIconRect.adjust(0, 4, 0, -textHeight); StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); painter->translate(0, -1); painter->drawText(tabTextRect, textFlags, tabText); painter->restore(); }