Hello Plasma-devs,

first of all: please cc me in answers as I am not subscribed to this list.

I just did some hacking on the tasks plasmoid and added an option to only show 
the icons and hide the text. So a kind of Windows 7 task bar. The advantage is 
that much less space is required, you can have bigger icons and most important 
it suites vertical panels much better. Currently tasks plasmoid kind of sucks 
when having a big vertical panel.

Please have a look at the attached patch and give comments on it ;-)

Regards
Martin Gräßlin
commit fc6184bef3a4491eaf2f303d4f6a94e416335758
Author: Martin Gräßlin <ubu...@martin-graesslin.com>
Date:   Fri Jan 16 17:21:22 2009 +0100

    Icons only mode for tasks plasmoid

diff --git a/applets/tasks/abstracttaskitem.cpp b/applets/tasks/abstracttaskitem.cpp
index e9e50ac..8739c32 100644
--- a/applets/tasks/abstracttaskitem.cpp
+++ b/applets/tasks/abstracttaskitem.cpp
@@ -98,8 +98,15 @@ QSize AbstractTaskItem::basicPreferredSize() const
         topMargin = qMax(1, topMargin/2); 
         bottomMargin = qMax(1, bottomMargin/2); 
     }
-    return QSize(mSize.width()*12 + m_applet->itemLeftMargin() + m_applet->itemRightMargin() + KIconLoader::SizeSmall,
+    if (m_applet->iconsOnly()) {
+        iconsize = KIconLoader::SizeMedium;
+        int size = qMin((int)m_applet->itemLeftMargin() + (int)m_applet->itemRightMargin() + iconsize,
+                            qMax(mSize.height(), iconsize) + topMargin + bottomMargin);
+        return QSize(size, size);
+    } else {
+        return QSize(mSize.width()*12 + m_applet->itemLeftMargin() + m_applet->itemRightMargin() + KIconLoader::SizeSmall,
                            qMax(mSize.height(), iconsize) + topMargin + bottomMargin);
+    }
 }
 
 AbstractTaskItem::~AbstractTaskItem()
@@ -453,17 +460,18 @@ void AbstractTaskItem::drawTask(QPainter *painter, const QStyleOptionGraphicsIte
     }
 
     painter->setPen(QPen(textColor(), 1.0));
+    if (!m_applet->iconsOnly()) {
+        QRect rect = textRect(bounds).toRect();
+        if (rect.height() > 20) {
+            rect.adjust(2, 2, -2, -2); // Create a text margin
+        }
+        QTextLayout layout;
+        layout.setFont(KGlobalSettings::taskbarFont());
+        layout.setTextOption(textOption());
 
-    QRect rect = textRect(bounds).toRect();
-    if (rect.height() > 20) {
-        rect.adjust(2, 2, -2, -2); // Create a text margin
+        layoutText(layout, m_text, rect.size());
+        drawTextLayout(painter, layout, rect);
     }
-    QTextLayout layout;
-    layout.setFont(KGlobalSettings::taskbarFont());
-    layout.setTextOption(textOption());
-
-    layoutText(layout, m_text, rect.size());
-    drawTextLayout(painter, layout, rect);
 
     TaskGroupItem *groupItem = qobject_cast<TaskGroupItem *>(this);
     if (groupItem) {
@@ -720,7 +728,9 @@ QRectF AbstractTaskItem::iconRect(const QRectF &b) const
     QRectF bounds(b);
     const int right = bounds.right();
     //leave enough space for the text. useful in vertical panel
-    bounds.setWidth(qMax(bounds.width() / 3, qMin(minimumSize().height(), bounds.width())));
+    if (!m_applet->iconsOnly()) {
+        bounds.setWidth(qMax(bounds.width() / 3, qMin(minimumSize().height(), bounds.width())));
+    }
 
     //restore right position if the layout is RTL
     if (QApplication::layoutDirection() == Qt::RightToLeft) {
@@ -728,8 +738,12 @@ QRectF AbstractTaskItem::iconRect(const QRectF &b) const
     }
 
     QSize iconSize = m_icon.actualSize(bounds.size().toSize());
+    Qt::Alignment align = Qt::AlignLeft;
+    if (m_applet->iconsOnly()) {
+        align = Qt::AlignCenter;
+    }
 
-    return QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignLeft | Qt::AlignVCenter,
+    return QStyle::alignedRect(QApplication::layoutDirection(), align | Qt::AlignVCenter,
                                iconSize, bounds.toRect());
 }
 
diff --git a/applets/tasks/tasks.cpp b/applets/tasks/tasks.cpp
index e7068af..558128b 100644
--- a/applets/tasks/tasks.cpp
+++ b/applets/tasks/tasks.cpp
@@ -123,6 +123,7 @@ void Tasks::init()
     m_groupManager->setShowOnlyMinimized( cg.readEntry("showOnlyMinimized", false));
     m_groupManager->setOnlyGroupWhenFull(cg.readEntry("groupWhenFull", true));
     m_showTooltip = cg.readEntry("showTooltip", true);
+    m_iconsOnly = cg.readEntry("iconsOnly", false);
 
     m_groupManager->setGroupingStrategy( static_cast<TaskManager::GroupManager::TaskGroupingStrategy>(cg.readEntry("groupingStrategy", static_cast<int>(TaskManager::GroupManager::ProgramGrouping))));
 
@@ -252,6 +253,7 @@ void Tasks::createConfigurationInterface(KConfigDialog *parent)
      parent->addPage(widget, i18n("General"), icon());
 
     m_ui.showTooltip->setChecked(m_showTooltip);
+    m_ui.iconsOnly->setChecked(m_iconsOnly);
     m_ui.showOnlyCurrentDesktop->setChecked(m_groupManager->showOnlyCurrentDesktop());
     m_ui.showOnlyCurrentScreen->setChecked(m_groupManager->showOnlyCurrentScreen());
     m_ui.showOnlyMinimized->setChecked(m_groupManager->showOnlyMinimized());
@@ -379,6 +381,13 @@ void Tasks::configAccepted()
         changed = true;
     }
 
+    if (m_iconsOnly != (m_ui.iconsOnly->checkState() == Qt::Checked)) {
+        m_iconsOnly = !m_iconsOnly;
+        KConfigGroup cg = config();
+        cg.writeEntry("iconsOnly", m_iconsOnly);
+        changed = true;
+    }
+
     if (changed) {
         emit settingsChanged();
         emit configNeedsSaving();
@@ -391,6 +400,10 @@ bool Tasks::showTooltip() const
     return m_showTooltip;
 }
 
+bool Tasks::iconsOnly() const
+{
+    return m_iconsOnly;
+}
 
 
 void Tasks::themeRefresh()
diff --git a/applets/tasks/tasks.h b/applets/tasks/tasks.h
index 9653907..c3aa57c 100644
--- a/applets/tasks/tasks.h
+++ b/applets/tasks/tasks.h
@@ -101,6 +101,7 @@ public:
         Qt::KeyboardModifiers groupModifierKey() const;
 
         bool showTooltip() const;
+        bool iconsOnly() const;
 
 
 signals:
@@ -132,6 +133,7 @@ private slots:
 
 private:
         bool m_showTooltip;
+        bool m_iconsOnly;
         Plasma::LayoutAnimator *m_animator;
         QGraphicsLinearLayout *layout;
 
diff --git a/applets/tasks/tasksConfig.ui b/applets/tasks/tasksConfig.ui
index d7c159e..37a7aa8 100644
--- a/applets/tasks/tasksConfig.ui
+++ b/applets/tasks/tasksConfig.ui
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>507</width>
-    <height>391</height>
+    <height>411</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout" >
@@ -54,7 +54,7 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="1" >
+   <item row="4" column="1" >
     <spacer name="verticalSpacer_6" >
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
@@ -70,7 +70,7 @@
      </property>
     </spacer>
    </item>
-   <item row="4" column="1" >
+   <item row="5" column="1" >
     <widget class="QLabel" name="label_3" >
      <property name="text" >
       <string>Maximum rows:</string>
@@ -80,7 +80,7 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="2" >
+   <item row="5" column="2" >
     <layout class="QHBoxLayout" name="horizontalLayout" >
      <item>
       <widget class="QSpinBox" name="maxRows" >
@@ -107,7 +107,7 @@
      </item>
     </layout>
    </item>
-   <item row="5" column="1" >
+   <item row="6" column="1" >
     <spacer name="verticalSpacer_2" >
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
@@ -123,7 +123,7 @@
      </property>
     </spacer>
    </item>
-   <item row="6" column="0" colspan="3" >
+   <item row="7" column="0" colspan="3" >
     <widget class="QLabel" name="label_6" >
      <property name="font" >
       <font>
@@ -136,7 +136,7 @@
      </property>
     </widget>
    </item>
-   <item row="7" column="1" >
+   <item row="8" column="1" >
     <widget class="QLabel" name="label" >
      <property name="text" >
       <string>Grouping:</string>
@@ -146,7 +146,7 @@
      </property>
     </widget>
    </item>
-   <item row="7" column="2" >
+   <item row="8" column="2" >
     <layout class="QHBoxLayout" name="horizontalLayout_2" >
      <item>
       <widget class="QComboBox" name="groupingStrategy" >
@@ -173,7 +173,7 @@
      </item>
     </layout>
    </item>
-   <item row="8" column="2" >
+   <item row="9" column="2" >
     <layout class="QHBoxLayout" name="horizontalLayout_4" >
      <item>
       <spacer name="horizontalSpacer" >
@@ -206,7 +206,7 @@
      </item>
     </layout>
    </item>
-   <item row="9" column="1" >
+   <item row="10" column="1" >
     <widget class="QLabel" name="label_2" >
      <property name="text" >
       <string>Sorting:</string>
@@ -216,7 +216,7 @@
      </property>
     </widget>
    </item>
-   <item row="9" column="2" >
+   <item row="10" column="2" >
     <layout class="QHBoxLayout" name="horizontalLayout_3" >
      <item>
       <widget class="QComboBox" name="sortingStrategy" >
@@ -243,7 +243,7 @@
      </item>
     </layout>
    </item>
-   <item row="10" column="0" >
+   <item row="11" column="0" >
     <widget class="QLabel" name="label_4" >
      <property name="font" >
       <font>
@@ -256,7 +256,7 @@
      </property>
     </widget>
    </item>
-   <item row="10" column="1" >
+   <item row="11" column="1" >
     <spacer name="verticalSpacer_4" >
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
@@ -272,28 +272,28 @@
      </property>
     </spacer>
    </item>
-   <item row="11" column="1" colspan="2" >
+   <item row="12" column="1" colspan="2" >
     <widget class="QCheckBox" name="showOnlyCurrentDesktop" >
      <property name="text" >
       <string>Only show tasks from the current desktop</string>
      </property>
     </widget>
    </item>
-   <item row="12" column="1" colspan="2" >
+   <item row="13" column="1" colspan="2" >
     <widget class="QCheckBox" name="showOnlyCurrentScreen" >
      <property name="text" >
       <string>Only show tasks from the current screen</string>
      </property>
     </widget>
    </item>
-   <item row="13" column="1" colspan="2" >
+   <item row="14" column="1" colspan="2" >
     <widget class="QCheckBox" name="showOnlyMinimized" >
      <property name="text" >
       <string>Only show tasks that are minimized</string>
      </property>
     </widget>
    </item>
-   <item row="14" column="1" >
+   <item row="15" column="1" >
     <spacer name="verticalSpacer" >
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
@@ -306,6 +306,23 @@
      </property>
     </spacer>
    </item>
+   <item row="3" column="2" >
+    <widget class="QCheckBox" name="iconsOnly" >
+     <property name="text" >
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1" >
+    <widget class="QLabel" name="label_9" >
+     <property name="text" >
+      <string>Show only icons:</string>
+     </property>
+     <property name="alignment" >
+      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to