improved calcHiddenButtons()

svn path=/trunk/kdebase/kwin/; revision=400782
This commit is contained in:
Sandro Giessl 2005-03-26 16:26:31 +00:00
parent 99c7f10187
commit 46482b1d0e
2 changed files with 27 additions and 20 deletions

View file

@ -41,7 +41,8 @@
KCommonDecoration::KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory) KCommonDecoration::KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory)
: KDecoration (bridge, factory), : KDecoration (bridge, factory),
m_previewWidget(0), m_previewWidget(0),
minBtnHideWidth(200), btnHideMinWidth(200),
btnHideLastWidth(0),
closing(false) closing(false)
{ {
// sizeof(...) is calculated at compile time // sizeof(...) is calculated at compile time
@ -275,10 +276,11 @@ void KCommonDecoration::resetLayout()
updateLayout(); updateLayout();
const int minTitleBarWidth = 35; const int minTitleBarWidth = 35;
minBtnHideWidth = buttonContainerWidth(m_buttonsLeft,true) + buttonContainerWidth(m_buttonsRight,true) + btnHideMinWidth = buttonContainerWidth(m_buttonsLeft,true) + buttonContainerWidth(m_buttonsRight,true) +
layoutMetric(LM_TitleEdgeLeft,false) + layoutMetric(LM_TitleEdgeRight,false) + layoutMetric(LM_TitleEdgeLeft,false) + layoutMetric(LM_TitleEdgeRight,false) +
layoutMetric(LM_TitleBorderLeft,false) + layoutMetric(LM_TitleBorderRight,false) + layoutMetric(LM_TitleBorderLeft,false) + layoutMetric(LM_TitleBorderRight,false) +
minTitleBarWidth; minTitleBarWidth;
btnHideLastWidth = 0;
} }
int KCommonDecoration::buttonsLeftWidth() const int KCommonDecoration::buttonsLeftWidth() const
@ -446,8 +448,12 @@ void KCommonDecoration::addButtons(ButtonContainer &btnContainer, const QString&
void KCommonDecoration::calcHiddenButtons() void KCommonDecoration::calcHiddenButtons()
{ {
//Hide buttons in this order: if (width() == btnHideLastWidth)
//Shade, Below, Above, OnAllDesktops, Help, Maximize, Menu, Minimize, Close. return;
btnHideLastWidth = width();
//Hide buttons in the following order:
KCommonDecorationButton* btnArray[] = { m_button[HelpButton], m_button[ShadeButton], m_button[BelowButton], KCommonDecorationButton* btnArray[] = { m_button[HelpButton], m_button[ShadeButton], m_button[BelowButton],
m_button[AboveButton], m_button[OnAllDesktopsButton], m_button[MaxButton], m_button[AboveButton], m_button[OnAllDesktopsButton], m_button[MaxButton],
m_button[MinButton], m_button[MenuButton], m_button[CloseButton] }; m_button[MinButton], m_button[MenuButton], m_button[CloseButton] };
@ -455,28 +461,27 @@ void KCommonDecoration::calcHiddenButtons()
int current_width = width(); int current_width = width();
int count = 0; int count = 0;
int i;
// Find out how many buttons we have to hide. // Hide buttons
while (current_width < minBtnHideWidth && count < buttonsCount) while (current_width < btnHideMinWidth && count < buttonsCount)
{ {
if (btnArray[count] ) if (btnArray[count] ) {
current_width += btnArray[count]->width(); current_width += btnArray[count]->width();
if (btnArray[count]->isVisible() )
btnArray[count]->hide();
}
count++; count++;
} }
// Hide the required buttons...
for(i = 0; i < count; i++)
{
if (btnArray[i] && btnArray[i]->isVisible() )
btnArray[i]->hide();
}
// Show the rest of the buttons... // Show the rest of the buttons...
for(i = count; i < buttonsCount; i++) for(int i = count; i < buttonsCount; i++)
{ {
if (btnArray[i] && (!btnArray[i]->isVisible()) ) if (btnArray[i] ) {
if (! btnArray[i]->isHidden() )
break; // all buttons shown...
btnArray[i]->show(); btnArray[i]->show();
}
} }
} }

View file

@ -265,7 +265,6 @@ class KWIN_EXPORT KCommonDecoration : public KDecoration
typedef QValueVector <KCommonDecorationButton*> ButtonContainer; ///< If the entry is 0, it's a spacer. typedef QValueVector <KCommonDecorationButton*> ButtonContainer; ///< If the entry is 0, it's a spacer.
int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const; int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const;
void addButtons(ButtonContainer &btnContainer, const QString& buttons, bool isLeft); void addButtons(ButtonContainer &btnContainer, const QString& buttons, bool isLeft);
void calcHiddenButtons();
KCommonDecorationButton *m_button[NumButtons]; KCommonDecorationButton *m_button[NumButtons];
@ -274,7 +273,10 @@ class KWIN_EXPORT KCommonDecoration : public KDecoration
QWidget *m_previewWidget; QWidget *m_previewWidget;
int minBtnHideWidth; // button hiding for small windows
void calcHiddenButtons();
int btnHideMinWidth;
int btnHideLastWidth;
bool closing; // for menu doubleclick closing... bool closing; // for menu doubleclick closing...