diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/accessible/simplewidgets.cpp | 12 | ||||
-rw-r--r-- | src/widgets/dialogs/qfileinfogatherer.cpp | 48 | ||||
-rw-r--r-- | src/widgets/dialogs/qfileinfogatherer_p.h | 4 | ||||
-rw-r--r-- | src/widgets/dialogs/qwizard_win.cpp | 3 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 10 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 8 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication_p.h | 6 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 24 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 3 | ||||
-rw-r--r-- | src/widgets/util/qsystemtrayicon.cpp | 117 | ||||
-rw-r--r-- | src/widgets/util/qsystemtrayicon.h | 1 | ||||
-rw-r--r-- | src/widgets/util/qsystemtrayicon_p.h | 19 | ||||
-rw-r--r-- | src/widgets/util/qsystemtrayicon_qpa.cpp | 17 | ||||
-rw-r--r-- | src/widgets/util/qsystemtrayicon_win.cpp | 57 | ||||
-rw-r--r-- | src/widgets/util/qsystemtrayicon_x11.cpp | 17 | ||||
-rw-r--r-- | src/widgets/widgets/qmenubar.cpp | 1 |
16 files changed, 175 insertions, 172 deletions
diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index e6fda103fb..bd9f0c6e01 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -468,21 +468,15 @@ QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > QAccessibleDisplay::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const { QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match); - if (match & QAccessible::Labelled) { - QVarLengthArray<QObject *, 4> relatedObjects; - #ifndef QT_NO_SHORTCUT + if (match & QAccessible::Labelled) { if (QLabel *label = qobject_cast<QLabel*>(object())) { - relatedObjects.append(label->buddy()); - } -#endif - for (int i = 0; i < relatedObjects.count(); ++i) { const QAccessible::Relation rel = QAccessible::Labelled; - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(relatedObjects.at(i)); - if (iface) + if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(label->buddy())) rels.append(qMakePair(iface, rel)); } } +#endif return rels; } diff --git a/src/widgets/dialogs/qfileinfogatherer.cpp b/src/widgets/dialogs/qfileinfogatherer.cpp index 6df020dd58..08c5a40c7c 100644 --- a/src/widgets/dialogs/qfileinfogatherer.cpp +++ b/src/widgets/dialogs/qfileinfogatherer.cpp @@ -65,6 +65,18 @@ Q_AUTOTEST_EXPORT bool qt_test_isFetchedRoot() } #endif +static QString translateDriveName(const QFileInfo &drive) +{ + QString driveName = drive.absoluteFilePath(); +#ifdef Q_OS_WIN + if (driveName.startsWith(QLatin1Char('/'))) // UNC host + return drive.fileName(); + if (driveName.endsWith(QLatin1Char('/'))) + driveName.chop(1); +#endif // Q_OS_WIN + return driveName; +} + /*! Creates thread */ @@ -82,6 +94,16 @@ QFileInfoGatherer::QFileInfoGatherer(QObject *parent) watcher = new QFileSystemWatcher(this); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(list(QString))); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString))); + +# if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + const QVariant listener = watcher->property("_q_driveListener"); + if (listener.canConvert<QObject *>()) { + if (QObject *driveListener = listener.value<QObject *>()) { + connect(driveListener, SIGNAL(driveAdded()), this, SLOT(driveAdded())); + connect(driveListener, SIGNAL(driveRemoved(QString)), this, SLOT(driveRemoved())); + } + } +# endif // Q_OS_WIN && !Q_OS_WINRT #endif start(LowPriority); } @@ -106,6 +128,20 @@ void QFileInfoGatherer::setResolveSymlinks(bool enable) #endif } +void QFileInfoGatherer::driveAdded() +{ + fetchExtendedInformation(QString(), QStringList()); +} + +void QFileInfoGatherer::driveRemoved() +{ + QStringList drives; + const QFileInfoList driveInfoList = QDir::drives(); + for (const QFileInfo &fi : driveInfoList) + drives.append(translateDriveName(fi)); + newListOfFiles(QString(), drives); +} + bool QFileInfoGatherer::resolveSymlinks() const { #ifdef Q_OS_WIN @@ -260,18 +296,6 @@ QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const return info; } -static QString translateDriveName(const QFileInfo &drive) -{ - QString driveName = drive.absoluteFilePath(); -#if defined(Q_OS_WIN) - if (driveName.startsWith(QLatin1Char('/'))) // UNC host - return drive.fileName(); - if (driveName.endsWith(QLatin1Char('/'))) - driveName.chop(1); -#endif - return driveName; -} - /* Get specific file info's, batch the files so update when we have 100 items and every 200ms after that diff --git a/src/widgets/dialogs/qfileinfogatherer_p.h b/src/widgets/dialogs/qfileinfogatherer_p.h index 3186e9d015..0018b6c387 100644 --- a/src/widgets/dialogs/qfileinfogatherer_p.h +++ b/src/widgets/dialogs/qfileinfogatherer_p.h @@ -180,6 +180,10 @@ public Q_SLOTS: void setResolveSymlinks(bool enable); void setIconProvider(QFileIconProvider *provider); +private Q_SLOTS: + void driveAdded(); + void driveRemoved(); + private: void run() Q_DECL_OVERRIDE; // called by run(): diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 9d8e7c4b66..1a38f43d35 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -46,6 +46,7 @@ #include "qwizard.h" #include "qpaintengine.h" #include "qapplication.h" +#include <QtCore/QOperatingSystemVersion> #include <QtCore/QVariant> #include <QtCore/QDebug> #include <QtGui/QMouseEvent> @@ -715,7 +716,7 @@ int QVistaHelper::topOffset() if (vistaState() != VistaAero) return titleBarSize() + 3; static const int aeroOffset = - QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS7 ? + QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8 ? QStyleHelper::dpiScaled(4) : QStyleHelper::dpiScaled(13); return aeroOffset + titleBarSize(); } diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index 6e10d18e11..6a9036997c 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -2575,10 +2575,12 @@ void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> & for (const AnchorData *ad : visited) identifyNonFloatItems_helper(ad, &nonFloating); - QSet<QGraphicsLayoutItem *> allItems; - foreach (QGraphicsLayoutItem *item, items) - allItems.insert(item); - m_floatItems[orientation] = allItems - nonFloating; + QSet<QGraphicsLayoutItem *> floatItems; + for (QGraphicsLayoutItem *item : qAsConst(items)) { + if (!nonFloating.contains(item)) + floatItems.insert(item); + } + m_floatItems[orientation] = std::move(floatItems); } diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 0788e0287a..d19e5d9a9f 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -2335,13 +2335,7 @@ void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) bool QListModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) { doStaticLayout(info); - if (batchStartRow > max) { // stop items layout - flowPositions.resize(flowPositions.count()); - segmentPositions.resize(segmentPositions.count()); - segmentStartRows.resize(segmentStartRows.count()); - return true; // done - } - return false; // not done + return batchStartRow > max; // returning true stops items layout } QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) const diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 3bef773187..2a7859b056 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -91,12 +91,6 @@ extern Q_GUI_EXPORT bool qt_is_gui_used; extern QClipboard *qt_clipboard; #endif -#if defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN) -extern QSysInfo::WinVersion qt_winver; -#elif defined (Q_OS_MAC) -extern QSysInfo::MacVersion qt_macver; -#endif - typedef QHash<QByteArray, QFont> FontHash; FontHash *qt_app_fonts_hash(); diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 007ce20175..2d1de790c4 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -84,6 +84,7 @@ #include <qtoolbutton.h> #include <qtreeview.h> #include <qtableview.h> +#include <qoperatingsystemversion.h> #include <qwizard.h> #include <qdebug.h> #include <qlibrary.h> @@ -1312,7 +1313,7 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem bdi->adornment = kThemeAdornmentFocus; if (combo->activeSubControls & QStyle::SC_ComboBoxArrow) bdi->state = kThemeStatePressed; - else if (tds == kThemeStateInactive && QSysInfo::MacintoshVersion < QSysInfo::MV_10_10) + else if (tds == kThemeStateInactive && QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite) bdi->state = kThemeStateActive; else bdi->state = tds; @@ -1634,7 +1635,7 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti || slider->tickPosition == QSlider::TicksBothSides; tdi->bounds = qt_hirectForQRect(slider->rect); - if (isScrollbar || QSysInfo::MacintoshVersion < QSysInfo::MV_10_10) { + if (isScrollbar || QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite) { tdi->min = slider->minimum; tdi->max = slider->maximum; tdi->value = slider->sliderPosition; @@ -1946,7 +1947,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD const bool button = opt->type == QStyleOption::SO_Button; const bool viewItem = opt->type == QStyleOption::SO_ViewItem; const bool pressed = bdi->state == kThemeStatePressed; - const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10; + const bool usingYosemiteOrLater = QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite; if (button && pressed) { if (bdi->kind == kThemePushButton) { @@ -3581,7 +3582,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QWindow *window = w && w->window() ? w->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window); - const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10; + const bool usingYosemiteOrLater = QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite; switch (ce) { case CE_HeaderSection: if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { @@ -3973,7 +3974,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter bool hasIcon = !btn.icon.isNull(); bool hasText = !btn.text.isEmpty(); - if (!hasMenu && QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) { + if (!hasMenu && QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite) { if (tds == kThemeStatePressed || (tds == kThemeStateActive && ((btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton) @@ -4078,8 +4079,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QStyleOptionComboBox comboCopy = *cb; comboCopy.direction = Qt::LeftToRight; if (opt->state & QStyle::State_Small) - comboCopy.rect.translate(0, w ? 0 : (QSysInfo::macVersion() >= QSysInfo::MV_10_10 ? 0 : -2)); // Supports Qt Quick Controls - else if (QSysInfo::macVersion() == QSysInfo::MV_10_9) + comboCopy.rect.translate(0, w ? 0 : (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite ? 0 : -2)); // Supports Qt Quick Controls + else if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXMavericks + && QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite) comboCopy.rect.translate(0, 1); QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w); } @@ -5287,7 +5289,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window); - const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10; + const bool usingYosemiteOrLater = QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite; switch (cc) { case CC_Slider: case CC_ScrollBar: @@ -5931,7 +5933,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex drawToolbarButtonArrow(tb->rect, tds, cg); } if (tb->state & State_On) { - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) { + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite) { QWindow *window = 0; if (widget && widget->window()) window = widget->window()->windowHandle(); @@ -6295,7 +6297,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op switch (sc) { case SC_ComboBoxEditField:{ ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite) ret.setHeight(ret.height() - 1); break; } case SC_ComboBoxArrow:{ @@ -6754,7 +6756,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, case CT_ComboBox: { sz.rwidth() += 50; const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt); - if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_10 || (cb && !cb->editable)) + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite || (cb && !cb->editable)) sz.rheight() += 2; break; } diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index bf5aad0187..8c91e3a420 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -39,6 +39,7 @@ #include "qwindowsvistastyle_p.h" #include "qwindowsvistastyle_p_p.h" +#include <qoperatingsystemversion.h> #include <qscreen.h> #include <qwindow.h> #include <private/qstyleanimation_p.h> @@ -1752,7 +1753,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle theme.stateId = stateId; d->drawBackground(theme); - if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS8) { + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8) { const QRect gripperBounds = QWindowsXPStylePrivate::scrollBarGripperBounds(flags, widget, &theme); // Draw gripper if there is enough space if (!gripperBounds.isEmpty() && flags & State_Enabled) { diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index 224ffeb6e2..64daad87ae 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -59,6 +59,25 @@ QT_BEGIN_NAMESPACE +static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon) +{ + QStyle::StandardPixmap stdIcon = QStyle::SP_CustomBase; // silence gcc 4.9.0 about uninited variable + switch (icon) { + case QSystemTrayIcon::Information: + stdIcon = QStyle::SP_MessageBoxInformation; + break; + case QSystemTrayIcon::Warning: + stdIcon = QStyle::SP_MessageBoxWarning; + break; + case QSystemTrayIcon::Critical: + stdIcon = QStyle::SP_MessageBoxCritical; + break; + case QSystemTrayIcon::NoIcon: + return QIcon(); + } + return QApplication::style()->standardIcon(stdIcon); +} + /*! \class QSystemTrayIcon \brief The QSystemTrayIcon class provides an icon for an application in the system tray. @@ -382,11 +401,29 @@ bool QSystemTrayIcon::supportsMessages() \sa show(), supportsMessages() */ void QSystemTrayIcon::showMessage(const QString& title, const QString& msg, - QSystemTrayIcon::MessageIcon icon, int msecs) + QSystemTrayIcon::MessageIcon msgIcon, int msecs) { Q_D(QSystemTrayIcon); if (d->visible) - d->showMessage_sys(title, msg, icon, msecs); + d->showMessage_sys(title, msg, messageIcon2qIcon(msgIcon), msgIcon, msecs); +} + +/*! + \fn void QSystemTrayIcon::showMessage(const QString &title, const QString &message, const QIcon &icon, int millisecondsTimeoutHint) + + \overload showMessage() + + Shows a balloon message for the entry with the given \a title, \a message, + and custom icon \a icon for the time specified in \a millisecondsTimeoutHint. + + \since 5.9 +*/ +void QSystemTrayIcon::showMessage(const QString &title, const QString &msg, + const QIcon &icon, int msecs) +{ + Q_D(QSystemTrayIcon); + if (d->visible) + d->showMessage_sys(title, msg, icon, QSystemTrayIcon::NoIcon, msecs); } void QSystemTrayIconPrivate::_q_emitActivated(QPlatformSystemTrayIcon::ActivationReason reason) @@ -398,9 +435,9 @@ void QSystemTrayIconPrivate::_q_emitActivated(QPlatformSystemTrayIcon::Activatio ////////////////////////////////////////////////////////////////////// static QBalloonTip *theSolitaryBalloonTip = 0; -void QBalloonTip::showBalloon(QSystemTrayIcon::MessageIcon icon, const QString& title, - const QString& message, QSystemTrayIcon *trayIcon, - const QPoint& pos, int timeout, bool showArrow) +void QBalloonTip::showBalloon(const QIcon &icon, const QString &title, + const QString &message, QSystemTrayIcon *trayIcon, + const QPoint &pos, int timeout, bool showArrow) { hideBalloon(); if (message.isEmpty() && title.isEmpty()) @@ -434,8 +471,8 @@ bool QBalloonTip::isBalloonVisible() return theSolitaryBalloonTip; } -QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title, - const QString& message, QSystemTrayIcon *ti) +QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, + const QString &message, QSystemTrayIcon *ti) : QWidget(0, Qt::ToolTip), trayIcon(ti), timerId(-1) { setAttribute(Qt::WA_DeleteOnClose); @@ -482,26 +519,10 @@ QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title msgLabel->setFixedSize(limit, msgLabel->heightForWidth(limit)); } - QIcon si; - switch (icon) { - case QSystemTrayIcon::Warning: - si = style()->standardIcon(QStyle::SP_MessageBoxWarning); - break; - case QSystemTrayIcon::Critical: - si = style()->standardIcon(QStyle::SP_MessageBoxCritical); - break; - case QSystemTrayIcon::Information: - si = style()->standardIcon(QStyle::SP_MessageBoxInformation); - break; - case QSystemTrayIcon::NoIcon: - default: - break; - } - QGridLayout *layout = new QGridLayout; - if (!si.isNull()) { + if (!icon.isNull()) { QLabel *iconLabel = new QLabel; - iconLabel->setPixmap(si.pixmap(iconSize, iconSize)); + iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); iconLabel->setMargin(2); layout->addWidget(iconLabel, 0, 0); @@ -678,52 +699,6 @@ void QSystemTrayIconPrivate::remove_sys_qpa() qpa_sys->cleanup(); } -QRect QSystemTrayIconPrivate::geometry_sys_qpa() const -{ - return qpa_sys->geometry(); -} - -void QSystemTrayIconPrivate::updateIcon_sys_qpa() -{ - qpa_sys->updateIcon(icon); -} - -void QSystemTrayIconPrivate::updateMenu_sys_qpa() -{ - if (menu) { - addPlatformMenu(menu); - qpa_sys->updateMenu(menu->platformMenu()); - } -} - -void QSystemTrayIconPrivate::updateToolTip_sys_qpa() -{ - qpa_sys->updateToolTip(toolTip); -} - -void QSystemTrayIconPrivate::showMessage_sys_qpa(const QString &title, - const QString &message, - QSystemTrayIcon::MessageIcon icon, - int msecs) -{ - QIcon notificationIcon; - switch (icon) { - case QSystemTrayIcon::Information: - notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation); - break; - case QSystemTrayIcon::Warning: - notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning); - break; - case QSystemTrayIcon::Critical: - notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical); - break; - default: - break; - } - qpa_sys->showMessage(title, message, notificationIcon, - static_cast<QPlatformSystemTrayIcon::MessageIcon>(icon), msecs); -} - void QSystemTrayIconPrivate::addPlatformMenu(QMenu *menu) const { if (menu->platformMenu()) diff --git a/src/widgets/util/qsystemtrayicon.h b/src/widgets/util/qsystemtrayicon.h index fb238c92b0..918dd0478e 100644 --- a/src/widgets/util/qsystemtrayicon.h +++ b/src/widgets/util/qsystemtrayicon.h @@ -101,6 +101,7 @@ public Q_SLOTS: void setVisible(bool visible); inline void show() { setVisible(true); } inline void hide() { setVisible(false); } + void showMessage(const QString &title, const QString &msg, const QIcon &icon, int msecs = 10000); void showMessage(const QString &title, const QString &msg, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 10000); diff --git a/src/widgets/util/qsystemtrayicon_p.h b/src/widgets/util/qsystemtrayicon_p.h index 79e824f4b7..3f5cab40be 100644 --- a/src/widgets/util/qsystemtrayicon_p.h +++ b/src/widgets/util/qsystemtrayicon_p.h @@ -84,7 +84,8 @@ public: void updateToolTip_sys(); void updateMenu_sys(); QRect geometry_sys() const; - void showMessage_sys(const QString &title, const QString &msg, QSystemTrayIcon::MessageIcon icon, int secs); + void showMessage_sys(const QString &title, const QString &msg, const QIcon &icon, + QSystemTrayIcon::MessageIcon msgIcon, int msecs); static bool isSystemTrayAvailable_sys(); static bool supportsMessages_sys(); @@ -101,11 +102,7 @@ public: private: void install_sys_qpa(); void remove_sys_qpa(); - void updateIcon_sys_qpa(); - void updateToolTip_sys_qpa(); - void updateMenu_sys_qpa(); - QRect geometry_sys_qpa() const; - void showMessage_sys_qpa(const QString &title, const QString &msg, QSystemTrayIcon::MessageIcon icon, int secs); + void addPlatformMenu(QMenu *menu) const; }; @@ -113,16 +110,16 @@ class QBalloonTip : public QWidget { Q_OBJECT public: - static void showBalloon(QSystemTrayIcon::MessageIcon icon, const QString& title, - const QString& msg, QSystemTrayIcon *trayIcon, - const QPoint& pos, int timeout, bool showArrow = true); + static void showBalloon(const QIcon &icon, const QString &title, + const QString &msg, QSystemTrayIcon *trayIcon, + const QPoint &pos, int timeout, bool showArrow = true); static void hideBalloon(); static bool isBalloonVisible(); static void updateBalloonPosition(const QPoint& pos); private: - QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title, - const QString& msg, QSystemTrayIcon *trayIcon); + QBalloonTip(const QIcon &icon, const QString &title, + const QString &msg, QSystemTrayIcon *trayIcon); ~QBalloonTip(); void balloon(const QPoint&, int, bool); diff --git a/src/widgets/util/qsystemtrayicon_qpa.cpp b/src/widgets/util/qsystemtrayicon_qpa.cpp index 643f17a5fe..8399732a4a 100644 --- a/src/widgets/util/qsystemtrayicon_qpa.cpp +++ b/src/widgets/util/qsystemtrayicon_qpa.cpp @@ -76,7 +76,7 @@ void QSystemTrayIconPrivate::remove_sys() QRect QSystemTrayIconPrivate::geometry_sys() const { if (qpa_sys) - return geometry_sys_qpa(); + return qpa_sys->geometry(); else return QRect(); } @@ -84,19 +84,21 @@ QRect QSystemTrayIconPrivate::geometry_sys() const void QSystemTrayIconPrivate::updateIcon_sys() { if (qpa_sys) - updateIcon_sys_qpa(); + qpa_sys->updateIcon(icon); } void QSystemTrayIconPrivate::updateMenu_sys() { - if (qpa_sys) - updateMenu_sys_qpa(); + if (qpa_sys && menu) { + addPlatformMenu(menu); + qpa_sys->updateMenu(menu->platformMenu()); + } } void QSystemTrayIconPrivate::updateToolTip_sys() { if (qpa_sys) - updateToolTip_sys_qpa(); + qpa_sys->updateToolTip(toolTip); } bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() @@ -118,10 +120,11 @@ bool QSystemTrayIconPrivate::supportsMessages_sys() } void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, - QSystemTrayIcon::MessageIcon icon, int msecs) + const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon, int msecs) { if (qpa_sys) - showMessage_sys_qpa(title, message, icon, msecs); + qpa_sys->showMessage(title, message, icon, + static_cast<QPlatformSystemTrayIcon::MessageIcon>(msgIcon), msecs); } QT_END_NAMESPACE diff --git a/src/widgets/util/qsystemtrayicon_win.cpp b/src/widgets/util/qsystemtrayicon_win.cpp index 2da24e482b..638d2050fb 100644 --- a/src/widgets/util/qsystemtrayicon_win.cpp +++ b/src/widgets/util/qsystemtrayicon_win.cpp @@ -81,11 +81,14 @@ struct Q_NOTIFYICONIDENTIFIER { # define NIN_BALLOONTIMEOUT (WM_USER + 4) # define NIN_BALLOONUSERCLICK (WM_USER + 5) # define NIF_SHOWTIP 0x00000080 +# define NIIF_LARGE_ICON 0x00000020 # define NOTIFYICON_VERSION_4 4 #endif #define Q_MSGFLT_ALLOW 1 +Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); + typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation); typedef BOOL (WINAPI *PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag); typedef BOOL (WINAPI *PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void* pChangeFilterStruct); @@ -107,7 +110,7 @@ public: ~QSystemTrayIconSys(); bool trayMessage(DWORD msg); void setIconContents(NOTIFYICONDATA &data); - bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs); + bool showMessage(const QString &title, const QString &message, const QIcon &icon, uint uSecs); QRect findIconGeometry(UINT iconId); HICON createIcon(); bool winEvent(MSG *m, long *result); @@ -184,7 +187,7 @@ static inline HWND createTrayIconMessageWindow() QSystemTrayIconSys::QSystemTrayIconSys(HWND hwnd, QSystemTrayIcon *object) : m_hwnd(hwnd), hIcon(0), q(object) - , notifyIconSize(NOTIFYICONDATA_V2_SIZE), version(NOTIFYICON_VERSION) + , notifyIconSize(sizeof(NOTIFYICONDATA)), version(NOTIFYICON_VERSION_4) , ignoreNextMouseRelease(false) { @@ -237,11 +240,7 @@ void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) qStringToLimitedWCharArray(tip, tnd.szTip, sizeof(tnd.szTip)/sizeof(wchar_t)); } -#ifndef NIIF_LARGE_ICON -# define NIIF_LARGE_ICON 0x00000020 -#endif - -bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs) +bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, const QIcon &icon, uint uSecs) { NOTIFYICONDATA tnd; memset(&tnd, 0, notifyIconSize); @@ -249,23 +248,32 @@ bool QSystemTrayIconSys::showMessage(const QString &title, const QString &messag qStringToLimitedWCharArray(title, tnd.szInfoTitle, 64); tnd.uID = q_uNOTIFYICONID; - switch (type) { - case QSystemTrayIcon::Information: + tnd.dwInfoFlags = NIIF_USER; + + HICON *phIcon = &tnd.hIcon; + QSize size(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + if (version == NOTIFYICON_VERSION_4) { + const QSize largeIcon(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); + QSize more = icon.actualSize(largeIcon); + if (more.height() > (largeIcon.height() * 3/4) || more.width() > (largeIcon.width() * 3/4)) { + tnd.dwInfoFlags |= NIIF_LARGE_ICON; + size = largeIcon; + } + phIcon = &tnd.hBalloonIcon; + } + QPixmap pm = icon.pixmap(size); + if (pm.isNull()) { tnd.dwInfoFlags = NIIF_INFO; - break; - case QSystemTrayIcon::Warning: - tnd.dwInfoFlags = NIIF_WARNING; - break; - case QSystemTrayIcon::Critical: - tnd.dwInfoFlags = NIIF_ERROR; - break; - case QSystemTrayIcon::NoIcon: - tnd.dwInfoFlags = hIcon ? NIIF_USER : NIIF_NONE; - break; + } else { + if (pm.size() != size) { + qWarning("QSystemTrayIcon::showMessage: Wrong icon size (%dx%d), please add standard one: %dx%d", + pm.size().width(), pm.size().height(), size.width(), size.height()); + pm = pm.scaled(size, Qt::IgnoreAspectRatio); + } + *phIcon = qt_pixmapToWinHICON(pm); } - if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) - tnd.dwInfoFlags |= NIIF_LARGE_ICON; tnd.cbSize = notifyIconSize; + tnd.uVersion = version; tnd.hWnd = m_hwnd; tnd.uTimeout = uSecs; tnd.uFlags = NIF_INFO | NIF_SHOWTIP; @@ -296,8 +304,6 @@ bool QSystemTrayIconSys::trayMessage(DWORD msg) return success; } -Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); - HICON QSystemTrayIconSys::createIcon() { const HICON oldIcon = hIcon; @@ -509,7 +515,8 @@ QRect QSystemTrayIconSys::findIconGeometry(UINT iconId) void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &messageIn, - QSystemTrayIcon::MessageIcon type, + const QIcon &icon, + QSystemTrayIcon::MessageIcon, int timeOut) { if (!sys || !allowsMessages()) @@ -522,7 +529,7 @@ void QSystemTrayIconPrivate::showMessage_sys(const QString &title, if (message.isEmpty() && !title.isEmpty()) message.append(QLatin1Char(' ')); - sys->showMessage(title, message, type, uSecs); + sys->showMessage(title, message, icon, uSecs); } QRect QSystemTrayIconPrivate::geometry_sys() const diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp index ea0604b6ed..20ab0f6377 100644 --- a/src/widgets/util/qsystemtrayicon_x11.cpp +++ b/src/widgets/util/qsystemtrayicon_x11.cpp @@ -284,7 +284,7 @@ void QSystemTrayIconPrivate::install_sys() QRect QSystemTrayIconPrivate::geometry_sys() const { if (qpa_sys) - return geometry_sys_qpa(); + return qpa_sys->geometry(); if (!sys) return QRect(); return sys->globalGeometry(); @@ -307,7 +307,7 @@ void QSystemTrayIconPrivate::remove_sys() void QSystemTrayIconPrivate::updateIcon_sys() { if (qpa_sys) { - updateIcon_sys_qpa(); + qpa_sys->updateIcon(icon); return; } if (sys) @@ -316,14 +316,16 @@ void QSystemTrayIconPrivate::updateIcon_sys() void QSystemTrayIconPrivate::updateMenu_sys() { - if (qpa_sys) - updateMenu_sys_qpa(); + if (qpa_sys && menu) { + addPlatformMenu(menu); + qpa_sys->updateMenu(menu->platformMenu()); + } } void QSystemTrayIconPrivate::updateToolTip_sys() { if (qpa_sys) { - updateToolTip_sys_qpa(); + qpa_sys->updateToolTip(toolTip); return; } if (!sys) @@ -357,10 +359,11 @@ bool QSystemTrayIconPrivate::supportsMessages_sys() } void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, - QSystemTrayIcon::MessageIcon icon, int msecs) + const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon, int msecs) { if (qpa_sys) { - showMessage_sys_qpa(title, message, icon, msecs); + qpa_sys->showMessage(title, message, icon, + static_cast<QPlatformSystemTrayIcon::MessageIcon>(msgIcon), msecs); return; } if (!sys) diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 63fe09f77e..6b0c2fd621 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1492,6 +1492,7 @@ bool QMenuBar::eventFilter(QObject *object, QEvent *event) case QEvent::FocusIn: case QEvent::FocusOut: case QEvent::ActivationChange: + case QEvent::Shortcut: d->altPressed = false; qApp->removeEventFilter(this); break; |