[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdeui
From: Aurélien Gâteau <agateau () kde ! org>
Date: 2010-10-22 21:39:43
Message-ID: 20101022213943.0F220AC89A () svn ! kde ! org
[Download RAW message or body]
SVN commit 1188666 by gateau:
Simplified API of KDualAction:
- Removed KDualAction::State enum
- Created set{Active,Inactive}* getters and setters
M +18 -55 actions/kdualaction.cpp
M +58 -18 actions/kdualaction.h
M +31 -1 actions/kdualaction_p.h
M +8 -8 tests/kdualactiontest.cpp
M +2 -2 xmlgui/kxmlguiwindow.cpp
--- trunk/KDE/kdelibs/kdeui/actions/kdualaction.cpp #1188665:1188666
@@ -25,11 +25,6 @@
#include "kdualaction_p.h"
-inline bool boolForState(KDualAction::State state)
-{
- return state == KDualAction::ActiveState;
-}
-
//---------------------------------------------------------------------
// KDualActionPrivate
//---------------------------------------------------------------------
@@ -85,64 +80,32 @@
delete d;
}
-void KDualAction::setGuiItemForState(KDualAction::State state, const KGuiItem &item)
-{
- d->item(state) = item;
- if (boolForState(state) == d->isActive) {
- d->updateFromCurrentState();
- }
-}
+void KDualAction::setActiveGuiItem(const KGuiItem &item) { d->setGuiItem(true, \
item); } +KGuiItem KDualAction::activeGuiItem() const { return \
d->item(true); } +void KDualAction::setInactiveGuiItem(const KGuiItem &item) { \
d->setGuiItem(false, item); } +KGuiItem KDualAction::inactiveGuiItem() const \
{ return d->item(false); }
-KGuiItem KDualAction::guiItemForState(KDualAction::State state) const
-{
- return d->item(state);
-}
+void KDualAction::setActiveIcon(const QIcon &icon) { d->setIcon(true, icon); }
+QIcon KDualAction::activeIcon() const { return d->item(true).icon(); \
} +void KDualAction::setInactiveIcon(const QIcon &icon) { d->setIcon(false, icon); }
+QIcon KDualAction::inactiveIcon() const { return d->item(false).icon(); \
}
-void KDualAction::setTextForState(KDualAction::State state, const QString &text)
-{
- d->item(state).setText(text);
- if (boolForState(state) == d->isActive) {
- d->updateFromCurrentState();
- }
-}
+void KDualAction::setActiveText(const QString &text) { d->setText(true, text); }
+QString KDualAction::activeText() const { return \
d->item(true).text(); } +void KDualAction::setInactiveText(const QString &text) { \
d->setText(false, text); } +QString KDualAction::inactiveText() const { \
return d->item(false).text(); }
-QString KDualAction::textForState(KDualAction::State state) const
-{
- return d->item(state).text();
-}
+void KDualAction::setActiveToolTip(const QString &toolTip) { d->setToolTip(true, \
toolTip); } +QString KDualAction::activeToolTip() const { return \
d->item(true).toolTip(); } +void KDualAction::setInactiveToolTip(const QString \
&toolTip) { d->setToolTip(false, toolTip); } +QString KDualAction::inactiveToolTip() \
const { return d->item(false).toolTip(); }
-void KDualAction::setIconForState(KDualAction::State state, const QIcon &icon)
-{
- d->item(state).setIcon(KIcon(icon));
- if (boolForState(state) == d->isActive) {
- d->updateFromCurrentState();
- }
-}
-
void KDualAction::setIconForStates(const QIcon &icon)
{
- setIconForState(KDualAction::InactiveState, icon);
- setIconForState(KDualAction::ActiveState, icon);
+ setInactiveIcon(icon);
+ setActiveIcon(icon);
}
-QIcon KDualAction::iconForState(KDualAction::State state) const
-{
- return d->item(state).icon();
-}
-
-void KDualAction::setToolTipForState(KDualAction::State state, const QString \
&toolTip)
-{
- d->item(state).setToolTip(toolTip);
- if (boolForState(state) == d->isActive) {
- d->updateFromCurrentState();
- }
-}
-
-QString KDualAction::toolTipForState(KDualAction::State state) const
-{
- return d->item(state).toolTip();
-}
-
void KDualAction::setAutoToggle(bool value)
{
d->autoToggle = value;
--- trunk/KDE/kdelibs/kdeui/actions/kdualaction.h #1188665:1188666
@@ -80,51 +80,91 @@
~KDualAction();
/**
- * Sets the icon, text and tooltip for the state with a KGuiItem.
+ * Sets the KGuiItem for the active state
*/
- void setGuiItemForState(State state, const KGuiItem &item);
+ void setActiveGuiItem(const KGuiItem &);
/**
- * Gets the KGuiItem for the state.
+ * Gets the KGuiItem for the active state
*/
- KGuiItem guiItemForState(State state) const;
+ KGuiItem activeGuiItem() const;
/**
- * Sets the text for the state.
+ * Sets the KGuiItem for the inactive state
*/
- void setTextForState(State state, const QString &text);
+ void setInactiveGuiItem(const KGuiItem &);
/**
- * Gets the text for the state.
+ * Gets the KGuiItem for the inactive state
*/
- QString textForState(State state) const;
+ KGuiItem inactiveGuiItem() const;
/**
- * Convenience method to set the icon for both active and inactive states.
+ * Sets the icon for the active state
*/
- void setIconForStates(const QIcon &icon);
+ void setActiveIcon(const QIcon &);
/**
- * Sets the icon for the state.
+ * Gets the icon for the active state
*/
- void setIconForState(State state, const QIcon &icon);
+ QIcon activeIcon() const;
/**
- * Gets the icon for the state.
+ * Sets the icon for the inactive state
*/
- QIcon iconForState(State) const;
+ void setInactiveIcon(const QIcon &);
/**
- * Sets the tooltip for the state.
+ * Gets the icon for the inactive state
*/
- void setToolTipForState(State state, const QString &tip);
+ QIcon inactiveIcon() const;
/**
- * Gets the tooltip for the state.
+ * Sets the text for the active state
*/
- QString toolTipForState(State state) const;
+ void setActiveText(const QString &);
/**
+ * Gets the text for the active state
+ */
+ QString activeText() const;
+
+ /**
+ * Sets the text for the inactive state
+ */
+ void setInactiveText(const QString &);
+
+ /**
+ * Gets the text for the inactive state
+ */
+ QString inactiveText() const;
+
+ /**
+ * Sets the tooltip for the active state
+ */
+ void setActiveToolTip(const QString &);
+
+ /**
+ * Gets the tooltip for the active state
+ */
+ QString activeToolTip() const;
+
+ /**
+ * Sets the tooltip for the inactive state
+ */
+ void setInactiveToolTip(const QString &);
+
+ /**
+ * Gets the tooltip for the inactive state
+ */
+ QString inactiveToolTip() const;
+
+ /**
+ * Convenience method to set the icon for both active and inactive states.
+ */
+ void setIconForStates(const QIcon &icon);
+
+ /**
* Returns the action state.
*/
bool isActive() const;
--- trunk/KDE/kdelibs/kdeui/actions/kdualaction_p.h #1188665:1188666
@@ -32,8 +32,38 @@
void init(KDualAction *q_ptr);
void updateFromCurrentState();
KGuiItem& item(bool active) { return active ? items[1] : items[0]; }
- KGuiItem& item(KDualAction::State state) { return state == \
KDualAction::ActiveState ? items[1] : items[0]; } void slotTriggered();
+
+ void updatedItem(bool active)
+ {
+ if (active == isActive) {
+ updateFromCurrentState();
+ }
+ }
+
+ void setGuiItem(bool active, const KGuiItem &_item)
+ {
+ item(active) = _item;
+ updatedItem(active);
+ }
+
+ void setIcon(bool active, const QIcon &icon)
+ {
+ item(active).setIcon(KIcon(icon));
+ updatedItem(active);
+ }
+
+ void setText(bool active, const QString &text)
+ {
+ item(active).setText(text);
+ updatedItem(active);
+ }
+
+ void setToolTip(bool active, const QString &toolTip)
+ {
+ item(active).setToolTip(toolTip);
+ updatedItem(active);
+ }
};
#endif /* KDUALACTION_P_H */
--- trunk/KDE/kdelibs/kdeui/tests/kdualactiontest.cpp #1188665:1188666
@@ -39,10 +39,10 @@
void testSetGuiItem()
{
KDualAction action(0);
- action.setGuiItemForState(KDualAction::InactiveState, \
KGuiItem(INACTIVE_TEXT));
- action.setGuiItemForState(KDualAction::ActiveState, KGuiItem(ACTIVE_TEXT));
- QCOMPARE(action.textForState(KDualAction::InactiveState), INACTIVE_TEXT);
- QCOMPARE(action.textForState(KDualAction::ActiveState), ACTIVE_TEXT);
+ action.setInactiveGuiItem(KGuiItem(INACTIVE_TEXT));
+ action.setActiveGuiItem(KGuiItem(ACTIVE_TEXT));
+ QCOMPARE(action.inactiveText(), INACTIVE_TEXT);
+ QCOMPARE(action.activeText(), ACTIVE_TEXT);
QCOMPARE(action.text(), INACTIVE_TEXT);
}
@@ -50,11 +50,11 @@
{
QIcon icon = KIcon("kde");
KDualAction action(0);
- QVERIFY(action.iconForState(KDualAction::InactiveState).isNull());
- QVERIFY(action.iconForState(KDualAction::ActiveState).isNull());
+ QVERIFY(action.inactiveIcon().isNull());
+ QVERIFY(action.activeIcon().isNull());
action.setIconForStates(icon);
- QCOMPARE(action.iconForState(KDualAction::InactiveState), icon);
- QCOMPARE(action.iconForState(KDualAction::ActiveState), icon);
+ QCOMPARE(action.inactiveIcon(), icon);
+ QCOMPARE(action.activeIcon(), icon);
}
void testSetActive()
--- trunk/KDE/kdelibs/kdeui/xmlgui/kxmlguiwindow.cpp #1188665:1188666
@@ -328,8 +328,8 @@
} else {
// If the language has changed, we'll need to grab the new text and \
whatsThis
KDualAction *tmpStatusBar = KStandardAction::showHideStatusbar(NULL, NULL, \
NULL);
- d->showStatusBarAction->setGuiItemForState(KDualAction::InactiveState, \
tmpStatusBar->guiItemForState(KDualAction::InactiveState));
- d->showStatusBarAction->setGuiItemForState(KDualAction::ActiveState, \
tmpStatusBar->guiItemForState(KDualAction::ActiveState)); + \
d->showStatusBarAction->setInactiveGuiItem(tmpStatusBar->inactiveGuiItem()); + \
d->showStatusBarAction->setActiveGuiItem(tmpStatusBar->activeGuiItem()); delete \
tmpStatusBar; }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic