save reset calls in setSize() etc., inform buttons about what has changed in reset() so they can better optimize for performance

svn path=/trunk/kdebase/kwin/; revision=397485
icc-effect-5.14.5
Sandro Giessl 2005-03-14 09:33:29 +00:00
parent 66ee8c3b4d
commit 7f9e658fb3
2 changed files with 33 additions and 8 deletions

View File

@ -193,6 +193,12 @@ void KCommonDecoration::updateButtons() const
if (m_button[n]) m_button[n]->update();
}
void KCommonDecoration::resetButtons() const
{
for (int n=0; n<NumButtons; n++)
if (m_button[n]) m_button[n]->reset(KCommonDecorationButton::ManualReset);
}
void KCommonDecoration::resetLayout()
{
for (int n=0; n<NumButtons; n++) {
@ -738,7 +744,7 @@ ButtonType KCommonDecorationButton::type()
return m_type;;
}
void KCommonDecorationButton::reset()
void KCommonDecorationButton::reset(unsigned long)
{
}
@ -749,10 +755,12 @@ void KCommonDecorationButton::setRealizeButtons(int btns)
void KCommonDecorationButton::setSize(const QSize &s)
{
m_size = s;
if (s != size() ) {
m_size = s;
setFixedSize(m_size);
reset();
setFixedSize(m_size);
reset(SizeChange);
}
}
QSize KCommonDecorationButton::sizeHint() const
@ -768,13 +776,15 @@ void KCommonDecorationButton::setTipText(const QString &tip) {
void KCommonDecorationButton::setToggleButton(bool toggle)
{
QButton::setToggleButton(toggle);
reset();
reset(ToggleChange);
}
void KCommonDecorationButton::setOn(bool on)
{
QButton::setOn(on);
reset();
if (on != isOn() ) {
QButton::setOn(on);
reset(StateChange);
}
}
void KCommonDecorationButton::mousePressEvent(QMouseEvent* e)

View File

@ -201,6 +201,10 @@ class KWIN_EXPORT KCommonDecoration : public KDecoration
* Makes sure all buttons are repainted.
*/
void updateButtons() const;
/**
* Manually call reset() on each button.
*/
void resetButtons() const;
/**
* Convenience method.
@ -276,10 +280,21 @@ class KWIN_EXPORT KCommonDecorationButton : public QButton
KCommonDecorationButton(ButtonType type, KCommonDecoration *parent, const char *name);
~KCommonDecorationButton();
/**
* These flags specify what has changed, e.g. the reason for a reset().
*/
enum
{
ManualReset = 1 << 0, ///< The button might want to do a full reset for some reason...
SizeChange = 1 << 1, ///< The button size changed @see setSize()
ToggleChange = 1 << 2, ///< The button toggle state has changed @see setToggleButton()
StateChange = 1 << 3, ///< The button has been set pressed or not... @see setOn()
DecorationReset = 1 << 4 ///< E.g. when decoration colors have changed
};
/**
* Initialize the button after size change etc.
*/
virtual void reset();
virtual void reset(unsigned long changed);
/**
* @returns the KCommonDecoration the button belongs to.
*/