summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-06-29 13:38:06 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-06-29 13:38:45 (GMT)
commit82c48b13249fbcd96d8287f3cd1fdfd61802523c (patch)
tree5713b0936f049492990db70acdd6da2c53e63781 /src/gui/widgets
parenta9c225e6b464337d253e6b9aa5eaac82d01b3301 (diff)
downloadQt-82c48b13249fbcd96d8287f3cd1fdfd61802523c.zip
Qt-82c48b13249fbcd96d8287f3cd1fdfd61802523c.tar.gz
Qt-82c48b13249fbcd96d8287f3cd1fdfd61802523c.tar.bz2
QMenuBar: adding autotest and simplify/fix geometry calculation
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qmenubar.cpp21
-rw-r--r--src/gui/widgets/qmenubar_p.h3
2 files changed, 9 insertions, 15 deletions
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index a31dc67..5a8c0e2 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -198,8 +198,6 @@ void QMenuBarPrivate::updateGeometries()
}
#endif
calcActionRects(q_width, q_start);
- itemsWidth = q_width;
- itemsStart = q_start;
currentAction = 0;
#ifndef QT_NO_SHORTCUT
if(itemsDirty) {
@@ -271,6 +269,9 @@ QRect QMenuBarPrivate::actionRect(QAction *act) const
if (index == -1)
return QRect();
+ //makes sure the geometries are up-to-date
+ const_cast<QMenuBarPrivate*>(this)->updateGeometries();
+
QRect ret = actionRects.at(index);
const int fw = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);
ret.translate(fw, fw);
@@ -415,9 +416,9 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const
{
Q_Q(const QMenuBar);
- if(!itemsDirty && itemsWidth == max_width && itemsStart == start) {
+ if(!itemsDirty)
return;
- }
+
//let's reinitialize the buffer
actionRects.resize(actions.count());
actionRects.fill(QRect());
@@ -1658,17 +1659,11 @@ QSize QMenuBar::sizeHint() const
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) {
- QMap<QAction*, QRect> actionRects;
- QList<QAction*> actionList;
const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0);
- for (QMap<QAction*, QRect>::const_iterator i = actionRects.constBegin();
- i != actionRects.constEnd(); ++i) {
- QRect actionRect(i.value());
- if(actionRect.x() + actionRect.width() > ret.width())
- ret.setWidth(actionRect.x() + actionRect.width());
- if(actionRect.y() + actionRect.height() > ret.height())
- ret.setHeight(actionRect.y() + actionRect.height());
+ for (int i = 0; i < d->actionRects.count(); ++i) {
+ const QRect &actionRect = d->actionRects.at(i);
+ ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height()));
}
ret += QSize(2*fw + 2*hmargin, 2*fw + 2*vmargin);
}
diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h
index 5b209b2..bac1912 100644
--- a/src/gui/widgets/qmenubar_p.h
+++ b/src/gui/widgets/qmenubar_p.h
@@ -69,7 +69,7 @@ class QMenuBarPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QMenuBar)
public:
- QMenuBarPrivate() : itemsDirty(0), itemsWidth(0), itemsStart(-1), currentAction(0), mouseDown(0),
+ QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0),
closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0),
nativeMenuBar(-1)
#ifdef Q_WS_MAC
@@ -95,7 +95,6 @@ public:
//item calculations
uint itemsDirty : 1;
- int itemsWidth, itemsStart;
QVector<int> shortcutIndexMap;
mutable QVector<QRect> actionRects;