Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
# Created by Mike Wille, SLSE, 2016-01-13
|
||||
#
|
||||
|
||||
|
||||
SET(LtsNoti_SRCS
|
||||
lts_notification.h
|
||||
lts_notification.cpp
|
||||
lts_notification_ctl.h
|
||||
lts_notification_ctl.cpp
|
||||
|
||||
lts_notification_export.h
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY(WS LtsNotification SHARED ${LtsNoti_SRCS})
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(LtsNotification
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsNotification
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(LtsNotification)
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
|
||||
|
||||
#include "lts_notification.h"
|
||||
#include "lts_notification_ctl.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
namespace LtsNotification
|
||||
{
|
||||
|
||||
LtsNotification::LtsNotification(LtsNotificationController *ctl)
|
||||
: QObject()
|
||||
, m_controller(ctl)
|
||||
{
|
||||
connect(ctl, &LtsNotificationController::destroyed,
|
||||
this, &LtsNotification::slotCtlDestroyed);
|
||||
}
|
||||
|
||||
|
||||
LtsNotification::~LtsNotification()
|
||||
{
|
||||
delete m_controller;
|
||||
}
|
||||
|
||||
|
||||
void LtsNotification::setIcon(const QIcon& icon)
|
||||
{
|
||||
m_controller->setIcon(icon);
|
||||
}
|
||||
|
||||
|
||||
void LtsNotification::setAction(const std::function<void(void)> &action)
|
||||
{
|
||||
m_controller->setAction(action);
|
||||
}
|
||||
|
||||
|
||||
void LtsNotification::setToolTip(const QString &toolTip)
|
||||
{
|
||||
m_controller->setToolTip(toolTip);
|
||||
}
|
||||
|
||||
|
||||
const QString &LtsNotification::tooltip() const
|
||||
{
|
||||
return m_controller->tooltip();
|
||||
}
|
||||
|
||||
|
||||
void LtsNotification::setCount(const int count)
|
||||
{
|
||||
m_controller->setCount(count);
|
||||
}
|
||||
|
||||
void LtsNotification::setEnabled(bool enable)
|
||||
{
|
||||
m_controller->setEnabled(enable);
|
||||
}
|
||||
|
||||
void LtsNotification::setBackground(const int r, const int g, const int b)
|
||||
{
|
||||
m_controller->setBackground(r, g, b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LtsNotification::slotCtlDestroyed(QObject *obj)
|
||||
{
|
||||
(void)obj;
|
||||
|
||||
m_controller = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_notification_export.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsNotification
|
||||
{
|
||||
class LtsNotificationController;
|
||||
|
||||
|
||||
|
||||
class LTSNOTIFICATION_EXPORT LtsNotification : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit LtsNotification(LtsNotificationController *ctl);
|
||||
~LtsNotification();
|
||||
|
||||
void setIcon(const QIcon &icon);
|
||||
void setAction(const std::function<void(void)> &action);
|
||||
void setToolTip(const QString &toolTip);
|
||||
void setCount(const int count);
|
||||
void setEnabled(bool enable);
|
||||
void setBackground(const int r, const int g, const int b);
|
||||
|
||||
const QString &tooltip() const;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
LtsNotificationController *m_controller;
|
||||
|
||||
|
||||
|
||||
private slots:
|
||||
void slotCtlDestroyed(QObject *obj);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
|
||||
|
||||
#include "lts_notification_ctl.h"
|
||||
|
||||
#include <QToolButton>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsNotification
|
||||
{
|
||||
|
||||
LtsNotificationController::LtsNotificationController(const QString &identifier)
|
||||
: QObject()
|
||||
, m_count(0)
|
||||
, m_identifier(QStringLiteral("LtsNotification%1").arg(identifier))
|
||||
{}
|
||||
|
||||
|
||||
LtsNotificationController::~LtsNotificationController()
|
||||
{
|
||||
qDeleteAll(m_notiList);
|
||||
}
|
||||
|
||||
|
||||
void LtsNotificationController::setIcon(const QIcon& icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
|
||||
setAllIcons();
|
||||
}
|
||||
|
||||
|
||||
void LtsNotificationController::setCount(const int count)
|
||||
{
|
||||
m_count = count;
|
||||
|
||||
setAllIcons();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LtsNotificationController::setBackground(const int r, const int g, const int b)
|
||||
{
|
||||
|
||||
for (QToolButton *tb : qAsConst(m_notiList))
|
||||
{
|
||||
|
||||
QString stylesheet;
|
||||
|
||||
if(r == -1 && g == -1 && b == -1)
|
||||
stylesheet = QStringLiteral("");
|
||||
else
|
||||
stylesheet = QStringLiteral("QToolButton {background-color: rgb(") +
|
||||
QString::number(r) + QStringLiteral(",") +
|
||||
QString::number(g) + QStringLiteral(",") +
|
||||
QString::number(b) + QStringLiteral(");}");
|
||||
|
||||
tb->setStyleSheet(stylesheet);
|
||||
}
|
||||
}
|
||||
|
||||
void LtsNotificationController::setEnabled(bool enable)
|
||||
{
|
||||
m_enable = enable;
|
||||
|
||||
setAllIcons();
|
||||
}
|
||||
|
||||
|
||||
void LtsNotificationController::setAction(const std::function<void(void)> &action)
|
||||
{
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
|
||||
void LtsNotificationController::setToolTip(const QString &toolTip)
|
||||
{
|
||||
m_toolTip = toolTip;
|
||||
|
||||
for (QToolButton *tb : qAsConst(m_notiList))
|
||||
{
|
||||
tb->setToolTip(toolTip);
|
||||
tb->setIconSize(QSize(30,30));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LtsNotificationController::setAllIcons()
|
||||
{
|
||||
if (m_icon.isNull())
|
||||
return;
|
||||
|
||||
|
||||
QIcon icon = modifyIcon(m_icon);
|
||||
|
||||
for (QToolButton *tb : qAsConst(m_notiList))
|
||||
{
|
||||
tb->setIcon(icon);
|
||||
tb->setIconSize(QSize(30,30));
|
||||
tb->setEnabled(m_enable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define SIZE 40
|
||||
|
||||
QIcon LtsNotificationController::modifyIcon(const QIcon &icon)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (m_count < 1)
|
||||
return icon;
|
||||
|
||||
QPixmap iconImage(icon.pixmap(SIZE * 8 / 10, SIZE * 8 / 10));
|
||||
QPainter painter(&iconImage);
|
||||
|
||||
painter.save();
|
||||
painter.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform);
|
||||
|
||||
QFont f;
|
||||
f.setFamily(QStringLiteral("Monospace"));
|
||||
f.setPointSize(16);
|
||||
f.setBold(true);
|
||||
painter.setFont(f);
|
||||
|
||||
QColor color(Qt::red);
|
||||
painter.setBrush(color);
|
||||
painter.setPen(QPen(color, 3.1));
|
||||
painter.drawText(QRect(0, 0, 30, 30), QString::number(m_count));
|
||||
painter.restore();
|
||||
|
||||
return iconImage;
|
||||
}
|
||||
|
||||
|
||||
QToolButton *LtsNotificationController::createWidget()
|
||||
{
|
||||
QToolButton *b = new QToolButton();
|
||||
b->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
b->setObjectName(m_identifier);
|
||||
|
||||
|
||||
|
||||
b->setMinimumSize(SIZE, SIZE);
|
||||
b->setMaximumSize(SIZE, SIZE);
|
||||
|
||||
connect(b, &QToolButton::destroyed,
|
||||
this, &LtsNotificationController::slotNotiWidgetDestroyed);
|
||||
connect(b, &QToolButton::clicked,
|
||||
this, [this](){ if (m_action) m_action(); });
|
||||
|
||||
if (!m_icon.isNull())
|
||||
b->setIcon(modifyIcon(m_icon));
|
||||
|
||||
b->setToolTip(m_toolTip);
|
||||
|
||||
m_notiList.append(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
void LtsNotificationController::slotNotiWidgetDestroyed(QObject *obj)
|
||||
{
|
||||
m_notiList.removeAll(static_cast<QToolButton*>(obj));
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_notification_export.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QIcon>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
|
||||
class QToolButton;
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsNotification
|
||||
{
|
||||
class LtsNotificationWidget;
|
||||
|
||||
|
||||
|
||||
class LTSNOTIFICATION_EXPORT LtsNotificationController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LtsNotificationController(const QString &identifier);
|
||||
~LtsNotificationController();
|
||||
|
||||
QToolButton *createWidget();
|
||||
|
||||
void setIcon(const QIcon& icon);
|
||||
void setAction(const std::function<void(void)> &action);
|
||||
void setToolTip(const QString &toolTip);
|
||||
void setCount(const int count);
|
||||
void setBackground(const int r, const int g, const int b);
|
||||
const QString &identifier() const { return m_identifier; }
|
||||
const QString &tooltip() const { return m_toolTip; }
|
||||
|
||||
void setEnabled(bool enable);
|
||||
|
||||
private:
|
||||
QList<QToolButton *> m_notiList;
|
||||
|
||||
|
||||
QIcon m_icon;
|
||||
std::function<void(void)> m_action;
|
||||
QString m_toolTip;
|
||||
int m_count;
|
||||
bool m_enable{true};
|
||||
QString m_identifier;
|
||||
|
||||
void setAllIcons();
|
||||
QIcon modifyIcon(const QIcon &icon);
|
||||
|
||||
private slots:
|
||||
void slotNotiWidgetDestroyed(QObject *obj);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef LTSNOTIFICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LTSNOTIFICATION_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_LTSNOTIFICATION_LIB)
|
||||
# define LTSNOTIFICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LTSNOTIFICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user