From e89a2b72050dd782da16ff24bc2eb84dc36ed6a5 Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Tue, 12 Apr 2011 13:55:46 +0200 Subject: Fix incorrect rendering of checked menu items on Windows Classic Modify rendering of checked menu items when using Windows Classic style to be more native looking. Changes: * Checked menu items with no icon are not drawn sunken * Disabled checked menu items with an icon have a plain background instead of a checkerboard pattern same as when enabled * Check mark is drawn with highlighted text color when selected to match text * Fix check mark offset for disabled unselected checked menu item as the entire check mark was drawn shifted (1, 1) * Fix color of check mark shadow for disabled unselected checked menu item as it was same color as the check mark when it should be a light color Task-number: QTBUG-15098 Merge-request: 2513 Reviewed-by: Jens Bache-Wiig --- src/gui/styles/qcommonstyle.cpp | 13 +++++-------- src/gui/styles/qwindowsstyle.cpp | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 8f99d6a..3d04c9a 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -223,16 +223,13 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q --yy; } if (!(opt->state & State_Enabled) && !(opt->state & State_On)) { - int pnt; - p->setPen(opt->palette.highlightedText().color()); - QPoint offset(1, 1); - for (pnt = 0; pnt < a.size(); ++pnt) - a[pnt].translate(offset.x(), offset.y()); + p->save(); + p->translate(1, 1); + p->setPen(opt->palette.light().color()); p->drawLines(a); - for (pnt = 0; pnt < a.size(); ++pnt) - a[pnt].translate(offset.x(), offset.y()); + p->restore(); } - p->setPen(opt->palette.text().color()); + p->setPen((opt->state & State_On) ? opt->palette.highlightedText().color() : opt->palette.text().color()); p->drawLines(a); break; } case PE_Frame: diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp index 44f3f92..1dcfd00 100644 --- a/src/gui/styles/qwindowsstyle.cpp +++ b/src/gui/styles/qwindowsstyle.cpp @@ -1858,8 +1858,8 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai } QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height())); - if (checked) { - if (act && !dis) { + if (!menuitem->icon.isNull() && checked) { + if (act) { qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &menuitem->palette.brush(QPalette::Button)); -- cgit v0.12 From b00089261eafbdf5f92ed94d7fb20b402bfcaeb2 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 10 Nov 2010 11:21:53 +0100 Subject: Add the QIdentityProxyModel. Older commit history is in KDE svn: http://websvn.kde.org/trunk/KDE/kdelibs/kdeui/itemviews/kidentityproxymodel.cpp?view=log Ammended to update the license headers. Merge-request: 900 Reviewed-by: Gabriel de Dietrich --- .../model-view-programming.qdoc | 7 + .../code/src_gui_itemviews_qidentityproxymodel.cpp | 66 +++ src/corelib/kernel/qabstractitemmodel.h | 1 + src/gui/itemviews/itemviews.pri | 2 + src/gui/itemviews/qidentityproxymodel.cpp | 582 +++++++++++++++++++++ src/gui/itemviews/qidentityproxymodel.h | 115 ++++ src/gui/itemviews/qsortfilterproxymodel.cpp | 2 +- tests/auto/gui.pro | 1 + tests/auto/headers/tst_headers.cpp | 4 + .../qidentityproxymodel/qidentityproxymodel.pro | 6 + .../tst_qidentityproxymodel.cpp | 329 ++++++++++++ 11 files changed, 1114 insertions(+), 1 deletion(-) create mode 100644 doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp create mode 100644 src/gui/itemviews/qidentityproxymodel.cpp create mode 100644 src/gui/itemviews/qidentityproxymodel.h create mode 100644 tests/auto/qidentityproxymodel/qidentityproxymodel.pro create mode 100644 tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp diff --git a/doc/src/frameworks-technologies/model-view-programming.qdoc b/doc/src/frameworks-technologies/model-view-programming.qdoc index 92067b9..42404b0 100644 --- a/doc/src/frameworks-technologies/model-view-programming.qdoc +++ b/doc/src/frameworks-technologies/model-view-programming.qdoc @@ -1934,6 +1934,13 @@ \l{QSortFilterProxyModel::lessThan()}{lessThan()} function to perform custom comparisons. + \section3 Custom data models + + QIdentityProxyModel instances do not sort or filter the structure of the source model, + but provide a base class for creating a data proxy. This could be useful on top of a + QFileSystemModel for example to provide different colours for the BackgroundRole for + different types of files. + \section1 Model subclassing reference Model subclasses need to provide implementations of many of the virtual functions diff --git a/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp new file mode 100644 index 0000000..8bd6520 --- /dev/null +++ b/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, +** a KDAB Group company, info@kdab.com, +** author Stephen Kelly +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +class DateFormatProxyModel : public QIdentityProxyModel +{ + // ... + + void setDateFormatString(const QString &formatString) + { + m_formatString = formatString; + } + + QVariant data(const QModelIndex &index, int role) + { + if (role != Qt::DisplayRole) + return QIdentityProxyModel::data(index, role); + + const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime(); + + return dateTime.toString(m_formatString); + } + +private: + QString m_formatString; +}; +//! [0] diff --git a/src/corelib/kernel/qabstractitemmodel.h b/src/corelib/kernel/qabstractitemmodel.h index 6de3bf5..7bed3a2 100644 --- a/src/corelib/kernel/qabstractitemmodel.h +++ b/src/corelib/kernel/qabstractitemmodel.h @@ -162,6 +162,7 @@ class Q_CORE_EXPORT QAbstractItemModel : public QObject friend class QPersistentModelIndexData; friend class QAbstractItemViewPrivate; + friend class QIdentityProxyModel; public: explicit QAbstractItemModel(QObject *parent = 0); diff --git a/src/gui/itemviews/itemviews.pri b/src/gui/itemviews/itemviews.pri index bbc1e98..149bfd6 100644 --- a/src/gui/itemviews/itemviews.pri +++ b/src/gui/itemviews/itemviews.pri @@ -4,6 +4,7 @@ HEADERS += \ itemviews/qabstractitemview.h \ itemviews/qabstractitemview_p.h \ itemviews/qheaderview.h \ + itemviews/qidentityproxymodel.h \ itemviews/qlistview.h \ itemviews/qlistview_p.h \ itemviews/qbsptree_p.h \ @@ -44,6 +45,7 @@ HEADERS += \ SOURCES += \ itemviews/qabstractitemview.cpp \ itemviews/qheaderview.cpp \ + itemviews/qidentityproxymodel.cpp \ itemviews/qlistview.cpp \ itemviews/qbsptree.cpp \ itemviews/qtableview.cpp \ diff --git a/src/gui/itemviews/qidentityproxymodel.cpp b/src/gui/itemviews/qidentityproxymodel.cpp new file mode 100644 index 0000000..9396e61 --- /dev/null +++ b/src/gui/itemviews/qidentityproxymodel.cpp @@ -0,0 +1,582 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, +** a KDAB Group company, info@kdab.com, +** author Stephen Kelly +** All rights reserved. +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +****************************************************************************/ + +#include "qidentityproxymodel.h" + +#ifndef QT_NO_IDENTITYPROXYMODEL + +#include "qitemselectionmodel.h" +#include + +QT_BEGIN_NAMESPACE + +class QIdentityProxyModelPrivate : public QAbstractProxyModelPrivate +{ + QIdentityProxyModelPrivate() + : ignoreNextLayoutAboutToBeChanged(false), + ignoreNextLayoutChanged(false) + { + + } + + Q_DECLARE_PUBLIC(QIdentityProxyModel) + + bool ignoreNextLayoutAboutToBeChanged; + bool ignoreNextLayoutChanged; + QList layoutChangePersistentIndexes; + QModelIndexList proxyIndexes; + + void _q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end); + void _q_sourceRowsInserted(const QModelIndex &parent, int start, int end); + void _q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); + void _q_sourceRowsRemoved(const QModelIndex &parent, int start, int end); + void _q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); + void _q_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); + + void _q_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end); + void _q_sourceColumnsInserted(const QModelIndex &parent, int start, int end); + void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end); + void _q_sourceColumnsRemoved(const QModelIndex &parent, int start, int end); + void _q_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); + void _q_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); + + void _q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); + void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last); + + void _q_sourceLayoutAboutToBeChanged(); + void _q_sourceLayoutChanged(); + void _q_sourceModelAboutToBeReset(); + void _q_sourceModelReset(); + +}; + +/*! + \since 4.8 + \class QIdentityProxyModel + \brief The QIdentityProxyModel class proxies its source model unmodified + + \ingroup model-view + + QIdentityProxyModel can be used to forward the structure of a source model exactly, with no sorting, filtering or other transformation. + This is similar in concept to an identity matrix where A.I = A. + + Because it does no sorting or filtering, this class is most suitable to proxy models which transform the data() of the source model. + For example, a proxy model could be created to define the font used, or the background colour, or the tooltip etc. This removes the + need to implement all data handling in the same class that creates the structure of the model, and can also be used to create + re-usable components. + + This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified. + + \snippet doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp 0 + + \sa QAbstractProxyModel, {Model/View Programming}, QAbstractItemModel + +*/ + +/*! + Constructs an identity model with the given \a parent. +*/ +QIdentityProxyModel::QIdentityProxyModel(QObject* parent) + : QAbstractProxyModel(*new QIdentityProxyModelPrivate, parent) +{ + +} + +/*! \internal + */ +QIdentityProxyModel::QIdentityProxyModel(QIdentityProxyModelPrivate &dd, QObject* parent) + : QAbstractProxyModel(dd, parent) +{ + +} + +/*! + Destroys this identity model. +*/ +QIdentityProxyModel::~QIdentityProxyModel() +{ +} + +/*! + \reimp + */ +int QIdentityProxyModel::columnCount(const QModelIndex& parent) const +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(const QIdentityProxyModel); + return d->model->columnCount(mapToSource(parent)); +} + +/*! + \reimp + */ +bool QIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(QIdentityProxyModel); + return d->model->dropMimeData(data, action, row, column, mapToSource(parent)); +} + +/*! + \reimp + */ +QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(const QIdentityProxyModel); + if (!hasIndex(row, column, parent)) + return QModelIndex(); + const QModelIndex sourceParent = mapToSource(parent); + const QModelIndex sourceIndex = d->model->index(row, column, sourceParent); + Q_ASSERT(sourceIndex.isValid()); + return mapFromSource(sourceIndex); +} + +/*! + \reimp + */ +bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent) +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(QIdentityProxyModel); + return d->model->insertColumns(column, count, mapToSource(parent)); +} + +/*! + \reimp + */ +bool QIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent) +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(QIdentityProxyModel); + return d->model->insertRows(row, count, mapToSource(parent)); +} + +/*! + \reimp + */ +QModelIndex QIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const +{ + Q_D(const QIdentityProxyModel); + if (!d->model || !sourceIndex.isValid()) + return QModelIndex(); + + Q_ASSERT(sourceIndex.model() == d->model); + return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer()); +} + +/*! + \reimp + */ +QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const +{ + Q_D(const QIdentityProxyModel); + QItemSelection proxySelection; + + if (!d->model) + return proxySelection; + + QItemSelection::const_iterator it = selection.constBegin(); + const QItemSelection::const_iterator end = selection.constEnd(); + for ( ; it != end; ++it) { + Q_ASSERT(it->model() == d->model); + const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight())); + proxySelection.append(range); + } + + return proxySelection; +} + +/*! + \reimp + */ +QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const +{ + Q_D(const QIdentityProxyModel); + QItemSelection sourceSelection; + + if (!d->model) + return sourceSelection; + + QItemSelection::const_iterator it = selection.constBegin(); + const QItemSelection::const_iterator end = selection.constEnd(); + for ( ; it != end; ++it) { + Q_ASSERT(it->model() == this); + const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight())); + sourceSelection.append(range); + } + + return sourceSelection; +} + +/*! + \reimp + */ +QModelIndex QIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const +{ + Q_D(const QIdentityProxyModel); + if (!d->model || !proxyIndex.isValid()) + return QModelIndex(); + Q_ASSERT(proxyIndex.model() == this); + return d->model->createIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer()); +} + +/*! + \reimp + */ +QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const +{ + Q_D(const QIdentityProxyModel); + Q_ASSERT(start.isValid() ? start.model() == this : true); + if (!d->model) + return QModelIndexList(); + + const QModelIndexList sourceList = d->model->match(mapToSource(start), role, value, hits, flags); + QModelIndexList::const_iterator it = sourceList.constBegin(); + const QModelIndexList::const_iterator end = sourceList.constEnd(); + QModelIndexList proxyList; + for ( ; it != end; ++it) + proxyList.append(mapFromSource(*it)); + return proxyList; +} + +/*! + \reimp + */ +QModelIndex QIdentityProxyModel::parent(const QModelIndex& child) const +{ + Q_ASSERT(child.isValid() ? child.model() == this : true); + const QModelIndex sourceIndex = mapToSource(child); + const QModelIndex sourceParent = sourceIndex.parent(); + return mapFromSource(sourceParent); +} + +/*! + \reimp + */ +bool QIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent) +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(QIdentityProxyModel); + return d->model->removeColumns(column, count, mapToSource(parent)); +} + +/*! + \reimp + */ +bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent) +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(QIdentityProxyModel); + return d->model->removeRows(row, count, mapToSource(parent)); +} + +/*! + \reimp + */ +int QIdentityProxyModel::rowCount(const QModelIndex& parent) const +{ + Q_ASSERT(parent.isValid() ? parent.model() == this : true); + Q_D(const QIdentityProxyModel); + return d->model->rowCount(mapToSource(parent)); +} + +/*! + \reimp + */ +void QIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel) +{ + beginResetModel(); + + if (sourceModel) { + disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), + this, SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), + this, SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + this, SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + disconnect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + this, SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), + this, SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), + this, SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), + this, SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), + this, SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int))); + disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + this, SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + disconnect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + this, SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + disconnect(sourceModel, SIGNAL(modelAboutToBeReset()), + this, SLOT(_q_sourceModelAboutToBeReset())); + disconnect(sourceModel, SIGNAL(modelReset()), + this, SLOT(_q_sourceModelReset())); + disconnect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &))); + disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), + this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int))); + disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()), + this, SLOT(_q_sourceLayoutAboutToBeChanged())); + disconnect(sourceModel, SIGNAL(layoutChanged()), + this, SLOT(_q_sourceLayoutChanged())); + } + + QAbstractProxyModel::setSourceModel(sourceModel); + + if (sourceModel) { + connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), + SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), + SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), + SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + connect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), + SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), + SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), + SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), + SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int))); + connect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + connect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); + connect(sourceModel, SIGNAL(modelAboutToBeReset()), + SLOT(_q_sourceModelAboutToBeReset())); + connect(sourceModel, SIGNAL(modelReset()), + SLOT(_q_sourceModelReset())); + connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &))); + connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), + SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int))); + connect(sourceModel, SIGNAL(layoutAboutToBeChanged()), + SLOT(_q_sourceLayoutAboutToBeChanged())); + connect(sourceModel, SIGNAL(layoutChanged()), + SLOT(_q_sourceLayoutChanged())); + } + + endResetModel(); +} + +void QIdentityProxyModelPrivate::_q_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + q->beginInsertColumns(q->mapFromSource(parent), start, end); +} + +void QIdentityProxyModelPrivate::_q_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) +{ + Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true); + Q_ASSERT(destParent.isValid() ? destParent.model() == model : true); + Q_Q(QIdentityProxyModel); + q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest); +} + +void QIdentityProxyModelPrivate::_q_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + q->beginRemoveColumns(q->mapFromSource(parent), start, end); +} + +void QIdentityProxyModelPrivate::_q_sourceColumnsInserted(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + q->endInsertColumns(); +} + +void QIdentityProxyModelPrivate::_q_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) +{ + Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true); + Q_ASSERT(destParent.isValid() ? destParent.model() == model : true); + Q_Q(QIdentityProxyModel); + Q_UNUSED(sourceParent) + Q_UNUSED(sourceStart) + Q_UNUSED(sourceEnd) + Q_UNUSED(destParent) + Q_UNUSED(dest) + q->endMoveColumns(); +} + +void QIdentityProxyModelPrivate::_q_sourceColumnsRemoved(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + q->endRemoveColumns(); +} + +void QIdentityProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + Q_ASSERT(topLeft.isValid() ? topLeft.model() == model : true); + Q_ASSERT(bottomRight.isValid() ? bottomRight.model() == model : true); + Q_Q(QIdentityProxyModel); + q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight)); +} + +void QIdentityProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last) +{ + Q_Q(QIdentityProxyModel); + q->headerDataChanged(orientation, first, last); +} + +void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged() +{ + if (ignoreNextLayoutAboutToBeChanged) + return; + + Q_Q(QIdentityProxyModel); + + foreach(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) { + proxyIndexes << proxyPersistentIndex; + Q_ASSERT(proxyPersistentIndex.isValid()); + const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); + Q_ASSERT(srcPersistentIndex.isValid()); + layoutChangePersistentIndexes << srcPersistentIndex; + } + + q->layoutAboutToBeChanged(); +} + +void QIdentityProxyModelPrivate::_q_sourceLayoutChanged() +{ + if (ignoreNextLayoutChanged) + return; + + Q_Q(QIdentityProxyModel); + + for (int i = 0; i < proxyIndexes.size(); ++i) { + q->changePersistentIndex(proxyIndexes.at(i), q->mapFromSource(layoutChangePersistentIndexes.at(i))); + } + + layoutChangePersistentIndexes.clear(); + proxyIndexes.clear(); + + q->layoutChanged(); +} + +void QIdentityProxyModelPrivate::_q_sourceModelAboutToBeReset() +{ + Q_Q(QIdentityProxyModel); + q->beginResetModel(); +} + +void QIdentityProxyModelPrivate::_q_sourceModelReset() +{ + Q_Q(QIdentityProxyModel); + q->endResetModel(); +} + +void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + q->beginInsertRows(q->mapFromSource(parent), start, end); +} + +void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) +{ + Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true); + Q_ASSERT(destParent.isValid() ? destParent.model() == model : true); + Q_Q(QIdentityProxyModel); + q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest); +} + +void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + q->beginRemoveRows(q->mapFromSource(parent), start, end); +} + +void QIdentityProxyModelPrivate::_q_sourceRowsInserted(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + q->endInsertRows(); +} + +void QIdentityProxyModelPrivate::_q_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) +{ + Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true); + Q_ASSERT(destParent.isValid() ? destParent.model() == model : true); + Q_Q(QIdentityProxyModel); + Q_UNUSED(sourceParent) + Q_UNUSED(sourceStart) + Q_UNUSED(sourceEnd) + Q_UNUSED(destParent) + Q_UNUSED(dest) + q->endMoveRows(); +} + +void QIdentityProxyModelPrivate::_q_sourceRowsRemoved(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(parent.isValid() ? parent.model() == model : true); + Q_Q(QIdentityProxyModel); + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + q->endRemoveRows(); +} + +QT_END_NAMESPACE + +#include "moc_qidentityproxymodel.cpp" + +#endif // QT_NO_IDENTITYPROXYMODEL diff --git a/src/gui/itemviews/qidentityproxymodel.h b/src/gui/itemviews/qidentityproxymodel.h new file mode 100644 index 0000000..b60aa0b --- /dev/null +++ b/src/gui/itemviews/qidentityproxymodel.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, +** a KDAB Group company, info@kdab.com, +** author Stephen Kelly +** All rights reserved. +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +****************************************************************************/ + + +#ifndef QIDENTITYPROXYMODEL_H +#define QIDENTITYPROXYMODEL_H + +#include + +#ifndef QT_NO_IDENTITYPROXYMODEL + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QIdentityProxyModelPrivate; + +class Q_GUI_EXPORT QIdentityProxyModel : public QAbstractProxyModel +{ + Q_OBJECT +public: + explicit QIdentityProxyModel(QObject* parent = 0); + ~QIdentityProxyModel(); + + int columnCount(const QModelIndex& parent = QModelIndex()) const; + QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; + QModelIndex mapFromSource(const QModelIndex& sourceIndex) const; + QModelIndex mapToSource(const QModelIndex& proxyIndex) const; + QModelIndex parent(const QModelIndex& child) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; + bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); + + QItemSelection mapSelectionFromSource(const QItemSelection& selection) const; + QItemSelection mapSelectionToSource(const QItemSelection& selection) const; + QModelIndexList match(const QModelIndex& start, int role, const QVariant& value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const; + void setSourceModel(QAbstractItemModel* sourceModel); + + bool insertColumns(int column, int count, const QModelIndex& parent = QModelIndex()); + bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()); + bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()); + bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); + +protected: + QIdentityProxyModel(QIdentityProxyModelPrivate &dd, QObject* parent); + +private: + Q_DECLARE_PRIVATE(QIdentityProxyModel) + Q_DISABLE_COPY(QIdentityProxyModel) + + Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeInserted(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsInserted(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsRemoved(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)) + + Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsInserted(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsRemoved(QModelIndex,int,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)) + + Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(QModelIndex,QModelIndex)) + Q_PRIVATE_SLOT(d_func(), void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)) + + Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutAboutToBeChanged()) + Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutChanged()) + Q_PRIVATE_SLOT(d_func(), void _q_sourceModelAboutToBeReset()) + Q_PRIVATE_SLOT(d_func(), void _q_sourceModelReset()) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QT_NO_IDENTITYPROXYMODEL + +#endif // QIDENTITYPROXYMODEL_H + diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index eb56f56..f73607b 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -1502,7 +1502,7 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( \l{Model Subclassing Reference}. \sa QAbstractProxyModel, QAbstractItemModel, {Model/View Programming}, - {Basic Sort/Filter Model Example}, {Custom Sort/Filter Model Example} + {Basic Sort/Filter Model Example}, {Custom Sort/Filter Model Example}, QIdentityProxyModel */ /*! diff --git a/tests/auto/gui.pro b/tests/auto/gui.pro index 186f00c..c752480 100644 --- a/tests/auto/gui.pro +++ b/tests/auto/gui.pro @@ -84,6 +84,7 @@ SUBDIRS=\ qheaderview \ qicoimageformat \ qicon \ + qidentityproxymodel \ qimageiohandler \ qimagereader \ qimagewriter \ diff --git a/tests/auto/headers/tst_headers.cpp b/tests/auto/headers/tst_headers.cpp index b5c65ef..b6135d0 100644 --- a/tests/auto/headers/tst_headers.cpp +++ b/tests/auto/headers/tst_headers.cpp @@ -243,6 +243,10 @@ void tst_Headers::licenseCheck() QCOMPARE(content.at(i++), QString("**")); if (sourceFile.endsWith("/tests/auto/modeltest/dynamictreemodel.cpp") || sourceFile.endsWith("/tests/auto/modeltest/dynamictreemodel.h") + || sourceFile.endsWith("/src/gui/itemviews/qidentityproxymodel.h") + || sourceFile.endsWith("/src/gui/itemviews/qidentityproxymodel.cpp") + || sourceFile.endsWith("/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp") + || sourceFile.endsWith("/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp") || sourceFile.endsWith("/src/network/kernel/qnetworkproxy_p.h")) { // These files are not copyrighted by Nokia. diff --git a/tests/auto/qidentityproxymodel/qidentityproxymodel.pro b/tests/auto/qidentityproxymodel/qidentityproxymodel.pro new file mode 100644 index 0000000..f529e20 --- /dev/null +++ b/tests/auto/qidentityproxymodel/qidentityproxymodel.pro @@ -0,0 +1,6 @@ +load(qttest_p4) + +INCLUDEPATH += $$PWD/../modeltest + +SOURCES += tst_qidentityproxymodel.cpp ../modeltest/dynamictreemodel.cpp ../modeltest/modeltest.cpp +HEADERS += ../modeltest/dynamictreemodel.h ../modeltest/modeltest.h diff --git a/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp new file mode 100644 index 0000000..bbcdb4c --- /dev/null +++ b/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -0,0 +1,329 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, +** a KDAB Group company, info@kdab.com, +** author Stephen Kelly +** All rights reserved. +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +****************************************************************************/ + + +#include +#include "../../shared/util.h" + +#include +#include + +#include "dynamictreemodel.h" +#include "qidentityproxymodel.h" + +//TESTED CLASS= +//TESTED_FILES= + +Q_DECLARE_METATYPE(QModelIndex) + +class tst_QIdentityProxyModel : public QObject +{ + Q_OBJECT + +public: + + tst_QIdentityProxyModel(); + virtual ~tst_QIdentityProxyModel(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void insertRows(); + void removeRows(); + void moveRows(); + void reset(); + +protected: + void verifyIdentity(QAbstractItemModel *model, const QModelIndex &parent = QModelIndex()); + +private: + QStandardItemModel *m_model; + QIdentityProxyModel *m_proxy; +}; + +tst_QIdentityProxyModel::tst_QIdentityProxyModel() + : m_model(0), m_proxy(0) +{ + +} + +tst_QIdentityProxyModel::~tst_QIdentityProxyModel() +{ + +} + +void tst_QIdentityProxyModel::initTestCase() +{ + qRegisterMetaType("QModelIndex"); + + m_model = new QStandardItemModel(0, 1); + m_proxy = new QIdentityProxyModel(); +} + +void tst_QIdentityProxyModel::cleanupTestCase() +{ + delete m_proxy; + delete m_model; +} + +void tst_QIdentityProxyModel::init() +{ +} + +void tst_QIdentityProxyModel::cleanup() +{ + m_model->clear(); + m_model->insertColumns(0, 1); +} + +void tst_QIdentityProxyModel::verifyIdentity(QAbstractItemModel *model, const QModelIndex &parent) +{ + const int rows = model->rowCount(parent); + const int columns = model->columnCount(parent); + const QModelIndex proxyParent = m_proxy->mapFromSource(parent); + + QVERIFY(m_proxy->mapToSource(proxyParent) == parent); + QVERIFY(rows == m_proxy->rowCount(proxyParent)); + QVERIFY(columns == m_proxy->columnCount(proxyParent)); + + for (int row = 0; row < rows; ++row) { + for (int column = 0; column < columns; ++column) { + const QModelIndex idx = model->index(row, column, parent); + const QModelIndex proxyIdx = m_proxy->mapFromSource(idx); + QVERIFY(proxyIdx.model() == m_proxy); + QVERIFY(m_proxy->mapToSource(proxyIdx) == idx); + QVERIFY(proxyIdx.isValid()); + QVERIFY(proxyIdx.row() == row); + QVERIFY(proxyIdx.column() == column); + QVERIFY(proxyIdx.parent() == proxyParent); + QVERIFY(proxyIdx.data() == idx.data()); + QVERIFY(proxyIdx.flags() == idx.flags()); + const int childCount = m_proxy->rowCount(proxyIdx); + const bool hasChildren = m_proxy->hasChildren(proxyIdx); + QVERIFY(model->hasChildren(idx) == hasChildren); + QVERIFY((childCount > 0) == hasChildren); + + if (hasChildren) + verifyIdentity(model, idx); + } + } +} + +/* + tests +*/ + +void tst_QIdentityProxyModel::insertRows() +{ + QStandardItem *parentItem = m_model->invisibleRootItem(); + for (int i = 0; i < 4; ++i) { + QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); + parentItem->appendRow(item); + parentItem = item; + } + + m_proxy->setSourceModel(m_model); + + verifyIdentity(m_model); + + QSignalSpy modelBeforeSpy(m_model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); + QSignalSpy modelAfterSpy(m_model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy proxyBeforeSpy(m_proxy, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); + QSignalSpy proxyAfterSpy(m_proxy, SIGNAL(rowsInserted(QModelIndex,int,int))); + + QStandardItem *item = new QStandardItem(QString("new item")); + parentItem->appendRow(item); + + QVERIFY(modelBeforeSpy.size() == 1 && 1 == proxyBeforeSpy.size()); + QVERIFY(modelAfterSpy.size() == 1 && 1 == proxyAfterSpy.size()); + + QVERIFY(modelBeforeSpy.first().first().value() == m_proxy->mapToSource(proxyBeforeSpy.first().first().value())); + QVERIFY(modelBeforeSpy.first().at(1) == proxyBeforeSpy.first().at(1)); + QVERIFY(modelBeforeSpy.first().at(2) == proxyBeforeSpy.first().at(2)); + + QVERIFY(modelAfterSpy.first().first().value() == m_proxy->mapToSource(proxyAfterSpy.first().first().value())); + QVERIFY(modelAfterSpy.first().at(1) == proxyAfterSpy.first().at(1)); + QVERIFY(modelAfterSpy.first().at(2) == proxyAfterSpy.first().at(2)); + + verifyIdentity(m_model); + +} + +void tst_QIdentityProxyModel::removeRows() +{ + QStandardItem *parentItem = m_model->invisibleRootItem(); + for (int i = 0; i < 4; ++i) { + QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); + parentItem->appendRow(item); + parentItem = item; + } + + m_proxy->setSourceModel(m_model); + + verifyIdentity(m_model); + + QSignalSpy modelBeforeSpy(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); + QSignalSpy modelAfterSpy(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int))); + QSignalSpy proxyBeforeSpy(m_proxy, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); + QSignalSpy proxyAfterSpy(m_proxy, SIGNAL(rowsRemoved(QModelIndex,int,int))); + + const QModelIndex topLevel = m_model->index(0, 0, QModelIndex()); + const QModelIndex secondLevel = m_model->index(0, 0, topLevel); + const QModelIndex thirdLevel = m_model->index(0, 0, secondLevel); + + QVERIFY(thirdLevel.isValid()); + + m_model->removeRow(0, secondLevel); + + QVERIFY(modelBeforeSpy.size() == 1 && 1 == proxyBeforeSpy.size()); + QVERIFY(modelAfterSpy.size() == 1 && 1 == proxyAfterSpy.size()); + + QVERIFY(modelBeforeSpy.first().first().value() == m_proxy->mapToSource(proxyBeforeSpy.first().first().value())); + QVERIFY(modelBeforeSpy.first().at(1) == proxyBeforeSpy.first().at(1)); + QVERIFY(modelBeforeSpy.first().at(2) == proxyBeforeSpy.first().at(2)); + + QVERIFY(modelAfterSpy.first().first().value() == m_proxy->mapToSource(proxyAfterSpy.first().first().value())); + QVERIFY(modelAfterSpy.first().at(1) == proxyAfterSpy.first().at(1)); + QVERIFY(modelAfterSpy.first().at(2) == proxyAfterSpy.first().at(2)); + + verifyIdentity(m_model); +} + +void tst_QIdentityProxyModel::moveRows() +{ + DynamicTreeModel model; + + { + ModelInsertCommand insertCommand(&model); + insertCommand.setStartRow(0); + insertCommand.setEndRow(9); + insertCommand.doCommand(); + } + { + ModelInsertCommand insertCommand(&model); + insertCommand.setAncestorRowNumbers(QList() << 5); + insertCommand.setStartRow(0); + insertCommand.setEndRow(9); + insertCommand.doCommand(); + } + + m_proxy->setSourceModel(&model); + + verifyIdentity(&model); + + QSignalSpy modelBeforeSpy(&model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); + QSignalSpy modelAfterSpy(&model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int))); + QSignalSpy proxyBeforeSpy(m_proxy, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); + QSignalSpy proxyAfterSpy(m_proxy, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int))); + + { + ModelMoveCommand moveCommand(&model, 0); + moveCommand.setAncestorRowNumbers(QList() << 5); + moveCommand.setStartRow(3); + moveCommand.setEndRow(4); + moveCommand.setDestRow(1); + moveCommand.doCommand(); + } + + QVERIFY(modelBeforeSpy.size() == 1 && 1 == proxyBeforeSpy.size()); + QVERIFY(modelAfterSpy.size() == 1 && 1 == proxyAfterSpy.size()); + + QVERIFY(modelBeforeSpy.first().first().value() == m_proxy->mapToSource(proxyBeforeSpy.first().first().value())); + QVERIFY(modelBeforeSpy.first().at(1) == proxyBeforeSpy.first().at(1)); + QVERIFY(modelBeforeSpy.first().at(2) == proxyBeforeSpy.first().at(2)); + QVERIFY(modelBeforeSpy.first().at(3).value() == m_proxy->mapToSource(proxyBeforeSpy.first().at(3).value())); + QVERIFY(modelBeforeSpy.first().at(4) == proxyBeforeSpy.first().at(4)); + + QVERIFY(modelAfterSpy.first().first().value() == m_proxy->mapToSource(proxyAfterSpy.first().first().value())); + QVERIFY(modelAfterSpy.first().at(1) == proxyAfterSpy.first().at(1)); + QVERIFY(modelAfterSpy.first().at(2) == proxyAfterSpy.first().at(2)); + QVERIFY(modelAfterSpy.first().at(3).value() == m_proxy->mapToSource(proxyAfterSpy.first().at(3).value())); + QVERIFY(modelAfterSpy.first().at(4) == proxyAfterSpy.first().at(4)); + + verifyIdentity(&model); + + m_proxy->setSourceModel(0); +} + +void tst_QIdentityProxyModel::reset() +{ + DynamicTreeModel model; + + { + ModelInsertCommand insertCommand(&model); + insertCommand.setStartRow(0); + insertCommand.setEndRow(9); + insertCommand.doCommand(); + } + { + ModelInsertCommand insertCommand(&model); + insertCommand.setAncestorRowNumbers(QList() << 5); + insertCommand.setStartRow(0); + insertCommand.setEndRow(9); + insertCommand.doCommand(); + } + + m_proxy->setSourceModel(&model); + + verifyIdentity(&model); + + QSignalSpy modelBeforeSpy(&model, SIGNAL(modelAboutToBeReset())); + QSignalSpy modelAfterSpy(&model, SIGNAL(modelReset())); + QSignalSpy proxyBeforeSpy(m_proxy, SIGNAL(modelAboutToBeReset())); + QSignalSpy proxyAfterSpy(m_proxy, SIGNAL(modelReset())); + + { + ModelResetCommandFixed resetCommand(&model, 0); + resetCommand.setAncestorRowNumbers(QList() << 5); + resetCommand.setStartRow(3); + resetCommand.setEndRow(4); + resetCommand.setDestRow(1); + resetCommand.doCommand(); + } + + QVERIFY(modelBeforeSpy.size() == 1 && 1 == proxyBeforeSpy.size()); + QVERIFY(modelAfterSpy.size() == 1 && 1 == proxyAfterSpy.size()); + + verifyIdentity(&model); + m_proxy->setSourceModel(0); +} + +QTEST_MAIN(tst_QIdentityProxyModel) +#include "tst_qidentityproxymodel.moc" -- cgit v0.12 From f7b60fffb673b182e633545bffd1d310337aca50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 14 Apr 2011 10:00:18 +0200 Subject: Fix warning about initialization order Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qmenu_p.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index 005ce1d..9fd55ca 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -154,6 +154,9 @@ public: #endif scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), hasCheckableItems(0), sloppyAction(0), doChildEffects(false) +#ifdef QT3_SUPPORT + ,emitHighlighted(false) +#endif #ifdef Q_WS_MAC ,mac_menu(0) #endif @@ -163,9 +166,6 @@ public: #ifdef Q_WS_S60 ,symbian_menu(0) #endif -#ifdef QT3_SUPPORT - ,emitHighlighted(false) -#endif { } ~QMenuPrivate() { -- cgit v0.12 From c664954295c0605c73f7e69deb9f6130c5f5fb05 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Thu, 14 Apr 2011 10:00:21 +0200 Subject: Hide QMenuAction This will help abstracting the platform specific parts of QMenuBarPrivate in a common interface. Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qmenu_mac.mm | 4 ++-- src/gui/widgets/qmenu_symbian.cpp | 4 ++-- src/gui/widgets/qmenu_wince.cpp | 4 ++-- src/gui/widgets/qmenubar.cpp | 2 +- src/gui/widgets/qmenubar_p.h | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index 2977558..f780ee7 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -1639,7 +1639,7 @@ QMenuBarPrivate::QMacMenuBarPrivate::~QMacMenuBarPrivate() } void -QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QMacMenuAction *before) +QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QAction *before) { if (a->isSeparator() || !menu) return; @@ -1649,7 +1649,7 @@ QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QMacMenuAction *befor #ifndef QT_MAC_USE_COCOA action->command = qt_mac_menu_static_cmd_id++; #endif - addAction(action, before); + addAction(action, findAction(before)); } void diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index d614bb8..12c6c6e 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -398,12 +398,12 @@ void QMenuPrivate::QSymbianMenuPrivate::rebuild(bool) { } -void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QAction *a, QSymbianMenuAction *before) +void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QAction *a, QAction *before) { QSymbianMenuAction *action = new QSymbianMenuAction; action->action = a; action->command = qt_symbian_menu_static_cmd_id++; - addAction(action, before); + addAction(action, findAction(before)); } void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QSymbianMenuAction *action, QSymbianMenuAction *before) diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index 86a78ad..2210409 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -504,12 +504,12 @@ void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) rebuild(); } -void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) +void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QAction *before) { QWceMenuAction *action = new QWceMenuAction; action->action = a; action->command = qt_wce_menu_static_cmd_id++; - addAction(action, before); + addAction(action, findAction(before)); } void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 5bfac9a..08c287e 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -1287,7 +1287,7 @@ void QMenuBar::actionEvent(QActionEvent *e) if (!nativeMenuBar) return; if(e->type() == QEvent::ActionAdded) - nativeMenuBar->addAction(e->action(), nativeMenuBar->findAction(e->before())); + nativeMenuBar->addAction(e->action(), e->before()); else if(e->type() == QEvent::ActionRemoved) nativeMenuBar->removeAction(e->action()); else if(e->type() == QEvent::ActionChanged) diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index 5afe713..2b8558b 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -181,7 +181,7 @@ public: QMacMenuBarPrivate(); ~QMacMenuBarPrivate(); - void addAction(QAction *, QMacMenuAction* =0); + void addAction(QAction *, QAction* =0); void addAction(QMacMenuAction *, QMacMenuAction* =0); void syncAction(QMacMenuAction *); inline void syncAction(QAction *a) { syncAction(findAction(a)); } @@ -220,7 +220,7 @@ public: QWceMenuBarPrivate(QMenuBarPrivate *menubar); ~QWceMenuBarPrivate(); - void addAction(QAction *, QWceMenuAction* =0); + void addAction(QAction *, QAction* =0); void addAction(QWceMenuAction *, QWceMenuAction* =0); void syncAction(QWceMenuAction *); inline void syncAction(QAction *a) { syncAction(findAction(a)); } @@ -250,7 +250,7 @@ public: QMenuBarPrivate *d; QSymbianMenuBarPrivate(QMenuBarPrivate *menubar); ~QSymbianMenuBarPrivate(); - void addAction(QAction *, QSymbianMenuAction* =0); + void addAction(QAction *, QAction* =0); void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); void syncAction(QSymbianMenuAction *); inline void syncAction(QAction *a) { syncAction(findAction(a)); } -- cgit v0.12 From 0432a6b79d35ac7db909a81793417107ebfb668f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 14 Apr 2011 10:00:24 +0200 Subject: Introduce QAbstractMenuBarImpl Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qabstractmenubarimpl_p.cpp | 44 +++++ src/gui/widgets/qabstractmenubarimpl_p.h | 104 +++++++++++ src/gui/widgets/qmenubar.cpp | 287 +++++++++++------------------ src/gui/widgets/qmenubar_p.h | 129 ++----------- src/gui/widgets/qmenubarimpl.cpp | 244 ++++++++++++++++++++++++ src/gui/widgets/qmenubarimpl_p.h | 182 ++++++++++++++++++ src/gui/widgets/widgets.pri | 3 + 7 files changed, 694 insertions(+), 299 deletions(-) create mode 100644 src/gui/widgets/qabstractmenubarimpl_p.cpp create mode 100644 src/gui/widgets/qabstractmenubarimpl_p.h create mode 100644 src/gui/widgets/qmenubarimpl.cpp create mode 100644 src/gui/widgets/qmenubarimpl_p.h diff --git a/src/gui/widgets/qabstractmenubarimpl_p.cpp b/src/gui/widgets/qabstractmenubarimpl_p.cpp new file mode 100644 index 0000000..bc16030 --- /dev/null +++ b/src/gui/widgets/qabstractmenubarimpl_p.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +QAbstractMenuBarImpl::~QAbstractMenuBarImpl() +{} diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h new file mode 100644 index 0000000..d001008 --- /dev/null +++ b/src/gui/widgets/qabstractmenubarimpl_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QABSTRACTMENUBARIMPL_P_H +#define QABSTRACTMENUBARIMPL_P_H + +#include + +#ifndef QT_NO_MENUBAR + +QT_BEGIN_NAMESPACE + +class QAction; +class QActionEvent; +class QEvent; +class QMenuBar; +class QObject; +class QWidget; + +/** + * The platform-specific implementation of a menubar + */ +class Q_GUI_EXPORT QAbstractMenuBarImpl +{ +public: + virtual ~QAbstractMenuBarImpl(); + + // QMenuBarPrivate::init() + virtual void init(QMenuBar *) = 0; + + // QMenuBar::setVisible() + virtual bool allowSetVisible() const = 0; + + virtual void actionEvent(QActionEvent *) = 0; + + // QMenuBar::handleReparent() + virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0; + + // QMenuBarPrivate::updateGeometries() + // QMenuBar::minimumSizeHint() + // QMenuBar::sizeHint() + // QMenuBar::heightForWidth() + virtual bool allowCornerWidgets() const = 0; + + // QMenuBar::_q_internalShortcutActivated() + virtual void popupAction(QAction*) = 0; + + // QMenuBar::setNativeMenuBar() + virtual void setNativeMenuBar(bool) = 0; + + virtual bool isNativeMenuBar() const = 0; + + /** + * Return true if the native menubar is capable of listening to the + * shortcut keys. If false is returned, QMenuBar will trigger actions on + * shortcut itself. + */ + virtual bool shortcutsHandledByNativeMenuBar() const = 0; + + virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_MENUBAR + +#endif // QABSTRACTMENUBARIMPL_P_H diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 08c287e..0d13574 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -63,9 +63,10 @@ #include #endif +#include "qdebug.h" #include "qmenu_p.h" #include "qmenubar_p.h" -#include "qdebug.h" +#include "qmenubarimpl_p.h" #ifdef Q_WS_WINCE extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp @@ -173,7 +174,8 @@ void QMenuBarPrivate::updateGeometries() return; int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2); int q_start = -1; - if(leftWidget || rightWidget) { + + if(impl->allowCornerWidgets() && (leftWidget || rightWidget)) { int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q) + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q) @@ -195,16 +197,8 @@ void QMenuBarPrivate::updateGeometries() } } -#ifdef Q_WS_MAC - if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. - itemsDirty = false; - return; - } -#endif - calcActionRects(q_width, q_start); - currentAction = 0; #ifndef QT_NO_SHORTCUT - if(itemsDirty) { + if(!impl->shortcutsHandledByNativeMenuBar() && itemsDirty) { for(int j = 0; j < shortcutIndexMap.size(); ++j) q->releaseShortcut(shortcutIndexMap.value(j)); shortcutIndexMap.resize(0); // faster than clear @@ -212,6 +206,12 @@ void QMenuBarPrivate::updateGeometries() shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); } #endif + if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. + itemsDirty = false; + return; + } + calcActionRects(q_width, q_start); + currentAction = 0; itemsDirty = false; hiddenActions.clear(); @@ -728,21 +728,9 @@ void QMenuBarPrivate::init() Q_Q(QMenuBar); q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); q->setAttribute(Qt::WA_CustomWhatsThis); -#ifdef Q_WS_MAC - macCreateMenuBar(q->parentWidget()); - if(mac_menubar) - q->hide(); -#endif -#ifdef Q_WS_WINCE - if (qt_wince_is_mobile()) { - wceCreateMenuBar(q->parentWidget()); - if(wce_menubar) - q->hide(); - } - else { - QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); - } -#endif + impl = new QMenuBarImpl; + impl->init(q); + q->setBackgroundRole(QPalette::Button); oldWindow = oldParent = 0; #ifdef QT3_SUPPORT @@ -751,6 +739,9 @@ void QMenuBarPrivate::init() #ifdef QT_SOFTKEYS_ENABLED menuBarAction = 0; #endif + cornerWidgetToolBar = 0; + cornerWidgetContainer = 0; + handleReparent(); q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q)); @@ -808,19 +799,8 @@ QMenuBar::QMenuBar(QWidget *parent, const char *name) : QWidget(*new QMenuBarPri */ QMenuBar::~QMenuBar() { -#ifdef Q_WS_MAC - Q_D(QMenuBar); - d->macDestroyMenuBar(); -#endif -#ifdef Q_WS_WINCE Q_D(QMenuBar); - if (qt_wince_is_mobile()) - d->wceDestroyMenuBar(); -#endif -#ifdef Q_WS_S60 - Q_D(QMenuBar); - d->symbianDestroyMenuBar(); -#endif + delete d->cornerWidgetToolBar; } /*! @@ -1072,13 +1052,10 @@ void QMenuBar::paintEvent(QPaintEvent *e) */ void QMenuBar::setVisible(bool visible) { -#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - if (isNativeMenuBar()) { - if (!visible) - QWidget::setVisible(false); + Q_D(QMenuBar); + if (!d->impl->allowSetVisible()) { return; } -#endif QWidget::setVisible(visible); } @@ -1275,25 +1252,7 @@ void QMenuBar::actionEvent(QActionEvent *e) { Q_D(QMenuBar); d->itemsDirty = true; -#if defined (Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - if (isNativeMenuBar()) { -#ifdef Q_WS_MAC - QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar; -#elif defined(Q_WS_S60) - QMenuBarPrivate::QSymbianMenuBarPrivate *nativeMenuBar = d->symbian_menubar; -#else - QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar; -#endif - if (!nativeMenuBar) - return; - if(e->type() == QEvent::ActionAdded) - nativeMenuBar->addAction(e->action(), e->before()); - else if(e->type() == QEvent::ActionRemoved) - nativeMenuBar->removeAction(e->action()); - else if(e->type() == QEvent::ActionChanged) - nativeMenuBar->syncAction(e->action()); - } -#endif + d->impl->actionEvent(e); if(e->type() == QEvent::ActionAdded) { connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); @@ -1369,55 +1328,10 @@ void QMenuBarPrivate::handleReparent() newWindow->installEventFilter(q); } + impl->handleReparent(oldParent, newParent, oldWindow, newWindow); + oldParent = newParent; oldWindow = newWindow; - -#ifdef Q_WS_MAC - if (q->isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { - // If the new parent got a native menubar from before, keep that - // menubar rather than replace it with this one (because a parents - // menubar has precedence over children menubars). - macDestroyMenuBar(); - macCreateMenuBar(newParent); - } -#endif - -#ifdef Q_WS_WINCE - if (qt_wince_is_mobile() && wce_menubar) - wce_menubar->rebuild(); -#endif -#ifdef Q_WS_S60 - - // 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(); - } - -#ifdef QT_SOFTKEYS_ENABLED - // Constuct menuBarAction when this code path is entered first time - if (!menuBarAction) { - if (newParent) { - menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent); - 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 @@ -1566,6 +1480,9 @@ bool QMenuBar::event(QEvent *e) bool QMenuBar::eventFilter(QObject *object, QEvent *event) { Q_D(QMenuBar); + if (d->impl->menuBarEventFilter(object, event)) { + return true; + } if (object == parent() && object) { #ifdef QT3_SUPPORT if (d->doAutoResize && event->type() == QEvent::Resize) { @@ -1659,11 +1576,7 @@ QRect QMenuBar::actionGeometry(QAction *act) const QSize QMenuBar::minimumSizeHint() const { Q_D(const QMenuBar); -#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); -#else - const bool as_gui_menubar = true; -#endif ensurePolished(); QSize ret(0, 0); @@ -1682,17 +1595,19 @@ QSize QMenuBar::minimumSizeHint() const ret += QSize(2*fw + hmargin, 2*fw + vmargin); } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if(d->leftWidget) { - QSize sz = d->leftWidget->minimumSizeHint(); - ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); - } - if(d->rightWidget) { - QSize sz = d->rightWidget->minimumSizeHint(); - ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); + if (d->impl->allowCornerWidgets()) { + if(d->leftWidget) { + QSize sz = d->leftWidget->minimumSizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } + if(d->rightWidget) { + QSize sz = d->rightWidget->minimumSizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } } if(as_gui_menubar) { QStyleOptionMenuItem opt; @@ -1715,12 +1630,7 @@ QSize QMenuBar::minimumSizeHint() const QSize QMenuBar::sizeHint() const { Q_D(const QMenuBar); -#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); -#else - const bool as_gui_menubar = true; -#endif - ensurePolished(); QSize ret(0, 0); @@ -1741,17 +1651,19 @@ QSize QMenuBar::sizeHint() const ret += QSize(fw + hmargin, fw + vmargin); } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if(d->leftWidget) { - QSize sz = d->leftWidget->sizeHint(); - ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); - } - if(d->rightWidget) { - QSize sz = d->rightWidget->sizeHint(); - ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); + if(d->impl->allowCornerWidgets()) { + if(d->leftWidget) { + QSize sz = d->leftWidget->sizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } + if(d->rightWidget) { + QSize sz = d->rightWidget->sizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } } if(as_gui_menubar) { QStyleOptionMenuItem opt; @@ -1774,11 +1686,7 @@ QSize QMenuBar::sizeHint() const int QMenuBar::heightForWidth(int) const { Q_D(const QMenuBar); -#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); -#else - const bool as_gui_menubar = true; -#endif const_cast(d)->updateGeometries(); int height = 0; @@ -1794,10 +1702,12 @@ int QMenuBar::heightForWidth(int) const height += 2*vmargin; } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if(d->leftWidget) - height = qMax(d->leftWidget->sizeHint().height() + margin, height); - if(d->rightWidget) - height = qMax(d->rightWidget->sizeHint().height() + margin, height); + if(d->impl->allowCornerWidgets()) { + if(d->leftWidget) + height = qMax(d->leftWidget->sizeHint().height() + margin, height); + if(d->rightWidget) + height = qMax(d->rightWidget->sizeHint().height() + margin, height); + } if(as_gui_menubar) { QStyleOptionMenuItem opt; opt.init(this); @@ -1817,7 +1727,11 @@ void QMenuBarPrivate::_q_internalShortcutActivated(int id) { Q_Q(QMenuBar); QAction *act = actions.at(id); - setCurrentAction(act, true, true); + if (q->isNativeMenuBar()) { + impl->popupAction(act); + } else { + setCurrentAction(act, true, true); + } if (act && !act->menu()) { activateAction(act, QAction::Trigger); //100 is the same as the default value in QPushButton::animateClick @@ -1838,6 +1752,37 @@ void QMenuBarPrivate::_q_updateLayout() } } +void QMenuBarPrivate::updateCornerWidgetToolBar() +{ + Q_Q(QMenuBar); + if (!cornerWidgetToolBar) { + QMainWindow *window = qobject_cast(q->window()); + if (!window) { + qWarning() << "Menubar parent is not a QMainWindow, not showing corner widgets"; + return; + } + cornerWidgetToolBar = window->addToolBar(QApplication::translate("QMenuBar", "Corner Toolbar")); + cornerWidgetToolBar->setObjectName(QLatin1String("CornerToolBar")); + cornerWidgetContainer = new QWidget; + cornerWidgetToolBar->addWidget(cornerWidgetContainer); + new QHBoxLayout(cornerWidgetContainer); + } else { + QLayout *layout = cornerWidgetContainer->layout(); + while (layout->count() > 0) { + layout->takeAt(0); + } + } + if (leftWidget) { + leftWidget->setParent(cornerWidgetContainer); + cornerWidgetContainer->layout()->addWidget(leftWidget); + } + if (rightWidget) { + rightWidget->setParent(cornerWidgetContainer); + cornerWidgetContainer->layout()->addWidget(rightWidget); + } +} + + /*! \fn void QMenuBar::setCornerWidget(QWidget *widget, Qt::Corner corner) @@ -1870,9 +1815,13 @@ void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner) return; } - if (w) { - w->setParent(this); - w->installEventFilter(this); + if(!d->impl->allowCornerWidgets()) { + d->updateCornerWidgetToolBar(); + } else { + if (w) { + w->setParent(this); + w->installEventFilter(this); + } } d->_q_updateLayout(); @@ -1923,39 +1872,13 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const void QMenuBar::setNativeMenuBar(bool nativeMenuBar) { Q_D(QMenuBar); - if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) { - d->nativeMenuBar = nativeMenuBar; -#ifdef Q_WS_MAC - if (!d->nativeMenuBar) { - extern void qt_mac_clear_menubar(); - qt_mac_clear_menubar(); - d->macDestroyMenuBar(); - const QList &menubarActions = actions(); - for (int i = 0; i < menubarActions.size(); ++i) { - const QAction *action = menubarActions.at(i); - if (QMenu *menu = action->menu()) { - delete menu->d_func()->mac_menu; - menu->d_func()->mac_menu = 0; - } - } - } else { - d->macCreateMenuBar(parentWidget()); - } - macUpdateMenuBar(); - updateGeometry(); - if (!d->nativeMenuBar && parentWidget()) - setVisible(true); -#endif - } + d->impl->setNativeMenuBar(nativeMenuBar); } bool QMenuBar::isNativeMenuBar() const { Q_D(const QMenuBar); - if (d->nativeMenuBar == -1) { - return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar); - } - return d->nativeMenuBar; + return d->impl->isNativeMenuBar(); } /*! @@ -1992,8 +1915,8 @@ void QMenuBar::setDefaultAction(QAction *act) connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); connect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); } - if (d->wce_menubar) { - d->wce_menubar->rebuild(); + if (d->impl->nativeMenuBarAdapter()) { + d->impl->nativeMenuBarAdapter()->rebuild(); } #endif } diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index 2b8558b..b49e039 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -61,6 +61,8 @@ #include "qguifunctions_wince.h" #endif +#include "qabstractmenubarimpl_p.h" + #ifndef QT_NO_MENUBAR #ifdef Q_WS_S60 class CCoeControl; @@ -71,6 +73,7 @@ class CEikMenuBar; QT_BEGIN_NAMESPACE #ifndef QT_NO_MENUBAR +class QToolBar; class QMenuBarExtension; class QMenuBarPrivate : public QWidgetPrivate { @@ -78,33 +81,19 @@ class QMenuBarPrivate : public QWidgetPrivate public: QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0), closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0), - nativeMenuBar(-1), doChildEffects(false) + doChildEffects(false) #ifdef QT3_SUPPORT , doAutoResize(false) #endif -#ifdef Q_WS_MAC - , mac_menubar(0) -#endif - + , impl(0) #ifdef Q_WS_WINCE - , wce_menubar(0), wceClassicMenu(false) -#endif -#ifdef Q_WS_S60 - , symbian_menubar(0) + , wceClassicMenu(false) #endif { } ~QMenuBarPrivate() { -#ifdef Q_WS_MAC - delete mac_menubar; -#endif -#ifdef Q_WS_WINCE - delete wce_menubar; -#endif -#ifdef Q_WS_S60 - delete symbian_menubar; -#endif + delete impl; } void init(); @@ -136,8 +125,6 @@ public: uint keyboardState : 1, altPressed : 1; QPointer keyboardFocusWidget; - - int nativeMenuBar : 3; // Only has values -1, 0, and 1 //firing of events void activateAction(QAction *, QAction::ActionEvent); @@ -173,106 +160,14 @@ public: #ifdef QT3_SUPPORT bool doAutoResize; #endif -#ifdef Q_WS_MAC - //mac menubar binding - struct QMacMenuBarPrivate { - QList actionItems; - OSMenuRef menu, apple_menu; - QMacMenuBarPrivate(); - ~QMacMenuBarPrivate(); - - void addAction(QAction *, QAction* =0); - void addAction(QMacMenuAction *, QMacMenuAction* =0); - void syncAction(QMacMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QMacMenuAction *); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QMacMenuAction *findAction(QAction *a) { - for(int i = 0; i < actionItems.size(); i++) { - QMacMenuAction *act = actionItems[i]; - if(a == act->action) - return act; - } - return 0; - } - } *mac_menubar; - static bool macUpdateMenuBarImmediatly(); - bool macWidgetHasNativeMenubar(QWidget *widget); - void macCreateMenuBar(QWidget *); - void macDestroyMenuBar(); - OSMenuRef macMenu(); -#endif -#ifdef Q_WS_WINCE - void wceCreateMenuBar(QWidget *); - void wceDestroyMenuBar(); - struct QWceMenuBarPrivate { - QList actionItems; - QList actionItemsLeftButton; - QList> actionItemsClassic; - HMENU menuHandle; - HMENU leftButtonMenuHandle; - HWND menubarHandle; - HWND parentWindowHandle; - bool leftButtonIsMenu; - QPointer leftButtonAction; - QMenuBarPrivate *d; - int leftButtonCommand; - - QWceMenuBarPrivate(QMenuBarPrivate *menubar); - ~QWceMenuBarPrivate(); - void addAction(QAction *, QAction* =0); - void addAction(QWceMenuAction *, QWceMenuAction* =0); - void syncAction(QWceMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QWceMenuAction *); - void rebuild(); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QWceMenuAction *findAction(QAction *a) { - for(int i = 0; i < actionItems.size(); i++) { - QWceMenuAction *act = actionItems[i]; - if(a == act->action) - return act; - } - return 0; - } - } *wce_menubar; - bool wceClassicMenu; - void wceCommands(uint command); - void wceRefresh(); - bool wceEmitSignals(QList actions, uint command); -#endif -#ifdef Q_WS_S60 - void symbianCreateMenuBar(QWidget *); - void symbianDestroyMenuBar(); - void reparentMenuBar(QWidget *oldParent, QWidget *newParent); - struct QSymbianMenuBarPrivate { - QList actionItems; - QMenuBarPrivate *d; - QSymbianMenuBarPrivate(QMenuBarPrivate *menubar); - ~QSymbianMenuBarPrivate(); - void addAction(QAction *, QAction* =0); - void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); - void syncAction(QSymbianMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QSymbianMenuAction *); - void rebuild(); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QSymbianMenuAction *findAction(QAction *a) { - for(int i = 0; i < actionItems.size(); i++) { - QSymbianMenuAction *act = actionItems[i]; - if(a == act->action) - return act; - } - return 0; - } - void insertNativeMenuItems(const QList &actions); - - } *symbian_menubar; - static int symbianCommands(int command); -#endif + QAbstractMenuBarImpl *impl; #ifdef QT_SOFTKEYS_ENABLED QAction *menuBarAction; #endif + + void updateCornerWidgetToolBar(); + QToolBar *cornerWidgetToolBar; + QWidget *cornerWidgetContainer; }; #endif diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp new file mode 100644 index 0000000..195f0ea --- /dev/null +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -0,0 +1,244 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmenubarimpl_p.h" + +#ifndef QT_NO_MENUBAR + +#include "qapplication.h" +#include "qdebug.h" +#include "qevent.h" +#include "qmenu.h" +#include "qmenubar.h" + +QT_BEGIN_NAMESPACE + +QMenuBarImpl::~QMenuBarImpl() +{ +#ifdef Q_WS_MAC + macDestroyMenuBar(); +#endif +#ifdef Q_WS_WINCE + if (qt_wince_is_mobile()) + wceDestroyMenuBar(); +#endif +#ifdef Q_WS_S60 + symbianDestroyMenuBar(); +#endif +} + +void QMenuBarImpl::init(QMenuBar *_menuBar) +{ + nativeMenuBar = -1; + menuBar = _menuBar; +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + adapter = 0; +#endif +#ifdef Q_WS_MAC + macCreateMenuBar(menuBar->parentWidget()); + if(adapter) + menuBar->hide(); +#endif +#ifdef Q_WS_WINCE + if (qt_wince_is_mobile()) { + wceCreateMenuBar(menuBar->parentWidget()); + if(adapter) + menuBar->hide(); + } + else { + QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); + } +#endif +} + +bool QMenuBarImpl::allowSetVisible() const +{ +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + // FIXME: Port this to a setVisible() method + /* + if (isNativeMenuBar()) { + if (!visible) + QWidget::setVisible(false); + return; + } + */ + return !isNativeMenuBar(); +#endif + return true; +} + +void QMenuBarImpl::actionEvent(QActionEvent *e) +{ +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + if (adapter) { + if(e->type() == QEvent::ActionAdded) + adapter->addAction(e->action(), e->before()); + else if(e->type() == QEvent::ActionRemoved) + adapter->removeAction(e->action()); + else if(e->type() == QEvent::ActionChanged) + adapter->syncAction(e->action()); + } +#else + Q_UNUSED(e); +#endif +} + +void QMenuBarImpl::handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) +{ +#ifdef Q_WS_X11 + Q_UNUSED(oldParent) + Q_UNUSED(newParent) + Q_UNUSED(oldWindow) + Q_UNUSED(newWindow) +#endif + +#ifdef Q_WS_MAC + if (isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { + // If the new parent got a native menubar from before, keep that + // menubar rather than replace it with this one (because a parents + // menubar has precedence over children menubars). + macDestroyMenuBar(); + macCreateMenuBar(newParent); + } +#endif +#ifdef Q_WS_WINCE + if (qt_wince_is_mobile() && nativeMenuBarAdapter()) + adapter->rebuild(); +#endif +#ifdef Q_WS_S60 + + // Construct d->impl->nativeMenuBarAdapter() when this code path is entered first time + // and when newParent != NULL + if (!adapter) + symbianCreateMenuBar(newParent); + + // Reparent and rebuild menubar when parent is changed + if (adapter) { + if (oldParent != newParent) + reparentMenuBar(oldParent, newParent); + menuBar->hide(); + adapter->rebuild(); + } + +#ifdef QT_SOFTKEYS_ENABLED + // Constuct menuBarAction when this code path is entered first time + if (!menuBarAction) { + if (newParent) { + menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent); + 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 +} + +bool QMenuBarImpl::allowCornerWidgets() const +{ + return true; +} + +void QMenuBarImpl::popupAction(QAction *) +{ +} + +void QMenuBarImpl::setNativeMenuBar(bool value) +{ + if (nativeMenuBar == -1 || (value != bool(nativeMenuBar))) { + nativeMenuBar = value; +#ifdef Q_WS_MAC + if (!nativeMenuBar) { + extern void qt_mac_clear_menubar(); + qt_mac_clear_menubar(); + macDestroyMenuBar(); + const QList &menubarActions = actions(); + for (int i = 0; i < menubarActions.size(); ++i) { + const QAction *action = menubarActions.at(i); + if (QMenu *menu = action->menu()) { + delete menu->d_func()->mac_menu; + menu->d_func()->mac_menu = 0; + } + } + } else { + macCreateMenuBar(parentWidget()); + } + macUpdateMenuBar(); + updateGeometry(); + if (!nativeMenuBar && parentWidget()) + setVisible(true); +#endif + } +} + +bool QMenuBarImpl::isNativeMenuBar() const +{ +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + if (nativeMenuBar == -1) { + return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar); + } + return nativeMenuBar; +#else + return false; +#endif +} + +bool QMenuBarImpl::shortcutsHandledByNativeMenuBar() const +{ +#ifdef Q_WS_MAC + return true; +#else + return false; +#endif +} + +bool QMenuBarImpl::menuBarEventFilter(QObject *, QEvent *) +{ + return false; +} + +QT_END_NAMESPACE + +#endif // QT_NO_MENUBAR diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h new file mode 100644 index 0000000..e770b5b --- /dev/null +++ b/src/gui/widgets/qmenubarimpl_p.h @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMENUBARIMPL_P_H +#define QMENUBARIMPL_P_H + +#ifndef QT_NO_MENUBAR + +#include "qabstractmenubarimpl_p.h" + +QT_BEGIN_NAMESPACE + +class QMenuBar; + +class QMenuBarImpl : public QAbstractMenuBarImpl +{ +public: + ~QMenuBarImpl(); + + virtual void init(QMenuBar *); + + virtual bool allowSetVisible() const; + + virtual void actionEvent(QActionEvent *e); + + virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow); + + virtual bool allowCornerWidgets() const; + + virtual void popupAction(QAction*); + + virtual void setNativeMenuBar(bool); + virtual bool isNativeMenuBar() const; + + virtual bool shortcutsHandledByNativeMenuBar() const; + virtual bool menuBarEventFilter(QObject *, QEvent *event); + +private: + QMenuBar *menuBar; + int nativeMenuBar : 3; // Only has values -1, 0, and 1 + +#ifdef Q_WS_MAC + //mac menubar binding + struct QMacMenuBarPrivate { + QList actionItems; + OSMenuRef menu, apple_menu; + QMacMenuBarPrivate(); + ~QMacMenuBarPrivate(); + + void addAction(QAction *, QAction* =0); + void addAction(QMacMenuAction *, QMacMenuAction* =0); + void syncAction(QMacMenuAction *); + inline void syncAction(QAction *a) { syncAction(findAction(a)); } + void removeAction(QMacMenuAction *); + inline void removeAction(QAction *a) { removeAction(findAction(a)); } + inline QMacMenuAction *findAction(QAction *a) { + for(int i = 0; i < actionItems.size(); i++) { + QMacMenuAction *act = actionItems[i]; + if(a == act->action) + return act; + } + return 0; + } + } adapter; + static bool macUpdateMenuBarImmediatly(); + bool macWidgetHasNativeMenubar(QWidget *widget); + void macCreateMenuBar(QWidget *); + void macDestroyMenuBar(); + OSMenuRef macMenu(); +#endif +#ifdef Q_WS_WINCE + void wceCreateMenuBar(QWidget *); + void wceDestroyMenuBar(); + struct QWceMenuBarPrivate { + QList actionItems; + QList actionItemsLeftButton; + QList> actionItemsClassic; + HMENU menuHandle; + HMENU leftButtonMenuHandle; + HWND menubarHandle; + HWND parentWindowHandle; + bool leftButtonIsMenu; + QPointer leftButtonAction; + QMenuBarPrivate *d; + int leftButtonCommand; + + QWceMenuBarPrivate(QMenuBarPrivate *menubar); + ~QWceMenuBarPrivate(); + void addAction(QAction *, QAction* =0); + void addAction(QWceMenuAction *, QWceMenuAction* =0); + void syncAction(QWceMenuAction *); + inline void syncAction(QAction *a) { syncAction(findAction(a)); } + void removeAction(QWceMenuAction *); + void rebuild(); + inline void removeAction(QAction *a) { removeAction(findAction(a)); } + inline QWceMenuAction *findAction(QAction *a) { + for(int i = 0; i < actionItems.size(); i++) { + QWceMenuAction *act = actionItems[i]; + if(a == act->action) + return act; + } + return 0; + } + } adapter; + bool wceClassicMenu; + void wceCommands(uint command); + void wceRefresh(); + bool wceEmitSignals(QList actions, uint command); +#endif +#ifdef Q_WS_S60 + void symbianCreateMenuBar(QWidget *); + void symbianDestroyMenuBar(); + void reparentMenuBar(QWidget *oldParent, QWidget *newParent); + struct QSymbianMenuBarPrivate { + QList actionItems; + QMenuBarPrivate *d; + QSymbianMenuBarPrivate(QMenuBarPrivate *menubar); + ~QSymbianMenuBarPrivate(); + void addAction(QAction *, QAction* =0); + void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); + void syncAction(QSymbianMenuAction *); + inline void syncAction(QAction *a) { syncAction(findAction(a)); } + void removeAction(QSymbianMenuAction *); + void rebuild(); + inline void removeAction(QAction *a) { removeAction(findAction(a)); } + inline QSymbianMenuAction *findAction(QAction *a) { + for(int i = 0; i < actionItems.size(); i++) { + QSymbianMenuAction *act = actionItems[i]; + if(a == act->action) + return act; + } + return 0; + } + void insertNativeMenuItems(const QList &actions); + + } adapter; + static int symbianCommands(int command); +#endif +}; + +QT_END_NAMESPACE + +#endif // QT_NO_MENUBAR + +#endif /* QMENUBARIMPL_P_H */ diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index 669b838..e5d6890 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -4,6 +4,7 @@ HEADERS += \ widgets/qbuttongroup.h \ widgets/qabstractbutton.h \ widgets/qabstractbutton_p.h \ + widgets/qabstractmenubarimpl_p.h \ widgets/qabstractslider.h \ widgets/qabstractslider_p.h \ widgets/qabstractspinbox.h \ @@ -84,6 +85,7 @@ HEADERS += \ widgets/qprintpreviewwidget.h SOURCES += \ widgets/qabstractbutton.cpp \ + widgets/qabstractmenubarimpl_p.cpp \ widgets/qabstractslider.cpp \ widgets/qabstractspinbox.cpp \ widgets/qcalendarwidget.cpp \ @@ -110,6 +112,7 @@ SOURCES += \ widgets/qmdisubwindow.cpp \ widgets/qmenu.cpp \ widgets/qmenubar.cpp \ + widgets/qmenubarimpl.cpp \ widgets/qmenudata.cpp \ widgets/qprogressbar.cpp \ widgets/qpushbutton.cpp \ -- cgit v0.12 From be0d346052d69693c2780e62401f3c0d4b0d89d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 14 Apr 2011 10:00:27 +0200 Subject: Introduce menubar plugin system Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qabstractmenubarimpl_p.h | 12 ++++++++++++ src/gui/widgets/qmenubar.cpp | 4 +++- src/gui/widgets/qmenubarimpl.cpp | 24 ++++++++++++++++++++++++ src/gui/widgets/qmenubarimpl_p.h | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h index d001008..76eef28 100644 --- a/src/gui/widgets/qabstractmenubarimpl_p.h +++ b/src/gui/widgets/qabstractmenubarimpl_p.h @@ -41,7 +41,9 @@ #ifndef QABSTRACTMENUBARIMPL_P_H #define QABSTRACTMENUBARIMPL_P_H +#include #include +#include #ifndef QT_NO_MENUBAR @@ -54,6 +56,16 @@ class QMenuBar; class QObject; class QWidget; +class QAbstractMenuBarImpl; + +struct QMenuBarImplFactoryInterface : public QFactoryInterface +{ + virtual QAbstractMenuBarImpl* createImpl() = 0; +}; + +#define QMenuBarImplFactoryInterface_iid "com.nokia.qt.QMenuBarImplFactoryInterface" +Q_DECLARE_INTERFACE(QMenuBarImplFactoryInterface, QMenuBarImplFactoryInterface_iid) + /** * The platform-specific implementation of a menubar */ diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 0d13574..ec19908 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #ifndef QT_NO_MENUBAR @@ -728,7 +729,8 @@ void QMenuBarPrivate::init() Q_Q(QMenuBar); q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); q->setAttribute(Qt::WA_CustomWhatsThis); - impl = new QMenuBarImpl; + + impl = qt_guiMenuBarImplFactory()->createImpl(); impl->init(q); q->setBackgroundRole(QPalette::Button); diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index 195f0ea..4844e4e 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -48,6 +48,8 @@ #include "qmenu.h" #include "qmenubar.h" +#include + QT_BEGIN_NAMESPACE QMenuBarImpl::~QMenuBarImpl() @@ -239,6 +241,28 @@ bool QMenuBarImpl::menuBarEventFilter(QObject *, QEvent *) return false; } +struct QMenuBarImplFactory : public QMenuBarImplFactoryInterface +{ + QAbstractMenuBarImpl* createImpl() { return new QMenuBarImpl; } + virtual QStringList keys() const { return QStringList(); } +}; + +QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory() +{ + static QMenuBarImplFactoryInterface *factory = 0; + if (!factory) { +#ifndef QT_NO_LIBRARY + QFactoryLoader loader(QMenuBarImplFactoryInterface_iid, QLatin1String("/menubar")); + factory = qobject_cast(loader.instance(QLatin1String("default"))); +#endif // QT_NO_LIBRARY + if(!factory) { + static QMenuBarImplFactory def; + factory = &def; + } + } + return factory; +} + QT_END_NAMESPACE #endif // QT_NO_MENUBAR diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h index e770b5b..0546eb2 100644 --- a/src/gui/widgets/qmenubarimpl_p.h +++ b/src/gui/widgets/qmenubarimpl_p.h @@ -175,6 +175,8 @@ private: #endif }; +QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory(); + QT_END_NAMESPACE #endif // QT_NO_MENUBAR -- cgit v0.12 From bafeffd7b8b2c40761369ba496ee655dff6cf2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 14 Apr 2011 10:00:30 +0200 Subject: QAbstractMenuBarImpl::allowSetVisible => setVisible This makes it possible to alter the behavior of QMenuBar::setVisible(). It seems to be needed for the Mac menubar. Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qabstractmenubarimpl_p.h | 3 +-- src/gui/widgets/qmenubar.cpp | 5 +---- src/gui/widgets/qmenubarimpl.cpp | 10 +++------- src/gui/widgets/qmenubarimpl_p.h | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h index 76eef28..25441df 100644 --- a/src/gui/widgets/qabstractmenubarimpl_p.h +++ b/src/gui/widgets/qabstractmenubarimpl_p.h @@ -77,8 +77,7 @@ public: // QMenuBarPrivate::init() virtual void init(QMenuBar *) = 0; - // QMenuBar::setVisible() - virtual bool allowSetVisible() const = 0; + virtual void setVisible(bool visible) = 0; virtual void actionEvent(QActionEvent *) = 0; diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index ec19908..556c192 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -1055,10 +1055,7 @@ void QMenuBar::paintEvent(QPaintEvent *e) void QMenuBar::setVisible(bool visible) { Q_D(QMenuBar); - if (!d->impl->allowSetVisible()) { - return; - } - QWidget::setVisible(visible); + d->impl->setVisible(visible); } /*! diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index 4844e4e..1ca2e11 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -90,20 +90,16 @@ void QMenuBarImpl::init(QMenuBar *_menuBar) #endif } -bool QMenuBarImpl::allowSetVisible() const +void QMenuBarImpl::setVisible(bool visible) { #if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - // FIXME: Port this to a setVisible() method - /* if (isNativeMenuBar()) { if (!visible) - QWidget::setVisible(false); + menuBar->QWidget::setVisible(false); return; } - */ - return !isNativeMenuBar(); #endif - return true; + menuBar->QWidget::setVisible(visible); } void QMenuBarImpl::actionEvent(QActionEvent *e) diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h index 0546eb2..e7a3bde 100644 --- a/src/gui/widgets/qmenubarimpl_p.h +++ b/src/gui/widgets/qmenubarimpl_p.h @@ -56,7 +56,7 @@ public: virtual void init(QMenuBar *); - virtual bool allowSetVisible() const; + virtual void setVisible(bool visible); virtual void actionEvent(QActionEvent *e); -- cgit v0.12 From a624a4011adca00d7334462c4d33f574c465110a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 14 Apr 2011 10:00:33 +0200 Subject: Make ctor and dtor of QAbstractMenuBarImpl inline This way the class does not need to be exported Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qabstractmenubarimpl_p.cpp | 44 ------------------------------ src/gui/widgets/qabstractmenubarimpl_p.h | 5 ++-- src/gui/widgets/widgets.pri | 1 - 3 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 src/gui/widgets/qabstractmenubarimpl_p.cpp diff --git a/src/gui/widgets/qabstractmenubarimpl_p.cpp b/src/gui/widgets/qabstractmenubarimpl_p.cpp deleted file mode 100644 index bc16030..0000000 --- a/src/gui/widgets/qabstractmenubarimpl_p.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include - -QAbstractMenuBarImpl::~QAbstractMenuBarImpl() -{} diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h index 25441df..156ee6a 100644 --- a/src/gui/widgets/qabstractmenubarimpl_p.h +++ b/src/gui/widgets/qabstractmenubarimpl_p.h @@ -69,10 +69,11 @@ Q_DECLARE_INTERFACE(QMenuBarImplFactoryInterface, QMenuBarImplFactoryInterface_i /** * The platform-specific implementation of a menubar */ -class Q_GUI_EXPORT QAbstractMenuBarImpl +class QAbstractMenuBarImpl { public: - virtual ~QAbstractMenuBarImpl(); + QAbstractMenuBarImpl() {} + virtual ~QAbstractMenuBarImpl() {} // QMenuBarPrivate::init() virtual void init(QMenuBar *) = 0; diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index e5d6890..f39b941 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -85,7 +85,6 @@ HEADERS += \ widgets/qprintpreviewwidget.h SOURCES += \ widgets/qabstractbutton.cpp \ - widgets/qabstractmenubarimpl_p.cpp \ widgets/qabstractslider.cpp \ widgets/qabstractspinbox.cpp \ widgets/qcalendarwidget.cpp \ -- cgit v0.12 From 3d188ffae259584c4351c5fa766a49da9b189112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 14 Apr 2011 10:00:36 +0200 Subject: Renamed QAbstractMenuBarImpl to QAbstractMenuBarInterface Merge-request: 916 Reviewed-by: Thierry Bastian --- src/gui/widgets/qabstractmenubarimpl_p.h | 116 -------------------------- src/gui/widgets/qabstractmenubarinterface_p.h | 116 ++++++++++++++++++++++++++ src/gui/widgets/qmenubar_p.h | 4 +- src/gui/widgets/qmenubarimpl.cpp | 2 +- src/gui/widgets/qmenubarimpl_p.h | 4 +- src/gui/widgets/widgets.pri | 2 +- 6 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 src/gui/widgets/qabstractmenubarimpl_p.h create mode 100644 src/gui/widgets/qabstractmenubarinterface_p.h diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h deleted file mode 100644 index 156ee6a..0000000 --- a/src/gui/widgets/qabstractmenubarimpl_p.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QABSTRACTMENUBARIMPL_P_H -#define QABSTRACTMENUBARIMPL_P_H - -#include -#include -#include - -#ifndef QT_NO_MENUBAR - -QT_BEGIN_NAMESPACE - -class QAction; -class QActionEvent; -class QEvent; -class QMenuBar; -class QObject; -class QWidget; - -class QAbstractMenuBarImpl; - -struct QMenuBarImplFactoryInterface : public QFactoryInterface -{ - virtual QAbstractMenuBarImpl* createImpl() = 0; -}; - -#define QMenuBarImplFactoryInterface_iid "com.nokia.qt.QMenuBarImplFactoryInterface" -Q_DECLARE_INTERFACE(QMenuBarImplFactoryInterface, QMenuBarImplFactoryInterface_iid) - -/** - * The platform-specific implementation of a menubar - */ -class QAbstractMenuBarImpl -{ -public: - QAbstractMenuBarImpl() {} - virtual ~QAbstractMenuBarImpl() {} - - // QMenuBarPrivate::init() - virtual void init(QMenuBar *) = 0; - - virtual void setVisible(bool visible) = 0; - - virtual void actionEvent(QActionEvent *) = 0; - - // QMenuBar::handleReparent() - virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0; - - // QMenuBarPrivate::updateGeometries() - // QMenuBar::minimumSizeHint() - // QMenuBar::sizeHint() - // QMenuBar::heightForWidth() - virtual bool allowCornerWidgets() const = 0; - - // QMenuBar::_q_internalShortcutActivated() - virtual void popupAction(QAction*) = 0; - - // QMenuBar::setNativeMenuBar() - virtual void setNativeMenuBar(bool) = 0; - - virtual bool isNativeMenuBar() const = 0; - - /** - * Return true if the native menubar is capable of listening to the - * shortcut keys. If false is returned, QMenuBar will trigger actions on - * shortcut itself. - */ - virtual bool shortcutsHandledByNativeMenuBar() const = 0; - - virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_MENUBAR - -#endif // QABSTRACTMENUBARIMPL_P_H diff --git a/src/gui/widgets/qabstractmenubarinterface_p.h b/src/gui/widgets/qabstractmenubarinterface_p.h new file mode 100644 index 0000000..a014bc1 --- /dev/null +++ b/src/gui/widgets/qabstractmenubarinterface_p.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QABSTRACTMENUBARINTERFACE_P_H +#define QABSTRACTMENUBARINTERFACE_P_H + +#include +#include +#include + +#ifndef QT_NO_MENUBAR + +QT_BEGIN_NAMESPACE + +class QAction; +class QActionEvent; +class QEvent; +class QMenuBar; +class QObject; +class QWidget; + +class QAbstractMenuBarInterface; + +struct QMenuBarImplFactoryInterface : public QFactoryInterface +{ + virtual QAbstractMenuBarInterface* createImpl() = 0; +}; + +#define QMenuBarImplFactoryInterface_iid "com.nokia.qt.QMenuBarImplFactoryInterface" +Q_DECLARE_INTERFACE(QMenuBarImplFactoryInterface, QMenuBarImplFactoryInterface_iid) + +/** + * The platform-specific implementation of a menubar + */ +class QAbstractMenuBarInterface +{ +public: + QAbstractMenuBarInterface() {} + virtual ~QAbstractMenuBarInterface() {} + + // QMenuBarPrivate::init() + virtual void init(QMenuBar *) = 0; + + virtual void setVisible(bool visible) = 0; + + virtual void actionEvent(QActionEvent *) = 0; + + // QMenuBar::handleReparent() + virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0; + + // QMenuBarPrivate::updateGeometries() + // QMenuBar::minimumSizeHint() + // QMenuBar::sizeHint() + // QMenuBar::heightForWidth() + virtual bool allowCornerWidgets() const = 0; + + // QMenuBar::_q_internalShortcutActivated() + virtual void popupAction(QAction*) = 0; + + // QMenuBar::setNativeMenuBar() + virtual void setNativeMenuBar(bool) = 0; + + virtual bool isNativeMenuBar() const = 0; + + /** + * Return true if the native menubar is capable of listening to the + * shortcut keys. If false is returned, QMenuBar will trigger actions on + * shortcut itself. + */ + virtual bool shortcutsHandledByNativeMenuBar() const = 0; + + virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_MENUBAR + +#endif // QABSTRACTMENUBARINTERFACE_P_H diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index b49e039..427cd30 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -61,7 +61,7 @@ #include "qguifunctions_wince.h" #endif -#include "qabstractmenubarimpl_p.h" +#include "qabstractmenubarinterface_p.h" #ifndef QT_NO_MENUBAR #ifdef Q_WS_S60 @@ -160,7 +160,7 @@ public: #ifdef QT3_SUPPORT bool doAutoResize; #endif - QAbstractMenuBarImpl *impl; + QAbstractMenuBarInterface *impl; #ifdef QT_SOFTKEYS_ENABLED QAction *menuBarAction; #endif diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index 1ca2e11..4f2ad72 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -239,7 +239,7 @@ bool QMenuBarImpl::menuBarEventFilter(QObject *, QEvent *) struct QMenuBarImplFactory : public QMenuBarImplFactoryInterface { - QAbstractMenuBarImpl* createImpl() { return new QMenuBarImpl; } + QAbstractMenuBarInterface* createImpl() { return new QMenuBarImpl; } virtual QStringList keys() const { return QStringList(); } }; diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h index e7a3bde..08ac6a0 100644 --- a/src/gui/widgets/qmenubarimpl_p.h +++ b/src/gui/widgets/qmenubarimpl_p.h @@ -43,13 +43,13 @@ #ifndef QT_NO_MENUBAR -#include "qabstractmenubarimpl_p.h" +#include "qabstractmenubarinterface_p.h" QT_BEGIN_NAMESPACE class QMenuBar; -class QMenuBarImpl : public QAbstractMenuBarImpl +class QMenuBarImpl : public QAbstractMenuBarInterface { public: ~QMenuBarImpl(); diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index f39b941..97d23f7 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -4,7 +4,7 @@ HEADERS += \ widgets/qbuttongroup.h \ widgets/qabstractbutton.h \ widgets/qabstractbutton_p.h \ - widgets/qabstractmenubarimpl_p.h \ + widgets/qabstractmenubarinterface_p.h \ widgets/qabstractslider.h \ widgets/qabstractslider_p.h \ widgets/qabstractspinbox.h \ -- cgit v0.12 From 56c3de426d97ab7c8fbb3f5766e1872d6f2e91e9 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 14 Apr 2011 11:26:34 +0200 Subject: Fix copyright and a few codestyle mistakes Reviewed-By: Trust-Me Merge-Request: 916 --- src/gui/widgets/qmenubar.cpp | 194 +++++++++++++++++++-------------------- src/gui/widgets/qmenubarimpl.cpp | 18 ++-- src/gui/widgets/qmenubarimpl_p.h | 15 +-- 3 files changed, 113 insertions(+), 114 deletions(-) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 556c192..357c0fa 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -122,8 +122,8 @@ QSize QMenuBarExtension::sizeHint() const */ QAction *QMenuBarPrivate::actionAt(QPoint p) const { - for(int i = 0; i < actions.size(); ++i) { - if(actionRect(actions.at(i)).contains(p)) + for (int i = 0; i < actions.size(); ++i) { + if (actionRect(actions.at(i)).contains(p)) return actions.at(i); } return 0; @@ -171,12 +171,12 @@ bool QMenuBarPrivate::isVisible(QAction *action) void QMenuBarPrivate::updateGeometries() { Q_Q(QMenuBar); - if(!itemsDirty) + if (!itemsDirty) return; int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2); int q_start = -1; - if(impl->allowCornerWidgets() && (leftWidget || rightWidget)) { + if (impl->allowCornerWidgets() && (leftWidget || rightWidget)) { int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q) + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q) @@ -199,7 +199,7 @@ void QMenuBarPrivate::updateGeometries() } #ifndef QT_NO_SHORTCUT - if(!impl->shortcutsHandledByNativeMenuBar() && itemsDirty) { + if (!impl->shortcutsHandledByNativeMenuBar() && itemsDirty) { for(int j = 0; j < shortcutIndexMap.size(); ++j) q->releaseShortcut(shortcutIndexMap.value(j)); shortcutIndexMap.resize(0); // faster than clear @@ -207,7 +207,7 @@ void QMenuBarPrivate::updateGeometries() shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); } #endif - if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. + if (q->isNativeMenuBar()) {//nothing to see here folks, move along.. itemsDirty = false; return; } @@ -282,7 +282,7 @@ QRect QMenuBarPrivate::actionRect(QAction *act) const void QMenuBarPrivate::focusFirstAction() { - if(!currentAction) { + if (!currentAction) { updateGeometries(); int index = 0; while (index < actions.count() && actionRects.at(index).isNull()) ++index; @@ -299,16 +299,16 @@ void QMenuBarPrivate::setKeyboardMode(bool b) return; } keyboardState = b; - if(b) { + if (b) { QWidget *fw = QApplication::focusWidget(); if (fw != q) keyboardFocusWidget = fw; focusFirstAction(); q->setFocus(Qt::MenuBarFocusReason); } else { - if(!popupState) + if (!popupState) setCurrentAction(0); - if(keyboardFocusWidget) { + if (keyboardFocusWidget) { if (QApplication::focusWidget() == q) keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); keyboardFocusWidget = 0; @@ -320,7 +320,7 @@ void QMenuBarPrivate::setKeyboardMode(bool b) void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) { Q_Q(QMenuBar); - if(!action || !action->menu() || closePopupMode) + if (!action || !action->menu() || closePopupMode) return; popupState = true; if (action->isEnabled() && action->menu()->isEnabled()) { @@ -360,10 +360,10 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) 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())); activeMenu->popup(pos); - if(activateFirst) + if (activateFirst) activeMenu->d_func()->setFirstActionActive(); } q->update(actionRect(action)); @@ -371,7 +371,7 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst) { - if(currentAction == action && popup == popupState) + if (currentAction == action && popup == popupState) return; autoReleaseTimer.stop(); @@ -379,7 +379,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat doChildEffects = (popup && !activeMenu); Q_Q(QMenuBar); QWidget *fw = 0; - if(QMenu *menu = activeMenu) { + if (QMenu *menu = activeMenu) { activeMenu = 0; if (popup) { fw = q->window()->focusWidget(); @@ -388,7 +388,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat menu->hide(); } - if(currentAction) + if (currentAction) q->update(actionRect(currentAction)); popupState = popup; @@ -398,7 +398,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat currentAction = action; if (action) { activateAction(action, QAction::Hover); - if(popup) + if (popup) popupAction(action, activateFirst); q->update(actionRect(action)); #ifndef QT_NO_STATUSTIP @@ -416,7 +416,7 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const { Q_Q(const QMenuBar); - if(!itemsDirty) + if (!itemsDirty) return; //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); for(int i = 0; i < actions.count(); i++) { QAction *action = actions.at(i); - if(!action->isVisible()) + if (!action->isVisible()) continue; QSize sz; //calc what I think the size is.. - if(action->isSeparator()) { + i f(action->isSeparator()) { if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) separator = i; continue; //we don't really position these! @@ -460,10 +460,10 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const q->initStyleOption(&opt, action); sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q); - if(!sz.isEmpty()) { + if (!sz.isEmpty()) { { //update the separator state int iWidth = sz.width() + itemSpacing; - if(separator == -1) + if (separator == -1) separator_start += iWidth; else separator_len += iWidth; @@ -488,9 +488,9 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const rect.setHeight(max_item_height); //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); - if(left < separator_start) { //wrap + if (left < separator_start) { //wrap separator_start = x = hmargin; y += max_item_height; } @@ -517,9 +517,9 @@ void QMenuBarPrivate::activateAction(QAction *action, QAction::ActionEvent actio if (action_e == QAction::Hover) action->showStatusText(q); -// if(action_e == QAction::Trigger) +// if (action_e == QAction::Trigger) // emit q->activated(action); -// else if(action_e == QAction::Hover) +// else if (action_e == QAction::Hover) // emit q->highlighted(action); } @@ -1011,7 +1011,7 @@ void QMenuBar::paintEvent(QPaintEvent *e) QRect adjustedActionRect = d->actionRect(action); if (adjustedActionRect.isEmpty() || !d->isVisible(action)) continue; - if(!e->rect().intersects(adjustedActionRect)) + if (!e->rect().intersects(adjustedActionRect)) continue; emptyArea -= adjustedActionRect; @@ -1022,7 +1022,7 @@ void QMenuBar::paintEvent(QPaintEvent *e) style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this); } //draw border - if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) { + if (int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) { QRegion borderReg; borderReg += QRect(0, 0, fw, height()); //left borderReg += QRect(width()-fw, 0, fw, height()); //right @@ -1064,7 +1064,7 @@ void QMenuBar::setVisible(bool visible) void QMenuBar::mousePressEvent(QMouseEvent *e) { Q_D(QMenuBar); - if(e->button() != Qt::LeftButton) + if (e->button() != Qt::LeftButton) return; d->mouseDown = true; @@ -1079,13 +1079,13 @@ void QMenuBar::mousePressEvent(QMouseEvent *e) return; } - if(d->currentAction == action && d->popupState) { - if(QMenu *menu = d->activeMenu) { + if (d->currentAction == action && d->popupState) { + if (QMenu *menu = d->activeMenu) { d->activeMenu = 0; menu->hide(); } #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)); #endif } else { @@ -1099,16 +1099,16 @@ void QMenuBar::mousePressEvent(QMouseEvent *e) void QMenuBar::mouseReleaseEvent(QMouseEvent *e) { Q_D(QMenuBar); - if(e->button() != Qt::LeftButton || !d->mouseDown) + if (e->button() != Qt::LeftButton || !d->mouseDown) return; d->mouseDown = false; 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 //so that we let the leave event set the current back to 0 d->setCurrentAction(action, false); - if(action) + if (action) d->activateAction(action, QAction::Trigger); } d->closePopupMode = 0; @@ -1122,15 +1122,15 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) Q_D(QMenuBar); d->updateGeometries(); int key = e->key(); - if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed - if(key == Qt::Key_Left) + if (isRightToLeft()) { // in reverse mode open/close key for submenues are reversed + if (key == Qt::Key_Left) key = Qt::Key_Right; - else if(key == Qt::Key_Right) + else if (key == Qt::Key_Right) key = Qt::Key_Left; } - if(key == Qt::Key_Tab) //means right + if (key == Qt::Key_Tab) //means 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; bool key_consumed = false; @@ -1140,11 +1140,11 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) case Qt::Key_Enter: case Qt::Key_Space: 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; - if(d->currentAction->menu()) { + if (d->currentAction->menu()) { 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->setCurrentAction(d->currentAction, false); d->setKeyboardMode(false); @@ -1154,7 +1154,7 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) case Qt::Key_Right: case Qt::Key_Left: { - if(d->currentAction) { + if (d->currentAction) { int index = d->actions.indexOf(d->currentAction); if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) { d->setCurrentAction(nextAction, d->popupState, true); @@ -1173,7 +1173,7 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) key_consumed = false; } - if(!key_consumed && + if (!key_consumed && (!e->modifiers() || (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) { int clashCount = 0; @@ -1185,14 +1185,14 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) continue; QAction *act = d->actions.at(i); QString s = act->text(); - if(!s.isEmpty()) { + if (!s.isEmpty()) { int ampersand = s.indexOf(QLatin1Char('&')); - if(ampersand >= 0) { - if(s[ampersand+1].toUpper() == c) { + if (ampersand >= 0) { + if (s[ampersand+1].toUpper() == c) { clashCount++; - if(!first) + if (!first) first = act; - if(act == d->currentAction) + if (act == d->currentAction) currentSelected = act; else if (!firstAfterCurrent && currentSelected) firstAfterCurrent = act; @@ -1202,18 +1202,18 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) } } QAction *next_action = 0; - if(clashCount >= 1) { - if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent)) + if (clashCount >= 1) { + if (clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent)) next_action = first; else next_action = firstAfterCurrent; } - if(next_action) { + if (next_action) { key_consumed = true; d->setCurrentAction(next_action, true, true); } } - if(key_consumed) + if (key_consumed) e->accept(); else e->ignore(); @@ -1239,7 +1239,7 @@ void QMenuBar::mouseMoveEvent(QMouseEvent *e) void QMenuBar::leaveEvent(QEvent *) { Q_D(QMenuBar); - if((!hasFocus() && !d->popupState) || + if ((!hasFocus() && !d->popupState) || (d->currentAction && d->currentAction->menu() == 0)) d->setCurrentAction(0); } @@ -1253,10 +1253,10 @@ void QMenuBar::actionEvent(QActionEvent *e) d->itemsDirty = true; 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(hovered()), this, SLOT(_q_actionHovered())); - } else if(e->type() == QEvent::ActionRemoved) { + } else if (e->type() == QEvent::ActionRemoved) { e->action()->disconnect(this); } if (isVisible()) { @@ -1271,7 +1271,7 @@ void QMenuBar::actionEvent(QActionEvent *e) void QMenuBar::focusInEvent(QFocusEvent *) { Q_D(QMenuBar); - if(d->keyboardState) + if (d->keyboardState) d->focusFirstAction(); } @@ -1281,7 +1281,7 @@ void QMenuBar::focusInEvent(QFocusEvent *) void QMenuBar::focusOutEvent(QFocusEvent *) { Q_D(QMenuBar); - if(!d->popupState) { + if (!d->popupState) { d->setCurrentAction(0); d->setKeyboardMode(false); } @@ -1371,10 +1371,10 @@ bool QMenuBar::autoGeometry() const void QMenuBar::changeEvent(QEvent *e) { Q_D(QMenuBar); - if(e->type() == QEvent::StyleChange) { + if (e->type() == QEvent::StyleChange) { d->itemsDirty = true; setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this)); - if(parentWidget()) + if (parentWidget()) resize(parentWidget()->width(), heightForWidth(parentWidget()->width())); d->updateGeometries(); } else if (e->type() == QEvent::ParentChange) { @@ -1403,12 +1403,12 @@ bool QMenuBar::event(QEvent *e) case QEvent::KeyPress: { QKeyEvent *ke = (QKeyEvent*)e; #if 0 - if(!d->keyboardState) { //all keypresses.. + if (!d->keyboardState) { //all keypresses.. d->setCurrentAction(0); return ; } #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); return true; } @@ -1426,7 +1426,7 @@ bool QMenuBar::event(QEvent *e) #endif case QEvent::Show: #ifdef QT3_SUPPORT - if(QWidget *p = parentWidget()) { + if (QWidget *p = parentWidget()) { // If itemsDirty == true, updateGeometries sends the MenubarUpdated event. if (!d->itemsDirty) { QMenubarUpdatedEvent menubarUpdated(this); @@ -1448,7 +1448,7 @@ bool QMenuBar::event(QEvent *e) #ifdef QT3_SUPPORT case QEvent::Hide: { - if(QWidget *p = parentWidget()) { + if (QWidget *p = parentWidget()) { QMenubarUpdatedEvent menubarUpdated(this); QApplication::sendEvent(p, &menubarUpdated); } @@ -1584,7 +1584,7 @@ QSize QMenuBar::minimumSizeHint() const const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 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(); d->calcActionRects(w - (2 * fw), 0); 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; if (d->impl->allowCornerWidgets()) { - if(d->leftWidget) { + if (d->leftWidget) { QSize sz = d->leftWidget->minimumSizeHint(); ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) + if (sz.height() + margin > ret.height()) ret.setHeight(sz.height() + margin); } - if(d->rightWidget) { + if (d->rightWidget) { QSize sz = d->rightWidget->minimumSizeHint(); ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) + if (sz.height() + margin > ret.height()) ret.setHeight(sz.height() + margin); } } - if(as_gui_menubar) { + if (as_gui_menubar) { QStyleOptionMenuItem opt; opt.rect = rect(); opt.menuRect = rect(); @@ -1638,7 +1638,7 @@ QSize QMenuBar::sizeHint() const const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 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(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; i < d->actionRects.count(); ++i) { @@ -1650,21 +1650,21 @@ QSize QMenuBar::sizeHint() const ret += QSize(fw + hmargin, fw + vmargin); } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if(d->impl->allowCornerWidgets()) { - if(d->leftWidget) { + if (d->impl->allowCornerWidgets()) { + if (d->leftWidget) { QSize sz = d->leftWidget->sizeHint(); ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) + if (sz.height() + margin > ret.height()) ret.setHeight(sz.height() + margin); } - if(d->rightWidget) { + if (d->rightWidget) { QSize sz = d->rightWidget->sizeHint(); ret.setWidth(ret.width() + sz.width()); - if(sz.height() + margin > ret.height()) + if (sz.height() + margin > ret.height()) ret.setHeight(sz.height() + margin); } } - if(as_gui_menubar) { + if (as_gui_menubar) { QStyleOptionMenuItem opt; opt.rect = rect(); opt.menuRect = rect(); @@ -1692,7 +1692,7 @@ int QMenuBar::heightForWidth(int) const const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 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) height = qMax(height, d->actionRects.at(i).height()); if (height) //there is at least one non-null item @@ -1701,13 +1701,13 @@ int QMenuBar::heightForWidth(int) const height += 2*vmargin; } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if(d->impl->allowCornerWidgets()) { - if(d->leftWidget) + if (d->impl->allowCornerWidgets()) { + if (d->leftWidget) height = qMax(d->leftWidget->sizeHint().height() + margin, height); - if(d->rightWidget) + if (d->rightWidget) height = qMax(d->rightWidget->sizeHint().height() + margin, height); } - if(as_gui_menubar) { + if (as_gui_menubar) { QStyleOptionMenuItem opt; opt.init(this); opt.menuRect = rect(); @@ -1814,13 +1814,11 @@ void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner) return; } - if(!d->impl->allowCornerWidgets()) { + if (!d->impl->allowCornerWidgets()) { d->updateCornerWidgetToolBar(); - } else { - if (w) { - w->setParent(this); - w->installEventFilter(this); - } + } else if (w) { + w->setParent(this); + w->installEventFilter(this); } 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) { QAction *act = popup ? popup->menuAction() : new QAction(this); - if(id != -1) + if (id != -1) static_cast(act)->setId(id); - if(icon) + if (icon) act->setIcon(*icon); - if(text) + if (text) act->setText(*text); - if(shortcut) + if (shortcut) act->setShortcut(*shortcut); - if(receiver && member) + if (receiver && member) QObject::connect(act, SIGNAL(triggered(bool)), receiver, member); - if(index == -1 || index >= actions().count()) + if (index == -1 || index >= actions().count()) addAction(act); else insertAction(actions().value(index), act); @@ -2006,7 +2004,7 @@ int QMenuBar::insertSeparator(int index) { QAction *act = new QAction(this); act->setSeparator(true); - if(index == -1 || index >= actions().count()) + if (index == -1 || index >= actions().count()) addAction(act); else insertAction(actions().value(index), act); @@ -2018,7 +2016,7 @@ int QMenuBar::insertSeparator(int index) */ bool QMenuBar::setItemParameter(int id, int param) { - if(QAction *act = findActionForId(id)) { + if (QAction *act = findActionForId(id)) { act->d_func()->param = param; return true; } @@ -2030,7 +2028,7 @@ bool QMenuBar::setItemParameter(int id, int param) */ int QMenuBar::itemParameter(int id) const { - if(QAction *act = findActionForId(id)) + if (QAction *act = findActionForId(id)) return act->d_func()->param; return id; } diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index 4f2ad72..d402507 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -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. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "qmenubarimpl_p.h" #ifndef QT_NO_MENUBAR @@ -75,16 +76,15 @@ void QMenuBarImpl::init(QMenuBar *_menuBar) #endif #ifdef Q_WS_MAC macCreateMenuBar(menuBar->parentWidget()); - if(adapter) + if (adapter) menuBar->hide(); #endif #ifdef Q_WS_WINCE if (qt_wince_is_mobile()) { wceCreateMenuBar(menuBar->parentWidget()); - if(adapter) + if (adapter) menuBar->hide(); - } - else { + } else { QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); } #endif @@ -106,11 +106,11 @@ void QMenuBarImpl::actionEvent(QActionEvent *e) { #if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) if (adapter) { - if(e->type() == QEvent::ActionAdded) + if (e->type() == QEvent::ActionAdded) adapter->addAction(e->action(), e->before()); - else if(e->type() == QEvent::ActionRemoved) + else if (e->type() == QEvent::ActionRemoved) adapter->removeAction(e->action()); - else if(e->type() == QEvent::ActionChanged) + else if (e->type() == QEvent::ActionChanged) adapter->syncAction(e->action()); } #else @@ -251,7 +251,7 @@ QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory() QFactoryLoader loader(QMenuBarImplFactoryInterface_iid, QLatin1String("/menubar")); factory = qobject_cast(loader.instance(QLatin1String("default"))); #endif // QT_NO_LIBRARY - if(!factory) { + if (!factory) { static QMenuBarImplFactory def; factory = &def; } diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h index 08ac6a0..749c395 100644 --- a/src/gui/widgets/qmenubarimpl_p.h +++ b/src/gui/widgets/qmenubarimpl_p.h @@ -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. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef QMENUBARIMPL_P_H #define QMENUBARIMPL_P_H @@ -91,9 +92,9 @@ private: void removeAction(QMacMenuAction *); inline void removeAction(QAction *a) { removeAction(findAction(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]; - if(a == act->action) + if (a == act->action) return act; } return 0; @@ -131,9 +132,9 @@ private: void rebuild(); inline void removeAction(QAction *a) { removeAction(findAction(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]; - if(a == act->action) + if (a == act->action) return act; } return 0; @@ -161,9 +162,9 @@ private: void rebuild(); inline void removeAction(QAction *a) { removeAction(findAction(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]; - if(a == act->action) + if (a == act->action) return act; } return 0; -- cgit v0.12 From 7b6a7f475119878681c9d0c06b29896ec3fe72c3 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 14 Apr 2011 13:58:25 +0200 Subject: Fix licence headers again for MR 900 See commit b00089261eafbdf5f92ed94d7fb20b402bfcaeb2 Reviewed-by: Trust me --- src/gui/itemviews/qidentityproxymodel.cpp | 21 +++++++------- src/gui/itemviews/qidentityproxymodel.h | 20 ++++++------- .../tst_qidentityproxymodel.cpp | 33 +++++++++++++--------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/gui/itemviews/qidentityproxymodel.cpp b/src/gui/itemviews/qidentityproxymodel.cpp index 9396e61..fcc0504 100644 --- a/src/gui/itemviews/qidentityproxymodel.cpp +++ b/src/gui/itemviews/qidentityproxymodel.cpp @@ -20,20 +20,21 @@ ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. ** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** +** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "qidentityproxymodel.h" #ifndef QT_NO_IDENTITYPROXYMODEL diff --git a/src/gui/itemviews/qidentityproxymodel.h b/src/gui/itemviews/qidentityproxymodel.h index b60aa0b..9845533 100644 --- a/src/gui/itemviews/qidentityproxymodel.h +++ b/src/gui/itemviews/qidentityproxymodel.h @@ -20,17 +20,17 @@ ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. ** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** +** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp index bbcdb4c..cfc3f1a 100644 --- a/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -1,13 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2011 Klarälvdalens Datakonsult AB, -** a KDAB Group company, info@kdab.com, -** author Stephen Kelly +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly ** All rights reserved. -** Contact: Nokia Corporation (info@qt.nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtGui module of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -20,17 +25,17 @@ ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** ** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. +** $QT_END_LICENSE$ ** ****************************************************************************/ -- cgit v0.12 From ea585d567bf0970c57e31846da044295d80774ba Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 14 Apr 2011 14:12:56 +0200 Subject: Build fix on QMenuBar Reviewed-By: gabi Merge-Request: 916 --- src/gui/widgets/qmenubar.cpp | 2 +- src/gui/widgets/qmenubarimpl.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 357c0fa..a968404 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -441,7 +441,7 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const QSize sz; //calc what I think the size is.. - i f(action->isSeparator()) { + if (action->isSeparator()) { if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) separator = i; continue; //we don't really position these! diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index d402507..db10c72 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -120,12 +120,10 @@ void QMenuBarImpl::actionEvent(QActionEvent *e) void QMenuBarImpl::handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) { -#ifdef Q_WS_X11 Q_UNUSED(oldParent) Q_UNUSED(newParent) Q_UNUSED(oldWindow) Q_UNUSED(newWindow) -#endif #ifdef Q_WS_MAC if (isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { -- cgit v0.12 From 68542b72f53f52df43063677e24994463872e81b Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 14 Apr 2011 14:50:33 +0200 Subject: Reverting merge request 916 Revert "Build fix on QMenuBar" This reverts commit ea585d567bf0970c57e31846da044295d80774ba. --- src/gui/widgets/qmenubar.cpp | 2 +- src/gui/widgets/qmenubarimpl.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index a968404..357c0fa 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -441,7 +441,7 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const QSize sz; //calc what I think the size is.. - if (action->isSeparator()) { + i f(action->isSeparator()) { if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) separator = i; continue; //we don't really position these! diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index db10c72..d402507 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -120,10 +120,12 @@ void QMenuBarImpl::actionEvent(QActionEvent *e) void QMenuBarImpl::handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) { +#ifdef Q_WS_X11 Q_UNUSED(oldParent) Q_UNUSED(newParent) Q_UNUSED(oldWindow) Q_UNUSED(newWindow) +#endif #ifdef Q_WS_MAC if (isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { -- cgit v0.12 From c6514537a8568050f5812a2b55fcf47a3ec2fce1 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 14 Apr 2011 14:58:25 +0200 Subject: Reverting merge request 916 Revert "Introduce menubar plugin system" This reverts commits 56c3de426d97ab7c8fb..f7b60fffb673b182e63 --- src/gui/widgets/qabstractmenubarimpl_p.cpp | 44 ++++++++++ src/gui/widgets/qabstractmenubarimpl_p.h | 104 +++++++++++++++++++++++ src/gui/widgets/qabstractmenubarinterface_p.h | 116 -------------------------- src/gui/widgets/qmenubar.cpp | 9 +- src/gui/widgets/qmenubar_p.h | 4 +- src/gui/widgets/qmenubarimpl.cpp | 34 ++------ src/gui/widgets/qmenubarimpl_p.h | 8 +- src/gui/widgets/widgets.pri | 3 +- 8 files changed, 167 insertions(+), 155 deletions(-) create mode 100644 src/gui/widgets/qabstractmenubarimpl_p.cpp create mode 100644 src/gui/widgets/qabstractmenubarimpl_p.h delete mode 100644 src/gui/widgets/qabstractmenubarinterface_p.h diff --git a/src/gui/widgets/qabstractmenubarimpl_p.cpp b/src/gui/widgets/qabstractmenubarimpl_p.cpp new file mode 100644 index 0000000..bc16030 --- /dev/null +++ b/src/gui/widgets/qabstractmenubarimpl_p.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +QAbstractMenuBarImpl::~QAbstractMenuBarImpl() +{} diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h new file mode 100644 index 0000000..d001008 --- /dev/null +++ b/src/gui/widgets/qabstractmenubarimpl_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QABSTRACTMENUBARIMPL_P_H +#define QABSTRACTMENUBARIMPL_P_H + +#include + +#ifndef QT_NO_MENUBAR + +QT_BEGIN_NAMESPACE + +class QAction; +class QActionEvent; +class QEvent; +class QMenuBar; +class QObject; +class QWidget; + +/** + * The platform-specific implementation of a menubar + */ +class Q_GUI_EXPORT QAbstractMenuBarImpl +{ +public: + virtual ~QAbstractMenuBarImpl(); + + // QMenuBarPrivate::init() + virtual void init(QMenuBar *) = 0; + + // QMenuBar::setVisible() + virtual bool allowSetVisible() const = 0; + + virtual void actionEvent(QActionEvent *) = 0; + + // QMenuBar::handleReparent() + virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0; + + // QMenuBarPrivate::updateGeometries() + // QMenuBar::minimumSizeHint() + // QMenuBar::sizeHint() + // QMenuBar::heightForWidth() + virtual bool allowCornerWidgets() const = 0; + + // QMenuBar::_q_internalShortcutActivated() + virtual void popupAction(QAction*) = 0; + + // QMenuBar::setNativeMenuBar() + virtual void setNativeMenuBar(bool) = 0; + + virtual bool isNativeMenuBar() const = 0; + + /** + * Return true if the native menubar is capable of listening to the + * shortcut keys. If false is returned, QMenuBar will trigger actions on + * shortcut itself. + */ + virtual bool shortcutsHandledByNativeMenuBar() const = 0; + + virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_MENUBAR + +#endif // QABSTRACTMENUBARIMPL_P_H diff --git a/src/gui/widgets/qabstractmenubarinterface_p.h b/src/gui/widgets/qabstractmenubarinterface_p.h deleted file mode 100644 index a014bc1..0000000 --- a/src/gui/widgets/qabstractmenubarinterface_p.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QABSTRACTMENUBARINTERFACE_P_H -#define QABSTRACTMENUBARINTERFACE_P_H - -#include -#include -#include - -#ifndef QT_NO_MENUBAR - -QT_BEGIN_NAMESPACE - -class QAction; -class QActionEvent; -class QEvent; -class QMenuBar; -class QObject; -class QWidget; - -class QAbstractMenuBarInterface; - -struct QMenuBarImplFactoryInterface : public QFactoryInterface -{ - virtual QAbstractMenuBarInterface* createImpl() = 0; -}; - -#define QMenuBarImplFactoryInterface_iid "com.nokia.qt.QMenuBarImplFactoryInterface" -Q_DECLARE_INTERFACE(QMenuBarImplFactoryInterface, QMenuBarImplFactoryInterface_iid) - -/** - * The platform-specific implementation of a menubar - */ -class QAbstractMenuBarInterface -{ -public: - QAbstractMenuBarInterface() {} - virtual ~QAbstractMenuBarInterface() {} - - // QMenuBarPrivate::init() - virtual void init(QMenuBar *) = 0; - - virtual void setVisible(bool visible) = 0; - - virtual void actionEvent(QActionEvent *) = 0; - - // QMenuBar::handleReparent() - virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0; - - // QMenuBarPrivate::updateGeometries() - // QMenuBar::minimumSizeHint() - // QMenuBar::sizeHint() - // QMenuBar::heightForWidth() - virtual bool allowCornerWidgets() const = 0; - - // QMenuBar::_q_internalShortcutActivated() - virtual void popupAction(QAction*) = 0; - - // QMenuBar::setNativeMenuBar() - virtual void setNativeMenuBar(bool) = 0; - - virtual bool isNativeMenuBar() const = 0; - - /** - * Return true if the native menubar is capable of listening to the - * shortcut keys. If false is returned, QMenuBar will trigger actions on - * shortcut itself. - */ - virtual bool shortcutsHandledByNativeMenuBar() const = 0; - - virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_MENUBAR - -#endif // QABSTRACTMENUBARINTERFACE_P_H diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 357c0fa..4a31132 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -55,7 +55,6 @@ #include #include #include -#include #ifndef QT_NO_MENUBAR @@ -729,8 +728,7 @@ void QMenuBarPrivate::init() Q_Q(QMenuBar); q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); q->setAttribute(Qt::WA_CustomWhatsThis); - - impl = qt_guiMenuBarImplFactory()->createImpl(); + impl = new QMenuBarImpl; impl->init(q); q->setBackgroundRole(QPalette::Button); @@ -1055,7 +1053,10 @@ void QMenuBar::paintEvent(QPaintEvent *e) void QMenuBar::setVisible(bool visible) { Q_D(QMenuBar); - d->impl->setVisible(visible); + if (!d->impl->allowSetVisible()) { + return; + } + QWidget::setVisible(visible); } /*! diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index 427cd30..b49e039 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -61,7 +61,7 @@ #include "qguifunctions_wince.h" #endif -#include "qabstractmenubarinterface_p.h" +#include "qabstractmenubarimpl_p.h" #ifndef QT_NO_MENUBAR #ifdef Q_WS_S60 @@ -160,7 +160,7 @@ public: #ifdef QT3_SUPPORT bool doAutoResize; #endif - QAbstractMenuBarInterface *impl; + QAbstractMenuBarImpl *impl; #ifdef QT_SOFTKEYS_ENABLED QAction *menuBarAction; #endif diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp index d402507..cbe9198 100644 --- a/src/gui/widgets/qmenubarimpl.cpp +++ b/src/gui/widgets/qmenubarimpl.cpp @@ -49,8 +49,6 @@ #include "qmenu.h" #include "qmenubar.h" -#include - QT_BEGIN_NAMESPACE QMenuBarImpl::~QMenuBarImpl() @@ -90,16 +88,20 @@ void QMenuBarImpl::init(QMenuBar *_menuBar) #endif } -void QMenuBarImpl::setVisible(bool visible) +bool QMenuBarImpl::allowSetVisible() const { #if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + // FIXME: Port this to a setVisible() method + /* if (isNativeMenuBar()) { if (!visible) - menuBar->QWidget::setVisible(false); + QWidget::setVisible(false); return; } + */ + return !isNativeMenuBar(); #endif - menuBar->QWidget::setVisible(visible); + return true; } void QMenuBarImpl::actionEvent(QActionEvent *e) @@ -237,28 +239,6 @@ bool QMenuBarImpl::menuBarEventFilter(QObject *, QEvent *) return false; } -struct QMenuBarImplFactory : public QMenuBarImplFactoryInterface -{ - QAbstractMenuBarInterface* createImpl() { return new QMenuBarImpl; } - virtual QStringList keys() const { return QStringList(); } -}; - -QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory() -{ - static QMenuBarImplFactoryInterface *factory = 0; - if (!factory) { -#ifndef QT_NO_LIBRARY - QFactoryLoader loader(QMenuBarImplFactoryInterface_iid, QLatin1String("/menubar")); - factory = qobject_cast(loader.instance(QLatin1String("default"))); -#endif // QT_NO_LIBRARY - if (!factory) { - static QMenuBarImplFactory def; - factory = &def; - } - } - return factory; -} - QT_END_NAMESPACE #endif // QT_NO_MENUBAR diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h index 749c395..c4ab2df 100644 --- a/src/gui/widgets/qmenubarimpl_p.h +++ b/src/gui/widgets/qmenubarimpl_p.h @@ -44,20 +44,20 @@ #ifndef QT_NO_MENUBAR -#include "qabstractmenubarinterface_p.h" +#include "qabstractmenubarimpl_p.h" QT_BEGIN_NAMESPACE class QMenuBar; -class QMenuBarImpl : public QAbstractMenuBarInterface +class QMenuBarImpl : public QAbstractMenuBarImpl { public: ~QMenuBarImpl(); virtual void init(QMenuBar *); - virtual void setVisible(bool visible); + virtual bool allowSetVisible() const; virtual void actionEvent(QActionEvent *e); @@ -176,8 +176,6 @@ private: #endif }; -QMenuBarImplFactoryInterface *qt_guiMenuBarImplFactory(); - QT_END_NAMESPACE #endif // QT_NO_MENUBAR diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index 97d23f7..e5d6890 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -4,7 +4,7 @@ HEADERS += \ widgets/qbuttongroup.h \ widgets/qabstractbutton.h \ widgets/qabstractbutton_p.h \ - widgets/qabstractmenubarinterface_p.h \ + widgets/qabstractmenubarimpl_p.h \ widgets/qabstractslider.h \ widgets/qabstractslider_p.h \ widgets/qabstractspinbox.h \ @@ -85,6 +85,7 @@ HEADERS += \ widgets/qprintpreviewwidget.h SOURCES += \ widgets/qabstractbutton.cpp \ + widgets/qabstractmenubarimpl_p.cpp \ widgets/qabstractslider.cpp \ widgets/qabstractspinbox.cpp \ widgets/qcalendarwidget.cpp \ -- cgit v0.12 From bc16ebdb7aeff70fe8149297183636ea7fd14ed1 Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Thu, 14 Apr 2011 15:30:34 +0200 Subject: Fix licence headers again for MR 900 See commit b00089261eafbdf5f92ed94d7fb20b402bfcaeb2 Reviewed-by: Gabriel de Dietrich --- .../code/src_gui_itemviews_qidentityproxymodel.cpp | 4 +--- src/gui/itemviews/qidentityproxymodel.cpp | 14 +++++++++----- src/gui/itemviews/qidentityproxymodel.h | 13 +++++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp index 8bd6520..6bf6c89 100644 --- a/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp +++ b/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp @@ -1,8 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2011 Klarälvdalens Datakonsult AB, -** a KDAB Group company, info@kdab.com, -** author Stephen Kelly +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/gui/itemviews/qidentityproxymodel.cpp b/src/gui/itemviews/qidentityproxymodel.cpp index fcc0504..60f7d98 100644 --- a/src/gui/itemviews/qidentityproxymodel.cpp +++ b/src/gui/itemviews/qidentityproxymodel.cpp @@ -1,13 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2011 Klarälvdalens Datakonsult AB, -** a KDAB Group company, info@kdab.com, -** author Stephen Kelly +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly ** All rights reserved. -** Contact: Nokia Corporation (info@qt.nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtGui module of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -34,7 +39,6 @@ ** ****************************************************************************/ - #include "qidentityproxymodel.h" #ifndef QT_NO_IDENTITYPROXYMODEL diff --git a/src/gui/itemviews/qidentityproxymodel.h b/src/gui/itemviews/qidentityproxymodel.h index 9845533..4b3176a 100644 --- a/src/gui/itemviews/qidentityproxymodel.h +++ b/src/gui/itemviews/qidentityproxymodel.h @@ -1,13 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2011 Klarälvdalens Datakonsult AB, -** a KDAB Group company, info@kdab.com, -** author Stephen Kelly +** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly ** All rights reserved. -** Contact: Nokia Corporation (info@qt.nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtGui module of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software -- cgit v0.12 From 443d5b17619002cd6bb428198c453271a01accab Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 15 Apr 2011 12:04:05 +0200 Subject: Totally kill MR 916 ... the hard way. Reviewed-by: Trust me --- src/gui/widgets/qabstractmenubarimpl_p.cpp | 44 --- src/gui/widgets/qabstractmenubarimpl_p.h | 104 ------- src/gui/widgets/qmenu_mac.mm | 4 +- src/gui/widgets/qmenu_p.h | 6 +- src/gui/widgets/qmenu_symbian.cpp | 4 +- src/gui/widgets/qmenu_wince.cpp | 4 +- src/gui/widgets/qmenubar.cpp | 439 +++++++++++++++++------------ src/gui/widgets/qmenubar_p.h | 129 ++++++++- src/gui/widgets/qmenubarimpl.cpp | 244 ---------------- src/gui/widgets/qmenubarimpl_p.h | 183 ------------ src/gui/widgets/widgets.pri | 3 - 11 files changed, 385 insertions(+), 779 deletions(-) delete mode 100644 src/gui/widgets/qabstractmenubarimpl_p.cpp delete mode 100644 src/gui/widgets/qabstractmenubarimpl_p.h delete mode 100644 src/gui/widgets/qmenubarimpl.cpp delete mode 100644 src/gui/widgets/qmenubarimpl_p.h diff --git a/src/gui/widgets/qabstractmenubarimpl_p.cpp b/src/gui/widgets/qabstractmenubarimpl_p.cpp deleted file mode 100644 index bc16030..0000000 --- a/src/gui/widgets/qabstractmenubarimpl_p.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include - -QAbstractMenuBarImpl::~QAbstractMenuBarImpl() -{} diff --git a/src/gui/widgets/qabstractmenubarimpl_p.h b/src/gui/widgets/qabstractmenubarimpl_p.h deleted file mode 100644 index d001008..0000000 --- a/src/gui/widgets/qabstractmenubarimpl_p.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QABSTRACTMENUBARIMPL_P_H -#define QABSTRACTMENUBARIMPL_P_H - -#include - -#ifndef QT_NO_MENUBAR - -QT_BEGIN_NAMESPACE - -class QAction; -class QActionEvent; -class QEvent; -class QMenuBar; -class QObject; -class QWidget; - -/** - * The platform-specific implementation of a menubar - */ -class Q_GUI_EXPORT QAbstractMenuBarImpl -{ -public: - virtual ~QAbstractMenuBarImpl(); - - // QMenuBarPrivate::init() - virtual void init(QMenuBar *) = 0; - - // QMenuBar::setVisible() - virtual bool allowSetVisible() const = 0; - - virtual void actionEvent(QActionEvent *) = 0; - - // QMenuBar::handleReparent() - virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0; - - // QMenuBarPrivate::updateGeometries() - // QMenuBar::minimumSizeHint() - // QMenuBar::sizeHint() - // QMenuBar::heightForWidth() - virtual bool allowCornerWidgets() const = 0; - - // QMenuBar::_q_internalShortcutActivated() - virtual void popupAction(QAction*) = 0; - - // QMenuBar::setNativeMenuBar() - virtual void setNativeMenuBar(bool) = 0; - - virtual bool isNativeMenuBar() const = 0; - - /** - * Return true if the native menubar is capable of listening to the - * shortcut keys. If false is returned, QMenuBar will trigger actions on - * shortcut itself. - */ - virtual bool shortcutsHandledByNativeMenuBar() const = 0; - - virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_MENUBAR - -#endif // QABSTRACTMENUBARIMPL_P_H diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index f780ee7..2977558 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -1639,7 +1639,7 @@ QMenuBarPrivate::QMacMenuBarPrivate::~QMacMenuBarPrivate() } void -QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QAction *before) +QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QMacMenuAction *before) { if (a->isSeparator() || !menu) return; @@ -1649,7 +1649,7 @@ QMenuBarPrivate::QMacMenuBarPrivate::addAction(QAction *a, QAction *before) #ifndef QT_MAC_USE_COCOA action->command = qt_mac_menu_static_cmd_id++; #endif - addAction(action, findAction(before)); + addAction(action, before); } void diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index 9fd55ca..005ce1d 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -154,9 +154,6 @@ public: #endif scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), hasCheckableItems(0), sloppyAction(0), doChildEffects(false) -#ifdef QT3_SUPPORT - ,emitHighlighted(false) -#endif #ifdef Q_WS_MAC ,mac_menu(0) #endif @@ -166,6 +163,9 @@ public: #ifdef Q_WS_S60 ,symbian_menu(0) #endif +#ifdef QT3_SUPPORT + ,emitHighlighted(false) +#endif { } ~QMenuPrivate() { diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 12c6c6e..d614bb8 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -398,12 +398,12 @@ void QMenuPrivate::QSymbianMenuPrivate::rebuild(bool) { } -void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QAction *a, QAction *before) +void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QAction *a, QSymbianMenuAction *before) { QSymbianMenuAction *action = new QSymbianMenuAction; action->action = a; action->command = qt_symbian_menu_static_cmd_id++; - addAction(action, findAction(before)); + addAction(action, before); } void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QSymbianMenuAction *action, QSymbianMenuAction *before) diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index 2210409..86a78ad 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -504,12 +504,12 @@ void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) rebuild(); } -void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QAction *before) +void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) { QWceMenuAction *action = new QWceMenuAction; action->action = a; action->command = qt_wce_menu_static_cmd_id++; - addAction(action, findAction(before)); + addAction(action, before); } void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 4a31132..5bfac9a 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -63,10 +63,9 @@ #include #endif -#include "qdebug.h" #include "qmenu_p.h" #include "qmenubar_p.h" -#include "qmenubarimpl_p.h" +#include "qdebug.h" #ifdef Q_WS_WINCE extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp @@ -121,8 +120,8 @@ QSize QMenuBarExtension::sizeHint() const */ QAction *QMenuBarPrivate::actionAt(QPoint p) const { - for (int i = 0; i < actions.size(); ++i) { - if (actionRect(actions.at(i)).contains(p)) + for(int i = 0; i < actions.size(); ++i) { + if(actionRect(actions.at(i)).contains(p)) return actions.at(i); } return 0; @@ -170,12 +169,11 @@ bool QMenuBarPrivate::isVisible(QAction *action) void QMenuBarPrivate::updateGeometries() { Q_Q(QMenuBar); - if (!itemsDirty) + if(!itemsDirty) return; int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2); int q_start = -1; - - if (impl->allowCornerWidgets() && (leftWidget || rightWidget)) { + if(leftWidget || rightWidget) { int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q) + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q) @@ -197,8 +195,16 @@ void QMenuBarPrivate::updateGeometries() } } +#ifdef Q_WS_MAC + if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. + itemsDirty = false; + return; + } +#endif + calcActionRects(q_width, q_start); + currentAction = 0; #ifndef QT_NO_SHORTCUT - if (!impl->shortcutsHandledByNativeMenuBar() && itemsDirty) { + if(itemsDirty) { for(int j = 0; j < shortcutIndexMap.size(); ++j) q->releaseShortcut(shortcutIndexMap.value(j)); shortcutIndexMap.resize(0); // faster than clear @@ -206,12 +212,6 @@ void QMenuBarPrivate::updateGeometries() shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); } #endif - if (q->isNativeMenuBar()) {//nothing to see here folks, move along.. - itemsDirty = false; - return; - } - calcActionRects(q_width, q_start); - currentAction = 0; itemsDirty = false; hiddenActions.clear(); @@ -281,7 +281,7 @@ QRect QMenuBarPrivate::actionRect(QAction *act) const void QMenuBarPrivate::focusFirstAction() { - if (!currentAction) { + if(!currentAction) { updateGeometries(); int index = 0; while (index < actions.count() && actionRects.at(index).isNull()) ++index; @@ -298,16 +298,16 @@ void QMenuBarPrivate::setKeyboardMode(bool b) return; } keyboardState = b; - if (b) { + if(b) { QWidget *fw = QApplication::focusWidget(); if (fw != q) keyboardFocusWidget = fw; focusFirstAction(); q->setFocus(Qt::MenuBarFocusReason); } else { - if (!popupState) + if(!popupState) setCurrentAction(0); - if (keyboardFocusWidget) { + if(keyboardFocusWidget) { if (QApplication::focusWidget() == q) keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); keyboardFocusWidget = 0; @@ -319,7 +319,7 @@ void QMenuBarPrivate::setKeyboardMode(bool b) void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) { Q_Q(QMenuBar); - if (!action || !action->menu() || closePopupMode) + if(!action || !action->menu() || closePopupMode) return; popupState = true; if (action->isEnabled() && action->menu()->isEnabled()) { @@ -359,10 +359,10 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) 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())); activeMenu->popup(pos); - if (activateFirst) + if(activateFirst) activeMenu->d_func()->setFirstActionActive(); } q->update(actionRect(action)); @@ -370,7 +370,7 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst) { - if (currentAction == action && popup == popupState) + if(currentAction == action && popup == popupState) return; autoReleaseTimer.stop(); @@ -378,7 +378,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat doChildEffects = (popup && !activeMenu); Q_Q(QMenuBar); QWidget *fw = 0; - if (QMenu *menu = activeMenu) { + if(QMenu *menu = activeMenu) { activeMenu = 0; if (popup) { fw = q->window()->focusWidget(); @@ -387,7 +387,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat menu->hide(); } - if (currentAction) + if(currentAction) q->update(actionRect(currentAction)); popupState = popup; @@ -397,7 +397,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat currentAction = action; if (action) { activateAction(action, QAction::Hover); - if (popup) + if(popup) popupAction(action, activateFirst); q->update(actionRect(action)); #ifndef QT_NO_STATUSTIP @@ -415,7 +415,7 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const { Q_Q(const QMenuBar); - if (!itemsDirty) + if(!itemsDirty) return; //let's reinitialize the buffer @@ -434,13 +434,13 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q); for(int i = 0; i < actions.count(); i++) { QAction *action = actions.at(i); - if (!action->isVisible()) + if(!action->isVisible()) continue; QSize sz; //calc what I think the size is.. - i f(action->isSeparator()) { + if(action->isSeparator()) { if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) separator = i; continue; //we don't really position these! @@ -459,10 +459,10 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const q->initStyleOption(&opt, action); sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q); - if (!sz.isEmpty()) { + if(!sz.isEmpty()) { { //update the separator state int iWidth = sz.width() + itemSpacing; - if (separator == -1) + if(separator == -1) separator_start += iWidth; else separator_len += iWidth; @@ -487,9 +487,9 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const rect.setHeight(max_item_height); //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); - if (left < separator_start) { //wrap + if(left < separator_start) { //wrap separator_start = x = hmargin; y += max_item_height; } @@ -516,9 +516,9 @@ void QMenuBarPrivate::activateAction(QAction *action, QAction::ActionEvent actio if (action_e == QAction::Hover) action->showStatusText(q); -// if (action_e == QAction::Trigger) +// if(action_e == QAction::Trigger) // emit q->activated(action); -// else if (action_e == QAction::Hover) +// else if(action_e == QAction::Hover) // emit q->highlighted(action); } @@ -728,9 +728,21 @@ void QMenuBarPrivate::init() Q_Q(QMenuBar); q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); q->setAttribute(Qt::WA_CustomWhatsThis); - impl = new QMenuBarImpl; - impl->init(q); - +#ifdef Q_WS_MAC + macCreateMenuBar(q->parentWidget()); + if(mac_menubar) + q->hide(); +#endif +#ifdef Q_WS_WINCE + if (qt_wince_is_mobile()) { + wceCreateMenuBar(q->parentWidget()); + if(wce_menubar) + q->hide(); + } + else { + QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); + } +#endif q->setBackgroundRole(QPalette::Button); oldWindow = oldParent = 0; #ifdef QT3_SUPPORT @@ -739,9 +751,6 @@ void QMenuBarPrivate::init() #ifdef QT_SOFTKEYS_ENABLED menuBarAction = 0; #endif - cornerWidgetToolBar = 0; - cornerWidgetContainer = 0; - handleReparent(); q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q)); @@ -799,8 +808,19 @@ QMenuBar::QMenuBar(QWidget *parent, const char *name) : QWidget(*new QMenuBarPri */ QMenuBar::~QMenuBar() { +#ifdef Q_WS_MAC + Q_D(QMenuBar); + d->macDestroyMenuBar(); +#endif +#ifdef Q_WS_WINCE + Q_D(QMenuBar); + if (qt_wince_is_mobile()) + d->wceDestroyMenuBar(); +#endif +#ifdef Q_WS_S60 Q_D(QMenuBar); - delete d->cornerWidgetToolBar; + d->symbianDestroyMenuBar(); +#endif } /*! @@ -1009,7 +1029,7 @@ void QMenuBar::paintEvent(QPaintEvent *e) QRect adjustedActionRect = d->actionRect(action); if (adjustedActionRect.isEmpty() || !d->isVisible(action)) continue; - if (!e->rect().intersects(adjustedActionRect)) + if(!e->rect().intersects(adjustedActionRect)) continue; emptyArea -= adjustedActionRect; @@ -1020,7 +1040,7 @@ void QMenuBar::paintEvent(QPaintEvent *e) style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this); } //draw border - if (int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) { + if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) { QRegion borderReg; borderReg += QRect(0, 0, fw, height()); //left borderReg += QRect(width()-fw, 0, fw, height()); //right @@ -1052,10 +1072,13 @@ void QMenuBar::paintEvent(QPaintEvent *e) */ void QMenuBar::setVisible(bool visible) { - Q_D(QMenuBar); - if (!d->impl->allowSetVisible()) { +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + if (isNativeMenuBar()) { + if (!visible) + QWidget::setVisible(false); return; } +#endif QWidget::setVisible(visible); } @@ -1065,7 +1088,7 @@ void QMenuBar::setVisible(bool visible) void QMenuBar::mousePressEvent(QMouseEvent *e) { Q_D(QMenuBar); - if (e->button() != Qt::LeftButton) + if(e->button() != Qt::LeftButton) return; d->mouseDown = true; @@ -1080,13 +1103,13 @@ void QMenuBar::mousePressEvent(QMouseEvent *e) return; } - if (d->currentAction == action && d->popupState) { - if (QMenu *menu = d->activeMenu) { + if(d->currentAction == action && d->popupState) { + if(QMenu *menu = d->activeMenu) { d->activeMenu = 0; menu->hide(); } #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)); #endif } else { @@ -1100,16 +1123,16 @@ void QMenuBar::mousePressEvent(QMouseEvent *e) void QMenuBar::mouseReleaseEvent(QMouseEvent *e) { Q_D(QMenuBar); - if (e->button() != Qt::LeftButton || !d->mouseDown) + if(e->button() != Qt::LeftButton || !d->mouseDown) return; d->mouseDown = false; 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 //so that we let the leave event set the current back to 0 d->setCurrentAction(action, false); - if (action) + if(action) d->activateAction(action, QAction::Trigger); } d->closePopupMode = 0; @@ -1123,15 +1146,15 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) Q_D(QMenuBar); d->updateGeometries(); int key = e->key(); - if (isRightToLeft()) { // in reverse mode open/close key for submenues are reversed - if (key == Qt::Key_Left) + if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed + if(key == Qt::Key_Left) key = Qt::Key_Right; - else if (key == Qt::Key_Right) + else if(key == Qt::Key_Right) key = Qt::Key_Left; } - if (key == Qt::Key_Tab) //means right + if(key == Qt::Key_Tab) //means 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; bool key_consumed = false; @@ -1141,11 +1164,11 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) case Qt::Key_Enter: case Qt::Key_Space: 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; - if (d->currentAction->menu()) { + if(d->currentAction->menu()) { 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->setCurrentAction(d->currentAction, false); d->setKeyboardMode(false); @@ -1155,7 +1178,7 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) case Qt::Key_Right: case Qt::Key_Left: { - if (d->currentAction) { + if(d->currentAction) { int index = d->actions.indexOf(d->currentAction); if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) { d->setCurrentAction(nextAction, d->popupState, true); @@ -1174,7 +1197,7 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) key_consumed = false; } - if (!key_consumed && + if(!key_consumed && (!e->modifiers() || (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) { int clashCount = 0; @@ -1186,14 +1209,14 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) continue; QAction *act = d->actions.at(i); QString s = act->text(); - if (!s.isEmpty()) { + if(!s.isEmpty()) { int ampersand = s.indexOf(QLatin1Char('&')); - if (ampersand >= 0) { - if (s[ampersand+1].toUpper() == c) { + if(ampersand >= 0) { + if(s[ampersand+1].toUpper() == c) { clashCount++; - if (!first) + if(!first) first = act; - if (act == d->currentAction) + if(act == d->currentAction) currentSelected = act; else if (!firstAfterCurrent && currentSelected) firstAfterCurrent = act; @@ -1203,18 +1226,18 @@ void QMenuBar::keyPressEvent(QKeyEvent *e) } } QAction *next_action = 0; - if (clashCount >= 1) { - if (clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent)) + if(clashCount >= 1) { + if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent)) next_action = first; else next_action = firstAfterCurrent; } - if (next_action) { + if(next_action) { key_consumed = true; d->setCurrentAction(next_action, true, true); } } - if (key_consumed) + if(key_consumed) e->accept(); else e->ignore(); @@ -1240,7 +1263,7 @@ void QMenuBar::mouseMoveEvent(QMouseEvent *e) void QMenuBar::leaveEvent(QEvent *) { Q_D(QMenuBar); - if ((!hasFocus() && !d->popupState) || + if((!hasFocus() && !d->popupState) || (d->currentAction && d->currentAction->menu() == 0)) d->setCurrentAction(0); } @@ -1252,12 +1275,30 @@ void QMenuBar::actionEvent(QActionEvent *e) { Q_D(QMenuBar); d->itemsDirty = true; - d->impl->actionEvent(e); +#if defined (Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) + if (isNativeMenuBar()) { +#ifdef Q_WS_MAC + QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar; +#elif defined(Q_WS_S60) + QMenuBarPrivate::QSymbianMenuBarPrivate *nativeMenuBar = d->symbian_menubar; +#else + QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar; +#endif + if (!nativeMenuBar) + return; + if(e->type() == QEvent::ActionAdded) + nativeMenuBar->addAction(e->action(), nativeMenuBar->findAction(e->before())); + else if(e->type() == QEvent::ActionRemoved) + nativeMenuBar->removeAction(e->action()); + else if(e->type() == QEvent::ActionChanged) + nativeMenuBar->syncAction(e->action()); + } +#endif - if (e->type() == QEvent::ActionAdded) { + if(e->type() == QEvent::ActionAdded) { connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); 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); } if (isVisible()) { @@ -1272,7 +1313,7 @@ void QMenuBar::actionEvent(QActionEvent *e) void QMenuBar::focusInEvent(QFocusEvent *) { Q_D(QMenuBar); - if (d->keyboardState) + if(d->keyboardState) d->focusFirstAction(); } @@ -1282,7 +1323,7 @@ void QMenuBar::focusInEvent(QFocusEvent *) void QMenuBar::focusOutEvent(QFocusEvent *) { Q_D(QMenuBar); - if (!d->popupState) { + if(!d->popupState) { d->setCurrentAction(0); d->setKeyboardMode(false); } @@ -1328,10 +1369,55 @@ void QMenuBarPrivate::handleReparent() newWindow->installEventFilter(q); } - impl->handleReparent(oldParent, newParent, oldWindow, newWindow); - oldParent = newParent; oldWindow = newWindow; + +#ifdef Q_WS_MAC + if (q->isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { + // If the new parent got a native menubar from before, keep that + // menubar rather than replace it with this one (because a parents + // menubar has precedence over children menubars). + macDestroyMenuBar(); + macCreateMenuBar(newParent); + } +#endif + +#ifdef Q_WS_WINCE + if (qt_wince_is_mobile() && wce_menubar) + wce_menubar->rebuild(); +#endif +#ifdef Q_WS_S60 + + // 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(); + } + +#ifdef QT_SOFTKEYS_ENABLED + // Constuct menuBarAction when this code path is entered first time + if (!menuBarAction) { + if (newParent) { + menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent); + 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 @@ -1372,10 +1458,10 @@ bool QMenuBar::autoGeometry() const void QMenuBar::changeEvent(QEvent *e) { Q_D(QMenuBar); - if (e->type() == QEvent::StyleChange) { + if(e->type() == QEvent::StyleChange) { d->itemsDirty = true; setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this)); - if (parentWidget()) + if(parentWidget()) resize(parentWidget()->width(), heightForWidth(parentWidget()->width())); d->updateGeometries(); } else if (e->type() == QEvent::ParentChange) { @@ -1404,12 +1490,12 @@ bool QMenuBar::event(QEvent *e) case QEvent::KeyPress: { QKeyEvent *ke = (QKeyEvent*)e; #if 0 - if (!d->keyboardState) { //all keypresses.. + if(!d->keyboardState) { //all keypresses.. d->setCurrentAction(0); return ; } #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); return true; } @@ -1427,7 +1513,7 @@ bool QMenuBar::event(QEvent *e) #endif case QEvent::Show: #ifdef QT3_SUPPORT - if (QWidget *p = parentWidget()) { + if(QWidget *p = parentWidget()) { // If itemsDirty == true, updateGeometries sends the MenubarUpdated event. if (!d->itemsDirty) { QMenubarUpdatedEvent menubarUpdated(this); @@ -1449,7 +1535,7 @@ bool QMenuBar::event(QEvent *e) #ifdef QT3_SUPPORT case QEvent::Hide: { - if (QWidget *p = parentWidget()) { + if(QWidget *p = parentWidget()) { QMenubarUpdatedEvent menubarUpdated(this); QApplication::sendEvent(p, &menubarUpdated); } @@ -1480,9 +1566,6 @@ bool QMenuBar::event(QEvent *e) bool QMenuBar::eventFilter(QObject *object, QEvent *event) { Q_D(QMenuBar); - if (d->impl->menuBarEventFilter(object, event)) { - return true; - } if (object == parent() && object) { #ifdef QT3_SUPPORT if (d->doAutoResize && event->type() == QEvent::Resize) { @@ -1576,7 +1659,11 @@ QRect QMenuBar::actionGeometry(QAction *act) const QSize QMenuBar::minimumSizeHint() const { Q_D(const QMenuBar); +#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); +#else + const bool as_gui_menubar = true; +#endif ensurePolished(); QSize ret(0, 0); @@ -1585,7 +1672,7 @@ QSize QMenuBar::minimumSizeHint() const const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 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(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; ret.isNull() && i < d->actions.count(); ++i) @@ -1595,21 +1682,19 @@ QSize QMenuBar::minimumSizeHint() const ret += QSize(2*fw + hmargin, 2*fw + vmargin); } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if (d->impl->allowCornerWidgets()) { - if (d->leftWidget) { - QSize sz = d->leftWidget->minimumSizeHint(); - ret.setWidth(ret.width() + sz.width()); - if (sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); - } - if (d->rightWidget) { - QSize sz = d->rightWidget->minimumSizeHint(); - ret.setWidth(ret.width() + sz.width()); - if (sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); - } - } - if (as_gui_menubar) { + if(d->leftWidget) { + QSize sz = d->leftWidget->minimumSizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } + if(d->rightWidget) { + QSize sz = d->rightWidget->minimumSizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } + if(as_gui_menubar) { QStyleOptionMenuItem opt; opt.rect = rect(); opt.menuRect = rect(); @@ -1630,7 +1715,12 @@ QSize QMenuBar::minimumSizeHint() const QSize QMenuBar::sizeHint() const { Q_D(const QMenuBar); +#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); +#else + const bool as_gui_menubar = true; +#endif + ensurePolished(); QSize ret(0, 0); @@ -1639,7 +1729,7 @@ QSize QMenuBar::sizeHint() const const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 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(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; i < d->actionRects.count(); ++i) { @@ -1651,21 +1741,19 @@ QSize QMenuBar::sizeHint() const ret += QSize(fw + hmargin, fw + vmargin); } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if (d->impl->allowCornerWidgets()) { - if (d->leftWidget) { - QSize sz = d->leftWidget->sizeHint(); - ret.setWidth(ret.width() + sz.width()); - if (sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); - } - if (d->rightWidget) { - QSize sz = d->rightWidget->sizeHint(); - ret.setWidth(ret.width() + sz.width()); - if (sz.height() + margin > ret.height()) - ret.setHeight(sz.height() + margin); - } - } - if (as_gui_menubar) { + if(d->leftWidget) { + QSize sz = d->leftWidget->sizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } + if(d->rightWidget) { + QSize sz = d->rightWidget->sizeHint(); + ret.setWidth(ret.width() + sz.width()); + if(sz.height() + margin > ret.height()) + ret.setHeight(sz.height() + margin); + } + if(as_gui_menubar) { QStyleOptionMenuItem opt; opt.rect = rect(); opt.menuRect = rect(); @@ -1686,14 +1774,18 @@ QSize QMenuBar::sizeHint() const int QMenuBar::heightForWidth(int) const { Q_D(const QMenuBar); +#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) const bool as_gui_menubar = !isNativeMenuBar(); +#else + const bool as_gui_menubar = true; +#endif const_cast(d)->updateGeometries(); int height = 0; const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 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) height = qMax(height, d->actionRects.at(i).height()); if (height) //there is at least one non-null item @@ -1702,13 +1794,11 @@ int QMenuBar::heightForWidth(int) const height += 2*vmargin; } int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; - if (d->impl->allowCornerWidgets()) { - if (d->leftWidget) - height = qMax(d->leftWidget->sizeHint().height() + margin, height); - if (d->rightWidget) - height = qMax(d->rightWidget->sizeHint().height() + margin, height); - } - if (as_gui_menubar) { + if(d->leftWidget) + height = qMax(d->leftWidget->sizeHint().height() + margin, height); + if(d->rightWidget) + height = qMax(d->rightWidget->sizeHint().height() + margin, height); + if(as_gui_menubar) { QStyleOptionMenuItem opt; opt.init(this); opt.menuRect = rect(); @@ -1727,11 +1817,7 @@ void QMenuBarPrivate::_q_internalShortcutActivated(int id) { Q_Q(QMenuBar); QAction *act = actions.at(id); - if (q->isNativeMenuBar()) { - impl->popupAction(act); - } else { - setCurrentAction(act, true, true); - } + setCurrentAction(act, true, true); if (act && !act->menu()) { activateAction(act, QAction::Trigger); //100 is the same as the default value in QPushButton::animateClick @@ -1752,37 +1838,6 @@ void QMenuBarPrivate::_q_updateLayout() } } -void QMenuBarPrivate::updateCornerWidgetToolBar() -{ - Q_Q(QMenuBar); - if (!cornerWidgetToolBar) { - QMainWindow *window = qobject_cast(q->window()); - if (!window) { - qWarning() << "Menubar parent is not a QMainWindow, not showing corner widgets"; - return; - } - cornerWidgetToolBar = window->addToolBar(QApplication::translate("QMenuBar", "Corner Toolbar")); - cornerWidgetToolBar->setObjectName(QLatin1String("CornerToolBar")); - cornerWidgetContainer = new QWidget; - cornerWidgetToolBar->addWidget(cornerWidgetContainer); - new QHBoxLayout(cornerWidgetContainer); - } else { - QLayout *layout = cornerWidgetContainer->layout(); - while (layout->count() > 0) { - layout->takeAt(0); - } - } - if (leftWidget) { - leftWidget->setParent(cornerWidgetContainer); - cornerWidgetContainer->layout()->addWidget(leftWidget); - } - if (rightWidget) { - rightWidget->setParent(cornerWidgetContainer); - cornerWidgetContainer->layout()->addWidget(rightWidget); - } -} - - /*! \fn void QMenuBar::setCornerWidget(QWidget *widget, Qt::Corner corner) @@ -1815,9 +1870,7 @@ void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner) return; } - if (!d->impl->allowCornerWidgets()) { - d->updateCornerWidgetToolBar(); - } else if (w) { + if (w) { w->setParent(this); w->installEventFilter(this); } @@ -1870,13 +1923,39 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const void QMenuBar::setNativeMenuBar(bool nativeMenuBar) { Q_D(QMenuBar); - d->impl->setNativeMenuBar(nativeMenuBar); + if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) { + d->nativeMenuBar = nativeMenuBar; +#ifdef Q_WS_MAC + if (!d->nativeMenuBar) { + extern void qt_mac_clear_menubar(); + qt_mac_clear_menubar(); + d->macDestroyMenuBar(); + const QList &menubarActions = actions(); + for (int i = 0; i < menubarActions.size(); ++i) { + const QAction *action = menubarActions.at(i); + if (QMenu *menu = action->menu()) { + delete menu->d_func()->mac_menu; + menu->d_func()->mac_menu = 0; + } + } + } else { + d->macCreateMenuBar(parentWidget()); + } + macUpdateMenuBar(); + updateGeometry(); + if (!d->nativeMenuBar && parentWidget()) + setVisible(true); +#endif + } } bool QMenuBar::isNativeMenuBar() const { Q_D(const QMenuBar); - return d->impl->isNativeMenuBar(); + if (d->nativeMenuBar == -1) { + return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar); + } + return d->nativeMenuBar; } /*! @@ -1913,8 +1992,8 @@ void QMenuBar::setDefaultAction(QAction *act) connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); connect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); } - if (d->impl->nativeMenuBarAdapter()) { - d->impl->nativeMenuBarAdapter()->rebuild(); + if (d->wce_menubar) { + d->wce_menubar->rebuild(); } #endif } @@ -1973,17 +2052,17 @@ int QMenuBar::insertAny(const QIcon *icon, const QString *text, const QObject *r const QKeySequence *shortcut, const QMenu *popup, int id, int index) { QAction *act = popup ? popup->menuAction() : new QAction(this); - if (id != -1) + if(id != -1) static_cast(act)->setId(id); - if (icon) + if(icon) act->setIcon(*icon); - if (text) + if(text) act->setText(*text); - if (shortcut) + if(shortcut) act->setShortcut(*shortcut); - if (receiver && member) + if(receiver && member) QObject::connect(act, SIGNAL(triggered(bool)), receiver, member); - if (index == -1 || index >= actions().count()) + if(index == -1 || index >= actions().count()) addAction(act); else insertAction(actions().value(index), act); @@ -2005,7 +2084,7 @@ int QMenuBar::insertSeparator(int index) { QAction *act = new QAction(this); act->setSeparator(true); - if (index == -1 || index >= actions().count()) + if(index == -1 || index >= actions().count()) addAction(act); else insertAction(actions().value(index), act); @@ -2017,7 +2096,7 @@ int QMenuBar::insertSeparator(int index) */ bool QMenuBar::setItemParameter(int id, int param) { - if (QAction *act = findActionForId(id)) { + if(QAction *act = findActionForId(id)) { act->d_func()->param = param; return true; } @@ -2029,7 +2108,7 @@ bool QMenuBar::setItemParameter(int id, int param) */ int QMenuBar::itemParameter(int id) const { - if (QAction *act = findActionForId(id)) + if(QAction *act = findActionForId(id)) return act->d_func()->param; return id; } diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index b49e039..5afe713 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -61,8 +61,6 @@ #include "qguifunctions_wince.h" #endif -#include "qabstractmenubarimpl_p.h" - #ifndef QT_NO_MENUBAR #ifdef Q_WS_S60 class CCoeControl; @@ -73,7 +71,6 @@ class CEikMenuBar; QT_BEGIN_NAMESPACE #ifndef QT_NO_MENUBAR -class QToolBar; class QMenuBarExtension; class QMenuBarPrivate : public QWidgetPrivate { @@ -81,19 +78,33 @@ class QMenuBarPrivate : public QWidgetPrivate public: QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0), closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0), - doChildEffects(false) + nativeMenuBar(-1), doChildEffects(false) #ifdef QT3_SUPPORT , doAutoResize(false) #endif - , impl(0) +#ifdef Q_WS_MAC + , mac_menubar(0) +#endif + #ifdef Q_WS_WINCE - , wceClassicMenu(false) + , wce_menubar(0), wceClassicMenu(false) +#endif +#ifdef Q_WS_S60 + , symbian_menubar(0) #endif { } ~QMenuBarPrivate() { - delete impl; +#ifdef Q_WS_MAC + delete mac_menubar; +#endif +#ifdef Q_WS_WINCE + delete wce_menubar; +#endif +#ifdef Q_WS_S60 + delete symbian_menubar; +#endif } void init(); @@ -125,6 +136,8 @@ public: uint keyboardState : 1, altPressed : 1; QPointer keyboardFocusWidget; + + int nativeMenuBar : 3; // Only has values -1, 0, and 1 //firing of events void activateAction(QAction *, QAction::ActionEvent); @@ -160,14 +173,106 @@ public: #ifdef QT3_SUPPORT bool doAutoResize; #endif - QAbstractMenuBarImpl *impl; +#ifdef Q_WS_MAC + //mac menubar binding + struct QMacMenuBarPrivate { + QList actionItems; + OSMenuRef menu, apple_menu; + QMacMenuBarPrivate(); + ~QMacMenuBarPrivate(); + + void addAction(QAction *, QMacMenuAction* =0); + void addAction(QMacMenuAction *, QMacMenuAction* =0); + void syncAction(QMacMenuAction *); + inline void syncAction(QAction *a) { syncAction(findAction(a)); } + void removeAction(QMacMenuAction *); + inline void removeAction(QAction *a) { removeAction(findAction(a)); } + inline QMacMenuAction *findAction(QAction *a) { + for(int i = 0; i < actionItems.size(); i++) { + QMacMenuAction *act = actionItems[i]; + if(a == act->action) + return act; + } + return 0; + } + } *mac_menubar; + static bool macUpdateMenuBarImmediatly(); + bool macWidgetHasNativeMenubar(QWidget *widget); + void macCreateMenuBar(QWidget *); + void macDestroyMenuBar(); + OSMenuRef macMenu(); +#endif +#ifdef Q_WS_WINCE + void wceCreateMenuBar(QWidget *); + void wceDestroyMenuBar(); + struct QWceMenuBarPrivate { + QList actionItems; + QList actionItemsLeftButton; + QList> actionItemsClassic; + HMENU menuHandle; + HMENU leftButtonMenuHandle; + HWND menubarHandle; + HWND parentWindowHandle; + bool leftButtonIsMenu; + QPointer leftButtonAction; + QMenuBarPrivate *d; + int leftButtonCommand; + + QWceMenuBarPrivate(QMenuBarPrivate *menubar); + ~QWceMenuBarPrivate(); + void addAction(QAction *, QWceMenuAction* =0); + void addAction(QWceMenuAction *, QWceMenuAction* =0); + void syncAction(QWceMenuAction *); + inline void syncAction(QAction *a) { syncAction(findAction(a)); } + void removeAction(QWceMenuAction *); + void rebuild(); + inline void removeAction(QAction *a) { removeAction(findAction(a)); } + inline QWceMenuAction *findAction(QAction *a) { + for(int i = 0; i < actionItems.size(); i++) { + QWceMenuAction *act = actionItems[i]; + if(a == act->action) + return act; + } + return 0; + } + } *wce_menubar; + bool wceClassicMenu; + void wceCommands(uint command); + void wceRefresh(); + bool wceEmitSignals(QList actions, uint command); +#endif +#ifdef Q_WS_S60 + void symbianCreateMenuBar(QWidget *); + void symbianDestroyMenuBar(); + void reparentMenuBar(QWidget *oldParent, QWidget *newParent); + struct QSymbianMenuBarPrivate { + QList actionItems; + QMenuBarPrivate *d; + QSymbianMenuBarPrivate(QMenuBarPrivate *menubar); + ~QSymbianMenuBarPrivate(); + void addAction(QAction *, QSymbianMenuAction* =0); + void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); + void syncAction(QSymbianMenuAction *); + inline void syncAction(QAction *a) { syncAction(findAction(a)); } + void removeAction(QSymbianMenuAction *); + void rebuild(); + inline void removeAction(QAction *a) { removeAction(findAction(a)); } + inline QSymbianMenuAction *findAction(QAction *a) { + for(int i = 0; i < actionItems.size(); i++) { + QSymbianMenuAction *act = actionItems[i]; + if(a == act->action) + return act; + } + return 0; + } + void insertNativeMenuItems(const QList &actions); + + } *symbian_menubar; + static int symbianCommands(int command); +#endif #ifdef QT_SOFTKEYS_ENABLED QAction *menuBarAction; #endif - - void updateCornerWidgetToolBar(); - QToolBar *cornerWidgetToolBar; - QWidget *cornerWidgetContainer; }; #endif diff --git a/src/gui/widgets/qmenubarimpl.cpp b/src/gui/widgets/qmenubarimpl.cpp deleted file mode 100644 index cbe9198..0000000 --- a/src/gui/widgets/qmenubarimpl.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmenubarimpl_p.h" - -#ifndef QT_NO_MENUBAR - -#include "qapplication.h" -#include "qdebug.h" -#include "qevent.h" -#include "qmenu.h" -#include "qmenubar.h" - -QT_BEGIN_NAMESPACE - -QMenuBarImpl::~QMenuBarImpl() -{ -#ifdef Q_WS_MAC - macDestroyMenuBar(); -#endif -#ifdef Q_WS_WINCE - if (qt_wince_is_mobile()) - wceDestroyMenuBar(); -#endif -#ifdef Q_WS_S60 - symbianDestroyMenuBar(); -#endif -} - -void QMenuBarImpl::init(QMenuBar *_menuBar) -{ - nativeMenuBar = -1; - menuBar = _menuBar; -#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - adapter = 0; -#endif -#ifdef Q_WS_MAC - macCreateMenuBar(menuBar->parentWidget()); - if (adapter) - menuBar->hide(); -#endif -#ifdef Q_WS_WINCE - if (qt_wince_is_mobile()) { - wceCreateMenuBar(menuBar->parentWidget()); - if (adapter) - menuBar->hide(); - } else { - QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); - } -#endif -} - -bool QMenuBarImpl::allowSetVisible() const -{ -#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - // FIXME: Port this to a setVisible() method - /* - if (isNativeMenuBar()) { - if (!visible) - QWidget::setVisible(false); - return; - } - */ - return !isNativeMenuBar(); -#endif - return true; -} - -void QMenuBarImpl::actionEvent(QActionEvent *e) -{ -#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - if (adapter) { - if (e->type() == QEvent::ActionAdded) - adapter->addAction(e->action(), e->before()); - else if (e->type() == QEvent::ActionRemoved) - adapter->removeAction(e->action()); - else if (e->type() == QEvent::ActionChanged) - adapter->syncAction(e->action()); - } -#else - Q_UNUSED(e); -#endif -} - -void QMenuBarImpl::handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) -{ -#ifdef Q_WS_X11 - Q_UNUSED(oldParent) - Q_UNUSED(newParent) - Q_UNUSED(oldWindow) - Q_UNUSED(newWindow) -#endif - -#ifdef Q_WS_MAC - if (isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { - // If the new parent got a native menubar from before, keep that - // menubar rather than replace it with this one (because a parents - // menubar has precedence over children menubars). - macDestroyMenuBar(); - macCreateMenuBar(newParent); - } -#endif -#ifdef Q_WS_WINCE - if (qt_wince_is_mobile() && nativeMenuBarAdapter()) - adapter->rebuild(); -#endif -#ifdef Q_WS_S60 - - // Construct d->impl->nativeMenuBarAdapter() when this code path is entered first time - // and when newParent != NULL - if (!adapter) - symbianCreateMenuBar(newParent); - - // Reparent and rebuild menubar when parent is changed - if (adapter) { - if (oldParent != newParent) - reparentMenuBar(oldParent, newParent); - menuBar->hide(); - adapter->rebuild(); - } - -#ifdef QT_SOFTKEYS_ENABLED - // Constuct menuBarAction when this code path is entered first time - if (!menuBarAction) { - if (newParent) { - menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent); - 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 -} - -bool QMenuBarImpl::allowCornerWidgets() const -{ - return true; -} - -void QMenuBarImpl::popupAction(QAction *) -{ -} - -void QMenuBarImpl::setNativeMenuBar(bool value) -{ - if (nativeMenuBar == -1 || (value != bool(nativeMenuBar))) { - nativeMenuBar = value; -#ifdef Q_WS_MAC - if (!nativeMenuBar) { - extern void qt_mac_clear_menubar(); - qt_mac_clear_menubar(); - macDestroyMenuBar(); - const QList &menubarActions = actions(); - for (int i = 0; i < menubarActions.size(); ++i) { - const QAction *action = menubarActions.at(i); - if (QMenu *menu = action->menu()) { - delete menu->d_func()->mac_menu; - menu->d_func()->mac_menu = 0; - } - } - } else { - macCreateMenuBar(parentWidget()); - } - macUpdateMenuBar(); - updateGeometry(); - if (!nativeMenuBar && parentWidget()) - setVisible(true); -#endif - } -} - -bool QMenuBarImpl::isNativeMenuBar() const -{ -#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) - if (nativeMenuBar == -1) { - return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar); - } - return nativeMenuBar; -#else - return false; -#endif -} - -bool QMenuBarImpl::shortcutsHandledByNativeMenuBar() const -{ -#ifdef Q_WS_MAC - return true; -#else - return false; -#endif -} - -bool QMenuBarImpl::menuBarEventFilter(QObject *, QEvent *) -{ - return false; -} - -QT_END_NAMESPACE - -#endif // QT_NO_MENUBAR diff --git a/src/gui/widgets/qmenubarimpl_p.h b/src/gui/widgets/qmenubarimpl_p.h deleted file mode 100644 index c4ab2df..0000000 --- a/src/gui/widgets/qmenubarimpl_p.h +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMENUBARIMPL_P_H -#define QMENUBARIMPL_P_H - -#ifndef QT_NO_MENUBAR - -#include "qabstractmenubarimpl_p.h" - -QT_BEGIN_NAMESPACE - -class QMenuBar; - -class QMenuBarImpl : public QAbstractMenuBarImpl -{ -public: - ~QMenuBarImpl(); - - virtual void init(QMenuBar *); - - virtual bool allowSetVisible() const; - - virtual void actionEvent(QActionEvent *e); - - virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow); - - virtual bool allowCornerWidgets() const; - - virtual void popupAction(QAction*); - - virtual void setNativeMenuBar(bool); - virtual bool isNativeMenuBar() const; - - virtual bool shortcutsHandledByNativeMenuBar() const; - virtual bool menuBarEventFilter(QObject *, QEvent *event); - -private: - QMenuBar *menuBar; - int nativeMenuBar : 3; // Only has values -1, 0, and 1 - -#ifdef Q_WS_MAC - //mac menubar binding - struct QMacMenuBarPrivate { - QList actionItems; - OSMenuRef menu, apple_menu; - QMacMenuBarPrivate(); - ~QMacMenuBarPrivate(); - - void addAction(QAction *, QAction* =0); - void addAction(QMacMenuAction *, QMacMenuAction* =0); - void syncAction(QMacMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QMacMenuAction *); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QMacMenuAction *findAction(QAction *a) { - for (int i = 0; i < actionItems.size(); i++) { - QMacMenuAction *act = actionItems[i]; - if (a == act->action) - return act; - } - return 0; - } - } adapter; - static bool macUpdateMenuBarImmediatly(); - bool macWidgetHasNativeMenubar(QWidget *widget); - void macCreateMenuBar(QWidget *); - void macDestroyMenuBar(); - OSMenuRef macMenu(); -#endif -#ifdef Q_WS_WINCE - void wceCreateMenuBar(QWidget *); - void wceDestroyMenuBar(); - struct QWceMenuBarPrivate { - QList actionItems; - QList actionItemsLeftButton; - QList> actionItemsClassic; - HMENU menuHandle; - HMENU leftButtonMenuHandle; - HWND menubarHandle; - HWND parentWindowHandle; - bool leftButtonIsMenu; - QPointer leftButtonAction; - QMenuBarPrivate *d; - int leftButtonCommand; - - QWceMenuBarPrivate(QMenuBarPrivate *menubar); - ~QWceMenuBarPrivate(); - void addAction(QAction *, QAction* =0); - void addAction(QWceMenuAction *, QWceMenuAction* =0); - void syncAction(QWceMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QWceMenuAction *); - void rebuild(); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QWceMenuAction *findAction(QAction *a) { - for (int i = 0; i < actionItems.size(); i++) { - QWceMenuAction *act = actionItems[i]; - if (a == act->action) - return act; - } - return 0; - } - } adapter; - bool wceClassicMenu; - void wceCommands(uint command); - void wceRefresh(); - bool wceEmitSignals(QList actions, uint command); -#endif -#ifdef Q_WS_S60 - void symbianCreateMenuBar(QWidget *); - void symbianDestroyMenuBar(); - void reparentMenuBar(QWidget *oldParent, QWidget *newParent); - struct QSymbianMenuBarPrivate { - QList actionItems; - QMenuBarPrivate *d; - QSymbianMenuBarPrivate(QMenuBarPrivate *menubar); - ~QSymbianMenuBarPrivate(); - void addAction(QAction *, QAction* =0); - void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); - void syncAction(QSymbianMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QSymbianMenuAction *); - void rebuild(); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QSymbianMenuAction *findAction(QAction *a) { - for (int i = 0; i < actionItems.size(); i++) { - QSymbianMenuAction *act = actionItems[i]; - if (a == act->action) - return act; - } - return 0; - } - void insertNativeMenuItems(const QList &actions); - - } adapter; - static int symbianCommands(int command); -#endif -}; - -QT_END_NAMESPACE - -#endif // QT_NO_MENUBAR - -#endif /* QMENUBARIMPL_P_H */ diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index e5d6890..669b838 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -4,7 +4,6 @@ HEADERS += \ widgets/qbuttongroup.h \ widgets/qabstractbutton.h \ widgets/qabstractbutton_p.h \ - widgets/qabstractmenubarimpl_p.h \ widgets/qabstractslider.h \ widgets/qabstractslider_p.h \ widgets/qabstractspinbox.h \ @@ -85,7 +84,6 @@ HEADERS += \ widgets/qprintpreviewwidget.h SOURCES += \ widgets/qabstractbutton.cpp \ - widgets/qabstractmenubarimpl_p.cpp \ widgets/qabstractslider.cpp \ widgets/qabstractspinbox.cpp \ widgets/qcalendarwidget.cpp \ @@ -112,7 +110,6 @@ SOURCES += \ widgets/qmdisubwindow.cpp \ widgets/qmenu.cpp \ widgets/qmenubar.cpp \ - widgets/qmenubarimpl.cpp \ widgets/qmenudata.cpp \ widgets/qprogressbar.cpp \ widgets/qpushbutton.cpp \ -- cgit v0.12 From 364ce5b7f5379499562b4f4f5a68da7ba068fe1e Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 19 Apr 2011 15:47:23 +0200 Subject: Fixed a crash on Windows XP with mingw in threaded-code The thread callback doesn't align the stack on 16-bytes on WinXP. That causes a crash when we call SSE code. So now we tell the compiler to force that alignment of the stack. Task: QTBUG-18631 Reviewed-By: Olivier --- src/corelib/thread/qthread_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 6b7932b..44e8958 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -288,7 +288,7 @@ void QThreadPrivate::createEventDispatcher(QThreadData *data) #ifndef QT_NO_THREAD -unsigned int __stdcall QThreadPrivate::start(void *arg) +unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(void *arg) { QThread *thr = reinterpret_cast(arg); QThreadData *data = QThreadData::get2(thr); -- cgit v0.12