Review Request 126369: [OS X] adaptation(s) to platform limitations (WIP)

René J.V. Bertin rjvbertin at gmail.com
Thu Dec 17 13:37:49 UTC 2015


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/126369/#review89652
-----------------------------------------------------------


Well, it isn't exactly easy, but I remembered that KMail can badge the system tray icon with the number of read messages. Adapted to KNotifications (no extra dependencies except for Qt5::MacExtras for the -optional?- app icon badging) that gives 

``` C++
void KStatusNotifierItemPrivate::syncLegacySystemTrayIcon()
{
    if (status == KStatusNotifierItem::NeedsAttention) {
#ifdef Q_OS_OSX
        QtMac::setBadgeLabelText(QStringLiteral("!"));
        if (attentionIconName.isNull() && attentionIcon.isNull()) {
            // code adapted from kmail's KMSystemTray::updateCount()
            int overlaySize = 22;
            QIcon attnIcon = qApp->windowIcon();
            if (!attnIcon.availableSizes().isEmpty()) {
                overlaySize = attnIcon.availableSizes().at(0).width();
            }
            QFont labelFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
            labelFont.setBold(true);
            QFontMetrics qfm(labelFont);
            float attnHeight = overlaySize * 0.667;
            if (qfm.height() > attnHeight) {
                float labelSize = attnHeight;
                labelFont.setPointSizeF(labelSize);
            }
            // Paint the label in a pixmap
            QPixmap overlayPixmap(overlaySize, overlaySize);
            overlayPixmap.fill(Qt::transparent);

            QPainter p(&overlayPixmap);
            p.setFont(labelFont);
            p.setBrush(Qt::NoBrush);
            // this sort of badge/label is red on OS X
            p.setPen(QColor(224,0,0));
            p.setOpacity(1.0);
            // use U+2022, the Unicode bullet
            p.drawText(overlayPixmap.rect(), Qt::AlignRight|Qt::AlignTop, QStringLiteral("•"));
            p.end();

            QPixmap iconPixmap = attnIcon.pixmap(overlaySize, overlaySize);
            QPainter pp(&iconPixmap);
            pp.drawPixmap(0, 0, overlayPixmap);
            pp.end();
            systemTrayIcon->setIcon(iconPixmap);
        } else
#endif
        {
            if (!movieName.isNull()) {
                if (!movie) {
                    movie = new QMovie(movieName);
                }
                systemTrayIcon->setMovie(movie);
            } else if (!attentionIconName.isNull()) {
                systemTrayIcon->setIcon(QIcon::fromTheme(attentionIconName));
            } else {
                systemTrayIcon->setIcon(attentionIcon);
            }
        }
    } else {
        if (!iconName.isNull()) {
            systemTrayIcon->setIcon(QIcon::fromTheme(iconName));
        } else {
            systemTrayIcon->setIcon(icon);
        }
#ifdef Q_OS_OSX
        QtMac::setBadgeLabelText(QString());
#endif
    }

    systemTrayIcon->setToolTip(toolTipTitle);
}
```

- René J.V. Bertin


On Dec. 17, 2015, 12:40 p.m., René J.V. Bertin wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/126369/
> -----------------------------------------------------------
> 
> (Updated Dec. 17, 2015, 12:40 p.m.)
> 
> 
> Review request for KDE Software on Mac OS X and KDE Frameworks.
> 
> 
> Repository: knotifications
> 
> 
> Description
> -------
> 
> OS X has a number of limitations in features used by KNotifications, notably concerning the status notifier item (aka system tray icon).
> 
> This RR will likely evolve to address multiple limitations (at least also the NeedsAttention state); at the moment it only proposes an emulation of `QMenu::addSection`.
> 
> `QMenu::addSection` works by adding a QAction with a "texted separator" at the insertion location. Texted separators do not exist in menu items in the OS X "global" menubar (they become regular separators), and Qt will not provide a platform-specific implementation. Loss of the section title text is maybe not always an issue, but I think it is in the system tray menu. I therefore propose to emulate `QMenu::addSection` by replacing the texted separator with an inactive (disabled) menu item that shows the text, followed by a standard separator. Menus in the notification area are much less subject to interface guidelines, so the presence of an item icon is acceptable and IMO useful for the `titleAction`.
> 
> Testing the NeedsAttention state with the tests/kstatusnotifieritemtest application leads to disappearance of the menubar icon, i.e. the access to the notifier menu becomes invisible rather than blinking (which is what I get on Linux using the same packaging). Adding a few qDebug statements shows that the `attentionIcon` is empty.
> I'd appreciate a crash course how this feature is supposed to work, so I can see if an OS X implementation might be feasible.
> 
> 
> Diffs
> -----
> 
>   src/kstatusnotifieritem.cpp f9bf460 
> 
> Diff: https://git.reviewboard.kde.org/r/126369/diff/
> 
> 
> Testing
> -------
> 
> On OS X 10.9.5 with Qt 5.5.1 and frameworks 5.17.0 .
> 
> 
> File Attachments
> ----------------
> 
> the systray icon & menu created by kstatusnotifieritemtest . This application has no icon to show.
>   https://git.reviewboard.kde.org/media/uploaded/files/2015/12/16/286037ae-07b3-454a-a226-1748854493a1__kstatusnotifieritemtest-systray.png
> The systray icon and menu created by the KDE4 kwalletmanager (code has an equivalent patch)
>   https://git.reviewboard.kde.org/media/uploaded/files/2015/12/16/4fc9d4e4-1537-478c-9196-94cbc17b6b7c__kwalletmanager-systray.png
> An Apple systray icon+menu that shows icons (which cannot be hidden)
>   https://git.reviewboard.kde.org/media/uploaded/files/2015/12/16/fc48a963-2e18-4396-bd38-062d41688118__Apple-systray-menu-with-icons.png
> kstatusnotifieritemtest with added appIcon
>   https://git.reviewboard.kde.org/media/uploaded/files/2015/12/17/e896e90d-f0a8-43f7-9199-847572832df7__kstatusnotifieritemtest-with-appIcon.png
> 
> 
> Thanks,
> 
> René J.V. Bertin
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20151217/e326e432/attachment.html>


More information about the Kde-frameworks-devel mailing list