Commit 28be81ec authored by Carsten Fuhrmann's avatar Carsten Fuhrmann

cosmetic

parent 84cb4ff6
......@@ -24,6 +24,7 @@ OverlayController::OverlayController() : QObject()
m_timer->setInterval(5000);
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), this, SLOT(hideChat()));
}
OverlayController::~OverlayController()
......@@ -41,7 +42,7 @@ OverlayController::~OverlayController()
delete m_timer;
}
void OverlayController::deleteChatLine(QLabel * line)
void OverlayController::deleteChatLine(QWidget * line)
{
//TODO: delete the given line instead of the last
delete m_msgLines.last();
......@@ -65,24 +66,33 @@ void OverlayController::addChatLine(QString message)
showChat();
// generate new chatline
QLabel* newChatLine = new QLabel;
QWidget* w = new QWidget;
QLabel* newChatLine = new QLabel(w);
w->setAttribute(Qt::WA_TranslucentBackground);
w->setAttribute(Qt::WA_ShowWithoutActivating);
w->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowTransparentForInput);
newChatLine->setText(message);
newChatLine->setStyleSheet("padding:2px;border-radius:5px;border-style:solid;border-width:1px;border-color:rgb(100,100,100);font:bold; font-size:20px;background-color:rgba(50,50,50,150); color:rgb(255,255,255);");
newChatLine->adjustSize();
newChatLine->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen);
newChatLine->setAttribute(Qt::WA_TranslucentBackground);
newChatLine->setAttribute(Qt::WA_ShowWithoutActivating);
newChatLine->setGeometry(BOARDEROFFSET, BOARDEROFFSET, newChatLine->geometry().width(), LINEHEIGHT);
newChatLine->setAlignment(Qt::AlignTop | Qt::AlignLeft);
newChatLine->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::WindowTransparentForInput);
newChatLine->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
w->adjustSize();
w->setGeometry(BORDEROFFSET, BORDEROFFSET, w->size().width(), w->size().height() + SPACING);
newChatLine->show();
w->show();
// move old messages down
for (auto &it : m_msgLines)
it->setGeometry(it->geometry().x(), it->geometry().y() + LINEHEIGHT, it->geometry().width(), it->geometry().height());
it->setGeometry(it->geometry().x(), it->geometry().y() + w->size().height(), it->geometry().width(), it->geometry().height());
// inseart new chat line
m_msgLines.push_front(newChatLine);
m_msgLines.push_front(w);
// limit the number of lines
if (m_msgLines.size() > MAXLINES)
......@@ -95,24 +105,32 @@ void OverlayController::addChatLine(QString message)
void OverlayController::addSpeaker(QString name)
{
int labelWidth = 0;
QLabel* newSpeaker = new QLabel;
QWidget* w = new QWidget;
QLabel* newSpeaker = new QLabel(w);
w->setAttribute(Qt::WA_TranslucentBackground);
w->setAttribute(Qt::WA_ShowWithoutActivating);
w->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowTransparentForInput);
w->setObjectName(name);
newSpeaker->setText(name);
newSpeaker->setStyleSheet("padding:2px;border-radius:5px;border-style:solid;border-width:1px;border-color:rgb(100,100,100);font:bold; font-size:20px;background-color:rgba(50,50,50,150); color:rgb(255,255,255);");
newSpeaker->adjustSize();
newSpeaker->resize(newSpeaker->size().width() + SPACING, LINEHEIGHT);
labelWidth = newSpeaker->geometry().width();
newSpeaker->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen);
newSpeaker->setAttribute(Qt::WA_TranslucentBackground);
newSpeaker->setAttribute(Qt::WA_ShowWithoutActivating);
newSpeaker->setGeometry(BOARDEROFFSET + m_speakerOffset, m_screenHeight - BOARDEROFFSET - LINEHEIGHT, labelWidth, LINEHEIGHT);
newSpeaker->setAlignment(Qt::AlignTop | Qt::AlignCenter);
//newSpeaker->setStyleSheet("border-style: none; padding: 2px; background-color: rgba(255, 255, 255, 10);");
newSpeaker->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::WindowTransparentForInput);
newSpeaker->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
w->adjustSize();
w->setGeometry(BORDEROFFSET + m_speakerOffset, m_screenHeight - BORDEROFFSET - w->size().height(), w->size().width() + SPACING, w->size().height());
labelWidth = w->geometry().width();
newSpeaker->show();
w->show();
m_speakerOffset += labelWidth;
m_speakers.push_back(newSpeaker);
m_speakers.push_back(w);
}
void OverlayController::removeSpeaker(QString name)
......@@ -123,11 +141,11 @@ void OverlayController::removeSpeaker(QString name)
// move all speaker to the left side and find the one to delete
for (int i = 0; i < m_speakers.size(); i++)
{
QLabel* it = m_speakers.at(i);
QWidget* it = m_speakers.at(i);
it->setGeometry(it->geometry().x() - labelWidth, it->geometry().y(), it->geometry().width(), it->geometry().height());
if (it->text() == name)
if (it->objectName() == name)
{
labelWidth = it->geometry().width();
m_speakerOffset -= labelWidth;
......
......@@ -3,13 +3,14 @@
#include "qttsoverlay_global.h"
#include <QObject>
#include <QString>
#include <QLabel>
#include <QWidget>
#include <QVector>
#include <QTimer>
#include <QLabel>
#define MAXLINES 5
#define BOARDEROFFSET 5
#define LINEHEIGHT 15
#define BORDEROFFSET 5
#define SPACING 10
......@@ -27,13 +28,13 @@ private:
int m_speakerOffset;
QLabel* m_debugWindow;
QVector<QLabel*> m_speakers;
QVector<QLabel*> m_msgLines;
QVector<QWidget*> m_speakers;
QVector<QWidget*> m_msgLines;
QTimer* m_timer;
private:
void deleteChatLine(QLabel* line);
void deleteChatLine(QWidget* line);
void showChat();
private slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment