[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Plasma::TabBar: highlight tabs
From:       Matthias Fuchs <mat69 () gmx ! net>
Date:       2011-04-30 15:35:20
Message-ID: 201104301735.20882.mat69 () gmx ! net
[Download RAW message or body]

Hi,

the attached patch adds functionality to highlight tabs.
_Yet_ the highlighting is not implemented in the paint event at the moment. I 
don't have the time right now (meaning today) to look into it in more detail 
and thought it might be good for others to look at the patch anyway.

Cheers,
matthias

["patch.diff" (text/x-patch)]

diff --git a/plasma/private/nativetabbar.cpp b/plasma/private/nativetabbar.cpp
index 916deed..e0fe64b 100644
--- a/plasma/private/nativetabbar.cpp
+++ b/plasma/private/nativetabbar.cpp
@@ -84,6 +84,8 @@ public:
     qreal buttonLeft, buttonTop, buttonRight, buttonBottom;
     KIcon closeIcon;
 
+    QList<bool> highlightedTabs;
+
     QWeakPointer<QPropertyAnimation> anim;
 
     QRect currentAnimRect;
@@ -212,6 +214,23 @@ QSize NativeTabBar::sizeHint() const
     return KTabBar::sizeHint();
 }
 
+void NativeTabBar::highlightTab(int index, bool highlight)
+{
+    if (index < 0 || index >= count() ) {
+        return;
+    }
+
+    d->highlightedTabs[index] = highlight;
+}
+
+bool NativeTabBar::isTabHighlighted(int index) const
+{
+    if (index < 0 || index >= count() ) {
+        return false;
+    }
+
+    return d->highlightedTabs[index];
+}
 void NativeTabBar::paintEvent(QPaintEvent *event)
 {
     if (!styleSheet().isNull()) {
@@ -237,6 +256,7 @@ void NativeTabBar::paintEvent(QPaintEvent *event)
     }
 
     //resizing here because in resizeevent the first time is invalid (still no tabs)
+    //TODO draw highlight if needed
     d->buttonSvg->resizeFrame(movingRect.size());
     d->buttonSvg->paintFrame(&painter, movingRect.topLeft());
 
@@ -262,6 +282,12 @@ void NativeTabBar::paintEvent(QPaintEvent *event)
     for (int i = 0; i < count(); ++i) {
         QRect rect = tabRect(i).adjusted(d->buttonLeft + buttonHMargin, d->buttonTop \
                + buttonVMargin,
                                          -(d->buttonRight + buttonHMargin), \
-(d->buttonBottom + buttonVMargin)); +
+        //TODO draw highlight
+        if (d->highlightedTabs[i]) {
+
+        }
+
         // draw tab icon
         QRect iconRect = QRect(rect.x(), rect.y(), iconSize().width(), \
iconSize().height());  
@@ -363,6 +389,7 @@ void NativeTabBar::resizeEvent(QResizeEvent *event)
 
 void NativeTabBar::tabInserted(int index)
 {
+    d->highlightedTabs.insert(index, false);
     KTabBar::tabInserted(index);
     emit sizeHintChanged();
 
@@ -375,6 +402,7 @@ void NativeTabBar::tabInserted(int index)
 
 void NativeTabBar::tabRemoved(int index)
 {
+    d->highlightedTabs.removeAt(index);
     KTabBar::tabRemoved(index);
     emit sizeHintChanged();
 
diff --git a/plasma/private/nativetabbar_p.h b/plasma/private/nativetabbar_p.h
index 665d99f..b31a35c 100644
--- a/plasma/private/nativetabbar_p.h
+++ b/plasma/private/nativetabbar_p.h
@@ -41,6 +41,20 @@ public:
     QSize tabSizeHint(int index) const;
     QSize sizeHint() const;
 
+    /**
+     * Highlight the specified tab
+     * @param index of the tab to highlight
+     * @param highlight true if it should be highlighted, wrong if not
+     * @since 4.7
+     */
+    void highlightTab(int index, bool highlight);
+
+    /**
+     * @return if the tab at index is highlighted
+     * @since 4.7
+     */
+    bool isTabHighlighted(int index) const;
+
 protected:
     int lastIndex() const;
 
diff --git a/plasma/widgets/tabbar.cpp b/plasma/widgets/tabbar.cpp
index 16da3b9..eb1a90f 100644
--- a/plasma/widgets/tabbar.cpp
+++ b/plasma/widgets/tabbar.cpp
@@ -590,6 +590,16 @@ QString TabBar::styleSheet() const
     return d->tabProxy->native->styleSheet();
 }
 
+void TabBar::highlightTab(int index, bool highlight)
+{
+    d->tabProxy->native->highlightTab(index, highlight);
+}
+
+bool TabBar::isTabHighlighted(int index) const
+{
+    return d->tabProxy->native->isTabHighlighted(index);
+}
+
 KTabBar *TabBar::nativeWidget() const
 {
     return d->tabProxy->native;
diff --git a/plasma/widgets/tabbar.h b/plasma/widgets/tabbar.h
index eb7a2aa..3167bc4 100644
--- a/plasma/widgets/tabbar.h
+++ b/plasma/widgets/tabbar.h
@@ -205,6 +205,20 @@ public:
     QString styleSheet() const;
 
     /**
+     * Highlight the specified tab
+     * @param index of the tab to highlight
+     * @param highlight true if it should be highlighted, wrong if not
+     * @since 4.7
+     */
+    void highlightTab(int index, bool highlight);
+
+    /**
+     * @return if the tab at index is highlighted
+     * @since 4.7
+     */
+    bool isTabHighlighted(int index) const;
+
+    /**
      * @return the native widget wrapped by this TabBar
      */
     KTabBar *nativeWidget() const;



_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic