[Kst] extragear/graphics/kst/kst

Rick Chern rchern at interchange.ubc.ca
Tue May 24 19:36:12 CEST 2005


SVN commit 417805 by rchern:

Make cleanup layout use a default approximately square grid, and allow custom columns as well

CCMAIL: 104636-done at bugs.kde.org

 M  +52 -3     ksttoplevelview.cpp  
 M  +2 -1      ksttoplevelview.h  
 M  +2 -1      kstviewobject.cpp  


--- trunk/extragear/graphics/kst/kst/ksttoplevelview.cpp #417804:417805
@@ -17,11 +17,14 @@
 
 #include <assert.h>
 #include <stdlib.h>
+#include <math.h>
 
 // include files for Qt
 
 // include files for KDE
 #include <kdebug.h>
+#include <kinputdialog.h>
+#include <klineeditdlg.h>
 #include <klocale.h>
 
 // application specific includes
@@ -720,7 +723,10 @@
     if (rc) {
       menu->insertSeparator();
     }
-    menu->insertItem(i18n("Cleanup Layout"), this, SLOT(cleanupAction()));
+    KPopupMenu *subMenu = new KPopupMenu(menu);
+    subMenu->insertItem(i18n("Default Tile"), this, SLOT(cleanupDefault()));
+    subMenu->insertItem(i18n("Custom..."), this, SLOT(cleanupCustom()));
+    menu->insertItem(i18n("Cleanup Layout"), subMenu);
     rc = true;
   }
 
@@ -1035,12 +1041,55 @@
   return _w;
 }
 
-
-void KstTopLevelView::cleanupAction() {
+void KstTopLevelView::cleanupDefault()
+{
+  // roughly layout in a square
   cleanup();
 }
 
+void KstTopLevelView::cleanupCustom()
+{
+  bool ok = false;
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
+  int numCols = KInputDialog::getInteger (i18n("Number of Columns"), 
+                                          i18n("Select number of columns:"), 
+                                          (int)sqrt(_children.count()), 
+                                          1, 
+                                          _children.count(), 
+                                          1, 
+                                          &ok, 
+                                          0L);
+  if (ok)
+  {
+    cleanup(numCols);
+  } 
+#else
+  bool done = false;
+  while (!done)
+  { 
+    QString numColsString = KLineEditDlg::getText(i18n("Enter number of columns:"), i18n("Number of Columns"), &ok, 0L);
+    if (ok)
+    {
+      int numCols = numColsString.toInt();
+      if (numCols < 1 || numCols > _children.count())
+      {
+        KMessageBox::sorry(0L, i18n("Please enter a number of columns between 1 and %d").arg(_selectionList.count()));
+      }
+      else
+      {
+        done = true;
+        cleanup(numCols);
+      }
+    }
+    else
+    {
+      done = true;
+    }
+  }
+#endif
+}
 
+
 void KstTopLevelView::release() {
   _hoverFocus = 0L;
   _pressTarget = 0L;
--- trunk/extragear/graphics/kst/kst/ksttoplevelview.h #417804:417805
@@ -78,7 +78,8 @@
     void packVertically();
     void packHorizontally();
     void groupSelection();
-    void cleanupAction();
+    void cleanupDefault();
+    void cleanupCustom();
 
   protected:
     void resized(const QSize& size);
--- trunk/extragear/graphics/kst/kst/kstviewobject.cpp #417804:417805
@@ -519,7 +519,8 @@
   } else {
     if (cols > 0) {
       _columns = cols;
-    } else if (_columns <= 0) {
+//    } else if (_columns <= 0) {
+    } else if (cols <= 0){
       _columns = QMAX(1, int(sqrt(_children.count())));
     }
   }


More information about the Kst mailing list