QSize ModeTabBar::tabSizeHint() const { QFont labelFont = font(); labelFont.setBold(true); QFontMetrics fm(labelFont); int maxWidth = minimumWidth(); for(int i = 0; i < count(); ++i) { maxWidth = qMax(maxWidth, fm.width(tabLabel(i)) + 3 * tabPadding); } return QSize(maxWidth, iconSize + fm.height() + (3 * tabPadding)); }
void KMdiDocumentViewTabWidget::updateIconInView( TQWidget *w, TQPixmap icon ) { changeTab( w, icon, tabLabel( w ) ); }
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(); } }
void TabWidget::updateIconInView( QWidget *w, QPixmap icon ) { changeTab(w,icon,tabLabel(w)); }