From e720a249663ce44843ea9a3a1e36d4bb833c4b8a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 25 Jan 2009 13:26:53 +0000 Subject: [PATCH] paint close buttons if asked to svn path=/trunk/KDE/kdelibs/; revision=916527 --- private/nativetabbar.cpp | 39 +++++++++++++++++++++++++++++++++++++++ private/nativetabbar_p.h | 1 + 2 files changed, 40 insertions(+) diff --git a/private/nativetabbar.cpp b/private/nativetabbar.cpp index 0e242694f..2f5924c3c 100644 --- a/private/nativetabbar.cpp +++ b/private/nativetabbar.cpp @@ -35,6 +35,8 @@ // KDE #include #include +#include +#include #include "plasma/plasma.h" #include "plasma/theme.h" @@ -54,6 +56,7 @@ public: : q(parent), backgroundSvg(0), buttonSvg(0), + closeIcon("window-close"), animationId(-1) { } @@ -73,6 +76,7 @@ public: qreal left, top, right, bottom; FrameSvg *buttonSvg; qreal buttonLeft, buttonTop, buttonRight, buttonBottom; + KIcon closeIcon; int animationId; @@ -259,8 +263,13 @@ void NativeTabBar::paintEvent(QPaintEvent *event) painter.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont)); painter.drawText(textRect, Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i)); + + if (isCloseButtonEnabled()) { + d->closeIcon.paint(&painter, QRect(closeButtonPos(i), QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)) ); + } } + QRect scrollButtonsRect; foreach (QObject *child, children()) { QToolButton *childWidget = qobject_cast(child); @@ -398,6 +407,36 @@ QSize NativeTabBar::tabSize(int index) const return hint; } +//Unfortunately copied from KTabBar +QPoint NativeTabBar::closeButtonPos( int tabIndex ) const +{ + QPoint buttonPos; + if ( tabIndex < 0 ) { + return buttonPos; + } + + int availableHeight = height(); + if ( tabIndex == currentIndex() ) { + QStyleOption option; + option.initFrom(this); + availableHeight -= style()->pixelMetric( QStyle::PM_TabBarTabShiftVertical, &option, this ); + } + + const QRect tabBounds = tabRect( tabIndex ); + const int xInc = (height() - KIconLoader::SizeSmall) / 2; + + if ( layoutDirection() == Qt::RightToLeft ) { + buttonPos = tabBounds.topLeft(); + buttonPos.rx() += xInc; + } else { + buttonPos = tabBounds.topRight(); + buttonPos.rx() -= KIconLoader::SizeSmall + xInc; + } + buttonPos.ry() += (availableHeight - KIconLoader::SizeSmall) / 2; + + return buttonPos; +} + } // namespace Plasma #include "nativetabbar_p.moc" diff --git a/private/nativetabbar_p.h b/private/nativetabbar_p.h index 86c8922e0..08bed6ec1 100644 --- a/private/nativetabbar_p.h +++ b/private/nativetabbar_p.h @@ -64,6 +64,7 @@ Q_SIGNALS: private: QSize tabSize(int index) const; + QPoint closeButtonPos( int tabIndex ) const; NativeTabBarPrivate * const d;