mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
NotificationIcon
This commit is contained in:
parent
b5b6ae99c0
commit
bb29536df1
6
qtox.pro
6
qtox.pro
|
@ -191,7 +191,8 @@ HEADERS += src/widget/form/addfriendform.h \
|
|||
src/chatlog/content/image.h \
|
||||
src/chatlog/customtextdocument.h \
|
||||
src/widget/form/settings/advancedform.h \
|
||||
src/audio.h
|
||||
src/audio.h \
|
||||
src/chatlog/content/notificationicon.h
|
||||
|
||||
SOURCES += \
|
||||
src/widget/form/addfriendform.cpp \
|
||||
|
@ -260,7 +261,8 @@ SOURCES += \
|
|||
src/chatlog/content/image.cpp \
|
||||
src/chatlog/customtextdocument.cpp\
|
||||
src/widget/form/settings/advancedform.cpp \
|
||||
src/audio.cpp
|
||||
src/audio.cpp \
|
||||
src/chatlog/content/notificationicon.cpp
|
||||
|
||||
contains(DEFINES, QTOX_FILTER_AUDIO) {
|
||||
HEADERS += src/audiofilterer.h
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "content/spinner.h"
|
||||
#include "content/filetransferwidget.h"
|
||||
#include "content/image.h"
|
||||
#include "content/notificationicon.h"
|
||||
|
||||
#include "src/misc/settings.h"
|
||||
#include "src/misc/smileypack.h"
|
||||
|
@ -100,7 +101,7 @@ ChatMessage::Ptr ChatMessage::createTypingNotification()
|
|||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||
|
||||
msg->addColumn(new Spinner(":/ui/chatArea/typing.png", QSizeF(18, 18), 6.0), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new NotificationIcon(QSizeF(18, 18)), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text("%1 ...", Style::getFont(Style::Big), false, ""), ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
|
||||
|
||||
return msg;
|
||||
|
|
83
src/chatlog/content/notificationicon.cpp
Normal file
83
src/chatlog/content/notificationicon.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (C) 2015 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "notificationicon.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
|
||||
NotificationIcon::NotificationIcon(QSizeF Size)
|
||||
: size(Size)
|
||||
{
|
||||
pmap.load(":/ui/chatArea/typing.png");
|
||||
|
||||
updateTimer = new QTimer(this);
|
||||
updateTimer->setInterval(1000/60);
|
||||
updateTimer->setSingleShot(false);
|
||||
|
||||
updateTimer->start();
|
||||
|
||||
connect(updateTimer, &QTimer::timeout, this, &NotificationIcon::updateGradient);
|
||||
}
|
||||
|
||||
QRectF NotificationIcon::boundingRect() const
|
||||
{
|
||||
return QRectF(QPointF(-size.width() / 2.0, -size.height() / 2.0), size);
|
||||
}
|
||||
|
||||
void NotificationIcon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter->translate(-size.width() / 2.0, -size.height() / 2.0);
|
||||
|
||||
painter->fillRect(QRect(0, 0, size.width(), size.height()), grad);
|
||||
painter->drawPixmap(0, 0, size.width(), size.height(), pmap);
|
||||
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
}
|
||||
|
||||
void NotificationIcon::setWidth(qreal width)
|
||||
{
|
||||
Q_UNUSED(width)
|
||||
}
|
||||
|
||||
QRectF NotificationIcon::boundingSceneRect() const
|
||||
{
|
||||
return QRectF(scenePos(), size);
|
||||
}
|
||||
|
||||
qreal NotificationIcon::getAscent() const
|
||||
{
|
||||
return 3.0;
|
||||
}
|
||||
|
||||
void NotificationIcon::updateGradient()
|
||||
{
|
||||
alpha += 0.005;
|
||||
|
||||
if(alpha + dotWidth >= 1.0)
|
||||
alpha = 0.0;
|
||||
|
||||
grad = QLinearGradient(QPointF(-0.5*size.width(),0), QPointF(3.0/2.0*size.width(),0));
|
||||
grad.setColorAt(0, Qt::lightGray);
|
||||
grad.setColorAt(qMax(0.0, alpha - dotWidth), Qt::lightGray);
|
||||
grad.setColorAt(alpha, Qt::darkGray);
|
||||
grad.setColorAt(qMin(1.0, alpha + dotWidth), Qt::lightGray);
|
||||
grad.setColorAt(1, Qt::lightGray);
|
||||
|
||||
update();
|
||||
}
|
52
src/chatlog/content/notificationicon.h
Normal file
52
src/chatlog/content/notificationicon.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Copyright (C) 2015 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef NOTIFICATIONICON_H
|
||||
#define NOTIFICATIONICON_H
|
||||
|
||||
#include "../chatlinecontent.h"
|
||||
|
||||
#include <QLinearGradient>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class NotificationIcon : public QObject, public ChatLineContent
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NotificationIcon(QSizeF size);
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
virtual void setWidth(qreal width) override;
|
||||
virtual QRectF boundingSceneRect() const override;
|
||||
virtual qreal getAscent() const override;
|
||||
|
||||
private slots:
|
||||
void updateGradient();
|
||||
|
||||
private:
|
||||
QSizeF size;
|
||||
QPixmap pmap;
|
||||
QLinearGradient grad;
|
||||
QTimer* updateTimer = nullptr;
|
||||
|
||||
qreal dotWidth = 0.2;
|
||||
qreal alpha = 0.0;
|
||||
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONICON_H
|
|
@ -153,4 +153,8 @@
|
|||
id="path3806-6-4"
|
||||
style="fill:#c84e4e;fill-opacity:1;stroke:none" />
|
||||
</g>
|
||||
<path
|
||||
d="m 458.1875,12.1875 0,209.46875 200.21875,0 0,-209.46875 -200.21875,0 z m 43.9375,137.125 a 25,25 0 0 1 24.28125,25 25,25 0 0 1 -50,0 25,25 0 0 1 25.71875,-25 z m 56.90625,0 a 25,25 0 0 1 24.28125,25 25,25 0 0 1 -50,0 25,25 0 0 1 25.71875,-25 z m 56.90625,0 a 25,25 0 0 1 24.25,25 25,25 0 0 1 -50,0 25,25 0 0 1 25.75,-25 z"
|
||||
id="mask"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 8.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 613 B After Width: | Height: | Size: 302 B |
Loading…
Reference in New Issue
Block a user