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

List:       kde-usability
Subject:    Support in KToggleAction for toggling the text itself
From:       David Faure <faure () kde ! org>
Date:       2004-02-06 17:05:37
Message-ID: 200402061805.37898.faure () kde ! org
[Download RAW message or body]

The problem:
--------------
Toggle actions plugged into menus currently toggle a checkmark in front of the menu item.
This is typically used with a text that represents a state (e.g. "View/Frame Borders").

But this is usually ambiguous (if I see "Case Insensitive Sort" in a menu, does that
mean it's currently sorting that way or that one should click on it to sort that way?).

Better is to use verbs, to describe actions. We do so already for e.g. "Show menubar".
However this is even worse currently: when the menubar is shown, the menuitem
still says "show menubar", which is a really wrong text for a menuitem hiding it.

The solution:
--------------
The attached patch adds support for (optionally) toggling the text instead of 
using a checkmark for toggleactions in menuitems, and uses this support for
the show/hide menubar and toolbar actions.

I hesitated to subclass KToggleAction for it, but that means copying thousands
(almost) of constructors :). So I preferred to add a setting to KToggleAction.

OK to commit?

-- 
David Faure, faure@kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).

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

Index: kactionclasses.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kactionclasses.cpp,v
retrieving revision 1.334
diff -u -p -b -r1.334 kactionclasses.cpp
--- kactionclasses.cpp	24 Nov 2003 11:40:10 -0000	1.334
+++ kactionclasses.cpp	6 Feb 2004 16:31:47 -0000
@@ -98,6 +98,7 @@ public:
 
   bool m_checked;
   QString m_exclusiveGroup;
+  QString m_checkedText;
 };
 
 KToggleAction::KToggleAction( const QString& text, const KShortcut& cut,
@@ -181,7 +182,11 @@ int KToggleAction::plug( QWidget* widget
   {
     int id = itemId( _index );
 
+    if ( d->m_checkedText.isEmpty() )
     static_cast<QPopupMenu*>(widget)->setItemChecked( id, d->m_checked );
+    else
+        static_cast<QPopupMenu*>(widget)->changeItem( id, d->m_checked ? \
d->m_checkedText : text() ); +
   } else if ( widget->inherits( "KToolBar" ) ) {
     KToolBar *bar = static_cast<KToolBar *>( widget );
 
@@ -227,9 +232,13 @@ void KToggleAction::updateChecked( int i
 {
   QWidget *w = container( id );
 
-  if ( w->inherits( "QPopupMenu" ) )
+  if ( w->inherits( "QPopupMenu" ) ) {
+    if ( d->m_checkedText.isEmpty() )
     static_cast<QPopupMenu*>(w)->setItemChecked( itemId( id ), d->m_checked );
-  else if ( w->inherits( "QMenuBar" ) )
+    else
+        static_cast<QPopupMenu*>(w)->changeItem( itemId( id ), d->m_checked ? \
d->m_checkedText : text() ); +  }
+  else if ( w->inherits( "QMenuBar" ) ) // not handled in plug...
     static_cast<QMenuBar*>(w)->setItemChecked( itemId( id ), d->m_checked );
   else if ( w->inherits( "KToolBar" ) )
   {
@@ -261,6 +270,15 @@ QString KToggleAction::exclusiveGroup() 
   return d->m_exclusiveGroup;
 }
 
+QString KToggleAction::checkedText() const
+{
+  return d->m_checkedText;
+}
+
+void KToggleAction::setCheckedText( const QString& text )
+{
+  d->m_checkedText = text;
+}
 
 KRadioAction::KRadioAction( const QString& text, const KShortcut& cut,
                             QObject* parent, const char* name )
Index: kactionclasses.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kactionclasses.h,v
retrieving revision 1.187
diff -u -p -b -r1.187 kactionclasses.h
--- kactionclasses.h	5 Jan 2004 11:05:55 -0000	1.187
+++ kactionclasses.h	6 Feb 2004 16:31:47 -0000
@@ -69,6 +69,7 @@ class KToggleAction : public KAction
     Q_OBJECT
     Q_PROPERTY( bool checked READ isChecked WRITE setChecked )
     Q_PROPERTY( QString exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup )
+    Q_PROPERTY( QString checkedText READ checkedText WRITE setCheckedText )
 public:
 
     /**
@@ -182,6 +183,21 @@ public:
      */
     virtual void setExclusiveGroup( const QString& name );
 
+    /**
+     * @return the text that should be displayed instead of the normal
+     * text, when the action is checked.
+     */
+    QString checkedText() const;
+
+    /**
+     * Defines the text that should be displayed instead of the normal
+     * text, when the action is checked. This feature replaces the checkmark
+     * that usually appears in front of the text, in menus.
+     * It is useful when the text is mainly a verb: e.g. "Show <foo>"
+     * should turn into "Hide <foo>" when activated.
+     */
+    void setCheckedText( const QString& text );
+
 public slots:
     /**
      *  Sets the state of the action.
Index: kstdaction.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kstdaction.cpp,v
retrieving revision 1.91
diff -u -p -b -r1.91 kstdaction.cpp
--- kstdaction.cpp	11 Dec 2003 17:53:18 -0000	1.91
+++ kstdaction.cpp	6 Feb 2004 16:31:48 -0000
@@ -228,6 +228,7 @@ KToggleAction *showMenubar( const QObjec
     KToggleAction *ret;
     ret = new KToggleAction(i18n("Show &Menubar"), "showmenu", \
KStdAccel::shortcut(KStdAccel::ShowMenubar), recvr, slot,  parent, _name ? _name : \
name(ShowMenubar)); +    ret->setCheckedText( i18n( "Hide &Menubar" ) );
     ret->setChecked(true);
     return ret;
 }
@@ -237,6 +238,7 @@ KToggleAction *showToolbar( const QObjec
     KToggleAction *ret;
     ret = new KToggleAction(i18n("Show &Toolbar"), 0, recvr, slot, parent,
                             _name ? _name : name(ShowToolbar));
+    ret->setCheckedText( i18n( "Hide &Toolbar" ) );
     ret->setChecked(true);
     return ret;
 
@@ -247,6 +249,7 @@ KToggleToolBarAction *showToolbar( const
     KToggleToolBarAction *ret;
     ret = new KToggleToolBarAction(toolBarName, i18n("Show &Toolbar"), parent,
                             _name ? _name : name(ShowToolbar));
+    ret->setCheckedText( i18n( "Hide &Toolbar" ) );
     return ret;
 }
 
@@ -256,6 +259,7 @@ KToggleAction *showStatusbar( const QObj
     KToggleAction *ret;
     ret = new KToggleAction(i18n("Show St&atusbar"), 0, recvr, slot, parent,
                             _name ? _name : name(ShowStatusbar));
+    ret->setCheckedText( i18n( "Hide St&atusbar" ) );
     ret->setChecked(true);
     return ret;
 }
Index: ktoolbarhandler.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbarhandler.cpp,v
retrieving revision 1.4
diff -u -p -b -r1.4 ktoolbarhandler.cpp
--- ktoolbarhandler.cpp	14 Aug 2002 01:23:57 -0000	1.4
+++ ktoolbarhandler.cpp	6 Feb 2004 16:31:48 -0000
@@ -82,7 +82,9 @@ namespace
                 return actions;
 
             if ( m_toolBarActions.count() == 1 ) {
-                m_toolBarActions.getFirst()->setText( i18n( "Show Toolbar" ) );
+                KToggleToolBarAction* action = static_cast<KToggleToolBarAction *>( \
m_toolBarActions.getFirst() ); +                action->setText( i18n( "Show Toolbar" \
) ); +                action->setCheckedText( i18n( "Hide Toolbar" ) );
                 return m_toolBarActions;
             }
 
@@ -101,11 +103,12 @@ namespace
     private:
         void handleToolBar( KToolBar *toolBar )
         {
-            KAction *action = new KToggleToolBarAction( toolBar,
+            KToggleToolBarAction *action = new KToggleToolBarAction(
+                toolBar,
                                                         i18n( "Show %1" ).arg( \
                toolBar->label() ),
                                                         m_actionCollection, 
                                                         toolBar->name() );
-
+            action->setCheckedText( i18n( "Hide %1" ).arg( toolBar->label() ) );
             m_toolBarActions.append( action );
         }
 



_______________________________________________
kde-usability mailing list
kde-usability@kde.org
https://mail.kde.org/mailman/listinfo/kde-usability


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

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