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

List:       kde-core-devel
Subject:    PATCH: KXMLGUIBuilder: QPopupMenu multiple seperator supression
From:       Waldo Bastian <bastian () kde ! org>
Date:       2003-01-12 21:02:14
[Download RAW message or body]

The following patch suppresses multiple seperators in popup-menus created with 
KXMLGUIBuilder

This is a problem for the KIOSK framework where the user (sysadmin) can 
disable actions at will. This often results in two seperators following 
directly behind each other. This patch prevents that.

I would like to include this in KDE 3.1

Cheers,
Waldo
-- 
bastian@kde.org -=|[ SuSE, The Linux Desktop Experts ]|=- bastian@suse.com

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

Index: kxmlguibuilder.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kxmlguibuilder.cpp,v
retrieving revision 1.58
diff -u -r1.58 kxmlguibuilder.cpp
--- kxmlguibuilder.cpp	26 May 2002 14:03:57 -0000	1.58
+++ kxmlguibuilder.cpp	12 Jan 2003 20:47:54 -0000
@@ -295,7 +295,28 @@
   if ( element.tagName().lower() == d->tagSeparator )
   {
     if ( parent->inherits( "QPopupMenu" ) )
-      return static_cast<QPopupMenu *>(parent)->insertSeparator( index );
+    {
+      // Don't insert multiple separators in a row
+      QPopupMenu *menu = static_cast<QPopupMenu *>(parent);
+      int count = menu->count();
+      if (count)
+      {
+         int previousId = -1;
+         if ((index == -1) || (index > count))
+            previousId = menu->idAt(count-1);
+         else if (index > 0)
+            previousId = menu->idAt(index-1);
+         if (previousId != -1)
+         {
+            if (menu->text(previousId).isEmpty() &&
+                !menu->iconSet(previousId) &&
+                !menu->pixmap(previousId))
+               return 0;
+         }
+      }
+      
+      return menu->insertSeparator( index );
+    }
     else if ( parent->inherits( "QMenuBar" ) )
        return static_cast<QMenuBar *>(parent)->insertSeparator( index );
     else if ( parent->inherits( "KToolBar" ) )


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

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