Fix copyright and a few codestyle mistakes

Reviewed-By: Trust-Me
Merge-Request: 916
(cherry picked from commit 56c3de426d97ab7c8fbb3f5766e1872d6f2e91e9)
This commit is contained in:
Thierry Bastian 2011-04-14 11:26:34 +02:00 committed by Olivier Goffart
parent 278b4ed012
commit 2e768aad98
3 changed files with 113 additions and 114 deletions

View File

@ -122,8 +122,8 @@ QSize QMenuBarExtension::sizeHint() const
*/ */
QAction *QMenuBarPrivate::actionAt(QPoint p) const QAction *QMenuBarPrivate::actionAt(QPoint p) const
{ {
for(int i = 0; i < actions.size(); ++i) { for (int i = 0; i < actions.size(); ++i) {
if(actionRect(actions.at(i)).contains(p)) if (actionRect(actions.at(i)).contains(p))
return actions.at(i); return actions.at(i);
} }
return 0; return 0;
@ -171,12 +171,12 @@ bool QMenuBarPrivate::isVisible(QAction *action)
void QMenuBarPrivate::updateGeometries() void QMenuBarPrivate::updateGeometries()
{ {
Q_Q(QMenuBar); Q_Q(QMenuBar);
if(!itemsDirty) if (!itemsDirty)
return; return;
int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2); int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2);
int q_start = -1; int q_start = -1;
if(impl->allowCornerWidgets() && (leftWidget || rightWidget)) { if (impl->allowCornerWidgets() && (leftWidget || rightWidget)) {
int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q) int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q)
+ q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);
int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q) int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q)
@ -199,7 +199,7 @@ void QMenuBarPrivate::updateGeometries()
} }
#ifndef QT_NO_SHORTCUT #ifndef QT_NO_SHORTCUT
if(!impl->shortcutsHandledByNativeMenuBar() && itemsDirty) { if (!impl->shortcutsHandledByNativeMenuBar() && itemsDirty) {
for(int j = 0; j < shortcutIndexMap.size(); ++j) for(int j = 0; j < shortcutIndexMap.size(); ++j)
q->releaseShortcut(shortcutIndexMap.value(j)); q->releaseShortcut(shortcutIndexMap.value(j));
shortcutIndexMap.resize(0); // faster than clear shortcutIndexMap.resize(0); // faster than clear
@ -207,7 +207,7 @@ void QMenuBarPrivate::updateGeometries()
shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text())));
} }
#endif #endif
if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. if (q->isNativeMenuBar()) {//nothing to see here folks, move along..
itemsDirty = false; itemsDirty = false;
return; return;
} }
@ -282,7 +282,7 @@ QRect QMenuBarPrivate::actionRect(QAction *act) const
void QMenuBarPrivate::focusFirstAction() void QMenuBarPrivate::focusFirstAction()
{ {
if(!currentAction) { if (!currentAction) {
updateGeometries(); updateGeometries();
int index = 0; int index = 0;
while (index < actions.count() && actionRects.at(index).isNull()) ++index; while (index < actions.count() && actionRects.at(index).isNull()) ++index;
@ -299,16 +299,16 @@ void QMenuBarPrivate::setKeyboardMode(bool b)
return; return;
} }
keyboardState = b; keyboardState = b;
if(b) { if (b) {
QWidget *fw = QApplication::focusWidget(); QWidget *fw = QApplication::focusWidget();
if (fw != q) if (fw != q)
keyboardFocusWidget = fw; keyboardFocusWidget = fw;
focusFirstAction(); focusFirstAction();
q->setFocus(Qt::MenuBarFocusReason); q->setFocus(Qt::MenuBarFocusReason);
} else { } else {
if(!popupState) if (!popupState)
setCurrentAction(0); setCurrentAction(0);
if(keyboardFocusWidget) { if (keyboardFocusWidget) {
if (QApplication::focusWidget() == q) if (QApplication::focusWidget() == q)
keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason);
keyboardFocusWidget = 0; keyboardFocusWidget = 0;
@ -320,7 +320,7 @@ void QMenuBarPrivate::setKeyboardMode(bool b)
void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
{ {
Q_Q(QMenuBar); Q_Q(QMenuBar);
if(!action || !action->menu() || closePopupMode) if (!action || !action->menu() || closePopupMode)
return; return;
popupState = true; popupState = true;
if (action->isEnabled() && action->menu()->isEnabled()) { if (action->isEnabled() && action->menu()->isEnabled()) {
@ -360,10 +360,10 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
pos.rx() += actionWidth; pos.rx() += actionWidth;
} }
if(!defaultPopDown || (fitUp && !fitDown)) if (!defaultPopDown || (fitUp && !fitDown))
pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y())); pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
activeMenu->popup(pos); activeMenu->popup(pos);
if(activateFirst) if (activateFirst)
activeMenu->d_func()->setFirstActionActive(); activeMenu->d_func()->setFirstActionActive();
} }
q->update(actionRect(action)); q->update(actionRect(action));
@ -371,7 +371,7 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst) void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst)
{ {
if(currentAction == action && popup == popupState) if (currentAction == action && popup == popupState)
return; return;
autoReleaseTimer.stop(); autoReleaseTimer.stop();
@ -379,7 +379,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat
doChildEffects = (popup && !activeMenu); doChildEffects = (popup && !activeMenu);
Q_Q(QMenuBar); Q_Q(QMenuBar);
QWidget *fw = 0; QWidget *fw = 0;
if(QMenu *menu = activeMenu) { if (QMenu *menu = activeMenu) {
activeMenu = 0; activeMenu = 0;
if (popup) { if (popup) {
fw = q->window()->focusWidget(); fw = q->window()->focusWidget();
@ -388,7 +388,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat
menu->hide(); menu->hide();
} }
if(currentAction) if (currentAction)
q->update(actionRect(currentAction)); q->update(actionRect(currentAction));
popupState = popup; popupState = popup;
@ -398,7 +398,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat
currentAction = action; currentAction = action;
if (action) { if (action) {
activateAction(action, QAction::Hover); activateAction(action, QAction::Hover);
if(popup) if (popup)
popupAction(action, activateFirst); popupAction(action, activateFirst);
q->update(actionRect(action)); q->update(actionRect(action));
#ifndef QT_NO_STATUSTIP #ifndef QT_NO_STATUSTIP
@ -416,7 +416,7 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const
{ {
Q_Q(const QMenuBar); Q_Q(const QMenuBar);
if(!itemsDirty) if (!itemsDirty)
return; return;
//let's reinitialize the buffer //let's reinitialize the buffer
@ -435,13 +435,13 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const
icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q); icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q);
for(int i = 0; i < actions.count(); i++) { for(int i = 0; i < actions.count(); i++) {
QAction *action = actions.at(i); QAction *action = actions.at(i);
if(!action->isVisible()) if (!action->isVisible())
continue; continue;
QSize sz; QSize sz;
//calc what I think the size is.. //calc what I think the size is..
if(action->isSeparator()) { i f(action->isSeparator()) {
if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q))
separator = i; separator = i;
continue; //we don't really position these! continue; //we don't really position these!
@ -460,10 +460,10 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const
q->initStyleOption(&opt, action); q->initStyleOption(&opt, action);
sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q); sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q);
if(!sz.isEmpty()) { if (!sz.isEmpty()) {
{ //update the separator state { //update the separator state
int iWidth = sz.width() + itemSpacing; int iWidth = sz.width() + itemSpacing;
if(separator == -1) if (separator == -1)
separator_start += iWidth; separator_start += iWidth;
else else
separator_len += iWidth; separator_len += iWidth;
@ -488,9 +488,9 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const
rect.setHeight(max_item_height); rect.setHeight(max_item_height);
//move //move
if(separator != -1 && i >= separator) { //after the separator if (separator != -1 && i >= separator) { //after the separator
int left = (max_width - separator_len - hmargin - itemSpacing) + (x - separator_start - hmargin); int left = (max_width - separator_len - hmargin - itemSpacing) + (x - separator_start - hmargin);
if(left < separator_start) { //wrap if (left < separator_start) { //wrap
separator_start = x = hmargin; separator_start = x = hmargin;
y += max_item_height; y += max_item_height;
} }
@ -517,9 +517,9 @@ void QMenuBarPrivate::activateAction(QAction *action, QAction::ActionEvent actio
if (action_e == QAction::Hover) if (action_e == QAction::Hover)
action->showStatusText(q); action->showStatusText(q);
// if(action_e == QAction::Trigger) // if (action_e == QAction::Trigger)
// emit q->activated(action); // emit q->activated(action);
// else if(action_e == QAction::Hover) // else if (action_e == QAction::Hover)
// emit q->highlighted(action); // emit q->highlighted(action);
} }
@ -1011,7 +1011,7 @@ void QMenuBar::paintEvent(QPaintEvent *e)
QRect adjustedActionRect = d->actionRect(action); QRect adjustedActionRect = d->actionRect(action);
if (adjustedActionRect.isEmpty() || !d->isVisible(action)) if (adjustedActionRect.isEmpty() || !d->isVisible(action))
continue; continue;
if(!e->rect().intersects(adjustedActionRect)) if (!e->rect().intersects(adjustedActionRect))
continue; continue;
emptyArea -= adjustedActionRect; emptyArea -= adjustedActionRect;
@ -1022,7 +1022,7 @@ void QMenuBar::paintEvent(QPaintEvent *e)
style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this); style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this);
} }
//draw border //draw border
if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) { if (int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) {
QRegion borderReg; QRegion borderReg;
borderReg += QRect(0, 0, fw, height()); //left borderReg += QRect(0, 0, fw, height()); //left
borderReg += QRect(width()-fw, 0, fw, height()); //right borderReg += QRect(width()-fw, 0, fw, height()); //right
@ -1064,7 +1064,7 @@ void QMenuBar::setVisible(bool visible)
void QMenuBar::mousePressEvent(QMouseEvent *e) void QMenuBar::mousePressEvent(QMouseEvent *e)
{ {
Q_D(QMenuBar); Q_D(QMenuBar);
if(e->button() != Qt::LeftButton) if (e->button() != Qt::LeftButton)
return; return;
d->mouseDown = true; d->mouseDown = true;
@ -1079,13 +1079,13 @@ void QMenuBar::mousePressEvent(QMouseEvent *e)
return; return;
} }
if(d->currentAction == action && d->popupState) { if (d->currentAction == action && d->popupState) {
if(QMenu *menu = d->activeMenu) { if (QMenu *menu = d->activeMenu) {
d->activeMenu = 0; d->activeMenu = 0;
menu->hide(); menu->hide();
} }
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
if((d->closePopupMode = style()->styleHint(QStyle::SH_MenuBar_DismissOnSecondClick))) if ((d->closePopupMode = style()->styleHint(QStyle::SH_MenuBar_DismissOnSecondClick)))
update(d->actionRect(action)); update(d->actionRect(action));
#endif #endif
} else { } else {
@ -1099,16 +1099,16 @@ void QMenuBar::mousePressEvent(QMouseEvent *e)
void QMenuBar::mouseReleaseEvent(QMouseEvent *e) void QMenuBar::mouseReleaseEvent(QMouseEvent *e)
{ {
Q_D(QMenuBar); Q_D(QMenuBar);
if(e->button() != Qt::LeftButton || !d->mouseDown) if (e->button() != Qt::LeftButton || !d->mouseDown)
return; return;
d->mouseDown = false; d->mouseDown = false;
QAction *action = d->actionAt(e->pos()); QAction *action = d->actionAt(e->pos());
if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) { if ((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) {
//we set the current action before activating //we set the current action before activating
//so that we let the leave event set the current back to 0 //so that we let the leave event set the current back to 0
d->setCurrentAction(action, false); d->setCurrentAction(action, false);
if(action) if (action)
d->activateAction(action, QAction::Trigger); d->activateAction(action, QAction::Trigger);
} }
d->closePopupMode = 0; d->closePopupMode = 0;
@ -1122,15 +1122,15 @@ void QMenuBar::keyPressEvent(QKeyEvent *e)
Q_D(QMenuBar); Q_D(QMenuBar);
d->updateGeometries(); d->updateGeometries();
int key = e->key(); int key = e->key();
if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed if (isRightToLeft()) { // in reverse mode open/close key for submenues are reversed
if(key == Qt::Key_Left) if (key == Qt::Key_Left)
key = Qt::Key_Right; key = Qt::Key_Right;
else if(key == Qt::Key_Right) else if (key == Qt::Key_Right)
key = Qt::Key_Left; key = Qt::Key_Left;
} }
if(key == Qt::Key_Tab) //means right if (key == Qt::Key_Tab) //means right
key = Qt::Key_Right; key = Qt::Key_Right;
else if(key == Qt::Key_Backtab) //means left else if (key == Qt::Key_Backtab) //means left
key = Qt::Key_Left; key = Qt::Key_Left;
bool key_consumed = false; bool key_consumed = false;
@ -1140,11 +1140,11 @@ void QMenuBar::keyPressEvent(QKeyEvent *e)
case Qt::Key_Enter: case Qt::Key_Enter:
case Qt::Key_Space: case Qt::Key_Space:
case Qt::Key_Return: { case Qt::Key_Return: {
if(!style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this) || !d->currentAction) if (!style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this) || !d->currentAction)
break; break;
if(d->currentAction->menu()) { if (d->currentAction->menu()) {
d->popupAction(d->currentAction, true); d->popupAction(d->currentAction, true);
} else if(key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Space) { } else if (key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Space) {
d->activateAction(d->currentAction, QAction::Trigger); d->activateAction(d->currentAction, QAction::Trigger);
d->setCurrentAction(d->currentAction, false); d->setCurrentAction(d->currentAction, false);
d->setKeyboardMode(false); d->setKeyboardMode(false);
@ -1154,7 +1154,7 @@ void QMenuBar::keyPressEvent(QKeyEvent *e)
case Qt::Key_Right: case Qt::Key_Right:
case Qt::Key_Left: { case Qt::Key_Left: {
if(d->currentAction) { if (d->currentAction) {
int index = d->actions.indexOf(d->currentAction); int index = d->actions.indexOf(d->currentAction);
if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) { if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) {
d->setCurrentAction(nextAction, d->popupState, true); d->setCurrentAction(nextAction, d->popupState, true);
@ -1173,7 +1173,7 @@ void QMenuBar::keyPressEvent(QKeyEvent *e)
key_consumed = false; key_consumed = false;
} }
if(!key_consumed && if (!key_consumed &&
(!e->modifiers() || (!e->modifiers() ||
(e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) { (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) {
int clashCount = 0; int clashCount = 0;
@ -1185,14 +1185,14 @@ void QMenuBar::keyPressEvent(QKeyEvent *e)
continue; continue;
QAction *act = d->actions.at(i); QAction *act = d->actions.at(i);
QString s = act->text(); QString s = act->text();
if(!s.isEmpty()) { if (!s.isEmpty()) {
int ampersand = s.indexOf(QLatin1Char('&')); int ampersand = s.indexOf(QLatin1Char('&'));
if(ampersand >= 0) { if (ampersand >= 0) {
if(s[ampersand+1].toUpper() == c) { if (s[ampersand+1].toUpper() == c) {
clashCount++; clashCount++;
if(!first) if (!first)
first = act; first = act;
if(act == d->currentAction) if (act == d->currentAction)
currentSelected = act; currentSelected = act;
else if (!firstAfterCurrent && currentSelected) else if (!firstAfterCurrent && currentSelected)
firstAfterCurrent = act; firstAfterCurrent = act;
@ -1202,18 +1202,18 @@ void QMenuBar::keyPressEvent(QKeyEvent *e)
} }
} }
QAction *next_action = 0; QAction *next_action = 0;
if(clashCount >= 1) { if (clashCount >= 1) {
if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent)) if (clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent))
next_action = first; next_action = first;
else else
next_action = firstAfterCurrent; next_action = firstAfterCurrent;
} }
if(next_action) { if (next_action) {
key_consumed = true; key_consumed = true;
d->setCurrentAction(next_action, true, true); d->setCurrentAction(next_action, true, true);
} }
} }
if(key_consumed) if (key_consumed)
e->accept(); e->accept();
else else
e->ignore(); e->ignore();
@ -1239,7 +1239,7 @@ void QMenuBar::mouseMoveEvent(QMouseEvent *e)
void QMenuBar::leaveEvent(QEvent *) void QMenuBar::leaveEvent(QEvent *)
{ {
Q_D(QMenuBar); Q_D(QMenuBar);
if((!hasFocus() && !d->popupState) || if ((!hasFocus() && !d->popupState) ||
(d->currentAction && d->currentAction->menu() == 0)) (d->currentAction && d->currentAction->menu() == 0))
d->setCurrentAction(0); d->setCurrentAction(0);
} }
@ -1253,10 +1253,10 @@ void QMenuBar::actionEvent(QActionEvent *e)
d->itemsDirty = true; d->itemsDirty = true;
d->impl->actionEvent(e); d->impl->actionEvent(e);
if(e->type() == QEvent::ActionAdded) { if (e->type() == QEvent::ActionAdded) {
connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered()));
} else if(e->type() == QEvent::ActionRemoved) { } else if (e->type() == QEvent::ActionRemoved) {
e->action()->disconnect(this); e->action()->disconnect(this);
} }
if (isVisible()) { if (isVisible()) {
@ -1271,7 +1271,7 @@ void QMenuBar::actionEvent(QActionEvent *e)
void QMenuBar::focusInEvent(QFocusEvent *) void QMenuBar::focusInEvent(QFocusEvent *)
{ {
Q_D(QMenuBar); Q_D(QMenuBar);
if(d->keyboardState) if (d->keyboardState)
d->focusFirstAction(); d->focusFirstAction();
} }
@ -1281,7 +1281,7 @@ void QMenuBar::focusInEvent(QFocusEvent *)
void QMenuBar::focusOutEvent(QFocusEvent *) void QMenuBar::focusOutEvent(QFocusEvent *)
{ {
Q_D(QMenuBar); Q_D(QMenuBar);
if(!d->popupState) { if (!d->popupState) {
d->setCurrentAction(0); d->setCurrentAction(0);
d->setKeyboardMode(false); d->setKeyboardMode(false);
} }
@ -1371,10 +1371,10 @@ bool QMenuBar::autoGeometry() const
void QMenuBar::changeEvent(QEvent *e) void QMenuBar::changeEvent(QEvent *e)
{ {
Q_D(QMenuBar); Q_D(QMenuBar);
if(e->type() == QEvent::StyleChange) { if (e->type() == QEvent::StyleChange) {
d->itemsDirty = true; d->itemsDirty = true;
setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this)); setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this));
if(parentWidget()) if (parentWidget())
resize(parentWidget()->width(), heightForWidth(parentWidget()->width())); resize(parentWidget()->width(), heightForWidth(parentWidget()->width()));
d->updateGeometries(); d->updateGeometries();
} else if (e->type() == QEvent::ParentChange) { } else if (e->type() == QEvent::ParentChange) {
@ -1403,12 +1403,12 @@ bool QMenuBar::event(QEvent *e)
case QEvent::KeyPress: { case QEvent::KeyPress: {
QKeyEvent *ke = (QKeyEvent*)e; QKeyEvent *ke = (QKeyEvent*)e;
#if 0 #if 0
if(!d->keyboardState) { //all keypresses.. if (!d->keyboardState) { //all keypresses..
d->setCurrentAction(0); d->setCurrentAction(0);
return ; return ;
} }
#endif #endif
if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) { if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
keyPressEvent(ke); keyPressEvent(ke);
return true; return true;
} }
@ -1426,7 +1426,7 @@ bool QMenuBar::event(QEvent *e)
#endif #endif
case QEvent::Show: case QEvent::Show:
#ifdef QT3_SUPPORT #ifdef QT3_SUPPORT
if(QWidget *p = parentWidget()) { if (QWidget *p = parentWidget()) {
// If itemsDirty == true, updateGeometries sends the MenubarUpdated event. // If itemsDirty == true, updateGeometries sends the MenubarUpdated event.
if (!d->itemsDirty) { if (!d->itemsDirty) {
QMenubarUpdatedEvent menubarUpdated(this); QMenubarUpdatedEvent menubarUpdated(this);
@ -1448,7 +1448,7 @@ bool QMenuBar::event(QEvent *e)
#ifdef QT3_SUPPORT #ifdef QT3_SUPPORT
case QEvent::Hide: { case QEvent::Hide: {
if(QWidget *p = parentWidget()) { if (QWidget *p = parentWidget()) {
QMenubarUpdatedEvent menubarUpdated(this); QMenubarUpdatedEvent menubarUpdated(this);
QApplication::sendEvent(p, &menubarUpdated); QApplication::sendEvent(p, &menubarUpdated);
} }
@ -1584,7 +1584,7 @@ QSize QMenuBar::minimumSizeHint() const
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) { if (as_gui_menubar) {
int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0); d->calcActionRects(w - (2 * fw), 0);
for (int i = 0; ret.isNull() && i < d->actions.count(); ++i) for (int i = 0; ret.isNull() && i < d->actions.count(); ++i)
@ -1595,20 +1595,20 @@ QSize QMenuBar::minimumSizeHint() const
} }
int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
if (d->impl->allowCornerWidgets()) { if (d->impl->allowCornerWidgets()) {
if(d->leftWidget) { if (d->leftWidget) {
QSize sz = d->leftWidget->minimumSizeHint(); QSize sz = d->leftWidget->minimumSizeHint();
ret.setWidth(ret.width() + sz.width()); ret.setWidth(ret.width() + sz.width());
if(sz.height() + margin > ret.height()) if (sz.height() + margin > ret.height())
ret.setHeight(sz.height() + margin); ret.setHeight(sz.height() + margin);
} }
if(d->rightWidget) { if (d->rightWidget) {
QSize sz = d->rightWidget->minimumSizeHint(); QSize sz = d->rightWidget->minimumSizeHint();
ret.setWidth(ret.width() + sz.width()); ret.setWidth(ret.width() + sz.width());
if(sz.height() + margin > ret.height()) if (sz.height() + margin > ret.height())
ret.setHeight(sz.height() + margin); ret.setHeight(sz.height() + margin);
} }
} }
if(as_gui_menubar) { if (as_gui_menubar) {
QStyleOptionMenuItem opt; QStyleOptionMenuItem opt;
opt.rect = rect(); opt.rect = rect();
opt.menuRect = rect(); opt.menuRect = rect();
@ -1638,7 +1638,7 @@ QSize QMenuBar::sizeHint() const
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) { if (as_gui_menubar) {
const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0); d->calcActionRects(w - (2 * fw), 0);
for (int i = 0; i < d->actionRects.count(); ++i) { for (int i = 0; i < d->actionRects.count(); ++i) {
@ -1650,21 +1650,21 @@ QSize QMenuBar::sizeHint() const
ret += QSize(fw + hmargin, fw + vmargin); ret += QSize(fw + hmargin, fw + vmargin);
} }
int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
if(d->impl->allowCornerWidgets()) { if (d->impl->allowCornerWidgets()) {
if(d->leftWidget) { if (d->leftWidget) {
QSize sz = d->leftWidget->sizeHint(); QSize sz = d->leftWidget->sizeHint();
ret.setWidth(ret.width() + sz.width()); ret.setWidth(ret.width() + sz.width());
if(sz.height() + margin > ret.height()) if (sz.height() + margin > ret.height())
ret.setHeight(sz.height() + margin); ret.setHeight(sz.height() + margin);
} }
if(d->rightWidget) { if (d->rightWidget) {
QSize sz = d->rightWidget->sizeHint(); QSize sz = d->rightWidget->sizeHint();
ret.setWidth(ret.width() + sz.width()); ret.setWidth(ret.width() + sz.width());
if(sz.height() + margin > ret.height()) if (sz.height() + margin > ret.height())
ret.setHeight(sz.height() + margin); ret.setHeight(sz.height() + margin);
} }
} }
if(as_gui_menubar) { if (as_gui_menubar) {
QStyleOptionMenuItem opt; QStyleOptionMenuItem opt;
opt.rect = rect(); opt.rect = rect();
opt.menuRect = rect(); opt.menuRect = rect();
@ -1692,7 +1692,7 @@ int QMenuBar::heightForWidth(int) const
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) { if (as_gui_menubar) {
for (int i = 0; i < d->actionRects.count(); ++i) for (int i = 0; i < d->actionRects.count(); ++i)
height = qMax(height, d->actionRects.at(i).height()); height = qMax(height, d->actionRects.at(i).height());
if (height) //there is at least one non-null item if (height) //there is at least one non-null item
@ -1701,13 +1701,13 @@ int QMenuBar::heightForWidth(int) const
height += 2*vmargin; height += 2*vmargin;
} }
int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
if(d->impl->allowCornerWidgets()) { if (d->impl->allowCornerWidgets()) {
if(d->leftWidget) if (d->leftWidget)
height = qMax(d->leftWidget->sizeHint().height() + margin, height); height = qMax(d->leftWidget->sizeHint().height() + margin, height);
if(d->rightWidget) if (d->rightWidget)
height = qMax(d->rightWidget->sizeHint().height() + margin, height); height = qMax(d->rightWidget->sizeHint().height() + margin, height);
} }
if(as_gui_menubar) { if (as_gui_menubar) {
QStyleOptionMenuItem opt; QStyleOptionMenuItem opt;
opt.init(this); opt.init(this);
opt.menuRect = rect(); opt.menuRect = rect();
@ -1814,14 +1814,12 @@ void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner)
return; return;
} }
if(!d->impl->allowCornerWidgets()) { if (!d->impl->allowCornerWidgets()) {
d->updateCornerWidgetToolBar(); d->updateCornerWidgetToolBar();
} else { } else if (w) {
if (w) {
w->setParent(this); w->setParent(this);
w->installEventFilter(this); w->installEventFilter(this);
} }
}
d->_q_updateLayout(); d->_q_updateLayout();
} }
@ -1974,17 +1972,17 @@ int QMenuBar::insertAny(const QIcon *icon, const QString *text, const QObject *r
const QKeySequence *shortcut, const QMenu *popup, int id, int index) const QKeySequence *shortcut, const QMenu *popup, int id, int index)
{ {
QAction *act = popup ? popup->menuAction() : new QAction(this); QAction *act = popup ? popup->menuAction() : new QAction(this);
if(id != -1) if (id != -1)
static_cast<QMenuItem*>(act)->setId(id); static_cast<QMenuItem*>(act)->setId(id);
if(icon) if (icon)
act->setIcon(*icon); act->setIcon(*icon);
if(text) if (text)
act->setText(*text); act->setText(*text);
if(shortcut) if (shortcut)
act->setShortcut(*shortcut); act->setShortcut(*shortcut);
if(receiver && member) if (receiver && member)
QObject::connect(act, SIGNAL(triggered(bool)), receiver, member); QObject::connect(act, SIGNAL(triggered(bool)), receiver, member);
if(index == -1 || index >= actions().count()) if (index == -1 || index >= actions().count())
addAction(act); addAction(act);
else else
insertAction(actions().value(index), act); insertAction(actions().value(index), act);
@ -2006,7 +2004,7 @@ int QMenuBar::insertSeparator(int index)
{ {
QAction *act = new QAction(this); QAction *act = new QAction(this);
act->setSeparator(true); act->setSeparator(true);
if(index == -1 || index >= actions().count()) if (index == -1 || index >= actions().count())
addAction(act); addAction(act);
else else
insertAction(actions().value(index), act); insertAction(actions().value(index), act);
@ -2018,7 +2016,7 @@ int QMenuBar::insertSeparator(int index)
*/ */
bool QMenuBar::setItemParameter(int id, int param) bool QMenuBar::setItemParameter(int id, int param)
{ {
if(QAction *act = findActionForId(id)) { if (QAction *act = findActionForId(id)) {
act->d_func()->param = param; act->d_func()->param = param;
return true; return true;
} }
@ -2030,7 +2028,7 @@ bool QMenuBar::setItemParameter(int id, int param)
*/ */
int QMenuBar::itemParameter(int id) const int QMenuBar::itemParameter(int id) const
{ {
if(QAction *act = findActionForId(id)) if (QAction *act = findActionForId(id))
return act->d_func()->param; return act->d_func()->param;
return id; return id;
} }

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved. ** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com) ** Contact: Nokia Corporation (qt-info@nokia.com)
** **
@ -38,6 +38,7 @@
** $QT_END_LICENSE$ ** $QT_END_LICENSE$
** **
****************************************************************************/ ****************************************************************************/
#include "qmenubarimpl_p.h" #include "qmenubarimpl_p.h"
#ifndef QT_NO_MENUBAR #ifndef QT_NO_MENUBAR
@ -75,16 +76,15 @@ void QMenuBarImpl::init(QMenuBar *_menuBar)
#endif #endif
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
macCreateMenuBar(menuBar->parentWidget()); macCreateMenuBar(menuBar->parentWidget());
if(adapter) if (adapter)
menuBar->hide(); menuBar->hide();
#endif #endif
#ifdef Q_WS_WINCE #ifdef Q_WS_WINCE
if (qt_wince_is_mobile()) { if (qt_wince_is_mobile()) {
wceCreateMenuBar(menuBar->parentWidget()); wceCreateMenuBar(menuBar->parentWidget());
if(adapter) if (adapter)
menuBar->hide(); menuBar->hide();
} } else {
else {
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
} }
#endif #endif
@ -106,11 +106,11 @@ void QMenuBarImpl::actionEvent(QActionEvent *e)
{ {
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) #if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60)
if (adapter) { if (adapter) {
if(e->type() == QEvent::ActionAdded) if (e->type() == QEvent::ActionAdded)
adapter->addAction(e->action(), e->before()); adapter->addAction(e->action(), e->before());
else if(e->type() == QEvent::ActionRemoved) else if (e->type() == QEvent::ActionRemoved)
adapter->removeAction(e->action()); adapter->removeAction(e->action());
else if(e->type() == QEvent::ActionChanged) else if (e->type() == QEvent::ActionChanged)
adapter->syncAction(e->action()); adapter->syncAction(e->action());
} }
#else #else
@ -251,7 +251,7 @@ QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory()
QFactoryLoader loader(QMenuBarImplFactoryInterface_iid, QLatin1String("/menubar")); QFactoryLoader loader(QMenuBarImplFactoryInterface_iid, QLatin1String("/menubar"));
factory = qobject_cast<QMenuBarImplFactoryInterface *>(loader.instance(QLatin1String("default"))); factory = qobject_cast<QMenuBarImplFactoryInterface *>(loader.instance(QLatin1String("default")));
#endif // QT_NO_LIBRARY #endif // QT_NO_LIBRARY
if(!factory) { if (!factory) {
static QMenuBarImplFactory def; static QMenuBarImplFactory def;
factory = &def; factory = &def;
} }

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved. ** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com) ** Contact: Nokia Corporation (qt-info@nokia.com)
** **
@ -38,6 +38,7 @@
** $QT_END_LICENSE$ ** $QT_END_LICENSE$
** **
****************************************************************************/ ****************************************************************************/
#ifndef QMENUBARIMPL_P_H #ifndef QMENUBARIMPL_P_H
#define QMENUBARIMPL_P_H #define QMENUBARIMPL_P_H
@ -91,9 +92,9 @@ private:
void removeAction(QMacMenuAction *); void removeAction(QMacMenuAction *);
inline void removeAction(QAction *a) { removeAction(findAction(a)); } inline void removeAction(QAction *a) { removeAction(findAction(a)); }
inline QMacMenuAction *findAction(QAction *a) { inline QMacMenuAction *findAction(QAction *a) {
for(int i = 0; i < actionItems.size(); i++) { for (int i = 0; i < actionItems.size(); i++) {
QMacMenuAction *act = actionItems[i]; QMacMenuAction *act = actionItems[i];
if(a == act->action) if (a == act->action)
return act; return act;
} }
return 0; return 0;
@ -131,9 +132,9 @@ private:
void rebuild(); void rebuild();
inline void removeAction(QAction *a) { removeAction(findAction(a)); } inline void removeAction(QAction *a) { removeAction(findAction(a)); }
inline QWceMenuAction *findAction(QAction *a) { inline QWceMenuAction *findAction(QAction *a) {
for(int i = 0; i < actionItems.size(); i++) { for (int i = 0; i < actionItems.size(); i++) {
QWceMenuAction *act = actionItems[i]; QWceMenuAction *act = actionItems[i];
if(a == act->action) if (a == act->action)
return act; return act;
} }
return 0; return 0;
@ -161,9 +162,9 @@ private:
void rebuild(); void rebuild();
inline void removeAction(QAction *a) { removeAction(findAction(a)); } inline void removeAction(QAction *a) { removeAction(findAction(a)); }
inline QSymbianMenuAction *findAction(QAction *a) { inline QSymbianMenuAction *findAction(QAction *a) {
for(int i = 0; i < actionItems.size(); i++) { for (int i = 0; i < actionItems.size(); i++) {
QSymbianMenuAction *act = actionItems[i]; QSymbianMenuAction *act = actionItems[i];
if(a == act->action) if (a == act->action)
return act; return act;
} }
return 0; return 0;