diff options
Diffstat (limited to 'src/gui/widgets')
41 files changed, 383 insertions, 288 deletions
diff --git a/src/gui/widgets/qabstractbutton.cpp b/src/gui/widgets/qabstractbutton.cpp index 61ed0ea..1900016 100644 --- a/src/gui/widgets/qabstractbutton.cpp +++ b/src/gui/widgets/qabstractbutton.cpp @@ -215,11 +215,8 @@ void QButtonGroup::setExclusive(bool exclusive) d->exclusive = exclusive; } -/*! - Adds the given \a button to the end of the group's internal list of buttons. - \sa removeButton() -*/ +// TODO: Qt 5: Merge with addButton(QAbstractButton *button, int id) void QButtonGroup::addButton(QAbstractButton *button) { addButton(button, -1); @@ -232,8 +229,18 @@ void QButtonGroup::addButton(QAbstractButton *button, int id) previous->removeButton(button); button->d_func()->group = this; d->buttonList.append(button); - if (id != -1) + if (id == -1) { + QList<int> ids = d->mapping.values(); + if (ids.isEmpty()) + d->mapping[button] = -2; + else { + qSort(ids); + d->mapping[button] = ids.first()-1; + } + } else { d->mapping[button] = id; + } + if (d->exclusive && button->isChecked()) button->d_func()->notifyChecked(); } @@ -1236,7 +1243,9 @@ void QAbstractButton::timerEvent(QTimerEvent *e) d->repeatTimer.start(d->autoRepeatInterval, this); if (d->down) { QPointer<QAbstractButton> guard(this); - d->emitReleased(); + nextCheckState(); + if (guard) + d->emitReleased(); if (guard) d->emitClicked(); if (guard) diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 9886969..0d8b4de 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -873,21 +873,22 @@ bool QAbstractScrollArea::event(QEvent *e) case QEvent::Resize: d->layoutChildren(); break; - case QEvent::Paint: + case QEvent::Paint: { + QStyleOption option; + option.initFrom(this); if (d->cornerPaintingRect.isValid()) { - QStyleOption option; option.rect = d->cornerPaintingRect; QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); } #ifdef Q_WS_MAC if (d->reverseCornerPaintingRect.isValid()) { - QStyleOption option; option.rect = d->reverseCornerPaintingRect; QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); } #endif + } QFrame::paintEvent((QPaintEvent*)e); break; #ifndef QT_NO_CONTEXTMENU diff --git a/src/gui/widgets/qabstractscrollarea_p.h b/src/gui/widgets/qabstractscrollarea_p.h index e4c47e9..f153711 100644 --- a/src/gui/widgets/qabstractscrollarea_p.h +++ b/src/gui/widgets/qabstractscrollarea_p.h @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE class QScrollBar; class QAbstractScrollAreaScrollBarContainer; -class Q_GUI_EXPORT QAbstractScrollAreaPrivate: public QFramePrivate +class QAbstractScrollAreaPrivate: public QFramePrivate { Q_DECLARE_PUBLIC(QAbstractScrollArea) diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp index 347f89a..d640c70 100644 --- a/src/gui/widgets/qabstractspinbox.cpp +++ b/src/gui/widgets/qabstractspinbox.cpp @@ -193,6 +193,7 @@ void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols) Q_D(QAbstractSpinBox); if (d->buttonSymbols != buttonSymbols) { d->buttonSymbols = buttonSymbols; + d->updateEditFieldGeometry(); update(); } } diff --git a/src/gui/widgets/qbuttongroup.cpp b/src/gui/widgets/qbuttongroup.cpp index 06bcf1e..ebfafe3 100644 --- a/src/gui/widgets/qbuttongroup.cpp +++ b/src/gui/widgets/qbuttongroup.cpp @@ -176,11 +176,21 @@ */ /*! - \fn void QButtonGroup::addButton(QAbstractButton *button, int id = -1); + \fn void QButtonGroup::addButton(QAbstractButton *button); + + Adds the given \a button to the end of the group's internal list of buttons. + An \a id will be assigned to the button by this QButtonGroup. Automatically + assigned ids are guaranteed to be negative, starting with -2. If you are also + assigning your own ids, use positive values to avoid conflicts. + + \sa removeButton() buttons() +*/ + +/*! + \fn void QButtonGroup::addButton(QAbstractButton *button, int id); Adds the given \a button to the button group, with the given \a - id. If \a id is -1 (the default), an id will be assigned to the - button by this QButtonGroup. + id. It is recommended to assign only positive ids. \sa removeButton() buttons() */ diff --git a/src/gui/widgets/qcalendarwidget.cpp b/src/gui/widgets/qcalendarwidget.cpp index 92c12a5..4436c04 100644 --- a/src/gui/widgets/qcalendarwidget.cpp +++ b/src/gui/widgets/qcalendarwidget.cpp @@ -2791,7 +2791,7 @@ QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format) { Q_D(QCalendarWidget); - if ( date.isNull() && !format.isValid() ) + if (date.isNull()) d->m_model->m_dateFormats.clear(); else d->m_model->m_dateFormats[date] = format; diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 09a51fe..01fe9d2 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -947,8 +947,9 @@ QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer() container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q); container->itemView()->setModel(model); container->itemView()->setTextElideMode(Qt::ElideMiddle); - updateDelegate(); + updateDelegate(true); updateLayoutDirection(); + updateViewContainerPaletteAndOpacity(); QObject::connect(container, SIGNAL(itemSelected(QModelIndex)), q, SLOT(_q_itemSelected(QModelIndex))); QObject::connect(container->itemView()->selectionModel(), @@ -1051,6 +1052,27 @@ void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, } +void QComboBoxPrivate::updateViewContainerPaletteAndOpacity() +{ + if (!container) + return; + Q_Q(QComboBox); + QStyleOptionComboBox opt; + q->initStyleOption(&opt); +#ifndef QT_NO_MENU + if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { + QMenu menu; + menu.ensurePolished(); + container->setPalette(menu.palette()); + container->setWindowOpacity(menu.windowOpacity()); + } else +#endif + { + container->setPalette(q->palette()); + container->setWindowOpacity(1.0); + } +} + /*! Initialize \a option with the values from this QComboBox. This method is useful for subclasses when they need a QStyleOptionComboBox, but don't want @@ -1567,15 +1589,25 @@ bool QComboBox::isEditable() const return d->lineEdit != 0; } -void QComboBoxPrivate::updateDelegate() +/*! \internal + update the default delegate + depending on the style's SH_ComboBox_Popup hint, we use a different default delegate. + + but we do not change the delegate is the combobox use a custom delegate, + unless \a force is set to true. + */ +void QComboBoxPrivate::updateDelegate(bool force) { Q_Q(QComboBox); QStyleOptionComboBox opt; q->initStyleOption(&opt); - if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) - q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); - else - q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); + if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { + if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate())) + q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); + } else { + if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate())) + q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); + } } QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const @@ -2572,20 +2604,7 @@ void QComboBox::changeEvent(QEvent *e) hidePopup(); break; case QEvent::PaletteChange: { - QStyleOptionComboBox opt; - initStyleOption(&opt); -#ifndef QT_NO_MENU - if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) { - QMenu menu; - menu.ensurePolished(); - d->viewContainer()->setPalette(menu.palette()); - d->viewContainer()->setWindowOpacity(menu.windowOpacity()); - } else -#endif - { - d->viewContainer()->setPalette(palette()); - d->viewContainer()->setWindowOpacity(1.0); - } + d->updateViewContainerPaletteAndOpacity(); break; } case QEvent::FontChange: diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h index c39a231..ee0da62 100644 --- a/src/gui/widgets/qcombobox_p.h +++ b/src/gui/widgets/qcombobox_p.h @@ -256,7 +256,7 @@ private: }; class QComboMenuDelegate : public QAbstractItemDelegate -{ +{ Q_OBJECT public: QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {} @@ -285,7 +285,7 @@ private: // Vista does not use the new theme for combo boxes and there might // be other side effects from using the new class class QComboBoxDelegate : public QItemDelegate -{ +{ Q_OBJECT public: QComboBoxDelegate(QObject *parent, QComboBox *cmb) : QItemDelegate(parent), mCombo(cmb) {} @@ -367,9 +367,10 @@ public: int itemRole() const; void updateLayoutDirection(); void setCurrentIndex(const QModelIndex &index); - void updateDelegate(); + void updateDelegate(bool force = false); void keyboardSearchString(const QString &text); void modelChanged(); + void updateViewContainerPaletteAndOpacity(); QAbstractItemModel *model; QLineEdit *lineEdit; diff --git a/src/gui/widgets/qcommandlinkbutton.cpp b/src/gui/widgets/qcommandlinkbutton.cpp index 13ee6af..92d89a1 100644 --- a/src/gui/widgets/qcommandlinkbutton.cpp +++ b/src/gui/widgets/qcommandlinkbutton.cpp @@ -140,10 +140,12 @@ QFont QCommandLinkButtonPrivate::titleFont() const Q_Q(const QCommandLinkButton); QFont font = q->font(); if (usingVistaStyle()) { - font.setPointSizeF(12.0); + if (!q->testAttribute(Qt::WA_SetFont)) + font.setPointSizeF(12.0); } else { font.setBold(true); - font.setPointSizeF(9.0); + if (!q->testAttribute(Qt::WA_SetFont)) + font.setPointSizeF(9.0); } return font; } @@ -152,7 +154,8 @@ QFont QCommandLinkButtonPrivate::descriptionFont() const { Q_Q(const QCommandLinkButton); QFont font = q->font(); - font.setPointSizeF(9.0); + if (!q->testAttribute(Qt::WA_SetFont)) + font.setPointSizeF(9.0); return font; } diff --git a/src/gui/widgets/qdatetimeedit.cpp b/src/gui/widgets/qdatetimeedit.cpp index 83bec68..e7afea0 100644 --- a/src/gui/widgets/qdatetimeedit.cpp +++ b/src/gui/widgets/qdatetimeedit.cpp @@ -220,6 +220,9 @@ QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWi \property QDateTimeEdit::dateTime \brief the QDateTime that is set in the QDateTimeEdit + When setting this property the timespec of the QDateTimeEdit remains the same + and the timespec of the new QDateTime is ignored. + By default, this property contains a date that refers to January 1, 2000 and a time of 00:00:00 and 0 milliseconds. @@ -239,7 +242,7 @@ void QDateTimeEdit::setDateTime(const QDateTime &datetime) d->clearCache(); if (!(d->sections & DateSections_Mask)) setDateRange(datetime.date(), datetime.date()); - d->setValue(QVariant(datetime), EmitIfChanged); + d->setValue(QDateTime(datetime.date(), datetime.time(), d->spec), EmitIfChanged); } } @@ -932,9 +935,6 @@ void QDateTimeEdit::setCalendarPopup(bool enable) \property QDateTimeEdit::timeSpec \brief the current timespec used by the date time edit. \since 4.4 - - All dates/passed to the date time edit will be converted to this - timespec. */ Qt::TimeSpec QDateTimeEdit::timeSpec() const diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp index a5be5f8..d573b8b 100644 --- a/src/gui/widgets/qdockwidget.cpp +++ b/src/gui/widgets/qdockwidget.cpp @@ -203,7 +203,7 @@ bool QDockWidgetLayout::nativeWindowDeco() const bool QDockWidgetLayout::nativeWindowDeco(bool floating) const { -#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_WINCE) +#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_WINCE) Q_UNUSED(floating); return false; #else diff --git a/src/gui/widgets/qframe_p.h b/src/gui/widgets/qframe_p.h index 4fd341d..3ea0c8b 100644 --- a/src/gui/widgets/qframe_p.h +++ b/src/gui/widgets/qframe_p.h @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE -class Q_GUI_EXPORT QFramePrivate : public QWidgetPrivate +class QFramePrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QFrame) public: diff --git a/src/gui/widgets/qgroupbox.cpp b/src/gui/widgets/qgroupbox.cpp index 6a82483..876c5d6 100644 --- a/src/gui/widgets/qgroupbox.cpp +++ b/src/gui/widgets/qgroupbox.cpp @@ -644,15 +644,11 @@ bool QGroupBox::isChecked() const void QGroupBox::setChecked(bool b) { Q_D(QGroupBox); - if (d->checkable) { - if (d->checked != b) - update(); - bool wasToggled = (b != d->checked); + if (d->checkable && b != d->checked) { + update(); d->checked = b; - if (wasToggled) { - d->_q_setChildrenEnabled(b); - emit toggled(b); - } + d->_q_setChildrenEnabled(b); + emit toggled(b); } } diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp index 63c1315..016b7c1 100644 --- a/src/gui/widgets/qlabel.cpp +++ b/src/gui/widgets/qlabel.cpp @@ -971,6 +971,13 @@ void QLabel::paintEvent(QPaintEvent *) #endif if (d->isTextLabel) { QRectF lr = d->layoutRect(); + QStyleOption opt; + opt.initFrom(this); +#ifndef QT_NO_STYLE_STYLESHEET + if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) { + cssStyle->styleSheetPalette(this, &opt, &opt.palette); + } +#endif if (d->control) { #ifndef QT_NO_SHORTCUT const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0); @@ -984,11 +991,9 @@ void QLabel::paintEvent(QPaintEvent *) d->ensureTextLayouted(); QAbstractTextDocumentLayout::PaintContext context; - QStyleOption opt(0); - opt.init(this); if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) { - context.palette = palette(); + context.palette = opt.palette; context.palette.setColor(QPalette::Text, context.palette.light().color()); painter.save(); painter.translate(lr.x() + 1, lr.y() + 1); @@ -999,12 +1004,7 @@ void QLabel::paintEvent(QPaintEvent *) } // Adjust the palette - context.palette = palette(); -#ifndef QT_NO_STYLE_STYLESHEET - if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) { - cssStyle->focusPalette(this, &opt, &context.palette); - } -#endif + context.palette = opt.palette; if (foregroundRole() != QPalette::Text && isEnabled()) context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole())); @@ -1019,12 +1019,10 @@ void QLabel::paintEvent(QPaintEvent *) int flags = align; if (d->hasShortcut) { flags |= Qt::TextShowMnemonic; - QStyleOption opt; - opt.initFrom(this); if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this)) flags |= Qt::TextHideMnemonic; } - style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole()); + style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole()); } } else #ifndef QT_NO_PICTURE diff --git a/src/gui/widgets/qlcdnumber.cpp b/src/gui/widgets/qlcdnumber.cpp index 0136f1a..6686d7e 100644 --- a/src/gui/widgets/qlcdnumber.cpp +++ b/src/gui/widgets/qlcdnumber.cpp @@ -403,7 +403,7 @@ QLCDNumber::QLCDNumber(QWidget *parent) Constructs an LCD number, sets the number of digits to \a numDigits, the base to decimal, the decimal point mode to 'small' and the frame style to a raised box. The segmentStyle() is set to - \c Outline. + \c Filled. The \a parent argument is passed to the QFrame constructor. @@ -427,7 +427,7 @@ void QLCDNumberPrivate::init() base = QLCDNumber::Dec; smallPoint = false; q->setNumDigits(ndigits); - q->setSegmentStyle(QLCDNumber::Outline); + q->setSegmentStyle(QLCDNumber::Filled); q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); } @@ -756,6 +756,10 @@ void QLCDNumber::paintEvent(QPaintEvent *) Q_D(QLCDNumber); QPainter p(this); drawFrame(&p); + p.setRenderHint(QPainter::Antialiasing); + if (d->shadow) + p.translate(0.5, 0.5); + if (d->smallPoint) d->drawString(d->digitStr, p, &d->points, false); else @@ -1070,7 +1074,7 @@ void QLCDNumberPrivate::drawSegment(const QPoint &pos, char segmentNo, QPainter q->objectName().toLocal8Bit().constData(), segmentNo); } // End exact copy - p.setPen(fgColor); + p.setPen(Qt::NoPen); p.setBrush(fgColor); p.drawPolygon(a); p.setBrush(Qt::NoBrush); @@ -1218,8 +1222,8 @@ void QLCDNumberPrivate::drawSegment(const QPoint &pos, char segmentNo, QPainter \header \i Style \i Result \row \i \c Outline \i Produces raised segments filled with the background color - (this is the default). \row \i \c Filled + (this is the default). \i Produces raised segments filled with the foreground color. \row \i \c Flat \i Produces flat segments filled with the foreground color. @@ -1271,7 +1275,7 @@ bool QLCDNumber::event(QEvent *e) /*! \fn int QLCDNumber::margin() const - Returns the with of the the margin around the contents of the widget. + Returns the width of the margin around the contents of the widget. Use QWidget::getContentsMargins() instead. \sa setMargin(), QWidget::getContentsMargins() diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index b03df9e..128f243 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -2518,7 +2518,7 @@ void QLineEdit::paintEvent(QPaintEvent *) // draw text, selections and cursors #ifndef QT_NO_STYLE_STYLESHEET if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) { - cssStyle->focusPalette(this, &panel, &pal); + cssStyle->styleSheetPalette(this, &panel, &pal); } #endif p.setPen(pal.text().color()); @@ -3523,6 +3523,8 @@ void QLineEditPrivate::redo() { case RemoveSelection: case DeleteSelection: text.remove(cmd.pos, 1); + selstart = cmd.selStart; + selend = cmd.selEnd; cursor = cmd.pos; break; case Separator: @@ -3673,7 +3675,7 @@ void QLineEditPrivate::redo() { /*! \fn int QLineEdit::margin() const - Returns the with of the the margin around the contents of the widget. + Returns the width of the margin around the contents of the widget. Use QWidget::getContentsMargins() instead. \sa setMargin(), QWidget::getContentsMargins() diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 502c1e9..558ba42 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -1408,10 +1408,10 @@ bool QMainWindow::event(QEvent *event) This property is false by default and only has any effect on Mac OS X 10.4 or higher. - If set to true, then the top toolbar area is replaced with a Carbon - HIToolbar and all toolbars in the top toolbar area are moved to that. Any - toolbars added afterwards will also be added to the Carbon HIToolbar. This - means a couple of things. + If set to true, then the top toolbar area is replaced with a Carbon HIToolbar + or a Cocoa NSToolbar (depending on whether Qt was built with Carbon or Cocoa). + All toolbars in the top toolbar area and any toolbars added afterwards are + moved to that. This means a couple of things. \list \i QToolBars in this toolbar area are not movable and you cannot drag other diff --git a/src/gui/widgets/qmainwindowlayout_mac.mm b/src/gui/widgets/qmainwindowlayout_mac.mm index c807afb..53e1ad5 100644 --- a/src/gui/widgets/qmainwindowlayout_mac.mm +++ b/src/gui/widgets/qmainwindowlayout_mac.mm @@ -502,11 +502,11 @@ void QMainWindowLayout::fixSizeInUnifiedToolbar(QToolBar *tb) const QMacCocoaAutoReleasePool pool; QWidgetItem layoutItem(tb); QSize size = layoutItem.maximumSize(); - NSSize nssize = NSMakeSize(size.width(), size.height()); + NSSize nssize = NSMakeSize(size.width(), size.height() - 2); [item setMaxSize:nssize]; size = layoutItem.minimumSize(); nssize.width = size.width(); - nssize.height = size.height(); + nssize.height = size.height() - 2; [item setMinSize:nssize]; } } diff --git a/src/gui/widgets/qmdiarea.cpp b/src/gui/widgets/qmdiarea.cpp index 598d3b5..6acd977 100644 --- a/src/gui/widgets/qmdiarea.cpp +++ b/src/gui/widgets/qmdiarea.cpp @@ -81,7 +81,7 @@ subwindows. This information could be used in a popup menu containing a list of windows, for example. - The subwindows are sorted by the the current + The subwindows are sorted by the current \l{QMdiArea::}{WindowOrder}. This is used for the subWindowList() and for activateNextSubWindow() and acivatePreviousSubWindow(). Also, it is used when cascading or tiling the windows with diff --git a/src/gui/widgets/qmdisubwindow.cpp b/src/gui/widgets/qmdisubwindow.cpp index 6bf7633..56df8ea 100644 --- a/src/gui/widgets/qmdisubwindow.cpp +++ b/src/gui/widgets/qmdisubwindow.cpp @@ -1772,7 +1772,7 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const if (isChildOfTabbedQMdiArea(q)) return false; -#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_OS_WINCE_WM) +#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_WS_WINCE_WM) return true; #else if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 7396a9d..3004841 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -2837,7 +2837,7 @@ void QMenu::actionEvent(QActionEvent *e) } #endif -#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR) +#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) if (!d->wce_menu) d->wce_menu = new QMenuPrivate::QWceMenuPrivate; if (e->type() == QEvent::ActionAdded) diff --git a/src/gui/widgets/qmenu.h b/src/gui/widgets/qmenu.h index 867baee..e1a6256 100644 --- a/src/gui/widgets/qmenu.h +++ b/src/gui/widgets/qmenu.h @@ -141,7 +141,7 @@ public: OSMenuRef macMenu(OSMenuRef merge=0); #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE HMENU wceMenu(bool create = false); #endif @@ -174,7 +174,7 @@ protected: bool focusNextPrevChild(bool next); void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE QAction* wceCommands(uint command); #endif diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index ad848c9..cce083f 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -71,7 +71,6 @@ QT_BEGIN_NAMESPACE /***************************************************************************** QMenu globals *****************************************************************************/ -bool qt_mac_no_native_menubar = false; bool qt_mac_no_menubar_merge = false; bool qt_mac_quit_menu_item_enabled = true; int qt_mac_menus_open_count = 0; @@ -143,6 +142,39 @@ static int qt_mac_CountMenuItems(OSMenuRef menu) return 0; } +static quint32 constructModifierMask(quint32 accel_key) +{ + quint32 ret = 0; + const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta); +#ifndef QT_MAC_USE_COCOA + if ((accel_key & Qt::ALT) == Qt::ALT) + ret |= kMenuOptionModifier; + if ((accel_key & Qt::SHIFT) == Qt::SHIFT) + ret |= kMenuShiftModifier; + if (dontSwap) { + if ((accel_key & Qt::META) != Qt::META) + ret |= kMenuNoCommandModifier; + if ((accel_key & Qt::CTRL) == Qt::CTRL) + ret |= kMenuControlModifier; + } else { + if ((accel_key & Qt::CTRL) != Qt::CTRL) + ret |= kMenuNoCommandModifier; + if ((accel_key & Qt::META) == Qt::META) + ret |= kMenuControlModifier; + } +#else + if ((accel_key & Qt::CTRL) == Qt::CTRL) + ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask); + if ((accel_key & Qt::META) == Qt::META) + ret |= (dontSwap ? NSCommandKeyMask : NSControlKeyMask); + if ((accel_key & Qt::ALT) == Qt::ALT) + ret |= NSAlternateKeyMask; + if ((accel_key & Qt::SHIFT) == Qt::SHIFT) + ret |= NSShiftKeyMask; +#endif + return ret; +} + static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp, const QMacMenuAction *action) { @@ -166,7 +198,7 @@ bool qt_mac_activate_action(MenuRef menu, uint command, QAction::ActionEvent act QMenuMergeList *list = 0; GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list); - if (!list && qt_mac_current_menubar.qmenubar) { + if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu; GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list); if (list) @@ -526,15 +558,7 @@ static bool qt_mac_auto_apple_menu(MenuCommand cmd) static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key) { if (modif) { - *modif = 0; - if ((accel_key & Qt::CTRL) != Qt::CTRL) - *modif |= kMenuNoCommandModifier; - if ((accel_key & Qt::META) == Qt::META) - *modif |= kMenuControlModifier; - if ((accel_key & Qt::ALT) == Qt::ALT) - *modif |= kMenuOptionModifier; - if ((accel_key & Qt::SHIFT) == Qt::SHIFT) - *modif |= kMenuShiftModifier; + *modif = constructModifierMask(accel_key); } accel_key &= ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL); @@ -728,6 +752,18 @@ QMacMenuAction::~QMacMenuAction() { #ifdef QT_MAC_USE_COCOA [menu release]; + if (action) { + QAction::MenuRole role = action->menuRole(); + // Check if the item is owned by Qt, and should be hidden to keep it from causing + // problems. Do it for everything but the quit menu item since that should always + // be visible. + if (role > QAction::ApplicationSpecificRole && role < QAction::QuitRole) { + [menuItem setHidden:YES]; + } else if (role == QAction::TextHeuristicRole + && menuItem != [getMenuLoader() quitMenuItem]) { + [menuItem setHidden:YES]; + } + } [menuItem setTag:nil]; [menuItem release]; #endif @@ -917,21 +953,22 @@ static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action) ret = action->action->shortcut(); #ifndef QT_MAC_USE_COCOA else if (action->command == kHICommandPreferences) - ret = QKeySequence(Qt::CTRL+Qt::Key_Comma); + ret = QKeySequence(QKeySequence::Preferences); else if (action->command == kHICommandQuit) - ret = QKeySequence(Qt::CTRL+Qt::Key_Q); + ret = QKeySequence(QKeySequence::Quit); #else else if (action->menuItem == [loader preferencesMenuItem]) - ret = QKeySequence(Qt::CTRL+Qt::Key_Comma); + ret = QKeySequence(QKeySequence::Preferences); else if (action->menuItem == [loader quitMenuItem]) - ret = QKeySequence(Qt::CTRL+Qt::Key_Q); + ret = QKeySequence(QKeySequence::Quit); #endif return ret; } void Q_GUI_EXPORT qt_mac_set_menubar_icons(bool b) { QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, !b); } -void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) { qt_mac_no_native_menubar = !b; } +void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) +{ QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, !b); } void Q_GUI_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge = !b; } /***************************************************************************** @@ -1208,58 +1245,21 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction NSString *keySequenceToKeyEqivalent(const QKeySequence &accel) { quint32 accel_key = (accel[0] & ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL)); - unichar keyEquiv[1] = { 0 }; - if (accel_key == Qt::Key_Return) - keyEquiv[0] = kReturnCharCode; - else if (accel_key == Qt::Key_Enter) - keyEquiv[0] = kEnterCharCode; - else if (accel_key == Qt::Key_Tab) - keyEquiv[0] = kTabCharCode; - else if (accel_key == Qt::Key_Backspace) - keyEquiv[0] = kBackspaceCharCode; - else if (accel_key == Qt::Key_Delete) - keyEquiv[0] = NSDeleteFunctionKey; - else if (accel_key == Qt::Key_Escape) - keyEquiv[0] = kEscapeCharCode; - else if (accel_key == Qt::Key_PageUp) - keyEquiv[0] = NSPageUpFunctionKey; - else if (accel_key == Qt::Key_PageDown) - keyEquiv[0] = NSPageDownFunctionKey; - else if (accel_key == Qt::Key_Up) - keyEquiv[0] = NSUpArrowFunctionKey; - else if (accel_key == Qt::Key_Down) - keyEquiv[0] = NSDownArrowFunctionKey; - else if (accel_key == Qt::Key_Left) - keyEquiv[0] = NSLeftArrowFunctionKey; - else if (accel_key == Qt::Key_Right) - keyEquiv[0] = NSRightArrowFunctionKey; - else if (accel_key == Qt::Key_CapsLock) - keyEquiv[0] = kMenuCapsLockGlyph; // ### Cocoa has no equivalent - else if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) - keyEquiv[0] = (accel_key - Qt::Key_F1) + NSF1FunctionKey; - else if (accel_key == Qt::Key_Home) - keyEquiv[0] = NSHomeFunctionKey; - else if (accel_key == Qt::Key_End) - keyEquiv[0] = NSEndFunctionKey; - else - keyEquiv[0] = unichar(QChar(accel_key).toLower().unicode()); - return [NSString stringWithCharacters:keyEquiv length:1]; + extern QChar qt_macSymbolForQtKey(int key); // qkeysequence.cpp + QChar keyEquiv = qt_macSymbolForQtKey(accel_key); + if (keyEquiv.isNull()) { + if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) + keyEquiv = (accel_key - Qt::Key_F1) + NSF1FunctionKey; + else + keyEquiv = unichar(QChar(accel_key).toLower().unicode()); + } + return [NSString stringWithCharacters:&keyEquiv.unicode() length:1]; } // return the cocoa modifier mask for the QKeySequence (currently only looks at the first one). NSUInteger keySequenceModifierMask(const QKeySequence &accel) { - NSUInteger ret = 0; - quint32 accel_key = accel[0]; - if ((accel_key & Qt::CTRL) == Qt::CTRL) - ret |= NSCommandKeyMask; - if ((accel_key & Qt::META) == Qt::META) - ret |= NSControlKeyMask; - if ((accel_key & Qt::ALT) == Qt::ALT) - ret |= NSAlternateKeyMask; - if ((accel_key & Qt::SHIFT) == Qt::SHIFT) - ret |= NSShiftKeyMask; - return ret; + return constructModifierMask(accel[0]); } void @@ -1728,9 +1728,14 @@ QMenuBarPrivate::macCreateMenuBar(QWidget *parent) { Q_Q(QMenuBar); static int checkEnv = -1; + // We call the isNativeMenuBar function here + // becasue that will make sure that local overrides + // are dealt with correctly. + bool qt_mac_no_native_menubar = !q->isNativeMenuBar(); if (qt_mac_no_native_menubar == false && checkEnv < 0) { checkEnv = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty(); - qt_mac_no_native_menubar = checkEnv; + QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, checkEnv); + qt_mac_no_native_menubar = !q->isNativeMenuBar(); } if (!qt_mac_no_native_menubar) { extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp @@ -1765,7 +1770,7 @@ void QMenuBarPrivate::macDestroyMenuBar() OSMenuRef QMenuBarPrivate::macMenu() { Q_Q(QMenuBar); - if (!mac_menubar) { + if (!q->isNativeMenuBar() || !mac_menubar) { return 0; } else if (!mac_menubar->menu) { mac_menubar->menu = qt_mac_create_menu(q); @@ -1886,9 +1891,6 @@ static void cancelAllMenuTracking() */ bool QMenuBar::macUpdateMenuBar() { - if (qt_mac_no_native_menubar) //nothing to be done.. - return true; - cancelAllMenuTracking(); QMenuBar *mb = 0; //find a menu bar @@ -1922,7 +1924,7 @@ bool QMenuBar::macUpdateMenuBar() mb = fallback; //now set it bool ret = false; - if (mb) { + if (mb && mb->isNativeMenuBar()) { #ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; #endif @@ -1943,7 +1945,7 @@ bool QMenuBar::macUpdateMenuBar() qt_mac_current_menubar.qmenubar = mb; qt_mac_current_menubar.modal = QApplicationPrivate::modalState(); ret = true; - } else if (qt_mac_current_menubar.qmenubar) { + } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { const bool modal = QApplicationPrivate::modalState(); if (modal != qt_mac_current_menubar.modal) { ret = true; diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index e3c4890..edfeee7 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -112,7 +112,7 @@ struct QMenuMergeItem typedef QList<QMenuMergeItem> QMenuMergeList; #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE struct QWceMenuAction { uint command; QPointer<QAction> action; @@ -132,7 +132,7 @@ public: #ifdef Q_WS_MAC ,mac_menu(0) #endif -#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR) +#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) ,wce_menu(0) #endif #ifdef QT3_SUPPORT @@ -145,7 +145,7 @@ public: #ifdef Q_WS_MAC delete mac_menu; #endif -#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR) +#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) delete wce_menu; #endif } @@ -208,7 +208,7 @@ public: QString searchBuffer; QBasicTimer searchBufferTimer; - //passing of mouse events up the parent heirarchy + //passing of mouse events up the parent hierarchy QPointer<QMenu> activeMenu; bool mouseEventTaken(QMouseEvent *); @@ -293,7 +293,7 @@ public: bool emitHighlighted; #endif -#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR) +#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) struct QWceMenuPrivate { QList<QWceMenuAction*> actionItems; HMENU menuHandle; diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index 847a623..2ce89f9 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ //Native menubars are only supported for Windows Mobile not the standard SDK/generic WinCE -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE #include "qmenu.h" #include "qt_windows.h" #include "qapplication.h" @@ -214,10 +214,12 @@ static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, i mbi.nToolBarId = toolbarID; if (ptrCreateMenuBar(&mbi)) { +#ifdef Q_OS_WINCE_WM // Tell the menu bar that we want to override hot key behaviour. LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY); SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam); +#endif return mbi.hwndMB; } } @@ -619,4 +621,4 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { QT_END_NAMESPACE #endif //QT_NO_MENUBAR -#endif //Q_OS_WINCE +#endif //Q_WS_WINCE diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index ccf37db..cffc3d5 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -67,7 +67,7 @@ #include "qmenubar_p.h" #include "qdebug.h" -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp #endif @@ -194,7 +194,7 @@ void QMenuBarPrivate::updateGeometries() } #ifdef Q_WS_MAC - if(mac_menubar) {//nothing to see here folks, move along.. + if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. itemsDirty = false; return; } @@ -725,7 +725,7 @@ void QMenuBarPrivate::init() if(mac_menubar) q->hide(); #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE if (qt_wince_is_mobile()) { wceCreateMenuBar(q->parentWidget()); if(wce_menubar) @@ -776,7 +776,7 @@ QMenuBar::~QMenuBar() Q_D(QMenuBar); d->macDestroyMenuBar(); #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE Q_D(QMenuBar); if (qt_wince_is_mobile()) d->wceDestroyMenuBar(); @@ -1025,14 +1025,8 @@ void QMenuBar::paintEvent(QPaintEvent *e) */ void QMenuBar::setVisible(bool visible) { -#ifdef Q_WS_MAC - Q_D(QMenuBar); - if(d->mac_menubar) - return; -#endif -#ifdef Q_OS_WINCE - Q_D(QMenuBar); - if(d->wce_menubar) +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) + if (isNativeMenuBar()) return; #endif QWidget::setVisible(visible); @@ -1272,24 +1266,21 @@ void QMenuBar::actionEvent(QActionEvent *e) { Q_D(QMenuBar); d->itemsDirty = true; +#if defined (Q_WS_MAC) || defined(Q_OS_WINCE) + if (isNativeMenuBar()) { #ifdef Q_WS_MAC - if(d->mac_menubar) { - if(e->type() == QEvent::ActionAdded) - d->mac_menubar->addAction(e->action(), d->mac_menubar->findAction(e->before())); - else if(e->type() == QEvent::ActionRemoved) - d->mac_menubar->removeAction(e->action()); - else if(e->type() == QEvent::ActionChanged) - d->mac_menubar->syncAction(e->action()); - } + QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar; +#else + QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar; #endif -#ifdef Q_OS_WINCE - if(d->wce_menubar) { + if (!nativeMenuBar) + return; if(e->type() == QEvent::ActionAdded) - d->wce_menubar->addAction(e->action(), d->wce_menubar->findAction(e->before())); + nativeMenuBar->addAction(e->action(), nativeMenuBar->findAction(e->before())); else if(e->type() == QEvent::ActionRemoved) - d->wce_menubar->removeAction(e->action()); + nativeMenuBar->removeAction(e->action()); else if(e->type() == QEvent::ActionChanged) - d->wce_menubar->syncAction(e->action()); + nativeMenuBar->syncAction(e->action()); } #endif if(e->type() == QEvent::ActionAdded) { @@ -1374,7 +1365,7 @@ void QMenuBarPrivate::handleReparent() macCreateMenuBar(newParent); #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE if (qt_wince_is_mobile() && wce_menubar) wce_menubar->rebuild(); #endif @@ -1612,10 +1603,8 @@ QRect QMenuBar::actionGeometry(QAction *act) const QSize QMenuBar::minimumSizeHint() const { Q_D(const QMenuBar); -#ifdef Q_WS_MAC - const bool as_gui_menubar = !d->mac_menubar; -#elif defined (Q_OS_WINCE) - const bool as_gui_menubar = !d->wce_menubar; +#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) + const bool as_gui_menubar = !isNativeMenuBar(); #else const bool as_gui_menubar = true; #endif @@ -1672,14 +1661,13 @@ QSize QMenuBar::minimumSizeHint() const QSize QMenuBar::sizeHint() const { Q_D(const QMenuBar); -#ifdef Q_WS_MAC - const bool as_gui_menubar = !d->mac_menubar; -#elif defined (Q_OS_WINCE) - const bool as_gui_menubar = !d->wce_menubar; +#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) + const bool as_gui_menubar = !isNativeMenuBar(); #else const bool as_gui_menubar = true; #endif + ensurePolished(); QSize ret(0, 0); const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); @@ -1735,13 +1723,12 @@ QSize QMenuBar::sizeHint() const int QMenuBar::heightForWidth(int) const { Q_D(const QMenuBar); -#ifdef Q_WS_MAC - const bool as_gui_menubar = !d->mac_menubar; -#elif defined (Q_OS_WINCE) - const bool as_gui_menubar = !d->wce_menubar; +#if defined(Q_WS_MAC) || defined(Q_WS_WINCE) + const bool as_gui_menubar = !isNativeMenuBar(); #else const bool as_gui_menubar = true; #endif + int height = 0; const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); @@ -1856,6 +1843,60 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const } /*! + \property QMenuBar::nativeMenuBar + \brief Whether or not a menubar will be used as a native menubar on platforms that support it + \since 4.6 + + This property specifies whether or not the menubar should be used as a native menubar on platforms + that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms + if this property is true, the menubar is used in the native menubar and is not in the window of + its parent, if false the menubar remains in the window. On other platforms the value of this + attribute has no effect. + + The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute + is set for the application. Explicitly settings this property overrides + the presence (or abscence) of the attribute. +*/ + +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<QAction *> &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(); + setVisible(false); + setVisible(true); +#endif + } +} + +bool QMenuBar::isNativeMenuBar() const +{ + Q_D(const QMenuBar); + if (d->nativeMenuBar == -1) { + return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar); + } + return d->nativeMenuBar; +} + +/*! \since 4.4 Sets the default action to \a act. @@ -1869,13 +1910,13 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const \sa defaultAction() */ -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE void QMenuBar::setDefaultAction(QAction *act) { Q_D(QMenuBar); if (d->defaultAction == act) return; -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE if (qt_wince_is_mobile()) if (d->defaultAction) { disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); @@ -1883,7 +1924,7 @@ void QMenuBar::setDefaultAction(QAction *act) } #endif d->defaultAction = act; -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE if (qt_wince_is_mobile()) if (d->defaultAction) { connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); @@ -2379,7 +2420,7 @@ int QMenuBar::findIdForAction(QAction *act) const /*! \fn int QMenuBar::margin() const - Returns the with of the the margin around the contents of the widget. + Returns the width of the margin around the contents of the widget. Use QWidget::getContentsMargins() instead. \sa setMargin(), QWidget::getContentsMargins() diff --git a/src/gui/widgets/qmenubar.h b/src/gui/widgets/qmenubar.h index 42f0c0c..58a03ff 100644 --- a/src/gui/widgets/qmenubar.h +++ b/src/gui/widgets/qmenubar.h @@ -64,6 +64,7 @@ class Q_GUI_EXPORT QMenuBar : public QWidget Q_OBJECT Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp) + Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar) public: explicit QMenuBar(QWidget *parent = 0); @@ -110,7 +111,7 @@ public: static bool macUpdateMenuBar(); #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE void setDefaultAction(QAction *); QAction *defaultAction() const; @@ -118,6 +119,9 @@ public: static void wceRefresh(); #endif + bool isNativeMenuBar() const; + void setNativeMenuBar(bool nativeMenuBar); + public Q_SLOTS: virtual void setVisible(bool visible); @@ -339,7 +343,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int)) Q_PRIVATE_SLOT(d_func(), void _q_updateLayout()) -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction()) #endif diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index 223346b..5dab310 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -57,7 +57,7 @@ #include "QtGui/qstyleoption.h" #include <private/qmenu_p.h> // Mac needs what in this file! -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE #include "qguifunctions_wince.h" #endif @@ -70,12 +70,13 @@ class QMenuBarPrivate : public QWidgetPrivate Q_DECLARE_PUBLIC(QMenuBar) public: QMenuBarPrivate() : itemsDirty(0), itemsWidth(0), itemsStart(-1), currentAction(0), mouseDown(0), - closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0) + closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0), + nativeMenuBar(-1) #ifdef Q_WS_MAC , mac_menubar(0) #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE , wce_menubar(0), wceClassicMenu(false) #endif { } @@ -84,7 +85,7 @@ public: #ifdef Q_WS_MAC delete mac_menubar; #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE delete wce_menubar; #endif } @@ -119,6 +120,8 @@ public: uint keyboardState : 1, altPressed : 1; QPointer<QWidget> keyboardFocusWidget; + + int nativeMenuBar : 3; // Only has values -1, 0, and 1 //firing of events void activateAction(QAction *, QAction::ActionEvent); @@ -127,7 +130,7 @@ public: void _q_internalShortcutActivated(int); void _q_updateLayout(); -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE void _q_updateDefaultAction(); #endif @@ -181,7 +184,7 @@ public: void macDestroyMenuBar(); OSMenuRef macMenu(); #endif -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE void wceCreateMenuBar(QWidget *); void wceDestroyMenuBar(); struct QWceMenuBarPrivate { diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index e563fa1..f317742 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -370,11 +370,16 @@ void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block) extraMargin += fm.width(QChar(0x21B5)); } tl->beginLayout(); + qreal availableWidth = d->width; + if (availableWidth <= 0) { + availableWidth = INT_MAX; // similar to text edit with pageSize.width == 0 + } + availableWidth -= 2*margin + extraMargin; while (1) { QTextLine line = tl->createLine(); if (!line.isValid()) break; - line.setLineWidth(d->width - 2*margin - extraMargin); + line.setLineWidth(availableWidth); height += leading; line.setPosition(QPointF(margin, height)); @@ -555,7 +560,8 @@ QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const { if (!currentBlock.isValid()) return QRectF(); Q_ASSERT(currentBlock.blockNumber() == currentBlockNumber); - QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); + QTextDocument *doc = document(); + QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); Q_ASSERT(documentLayout); QPointF offset; @@ -566,13 +572,22 @@ QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const { offset.ry() += r.height(); currentBlock = currentBlock.next(); ++currentBlockNumber; + if (!currentBlock.isVisible()) { + currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber()); + currentBlockNumber = currentBlock.blockNumber(); + } r = documentLayout->blockBoundingRect(currentBlock); } while (currentBlockNumber > blockNumber && offset.y() >= -textEdit->viewport()->height()) { currentBlock = currentBlock.previous(); + --currentBlockNumber; + while (!currentBlock.isVisible()) { + currentBlock = currentBlock.previous(); + --currentBlockNumber; + } if (!currentBlock.isValid()) break; - --currentBlockNumber; + r = documentLayout->blockBoundingRect(currentBlock); offset.ry() -= r.height(); } diff --git a/src/gui/widgets/qprintpreviewwidget.cpp b/src/gui/widgets/qprintpreviewwidget.cpp index 16334b8..d4e5122 100644 --- a/src/gui/widgets/qprintpreviewwidget.cpp +++ b/src/gui/widgets/qprintpreviewwidget.cpp @@ -98,29 +98,8 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QRectF paperRect(0,0, paperSize.width(), paperSize.height()); - painter->setClipRect(paperRect & option->exposedRect); - painter->fillRect(paperRect, Qt::white); - if (!pagePicture) - return; - painter->drawPicture(pageRect.topLeft(), *pagePicture); - - // Effect: make anything drawn in the margins look washed out. - QPainterPath path; - path.addRect(paperRect); - path.addRect(pageRect); - painter->setPen(QPen(Qt::NoPen)); - painter->setBrush(QColor(255, 255, 255, 180)); - painter->drawPath(path); - - painter->setClipRect(option->exposedRect); -#if 0 - // Draw frame around paper. - painter->setPen(QPen(Qt::black, 0)); - painter->setBrush(Qt::NoBrush); - painter->drawRect(paperRect); -#endif - // Draw shadow + painter->setClipRect(option->exposedRect); qreal shWidth = paperRect.width()/100; QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth), paperRect.bottomRight() + QPointF(shWidth, 0)); @@ -141,6 +120,27 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, cgrad.setColorAt(1.0, QColor(0,0,0,0)); painter->fillRect(cshadow, QBrush(cgrad)); + painter->setClipRect(paperRect & option->exposedRect); + painter->fillRect(paperRect, Qt::white); + if (!pagePicture) + return; + painter->drawPicture(pageRect.topLeft(), *pagePicture); + + // Effect: make anything drawn in the margins look washed out. + QPainterPath path; + path.addRect(paperRect); + path.addRect(pageRect); + painter->setPen(QPen(Qt::NoPen)); + painter->setBrush(QColor(255, 255, 255, 180)); + painter->drawPath(path); + +#if 0 + // Draw frame around paper. + painter->setPen(QPen(Qt::black, 0)); + painter->setBrush(Qt::NoBrush); + painter->drawRect(paperRect); +#endif + // todo: drawtext "Page N" below paper } diff --git a/src/gui/widgets/qscrollarea.cpp b/src/gui/widgets/qscrollarea.cpp index 6aca7d3..8b01453 100644 --- a/src/gui/widgets/qscrollarea.cpp +++ b/src/gui/widgets/qscrollarea.cpp @@ -127,7 +127,7 @@ QT_BEGIN_NAMESPACE setting the layout's \l{QLayout::sizeConstraint}{size constraint} property to one which provides constraints on the minimum and/or maximum size of the layout (e.g., QLayout::SetMinAndMaxSize) will - cause the size of the the scroll area to be updated whenever the + cause the size of the scroll area to be updated whenever the contents of the layout changes. For a complete example using the QScrollArea class, see the \l diff --git a/src/gui/widgets/qslider.cpp b/src/gui/widgets/qslider.cpp index 32b9021..5b9c8a4 100644 --- a/src/gui/widgets/qslider.cpp +++ b/src/gui/widgets/qslider.cpp @@ -62,7 +62,6 @@ public: int tickInterval; QSlider::TickPosition tickPosition; int clickOffset; - int snapBackPosition; void init(); void resetLayoutItemMargins(); int pixelPosToRangeValue(int pos) const; @@ -493,7 +492,6 @@ void QSlider::mousePressEvent(QMouseEvent *ev) setRepeatAction(SliderNoAction); QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); d->clickOffset = d->pick(ev->pos() - sr.topLeft()); - d->snapBackPosition = d->position; update(sr); setSliderDown(true); } @@ -513,14 +511,6 @@ void QSlider::mouseMoveEvent(QMouseEvent *ev) int newPosition = d->pixelPosToRangeValue(d->pick(ev->pos()) - d->clickOffset); QStyleOptionSlider opt; initStyleOption(&opt); - int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this); - if (m >= 0) { - QRect r = rect(); - r.adjust(-m, -m, m, m); - if (!r.contains(ev->pos())) { - newPosition = d->snapBackPosition; - } - } setSliderPosition(newPosition); } diff --git a/src/gui/widgets/qsplitter.cpp b/src/gui/widgets/qsplitter.cpp index bf8af35..400d78a 100644 --- a/src/gui/widgets/qsplitter.cpp +++ b/src/gui/widgets/qsplitter.cpp @@ -119,7 +119,6 @@ QSplitterHandle::QSplitterHandle(Qt::Orientation orientation, QSplitter *parent) { Q_D(QSplitterHandle); d->s = parent; - d->hover = false; setOrientation(orientation); } @@ -269,8 +268,11 @@ void QSplitterHandle::mouseMoveEvent(QMouseEvent *e) void QSplitterHandle::mousePressEvent(QMouseEvent *e) { Q_D(QSplitterHandle); - if (e->button() == Qt::LeftButton) + if (e->button() == Qt::LeftButton) { d->mouseOffset = d->pick(e->pos()); + d->pressed = true; + update(); + } } /*! @@ -285,6 +287,10 @@ void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e) d->s->setRubberBand(-1); moveSplitter(pos); } + if (e->button() == Qt::LeftButton) { + d->pressed = false; + update(); + } } /*! @@ -303,6 +309,8 @@ void QSplitterHandle::paintEvent(QPaintEvent *) opt.state = QStyle::State_None; if (d->hover) opt.state |= QStyle::State_MouseOver; + if (d->pressed) + opt.state |= QStyle::State_Sunken; if (isEnabled()) opt.state |= QStyle::State_Enabled; parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s); @@ -1517,7 +1525,7 @@ void QSplitter::setOpaqueResize(bool on) /*! \fn int QSplitter::margin() const - Returns the with of the the margin around the contents of the widget. + Returns the width of the margin around the contents of the widget. Use QWidget::getContentsMargins() instead. \sa setMargin(), QWidget::getContentsMargins() diff --git a/src/gui/widgets/qsplitter_p.h b/src/gui/widgets/qsplitter_p.h index 5cc43af..9f6fe0c 100644 --- a/src/gui/widgets/qsplitter_p.h +++ b/src/gui/widgets/qsplitter_p.h @@ -131,16 +131,17 @@ class QSplitterHandlePrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QSplitterHandle) public: - QSplitterHandlePrivate() : orient(Qt::Horizontal), opaq(false), s(0), mouseOffset(0) {} + QSplitterHandlePrivate() : s(0), orient(Qt::Horizontal), mouseOffset(0), opaq(false), hover(false), pressed(false) {} inline int pick(const QPoint &pos) const { return orient == Qt::Horizontal ? pos.x() : pos.y(); } - Qt::Orientation orient; - bool opaq; QSplitter *s; - bool hover; + Qt::Orientation orient; int mouseOffset; + bool opaq : 1; + bool hover : 1; + bool pressed : 1; }; QT_END_NAMESPACE diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index 69221ba..0b4ce9d 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -176,12 +176,11 @@ void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner)) option->cornerWidgets |= QStyleOptionTab::RightCornerWidget; } +#endif QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this); - option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(), Qt::TextShowMnemonic); -#endif } /*! @@ -1941,8 +1940,10 @@ void QTabBar::changeEvent(QEvent *event) if (event->type() == QEvent::StyleChange) { d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); + d->refresh(); + } else if (event->type() == QEvent::FontChange) { + d->refresh(); } - d->refresh(); QWidget::changeEvent(event); } diff --git a/src/gui/widgets/qtabwidget.cpp b/src/gui/widgets/qtabwidget.cpp index c16e000..43b2f54 100644 --- a/src/gui/widgets/qtabwidget.cpp +++ b/src/gui/widgets/qtabwidget.cpp @@ -504,7 +504,7 @@ QIcon QTabWidget::tabIcon(int index) const } /*! - Returns true if the the page at position \a index is enabled; otherwise returns false. + Returns true if the page at position \a index is enabled; otherwise returns false. \sa setTabEnabled(), QWidget::isEnabled() */ diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp index 1babb6d..d765794 100644 --- a/src/gui/widgets/qtoolbar.cpp +++ b/src/gui/widgets/qtoolbar.cpp @@ -274,9 +274,11 @@ void QToolBarPrivate::endDrag() bool QToolBarPrivate::mousePressEvent(QMouseEvent *event) { - if (layout->handleRect().contains(event->pos()) == false) { + Q_Q(QToolBar); + QStyleOptionToolBar opt; + q->initStyleOption(&opt); + if (q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->pos()) == false) { #ifdef Q_WS_MAC - Q_Q(QToolBar); // When using the unified toolbar on Mac OS X the user can can click and // drag between toolbar contents to move the window. Make this work by // implementing the standard mouse-dragging code and then call @@ -1041,7 +1043,7 @@ void QToolBar::paintEvent(QPaintEvent *) style->drawControl(QStyle::CE_ToolBar, &opt, &p, this); } - opt.rect = d->layout->handleRect(); + opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this); if (opt.rect.isValid()) style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this); } @@ -1142,7 +1144,9 @@ bool QToolBar::event(QEvent *event) case QEvent::HoverMove: { #ifndef QT_NO_CURSOR QHoverEvent *e = static_cast<QHoverEvent*>(event); - if (d->layout->handleRect().contains(e->pos())) + QStyleOptionToolBar opt; + initStyleOption(&opt); + if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos())) setCursor(Qt::SizeAllCursor); else unsetCursor(); @@ -1153,7 +1157,7 @@ bool QToolBar::event(QEvent *event) if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event))) return true; break; -#ifdef Q_OS_WINCE +#ifdef Q_WS_WINCE case QEvent::ContextMenu: { QContextMenuEvent* contextMenuEvent = static_cast<QContextMenuEvent*>(event); diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp index 7771f46..0bfa493 100644 --- a/src/gui/widgets/qtoolbarlayout.cpp +++ b/src/gui/widgets/qtoolbarlayout.cpp @@ -334,7 +334,7 @@ void QToolBarLayout::updateGeomArray() const if (QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget()->parentWidget())) { if (mw->unifiedTitleAndToolBarOnMac() && mw->toolBarArea(static_cast<QToolBar *>(parentWidget())) == Qt::TopToolBarArea) { - if (that->expandFlag) { + if (expandFlag) { tb->setMaximumSize(0xFFFFFF, 0xFFFFFF); } else { tb->setMaximumSize(hint); @@ -360,23 +360,11 @@ void QToolBarLayout::setGeometry(const QRect &rect) QStyle *style = tb->style(); QStyleOptionToolBar opt; tb->initStyleOption(&opt); - const int handleExtent = movable() - ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0; const int margin = this->margin(); const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb); Qt::Orientation o = tb->orientation(); QLayout::setGeometry(rect); - if (movable()) { - if (o == Qt::Horizontal) { - handRect = QRect(margin, margin, handleExtent, rect.height() - 2*margin); - handRect = QStyle::visualRect(parentWidget()->layoutDirection(), rect, handRect); - } else { - handRect = QRect(margin, margin, rect.width() - 2*margin, handleExtent); - } - } else { - handRect = QRect(); - } bool ranOutOfSpace = false; if (!animating) @@ -742,11 +730,6 @@ QToolBarItem *QToolBarLayout::createItem(QAction *action) return result; } -QRect QToolBarLayout::handleRect() const -{ - return handRect; -} - QT_END_NAMESPACE #endif // QT_NO_TOOLBAR diff --git a/src/gui/widgets/qtoolbarlayout_p.h b/src/gui/widgets/qtoolbarlayout_p.h index 2eca773..37755b1 100644 --- a/src/gui/widgets/qtoolbarlayout_p.h +++ b/src/gui/widgets/qtoolbarlayout_p.h @@ -65,7 +65,7 @@ class QAction; class QToolBarExtension; class QMenu; -class Q_GUI_EXPORT QToolBarItem : public QWidgetItem +class QToolBarItem : public QWidgetItem { public: QToolBarItem(QWidget *widget); @@ -75,7 +75,7 @@ public: bool customWidget; }; -class Q_GUI_EXPORT QToolBarLayout : public QLayout +class QToolBarLayout : public QLayout { Q_OBJECT @@ -100,8 +100,6 @@ public: int indexOf(QAction *action) const; int indexOf(QWidget *widget) const { return QLayout::indexOf(widget); } - QRect handleRect() const; - bool layoutActions(const QSize &size); QSize expandedSize(const QSize &size) const; bool expanded, animating; diff --git a/src/gui/widgets/qtoolbox.cpp b/src/gui/widgets/qtoolbox.cpp index 81935a5..271130a 100644 --- a/src/gui/widgets/qtoolbox.cpp +++ b/src/gui/widgets/qtoolbox.cpp @@ -802,7 +802,7 @@ void QToolBox::itemRemoved(int index) /*! \fn int QToolBox::margin() const - Returns the with of the the margin around the contents of the widget. + Returns the width of the margin around the contents of the widget. Use QWidget::getContentsMargins() instead. \sa setMargin(), QWidget::getContentsMargins() diff --git a/src/gui/widgets/qtoolbutton.cpp b/src/gui/widgets/qtoolbutton.cpp index 7390d04..20b84ef 100644 --- a/src/gui/widgets/qtoolbutton.cpp +++ b/src/gui/widgets/qtoolbutton.cpp @@ -859,8 +859,7 @@ void QToolButtonPrivate::_q_buttonPressed() Q_Q(QToolButton); if (!hasMenu()) return; // no menu to show - - if (delay > 0 && popupMode == QToolButton::DelayedPopup) + if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup) popupTimer.start(delay, q); else if (delay == 0 || popupMode == QToolButton::InstantPopup) q->showMenu(); |