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

List:       kde-core-devel
Subject:    Re: [PATCH] "Show only important text" mode for toolbars
From:       "Peter Rockai \(mornfall\)" <mornfall () danill ! sk>
Date:       2004-09-22 14:17:57
Message-ID: 200409221618.02701.mornfall () danill ! sk
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


On Wednesday 22 September 2004 12:07, Waldo Bastian wrote:
> On Wednesday 22 September 2004 08:24, Simon Edwards wrote:
> I'm not convinced. Wouldn't it be better to look for shorter texts?
[snip]
Ok, i reworked the patch to attach short text to KAction instead fo the 
boolean flag. Remaining machinery is about the same. Short text can be set to 
empty string to hide the text (and effectively turn the button into 
IconOnly). Original (long) text is shown as a tooltip if it's different from 
the short variant.

It may be also possible to use short text uncoditionally (and ensure it's not 
empty) and use the flag (like in original patch) as well or to display text 
unconditionally everywhere (in IconTextRight or IconTextBottom modes) but i 
don't like it as it doesn't address many of the issues original patch does.
> Cheers,
> Waldo

Yours,
    Peter

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

Index: kaction.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kaction.cpp,v
retrieving revision 1.315
diff -u -p -r1.315 kaction.cpp
--- kaction.cpp	15 Jul 2004 09:38:46 -0000	1.315
+++ kaction.cpp	22 Sep 2004 13:22:00 -0000
@@ -79,6 +79,7 @@ public:
   {
     m_kaccel = 0;
     m_configurable = true;
+    m_shortText = "";
   }
 
   KAccel *m_kaccel;
@@ -86,11 +87,12 @@ public:
 
   QString m_groupText;
   QString m_group;
+  QString m_shortText;
 
   KShortcut m_cut;
   KShortcut m_cutDefault;
 
-  bool m_configurable;
+  bool m_configurable: 1;
 
   struct Container
   {
@@ -687,6 +689,7 @@ int KAction::plug( QWidget *w, int index
                            d->isEnabled(), d->plainText(), index, instance );
     }
     bar->getButton( id_ )->setName( QCString("toolbutton_")+name() );
+    bar->getButton( id_ )->setShortText( KGuiItem::textToPlain( d->m_shortText ) );
 
     if ( !d->whatsThis().isEmpty() )
         QWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() );
@@ -828,6 +831,11 @@ void KAction::setShortcutConfigurable( b
     d->m_configurable = b;
 }
 
+void KAction::setShortText( const QString &text )
+{
+    d->m_shortText = text;
+}
+
 void KAction::setText( const QString& text )
 {
   // KDE 4: remove
Index: kaction.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kaction.h,v
retrieving revision 1.183
diff -u -p -r1.183 kaction.h
--- kaction.h	9 Sep 2004 20:07:26 -0000	1.183
+++ kaction.h	22 Sep 2004 13:22:02 -0000
@@ -540,6 +540,13 @@ public slots:
      */
     virtual void activate();
 
+    /**
+     * Set short variant of text (useful for toolbar labels). Any accelerator
+     * markings will be stripped and ignored.
+     * @since 3.4
+     */
+    void setShortText( const QString &text );
+
 protected slots:
     virtual void slotDestroyed();
     virtual void slotKeycodeChanged();
Index: kguiitem.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kguiitem.cpp,v
retrieving revision 1.19
diff -u -p -r1.19 kguiitem.cpp
--- kguiitem.cpp	22 Sep 2003 19:35:24 -0000	1.19
+++ kguiitem.cpp	22 Sep 2004 13:22:02 -0000
@@ -122,12 +122,12 @@ QString KGuiItem::text() const
 }
 
 
-QString KGuiItem::plainText() const
+QString KGuiItem::textToPlain( const QString &text )
 {
-    int len = d->m_text.length();
+    int len = text.length();
 
     if (len == 0)
-        return d->m_text;
+        return text;
 
     //Can assume len >= 1 from now on.
     QString stripped;
@@ -135,7 +135,7 @@ QString KGuiItem::plainText() const
     int resultLength = 0;
     stripped.setLength(len);
 
-    const QChar* data    = d->m_text.unicode();
+    const QChar* data    = text.unicode();
     for ( int pos = 0; pos < len; pos++ )
     {
         if ( data[ pos ] != '&' )
@@ -149,6 +149,11 @@ QString KGuiItem::plainText() const
     return stripped;
 }
 
+QString KGuiItem::plainText() const
+{
+    return textToPlain(d->m_text);
+}
+
 QIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) \
const  {
     if( d->m_hasIcon )
Index: kguiitem.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kguiitem.h,v
retrieving revision 1.10
diff -u -p -r1.10 kguiitem.h
--- kguiitem.h	8 Sep 2004 19:30:57 -0000	1.10
+++ kguiitem.h	22 Sep 2004 13:22:05 -0000
@@ -57,6 +57,7 @@ public:
 
     ~KGuiItem();
 
+    static QString textToPlain( const QString &text );
     QString text() const;
     QString plainText() const;
     QIconSet iconSet( KIcon::Group, int size = 0, KInstance* instance = \
                KGlobal::instance()) const;
Index: ktoolbar.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbar.cpp,v
retrieving revision 1.390
diff -u -p -r1.390 ktoolbar.cpp
--- ktoolbar.cpp	16 Sep 2004 21:28:08 -0000	1.390
+++ ktoolbar.cpp	22 Sep 2004 13:22:15 -0000
@@ -73,6 +73,7 @@ enum {
     CONTEXT_TEXT = 7,
     CONTEXT_TEXTRIGHT = 8,
     CONTEXT_TEXTUNDER = 9,
+    CONTEXT_TEXTIMPORTANT = 10,
     CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything \
else before  };
 
@@ -82,6 +83,7 @@ public:
     KToolBarPrivate() {
         m_iconSize     = 0;
         m_iconText     = KToolBar::IconOnly;
+        m_iconTextImportant = false;
         m_highlight    = true;
         m_transparent  = true;
         m_honorStyle   = false;
@@ -96,6 +98,7 @@ public:
 
         IconSizeDefault = 0;
         IconTextDefault = "IconOnly";
+        IconTextImportantDefault = false;
 
         NewLineDefault = false;
         OffsetDefault = 0;
@@ -113,6 +116,7 @@ public:
     bool m_enableContext : 1;
     bool modified : 1;
     bool positioned : 1;
+    bool m_iconTextImportant : 1;
 
     QWidget *m_parent;
 
@@ -137,6 +141,7 @@ public:
   bool HiddenDefault;
   int IconSizeDefault;
   QString IconTextDefault;
+  bool IconTextImportantDefault;
   bool NewLineDefault;
   int OffsetDefault;
   QString PositionDefault;
@@ -860,13 +865,24 @@ void KToolBar::setIconText(IconText icon
     }
 }
 
-
 KToolBar::IconText KToolBar::iconText() const
 {
     return d->m_iconText;
 }
 
 
+void KToolBar::setIconTextImportant(bool b)
+{
+    d->m_iconTextImportant = b;
+    doModeChange();
+}
+
+bool KToolBar::iconTextImportant()
+{
+    return d->m_iconTextImportant;
+}
+
+
 void KToolBar::setIconSize(int size)
 {
     setIconSize( size, true );
@@ -1066,6 +1082,20 @@ void KToolBar::saveSettings(KConfig *con
       config->writeEntry("IconText", icontext);
     }
 
+    if(d->m_honorStyle && d->m_iconTextImportant ==
+            d->IconTextImportantDefault &&
+            !config->hasDefault("IconTextImportant") )
+    {
+      //kdDebug(220) << name() << "                reverting icontext to default" << \
endl; +      config->revertToDefault("IconTextImportant");
+    }
+    else
+    {
+      //kdDebug(220) << name() << "                writing icontext " << icontext << \
endl; +      config->writeEntry("IconTextImportant", d->m_iconTextImportant ? "true" \
: +              "false");
+    }
+
     if(!config->hasDefault("IconSize") && iconSize() == d->IconSizeDefault )
       config->revertToDefault("IconSize");
     else
@@ -1191,6 +1221,9 @@ void KToolBar::mousePressEvent ( QMouseE
             case CONTEXT_TEXTUNDER:
                 setIconText( IconTextBottom );
                 break;
+            case CONTEXT_TEXTIMPORTANT:
+                setIconTextImportant( !d->m_iconTextImportant );
+                break;
             default:
                 if ( i >= CONTEXT_ICONSIZES )
                     setIconSize( i - CONTEXT_ICONSIZES );
@@ -1504,6 +1537,16 @@ KToolBar::IconText KToolBar::iconTextSet
         return IconOnly;
 }
 
+bool KToolBar::iconTextImportantSetting()
+{
+    QString grpToolbar(QString::fromLatin1("Toolbar style"));
+    KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
+    QString icontext = \
KGlobal::config()->readEntry(QString::fromLatin1("IconTextImportant"),QString::fromLatin1("false"));
 +    if ( icontext == "true" )
+        return true;
+    return false;
+}
+
 void KToolBar::applyAppearanceSettings(KConfig *config, const QString &_configGroup, \
bool forceGlobal)  {
     QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
@@ -1522,6 +1565,7 @@ void KToolBar::applyAppearanceSettings(K
     static const QString &attrHighlight = KGlobal::staticQString("Highlighting");
     static const QString &attrTrans     = \
                KGlobal::staticQString("TransparentMoving");
     static const QString &attrIconSize  = KGlobal::staticQString("IconSize");
+    static const QString &attrIconTextImportant = \
KGlobal::staticQString("IconTextImportant");  
     // we actually do this in two steps.
     // First, we read in the global styles [Toolbar style] (from the KControl \
module). @@ -1530,9 +1574,11 @@ void KToolBar::applyAppearanceSettings(K
     int transparent;
     bool applyIconText = !xmlgui; // if xmlgui is used, global defaults won't apply
     bool applyIconSize = !xmlgui;
+    bool applyIconTextImportant = !xmlgui;
 
     int iconSize = d->IconSizeDefault;
     QString iconText = d->IconTextDefault;
+    bool iconTextImportant = false;
 
     // this is the first iteration
     QString grpToolbar(QString::fromLatin1("Toolbar style"));
@@ -1545,10 +1591,15 @@ void KToolBar::applyAppearanceSettings(K
 
         // we read in the IconText property *only* if we intend on actually
         // honoring it
-        if (d->m_honorStyle)
+        if (d->m_honorStyle) {
             d->IconTextDefault = gconfig->readEntry(attrIconText, \
                d->IconTextDefault);
-        else
+            d->IconTextImportantDefault =
+                gconfig->readBoolEntry(attrIconTextImportant,
+                        d->IconTextImportantDefault);
+        } else {
             d->IconTextDefault = "IconOnly";
+            d->IconTextImportantDefault = false;
+        }
 
         // Use the default icon size for toolbar icons.
         d->IconSizeDefault = gconfig->readNumEntry(attrIconSize, \
d->IconSizeDefault); @@ -1571,6 +1622,13 @@ void KToolBar::applyAppearanceSettings(K
                 //kdDebug(220) << name() << " read icontext=" << d->IconTextDefault \
<< ", that will be the default" << endl;  }
 
+            // read in the IconTextImportant property
+            if ( config->hasKey( attrIconTextImportant ) ) {
+                iconTextImportant = config->readBoolEntry(attrIconTextImportant);
+                applyIconTextImportant = true;
+                //kdDebug(220) << name() << " read icontext=" << d->IconTextDefault \
<< ", that will be the default" << endl; +            }
+
             // now get the size
             if ( config->hasKey( attrIconSize ) ) {
                 iconSize = config->readNumEntry(attrIconSize);
@@ -1600,6 +1658,11 @@ void KToolBar::applyAppearanceSettings(K
         doUpdate = true;
     }
 
+    if (iconTextImportant != d->m_iconTextImportant && applyIconTextImportant) {
+        d->m_iconTextImportant = iconTextImportant;
+        doUpdate = true;
+    }
+
     // ...and check if the icon size has changed
     if (iconSize != d->m_iconSize && applyIconSize) {
         setIconSize(iconSize, false);
@@ -1810,6 +1873,17 @@ void KToolBar::loadState( const QDomElem
     }
 
     {
+        QCString attrIconTextImportant = element.attribute( "iconTextImportant" \
).lower().latin1(); +        if ( !attrIconTextImportant.isEmpty() ) {
+            setIconTextImportant ( attrIconTextImportant == "true" );
+        } else
+        {
+            if (d->m_honorStyle)
+                setIconTextImportant( iconTextImportantSetting() );
+        }
+    }
+
+    {
         QString attrIconSize = element.attribute( "iconSize" ).lower();
         if ( !attrIconSize.isEmpty() )
             d->IconSizeDefault = attrIconSize.toInt();
@@ -1931,6 +2005,8 @@ void KToolBar::saveState( QDomElement &c
     current.setAttribute( "noMerge", "1" );
     current.setAttribute( "position", position );
     current.setAttribute( "iconText", icontext );
+    current.setAttribute( "iconTextImportant",
+            d->m_iconTextImportant ? "true" : "false" );
     current.setAttribute( "index", index );
     current.setAttribute( "offset", offset() );
     current.setAttribute( "newline", newLine() );
@@ -1990,6 +2066,8 @@ KPopupMenu *KToolBar::contextMenu()
   mode->insertItem( i18n("Text Only"), CONTEXT_TEXT );
   mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT );
   mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER );
+  mode->insertSeparator(-1);
+  mode->insertItem( i18n("Show Only Important Text"), CONTEXT_TEXTIMPORTANT );
 
   KPopupMenu *size = new KPopupMenu( context, "size" );
   size->insertItem( i18n("Default"), CONTEXT_ICONSIZES );
@@ -2108,6 +2186,10 @@ void KToolBar::slotContextAboutToShow()
             context->setItemChecked(CONTEXT_TEXTUNDER, true);
             break;
   }
+  context->setItemEnabled(CONTEXT_TEXTIMPORTANT,
+          (d->m_iconText == IconTextRight)
+          || (d->m_iconText == IconTextBottom));
+  context->setItemChecked(CONTEXT_TEXTIMPORTANT, d->m_iconTextImportant);
 
   QValueList<int>::ConstIterator iIt = d->iconSizes.begin();
   QValueList<int>::ConstIterator iEnd = d->iconSizes.end();
Index: ktoolbar.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbar.h,v
retrieving revision 1.180
diff -u -p -r1.180 ktoolbar.h
--- ktoolbar.h	8 Sep 2004 19:30:58 -0000	1.180
+++ ktoolbar.h	22 Sep 2004 13:22:28 -0000
@@ -827,6 +827,9 @@ public:
    */
     IconText iconText() const;
 
+    void setIconTextImportant(bool b);
+    bool iconTextImportant();
+
   /**
    * Set the icon size to load. Usually you should not call
    * this, the icon size is taken care of by KIconLoader
@@ -1067,6 +1070,12 @@ public:
      */
     static IconText iconTextSetting();
 
+    /**
+     * Returns the global setting for "Show Only Important (Icon) Text"
+     * @return global setting for "Show Only Important (Icon) Text"
+     */
+    static bool iconTextImportantSetting();
+
 public slots:
     virtual void setIconText( const QString &txt )
     { QToolBar::setIconText( txt ); }
Index: ktoolbarbutton.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbarbutton.cpp,v
retrieving revision 1.79
diff -u -p -r1.79 ktoolbarbutton.cpp
--- ktoolbarbutton.cpp	12 Aug 2004 12:04:54 -0000	1.79
+++ ktoolbarbutton.cpp	22 Sep 2004 13:22:33 -0000
@@ -65,6 +65,7 @@ public:
     m_iconName    = QString::null;
     m_iconText    = KToolBar::IconOnly;
     m_iconSize    = 0;
+    m_shortText   = "";
 
     m_parent   = 0;
     m_instance = KGlobal::instance();
@@ -80,6 +81,7 @@ public:
   bool    m_highlight: 1;
   bool    m_isRaised: 1;
   bool    m_isActive: 1;
+  QString m_shortText;
 
   QString m_iconName;
 
@@ -189,6 +191,11 @@ void KToolBarButton::modeChange()
   if (!d->m_iconName.isNull())
     setIcon(d->m_iconName);
 
+  // make the text-less icons prettier (symmetric)
+  if (textLabel().isEmpty() && (d->m_iconText == KToolBar::IconTextRight
+              || (d->m_iconText == KToolBar::IconTextBottom)))
+      d->m_iconText = KToolBar::IconOnly;
+
   // we'll start with the size of our pixmap
   int pix_width  = d->m_iconSize;
   if ( d->m_iconSize == 0 ) {
@@ -215,10 +222,12 @@ void KToolBarButton::modeChange()
     text_width  = fm.width(textLabel());
 
     // none of the other modes want tooltips
+    if(tooltipText() != textLabel())
+        QToolTip::add(this, tooltipText());
   }
   else
   {
-    QToolTip::add(this, textLabel());
+    QToolTip::add(this, tooltipText());
   }
 
   switch (d->m_iconText)
@@ -273,6 +282,29 @@ void KToolBarButton::setText( const QStr
   modeChange();
 }
 
+void KToolBarButton::setShortText( const QString &txt )
+{
+  d->m_shortText = txt;
+  /* if (d->m_iconText == KToolBar::IconTextRight || d->m_iconText ==
+          KToolBar::IconTextBottom) */
+  modeChange();
+}
+
+QString KToolBarButton::textLabel()
+{
+  if (d->m_parent)
+      if (d->m_parent->iconTextImportant()) {
+          if (d->m_iconText == KToolBar::TextOnly && d->m_shortText.isEmpty())
+              return QToolButton::textLabel();
+          return d->m_shortText;
+      }
+  return QToolButton::textLabel();
+}
+QString KToolBarButton::tooltipText()
+{
+  return QToolButton::textLabel();
+}
+
 void KToolBarButton::setIcon( const QString &icon )
 {
   d->m_iconName = icon;
Index: ktoolbarbutton.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbarbutton.h,v
retrieving revision 1.37
diff -u -p -r1.37 ktoolbarbutton.h
--- ktoolbarbutton.h	8 Sep 2004 19:30:58 -0000	1.37
+++ ktoolbarbutton.h	22 Sep 2004 13:22:33 -0000
@@ -268,6 +268,10 @@ public slots:
    */
    void modeChange();
    virtual void setTextLabel(const QString&, bool tipToo);
+   /// @since 3.4
+   void setShortText(const QString &text); // XXX: probably make virtual for 4.0
+   QString textLabel();
+   QString tooltipText();
 
 protected:
   void paletteChange(const QPalette &);


[Attachment #6 (application/pgp-signature)]

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

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