Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+29
View File
@@ -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
View File
@@ -0,0 +1,92 @@
// TODO: hdr
#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::setToolTip()
//{
//}
//void LtsNotification::setVisible()
//{
//}
//void LtsNotification::setMenu()
//{
//}
void LtsNotification::slotCtlDestroyed(QObject *obj)
{
(void)obj;
m_controller = nullptr;
}
} // namespace LtsWidgets
+59
View File
@@ -0,0 +1,59 @@
// TODO: hdr
#pragma once
#include "lts_notification_export.h"
#include <QList>
#include <QObject>
#include <memory>
#include <functional>
namespace LtsSession
{
class LtsSession;
}
namespace LtsNotification
{
class LtsNotificationController;
/**
* @brief The LtsNotification class provides a Notification Icon which is automatically added, when created, to (and deleted from) the BaseLayout.
* >>> !! Do not use by yourself! Call 'createNotification' from LtsSession to create a new LtsNotification !! <<<
*/
class LTSNOTIFICATION_EXPORT LtsNotification : public QObject
{
Q_OBJECT
public:
// Attn: LtsNotification takes ownership of ctl!
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;
// TODO: add these
// void setVisible();
// void setMenu();
private:
LtsNotificationController *m_controller; // TODO: connect to destroyed to set this to nullptr ! but needed?
//QList<LtsNotificationIconWidget *> m_notiList; // all notis on all blws of one session
//LtsSession::LtsSession *m_session; // the selected session FIXME: ShdPtr ?! but there can't be a LNI without a Session, so I think this is okay
private slots:
void slotCtlDestroyed(QObject *obj);
};
} // namespace LtsWidgets
+180
View File
@@ -0,0 +1,180 @@
// TODO: hdr
#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();
}
/*!
* \brief LtsNotificationController::setBackground
* \param r red
* \param g green
* \param b yellow
* \author Niklas Schmidt
* \details If all params(r,g,b) are -1, than reset Stylesheet = non stylesheet
*/
//TODO: Extra function resetBackground instead of -1 params
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;
// prepare new Icon (add count), then set to all ToolButtons
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) // TODO: automatic advanced scope ??!
{
/* FIXME: it is impossible to check if QIcon is valid, so calling modifyIcon will start
* a painter on an invalid QPixmap (hence the QIcon) which produces error messages in
* the log file & stdout.
*/
if (m_count < 1) // do not draw '0' on it..
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)); // TODO: working version of this: , QTextOption(Qt::AlignRight | Qt::AlignBottom));
painter.restore();
return iconImage;
}
QToolButton *LtsNotificationController::createWidget()
{
QToolButton *b = new QToolButton();
b->setToolButtonStyle(Qt::ToolButtonIconOnly);
b->setObjectName(m_identifier);
//qWarning() << "object name" << b->objectName() << "==" << m_identifier;
// FIXME: variable sizes !! LtsDragIcon ?
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(); }); // TODO: FIXME: BAD, BAD HACK?!
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)); // no qobject_cast for destroyed objects
}
} // namespace LtsNotification
+70
View File
@@ -0,0 +1,70 @@
// TODO: hdr
#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;
/**
* @brief The LtsNotificationController class is the Controller for exactly one LtsNotification and creates / keeps track
* on all Notification Icons of all BaseLayouts in one Session.
* >>> !! Do not use by yourself! Call 'createNotification' from LtsSession to create a new LtsNotification !! <<<
*/
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; // all notis on all blws of one session
//LtsSession::LtsSession *m_session; // the selected session FIXME: ShdPtr ?! but there can't be a LNI without a Session, so I think this is okay
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);
};
} // namespace LtsWidgets
+24
View File
@@ -0,0 +1,24 @@
/**
* Export definitions
* $Id$
* $HeadURL$
* $Author$
* Created by Mike Wille, SLSE, 2017-01-13
*/
#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