File indexing completed on 2024-06-23 04:42:08
0001 /* 0002 SnoreNotify is a Notification Framework based on Qt 0003 Copyright (C) 2014-2015 Hannah von Reth <vonreth@kde.org> 0004 0005 SnoreNotify is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 SnoreNotify is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public License 0016 along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef NOTIFYWIDGET_H 0020 #define NOTIFYWIDGET_H 0021 0022 #include <QSharedMemory> 0023 #include "libsnore/notification/notification.h" 0024 0025 #include <QtQuick/QtQuick> 0026 0027 namespace SnorePlugin { 0028 class Snore; 0029 } 0030 0031 typedef struct { 0032 bool free; 0033 int date; 0034 int timeout; 0035 0036 } SHARED_MEM_TYPE; 0037 0038 inline int SHARED_MEM_TYPE_REV() 0039 { 0040 return 2; 0041 } 0042 0043 class NotifyWidget : public QObject 0044 { 0045 Q_OBJECT 0046 Q_PROPERTY(int id READ id) 0047 Q_PROPERTY(Qt::Corner position MEMBER m_corner NOTIFY positionChanged) 0048 Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged) 0049 Q_PROPERTY(QColor textColor MEMBER m_textColor NOTIFY textColorChanged) 0050 Q_PROPERTY(QString title MEMBER m_title NOTIFY titleChanged) 0051 Q_PROPERTY(QString body MEMBER m_body NOTIFY bodyChanged) 0052 Q_PROPERTY(int imageSize MEMBER m_imageSize) 0053 Q_PROPERTY(int appIconSize MEMBER m_appIconSize) 0054 Q_PROPERTY(QUrl image MEMBER m_image NOTIFY imageChanged) 0055 Q_PROPERTY(QUrl appIcon MEMBER m_appIcon NOTIFY appIconChanged) 0056 Q_PROPERTY(QString fontFamily MEMBER m_fontFamily NOTIFY fontFamilyChanged) 0057 0058 public: 0059 explicit NotifyWidget(int id, const SnorePlugin::Snore *parent); 0060 ~NotifyWidget(); 0061 0062 void display(const Snore::Notification ¬ification); 0063 0064 bool acquire(int timeout); 0065 bool release(); 0066 0067 Snore::Notification ¬ification(); 0068 0069 int id() const; 0070 0071 Q_SIGNALS: 0072 void invoked(); 0073 void dismissed(); 0074 0075 void positionChanged(); 0076 0077 void textColorChanged(); 0078 void colorChanged(); 0079 void titleChanged(); 0080 void bodyChanged(); 0081 0082 void imageChanged(); 0083 void appIconChanged(); 0084 0085 void fontFamilyChanged(); 0086 0087 private: 0088 void syncSettings(); 0089 QColor computeBackgrondColor(const QImage &img); 0090 QColor compueTextColor(const QColor &backgroundColor); 0091 0092 void updateCornerValues(Qt::Corner c); 0093 0094 Snore::Notification m_notification; 0095 int m_id; 0096 const SnorePlugin::Snore *m_parent; 0097 QSharedMemory m_mem; 0098 bool m_ready; 0099 0100 Qt::Corner m_corner = Qt::TopLeftCorner; 0101 0102 int m_imageSize; 0103 int m_appIconSize; 0104 0105 QColor m_color; 0106 QColor m_textColor; 0107 0108 QString m_title; 0109 QString m_body; 0110 0111 QString m_fontFamily; 0112 0113 bool m_initialized = false; 0114 0115 QUrl m_appIcon; 0116 QUrl m_image; 0117 0118 QQuickWindow *m_window; 0119 0120 }; 0121 0122 #endif // NOTIFYWIDGET_H