-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
SysTrayItem.cxx
79 lines (58 loc) · 1.94 KB
/
SysTrayItem.cxx
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <kollix@aon.at>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <SysTrayItem.hxx>
#include <DesktopWidget.hxx>
#include <QMouseEvent>
#include <QApplication>
#include <QScreen>
#include <QIcon>
#include <KIconLoader>
//--------------------------------------------------------------------------------
SysTrayItem::SysTrayItem(QWidget *parent, const QString &icon)
: QLabel(parent), iconName(icon)
{
setFixedSize(QSize(22, 22));
if ( !iconName.isEmpty() )
{
setPixmap(QIcon::fromTheme(iconName).pixmap(size()));
connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this,
[this]() { setPixmap(QIcon::fromTheme(iconName).pixmap(size())); });
}
}
//--------------------------------------------------------------------------------
void SysTrayItem::mousePressEvent(QMouseEvent *event)
{
if ( event->button() != Qt::LeftButton )
return;
toggleDetailsList();
}
//--------------------------------------------------------------------------------
void SysTrayItem::showDetailsList()
{
QWidget *detailsList = getDetailsList();
if ( !detailsList )
return;
QPoint point = mapToGlobal(pos());
QRect screen = DesktopWidget::availableGeometry();
QSize size = detailsList->windowHandle() ? detailsList->size() : detailsList->sizeHint();
point.setX(std::min(point.x(), screen.x() + screen.width() - size.width()));
point.setY(screen.bottom() - size.height());
detailsList->move(point);
detailsList->show();
detailsList->raise();
}
//--------------------------------------------------------------------------------
void SysTrayItem::toggleDetailsList()
{
QWidget *detailsList = getDetailsList();
if ( !detailsList )
return;
if ( detailsList->isVisible() )
detailsList->close();
else
showDetailsList();
}
//--------------------------------------------------------------------------------