summary refs log tree commit diff
path: root/src/TrayIcon.h
blob: f20096123cf115664858fb3676fba2d6d6964e8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QIcon>
#include <QIconEngine>
#include <QRect>
#include <QSystemTrayIcon>

class QAction;
class QPainter;

class MsgCountComposedIcon final : public QIconEngine
{
public:
    MsgCountComposedIcon(const QString &filename);

    void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
    QIconEngine *clone() const override;
    QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
      const
#endif
      override;
    QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;

    int msgCount = 0;

private:
    const int BubbleDiameter = 17;

    QIcon icon_;
};

class TrayIcon final : public QSystemTrayIcon
{
    Q_OBJECT
public:
    TrayIcon(const QString &filename, QWindow *parent);

public slots:
    void setUnreadCount(int count);

private:
    QAction *viewAction_;
    QAction *quitAction_;

#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
    MsgCountComposedIcon *icon_;
#endif
};