Bug 56283

Summary: quicklauncher, more then 2 rows/columns
Product: [Plasma] kicker Reporter: J <dad>
Component: quicklauncherAssignee: Bill Nagel <bn>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: patch

Description J 2003-03-23 19:55:39 UTC
Version:            (using KDE KDE 3.1.1)
Installed from:    Compiled From Sources

Here is a patch against quicklauncher.cpp 3.1.1 to support more than 2 rows/columns of icons.

--- quicklauncher.cpp.ori	2003-03-23 13:12:54.000000000 +0100
+++ quicklauncher.cpp	2003-03-23 13:16:26.000000000 +0100
@@ -85,17 +85,25 @@
 int QuickLauncher :: widthForHeight(int h) const
 {
    int n = buttonList.count();
-   if (!n) n++;
-   if (h < 2 * iconSize) return n * iconSize + 4;
-   else return (n / 2 + n % 2) * iconSize + 4;
+   int size = iconSize;
+   int cols = 0;
+
+   size += (iconSize<24) ? 1 : 2;
+
+   int ipr = (int) (h / size);
+   if ( ipr<=0 ) ipr=1;
+
+   while ( n > 0 ) {
+       cols++;
+       n -= ipr;
+   }
+   
+   return( cols*size );
 }
 
 int QuickLauncher :: heightForWidth(int w) const
 {
-   int n = buttonList.count();
-   if (!n) n++;
-   if (w < 2 * iconSize) return n * iconSize + 4;
-   else return (n / 2 + n % 2) * iconSize + 4;
+    return( widthForHeight( w ) );
 }
 
 void QuickLauncher :: addApp(int i, QString url)
@@ -202,22 +210,32 @@
    }
 
    if (orientation() == Vertical) {
+      int x = padding;
       for (button = buttonList.first(); button; button = buttonList.next()) {
          if ((buttonList.count() == 1) || width() < 2*iconSize)
             button->move(width() / 2 - iconSize/2, 2 + i * iconSize);
          else {
-            button->move(((i % 2) == 0) ? padding : width() - iconSize - padding, 2 + row * iconSize);
-            if (i % 2) row++;
+            if ( ((x + iconSize) > width()) && i ) {
+                x = padding;
+                row++;
+            }
+            button->move( x, padding + (row * iconSize) );
+            x += iconSize + padding;
          }
          i++;
       }
    } else {
+      int y = padding;
       for (button = buttonList.first(); button; button = buttonList.next()) {
          if ((buttonList.count() == 1) || height() < 2*iconSize)
             button->move(2 + i * iconSize, height() / 2 - iconSize/2);
          else {
-            button->move(2 + col * iconSize, ((i % 2) == 0) ? padding : height() - iconSize - padding);
-            if (i % 2) col++;
+            if ( ((y + iconSize) > height()) && i ) {
+                y = padding;
+                col++;
+            }
+            button->move(2 + col * iconSize, y );
+            y += iconSize + padding;
          }
          i++;
       }
Comment 1 J 2003-03-23 19:59:35 UTC
Created attachment 1227 [details]
patch
Comment 2 Scott Wheeler 2003-03-28 23:34:01 UTC
Subject: kdebase/kicker/applets/launcher

CVS commit by wheeler: 

Applying Joerg's patch from #56283 with minor cleanups to make it possible
for the quick launcher to have more than two rows.  Of course you have to 
make Kicker friggin' huge before this kicks in, but...

CCMAIL:56283-done@bugs.kde.org


  M +35 -15    quicklauncher.cpp   1.8


--- kdebase/kicker/applets/launcher/quicklauncher.cpp  #1.7:1.8
@@ -87,15 +87,25 @@ int QuickLauncher :: widthForHeight(int 
 {
    int n = buttonList.count();
-   if (!n) n++;
-   if (h < 2 * iconSize) return n * iconSize + 4;
-   else return (n / 2 + n % 2) * iconSize + 4;
+   int size = iconSize;
+   int cols = 0;
+
+   size += ( iconSize < 24 ) ? 1 : 2;
+
+   int iconsPerRow = int( h / size );
+   if ( iconsPerRow <= 0 )
+       iconsPerRow = 1;
+
+   while ( n > 0 ) {
+       cols++;
+       n -= iconsPerRow;
+   }
+   
+   return cols * size;
 }
 
 int QuickLauncher :: heightForWidth(int w) const
 {
-   int n = buttonList.count();
-   if (!n) n++;
-   if (w < 2 * iconSize) return n * iconSize + 4;
-   else return (n / 2 + n % 2) * iconSize + 4;
+    // counterintuitive though it seems, this was actually the same code
+    return widthForHeight( w );
 }
 
@@ -204,20 +214,30 @@ void QuickLauncher :: arrangeIcons()
 
    if (orientation() == Vertical) {
+      int x = padding;
       for (button = buttonList.first(); button; button = buttonList.next()) {
-         if ((buttonList.count() == 1) || width() < 2*iconSize)
-            button->move(width() / 2 - iconSize/2, 2 + i * iconSize);
+         if ( buttonList.count() == 1 || width() < 2 * iconSize )
+            button->move(width() / 2 - iconSize / 2, 2 + i * iconSize);
          else {
-            button->move(((i % 2) == 0) ? padding : width() - iconSize - padding, 2 + row * iconSize);
-            if (i % 2) row++;
+            if (x + iconSize > width() && i)  {
+               x = padding;
+               row++;
+            }
+            button->move(x, padding + row * iconSize);
+            x += iconSize + padding;
          }
          i++;
       }
    } else {
+      int y = padding;
       for (button = buttonList.first(); button; button = buttonList.next()) {
-         if ((buttonList.count() == 1) || height() < 2*iconSize)
-            button->move(2 + i * iconSize, height() / 2 - iconSize/2);
+         if (buttonList.count() == 1 || height() < 2 * iconSize)
+            button->move(2 + i * iconSize, height() / 2 - iconSize / 2);
          else {
-            button->move(2 + col * iconSize, ((i % 2) == 0) ? padding : height() - iconSize - padding);
-            if (i % 2) col++;
+            if (y + iconSize > height() && i) {
+               y = padding;
+               col++;
+            }
+            button->move(2 + col * iconSize, y);
+            y += iconSize + padding;
          }
          i++;