File indexing completed on 2024-03-24 17:23:11
0001 // SPDX-License-Identifier: GPL-3.0-or-later 0002 /* 0003 Copyright 2017 - 2021 Martin Koller, kollix@aon.at 0004 0005 This file is part of liquidshell. 0006 0007 liquidshell is free software: you can redistribute it and/or modify 0008 it under the terms of the GNU General Public License as published by 0009 the Free Software Foundation, either version 3 of the License, or 0010 (at your option) any later version. 0011 0012 liquidshell is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with liquidshell. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include <SysTrayItem.hxx> 0022 #include <DesktopWidget.hxx> 0023 0024 #include <QMouseEvent> 0025 #include <QApplication> 0026 #include <QScreen> 0027 #include <QIcon> 0028 0029 #include <KWindowSystem> 0030 #include <KIconLoader> 0031 0032 //-------------------------------------------------------------------------------- 0033 0034 SysTrayItem::SysTrayItem(QWidget *parent, const QString &icon) 0035 : QLabel(parent), iconName(icon) 0036 { 0037 setFixedSize(QSize(22, 22)); 0038 0039 if ( !iconName.isEmpty() ) 0040 { 0041 setPixmap(QIcon::fromTheme(iconName).pixmap(size())); 0042 0043 connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, 0044 [this]() { setPixmap(QIcon::fromTheme(iconName).pixmap(size())); }); 0045 } 0046 } 0047 0048 //-------------------------------------------------------------------------------- 0049 0050 void SysTrayItem::mousePressEvent(QMouseEvent *event) 0051 { 0052 if ( event->button() != Qt::LeftButton ) 0053 return; 0054 0055 toggleDetailsList(); 0056 } 0057 0058 //-------------------------------------------------------------------------------- 0059 0060 void SysTrayItem::showDetailsList() 0061 { 0062 QWidget *detailsList = getDetailsList(); 0063 0064 if ( !detailsList ) 0065 return; 0066 0067 QPoint point = mapToGlobal(pos()); 0068 QRect screen = DesktopWidget::availableGeometry(); 0069 QSize size = detailsList->windowHandle() ? detailsList->size() : detailsList->sizeHint(); 0070 point.setX(std::min(point.x(), screen.x() + screen.width() - size.width())); 0071 point.setY(screen.bottom() - size.height()); 0072 detailsList->move(point); 0073 detailsList->show(); 0074 KWindowSystem::raiseWindow(detailsList->winId()); 0075 } 0076 0077 //-------------------------------------------------------------------------------- 0078 0079 void SysTrayItem::toggleDetailsList() 0080 { 0081 QWidget *detailsList = getDetailsList(); 0082 0083 if ( !detailsList ) 0084 return; 0085 0086 if ( detailsList->isVisible() ) 0087 detailsList->close(); 0088 else 0089 showDetailsList(); 0090 } 0091 0092 //--------------------------------------------------------------------------------