summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorJanne Anttila <janne.anttila@digia.com>2010-03-12 11:32:38 (GMT)
committerJanne Anttila <janne.anttila@digia.com>2010-03-12 11:36:11 (GMT)
commit7829fe1507741c7196fe3904d90ea10178625393 (patch)
tree2062721f23dc7e8bb0c9d234058c6bb3602a1855 /src/gui/widgets
parent76c0bc4f95fce3c5fd9f77b778180d1b50b2b095 (diff)
downloadQt-7829fe1507741c7196fe3904d90ea10178625393.zip
Qt-7829fe1507741c7196fe3904d90ea10178625393.tar.gz
Qt-7829fe1507741c7196fe3904d90ea10178625393.tar.bz2
Moved softkey "Options" action handling from QMainWindow to QMenuBar.
This change is done to enable QMenuBar usage and related "Options" softkey also on other than QMainWindow objects. For example with this change it is possible to create menubar and set it to QLayout by using setMenuBar, and it will then be usable via "Options" softkey. This functionality makes it easy to use different menus for different views in QStackedWidget. Task-number: QT-2275 (Not yet finished, but related) Reviewed-by: Sami Merila Reviewed-by: Alessandro Portale
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qmainwindow.cpp25
-rw-r--r--src/gui/widgets/qmenu_symbian.cpp8
-rw-r--r--src/gui/widgets/qmenubar.cpp51
-rw-r--r--src/gui/widgets/qmenubar_p.h5
4 files changed, 55 insertions, 34 deletions
diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp
index 7e59bb0..16a7c31 100644
--- a/src/gui/widgets/qmainwindow.cpp
+++ b/src/gui/widgets/qmainwindow.cpp
@@ -65,9 +65,6 @@ QT_BEGIN_NAMESPACE
extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp
QT_END_NAMESPACE
#endif
-#ifdef QT_SOFTKEYS_ENABLED
-#include <private/qsoftkeymanager_p.h>
-#endif
QT_BEGIN_NAMESPACE
@@ -80,9 +77,6 @@ public:
#ifdef Q_WS_MAC
, useHIToolBar(false)
#endif
-#ifdef QT_SOFTKEYS_ENABLED
- , menuBarAction(0)
-#endif
#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR)
, hasOldCursor(false) , cursorAdjusted(false)
#endif
@@ -94,9 +88,6 @@ public:
#ifdef Q_WS_MAC
bool useHIToolBar;
#endif
-#ifdef QT_SOFTKEYS_ENABLED
- QAction *menuBarAction;
-#endif
void init();
QList<int> hoverSeparator;
QPoint hoverPos;
@@ -117,10 +108,6 @@ void QMainWindowPrivate::init()
const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q);
iconSize = QSize(metric, metric);
q->setAttribute(Qt::WA_Hover);
-#ifdef QT_SOFTKEYS_ENABLED
- menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, q);
- menuBarAction->setVisible(false);
-#endif
}
/*
@@ -492,13 +479,6 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar)
oldMenuBar->deleteLater();
}
d->layout->setMenuBar(menuBar);
-
-#ifdef QT_SOFTKEYS_ENABLED
- if (menuBar)
- addAction(d->menuBarAction);
- else
- removeAction(d->menuBarAction);
-#endif
}
/*!
@@ -1427,11 +1407,6 @@ bool QMainWindow::event(QEvent *event)
}
break;
#endif
-#ifdef QT_SOFTKEYS_ENABLED
- case QEvent::LanguageChange:
- d->menuBarAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::MenuSoftKey));
- break;
-#endif
default:
break;
}
diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp
index e46688c..7224768 100644
--- a/src/gui/widgets/qmenu_symbian.cpp
+++ b/src/gui/widgets/qmenu_symbian.cpp
@@ -324,6 +324,14 @@ void QMenuBarPrivate::symbianDestroyMenuBar()
symbian_menubar = 0;
}
+void QMenuBarPrivate::reparentMenuBar(QWidget *oldParent, QWidget *newParent)
+{
+ if (menubars()->contains(oldParent)) {
+ QMenuBarPrivate *object = menubars()->take(oldParent);
+ menubars()->insert(newParent, object);
+ }
+}
+
QMenuBarPrivate::QSymbianMenuBarPrivate::QSymbianMenuBarPrivate(QMenuBarPrivate *menubar)
{
d = menubar;
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index 9caadb7..13aa02b 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -71,6 +71,10 @@
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
#endif
+#ifdef QT_SOFTKEYS_ENABLED
+#include <private/qsoftkeymanager_p.h>
+#endif
+
QT_BEGIN_NAMESPACE
class QMenuBarExtension : public QToolButton
@@ -740,17 +744,14 @@ void QMenuBarPrivate::init()
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
}
#endif
-#ifdef Q_WS_S60
- symbianCreateMenuBar(q->parentWidget());
- if(symbian_menubar)
- q->hide();
-#endif
-
q->setBackgroundRole(QPalette::Button);
oldWindow = oldParent = 0;
#ifdef QT3_SUPPORT
doAutoResize = false;
#endif
+#ifdef QT_SOFTKEYS_ENABLED
+ menuBarAction = 0;
+#endif
handleReparent();
q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q));
@@ -1384,10 +1385,38 @@ void QMenuBarPrivate::handleReparent()
wce_menubar->rebuild();
#endif
#ifdef Q_WS_S60
- if (symbian_menubar)
+
+ // Construct symbian_menubar when this code path is entered first time
+ // and when newParent != NULL
+ if (!symbian_menubar)
+ symbianCreateMenuBar(newParent);
+
+ // Reparent and rebuild menubar when parent is changed
+ if (symbian_menubar) {
+ if (oldParent != newParent)
+ reparentMenuBar(oldParent, newParent);
+ q->hide();
symbian_menubar->rebuild();
-#endif
+ }
+#ifdef QT_SOFTKEYS_ENABLED
+ // Constuct menuBarAction when this code path is entered first time
+ if (!menuBarAction) {
+ if (newParent) {
+ menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent);
+ menuBarAction->setVisible(false);
+ newParent->addAction(menuBarAction);
+ }
+ } else {
+ // If reparenting i.e. we already have menuBarAction, remove it from old parent
+ // and add for a new parent
+ if (oldParent)
+ oldParent->removeAction(menuBarAction);
+ if (newParent)
+ newParent->addAction(menuBarAction);
+ }
+#endif // QT_SOFTKEYS_ENABLED
+#endif // Q_WS_S60
}
#ifdef QT3_SUPPORT
@@ -1440,7 +1469,13 @@ void QMenuBar::changeEvent(QEvent *e)
|| e->type() == QEvent::ApplicationFontChange) {
d->itemsDirty = true;
d->updateGeometries();
+#ifdef QT_SOFTKEYS_ENABLED
+ } else if (e->type() == QEvent::LanguageChange) {
+ if (d->menuBarAction)
+ d->menuBarAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::MenuSoftKey));
+#endif
}
+
QWidget::changeEvent(e);
}
diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h
index f2e5357..e4db6ce 100644
--- a/src/gui/widgets/qmenubar_p.h
+++ b/src/gui/widgets/qmenubar_p.h
@@ -243,6 +243,7 @@ public:
#ifdef Q_WS_S60
void symbianCreateMenuBar(QWidget *);
void symbianDestroyMenuBar();
+ void reparentMenuBar(QWidget *oldParent, QWidget *newParent);
struct QSymbianMenuBarPrivate {
QList<QSymbianMenuAction*> actionItems;
QMenuBarPrivate *d;
@@ -267,7 +268,9 @@ public:
} *symbian_menubar;
static int symbianCommands(int command);
-
+#ifdef QT_SOFTKEYS_ENABLED
+ QAction *menuBarAction;
+#endif
#endif
};
#endif