[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [PATCH] "Show only important text" mode for toolbars
From: "Peter Rockai \(mornfall\)" <mornfall () danill ! sk>
Date: 2004-09-22 2:20:26
Message-ID: 200409220420.45936.mornfall () danill ! sk
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hello!
I spoke with Aaron yesterday on IRC about toolbar plans for 3.4 and I asked
what about the text-alongside-icons mode and overly long texts. He suggested
adding a flag like textImportant to the actions and a checkbox (and toolbar
context menu item) to show/hide "unimportant" texts. This is an initial
implementation, sticking the "text important" flag to KAction. It should be
fairly complete, with toolbar configuration handling and everything. I'd be
happy if someone could review the patch. I have done some amount of testing
with various apps, but i'm not 100% of it (given it's past 4 am already).
Also, i'm not sure if the result of IconTextBottom mode and KToolBar's
iconTextImportant flag being both in effect at the same time is optimal.
Attached are patches for kdelibs/kdeui and kdebase/kcontrol/style.
Yours,
Peter
["kdeui.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 01:53:34 -0000
@@ -79,6 +79,7 @@ public:
{
m_kaccel = 0;
m_configurable = true;
+ m_toolbarTextImportant = false;
}
KAccel *m_kaccel;
@@ -90,7 +91,8 @@ public:
KShortcut m_cut;
KShortcut m_cutDefault;
- bool m_configurable;
+ bool m_configurable: 1;
+ bool m_toolbarTextImportant: 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_ )->setIconTextImportant(d->m_toolbarTextImportant);
if ( !d->whatsThis().isEmpty() )
QWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() );
@@ -828,6 +831,11 @@ void KAction::setShortcutConfigurable( b
d->m_configurable = b;
}
+void KAction::setToolbarTextImportant( bool b )
+{
+ d->m_toolbarTextImportant = b;
+}
+
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 01:53:36 -0000
@@ -540,6 +540,12 @@ public slots:
*/
virtual void activate();
+ /**
+ * Indicate whether this item's text is important to show.
+ * @since 3.4
+ */
+ void setToolbarTextImportant(bool enabled);
+
protected slots:
virtual void slotDestroyed();
virtual void slotKeycodeChanged();
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 01:53:44 -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 01:53:47 -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 01:53:49 -0000
@@ -65,6 +65,7 @@ public:
m_iconName = QString::null;
m_iconText = KToolBar::IconOnly;
m_iconSize = 0;
+ m_iconTextImportant = false;
m_parent = 0;
m_instance = KGlobal::instance();
@@ -80,6 +81,7 @@ public:
bool m_highlight: 1;
bool m_isRaised: 1;
bool m_isActive: 1;
+ bool m_iconTextImportant: 1;
QString m_iconName;
@@ -183,6 +185,11 @@ void KToolBarButton::modeChange()
if (d->m_parent) {
d->m_highlight = d->m_parent->highlight();
d->m_iconText = d->m_parent->iconText();
+ if (d->m_iconText == KToolBar::IconTextRight
+ || d->m_iconText == KToolBar::IconTextBottom) {
+ if (d->m_parent->iconTextImportant() && ! d->m_iconTextImportant)
+ d->m_iconText = KToolBar::IconOnly;
+ }
d->m_iconSize = d->m_parent->iconSize();
}
@@ -273,6 +280,12 @@ void KToolBarButton::setText( const QStr
modeChange();
}
+void KToolBarButton::setIconTextImportant (bool important)
+{
+ d->m_iconTextImportant = important;
+ modeChange();
+}
+
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 01:53:50 -0000
@@ -268,6 +268,8 @@ public slots:
*/
void modeChange();
virtual void setTextLabel(const QString&, bool tipToo);
+ /// @since 3.4
+ void setIconTextImportant(bool important); // XXX: probably make virtual for 4.0
protected:
void paletteChange(const QPalette &);
@@ -286,6 +288,8 @@ protected:
bool isActive() const;
/// @since 3.1
int iconTextMode() const;
+ /// @since 3.4
+ bool iconTextImportant() const;
protected slots:
void slotClicked();
["kcontrol-style.diff" (text/x-diff)]
Index: kcmstyle.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/style/kcmstyle.cpp,v
retrieving revision 1.77
diff -u -p -r1.77 kcmstyle.cpp
--- kcmstyle.cpp 18 Jul 2004 23:05:47 -0000 1.77
+++ kcmstyle.cpp 22 Sep 2004 02:02:46 -0000
@@ -335,6 +335,7 @@ KCMStyle::KCMStyle( QWidget* parent, con
gbToolbarSettings = new QGroupBox( 1, Qt::Horizontal, i18n("Toolbar Settings"), page3 );
cbHoverButtons = new QCheckBox( i18n("High&light buttons under mouse"), gbToolbarSettings );
cbTransparentToolbars = new QCheckBox( i18n("Transparent tool&bars when moving"), gbToolbarSettings );
+ cbToolbarText = new QCheckBox( i18n("Show only important text"), gbToolbarSettings );
QWidget * dummy = new QWidget( gbToolbarSettings );
QHBoxLayout* box2 = new QHBoxLayout( dummy, 0, KDialog::spacingHint() );
@@ -344,6 +345,8 @@ KCMStyle::KCMStyle( QWidget* parent, con
comboToolbarIcons->insertItem( i18n("Text Only") );
comboToolbarIcons->insertItem( i18n("Text Alongside Icons") );
comboToolbarIcons->insertItem( i18n("Text Under Icons") );
+ connect( comboToolbarIcons, SIGNAL(activated(int)), this, SLOT(toolbarIconsChanged()) );
+ connect( comboToolbarIcons, SIGNAL(highlighted(int)), this, SLOT(toolbarIconsChanged()) );
lbl->setBuddy( comboToolbarIcons );
box2->addWidget( lbl );
@@ -374,6 +377,7 @@ KCMStyle::KCMStyle( QWidget* parent, con
// Page3
connect( cbHoverButtons, SIGNAL(toggled(bool)), this, SLOT(setToolbarsDirty()));
connect( cbTransparentToolbars, SIGNAL(toggled(bool)), this, SLOT(setToolbarsDirty()));
+ connect( cbToolbarText, SIGNAL(toggled(bool)), this, SLOT(setToolbarsDirty()));
connect( cbEnableTooltips, SIGNAL(toggled(bool)), this, SLOT(setEffectsDirty()));
connect( cbIconsOnButtons, SIGNAL(toggled(bool)), this, SLOT(setEffectsDirty()));
connect( cbTearOffHandles, SIGNAL(toggled(bool)), this, SLOT(setEffectsDirty()));
@@ -589,6 +593,7 @@ void KCMStyle::save()
config.setGroup("Toolbar style");
config.writeEntry( "Highlighting", cbHoverButtons->isChecked(), true, true );
config.writeEntry( "TransparentMoving", cbTransparentToolbars->isChecked(), true, true );
+ config.writeEntry( "IconTextImportant", cbToolbarText->isChecked(), true, true );
QString tbIcon;
switch( comboToolbarIcons->currentItem() )
{
@@ -1022,12 +1027,23 @@ void KCMStyle::menuEffectChanged( bool e
// All the Miscellaneous stuff
// ----------------------------------------------------------------
+void KCMStyle::toolbarIconsChanged()
+{
+ switch( comboToolbarIcons->currentItem()) {
+ case 0: case 1:
+ cbToolbarText->setEnabled(false); break;
+ case 2: case 3:
+ cbToolbarText->setEnabled(true); break;
+ }
+}
+
void KCMStyle::loadMisc( KConfig& config )
{
// KDE's Part via KConfig
config.setGroup("Toolbar style");
cbHoverButtons->setChecked(config.readBoolEntry("Highlighting", true));
cbTransparentToolbars->setChecked(config.readBoolEntry("TransparentMoving", true));
+ cbToolbarText->setChecked(config.readBoolEntry("IconTextImportant", false));
QString tbIcon = config.readEntry("IconText", "IconOnly");
if (tbIcon == "TextOnly")
Index: kcmstyle.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/style/kcmstyle.h,v
retrieving revision 1.20
diff -u -p -r1.20 kcmstyle.h
--- kcmstyle.h 18 Jul 2004 23:05:47 -0000 1.20
+++ kcmstyle.h 22 Sep 2004 02:02:46 -0000
@@ -93,6 +93,7 @@ protected slots:
void menuEffectChanged( bool enabled );
void menuEffectChanged();
void menuEffectTypeChanged();
+ void toolbarIconsChanged();
private:
QString currentStyle();
@@ -154,6 +155,7 @@ private:
QCheckBox* cbTransparentToolbars;
QCheckBox* cbEnableTooltips;
QComboBox* comboToolbarIcons;
+ QCheckBox* cbToolbarText;
QCheckBox* cbIconsOnButtons;
QCheckBox* cbTearOffHandles;
[Attachment #7 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic