added code for a notification system

This commit is contained in:
fourtf
2018-05-23 22:27:29 +02:00
parent a74c19d1f3
commit 48e94a1169
12 changed files with 182 additions and 69 deletions
+4 -2
View File
@@ -203,7 +203,8 @@ SOURCES += \
src/controllers/accounts/account.cpp \ src/controllers/accounts/account.cpp \
src/widgets/helper/splitoverlay.cpp \ src/widgets/helper/splitoverlay.cpp \
src/widgets/helper/dropoverlay.cpp \ src/widgets/helper/dropoverlay.cpp \
src/widgets/helper/splitnode.cpp src/widgets/helper/splitnode.cpp \
src/widgets/notificationpopup.cpp
HEADERS += \ HEADERS += \
src/precompiled_header.hpp \ src/precompiled_header.hpp \
@@ -351,7 +352,8 @@ HEADERS += \
src/util/sharedptrelementless.hpp \ src/util/sharedptrelementless.hpp \
src/widgets/helper/splitoverlay.hpp \ src/widgets/helper/splitoverlay.hpp \
src/widgets/helper/dropoverlay.hpp \ src/widgets/helper/dropoverlay.hpp \
src/widgets/helper/splitnode.hpp src/widgets/helper/splitnode.hpp \
src/widgets/notificationpopup.hpp
RESOURCES += \ RESOURCES += \
resources/resources.qrc resources/resources.qrc
@@ -2,6 +2,7 @@
#include "application.hpp" #include "application.hpp"
#include "controllers/highlights/highlightmodel.hpp" #include "controllers/highlights/highlightmodel.hpp"
#include "widgets/notificationpopup.hpp"
namespace chatterino { namespace chatterino {
namespace controllers { namespace controllers {
@@ -34,6 +35,15 @@ HighlightModel *HighlightController::createModel(QObject *parent)
return model; return model;
} }
void HighlightController::addHighlight(const messages::MessagePtr &msg)
{
// static widgets::NotificationPopup popup;
// popup.updatePosition();
// popup.addMessage(msg);
// popup.show();
}
} // namespace highlights } // namespace highlights
} // namespace controllers } // namespace controllers
} // namespace chatterino } // namespace chatterino
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "controllers/highlights/highlightphrase.hpp" #include "controllers/highlights/highlightphrase.hpp"
#include "messages/message.hpp"
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
#include "util/signalvector2.hpp" #include "util/signalvector2.hpp"
@@ -21,6 +22,8 @@ public:
HighlightModel *createModel(QObject *parent); HighlightModel *createModel(QObject *parent);
void addHighlight(const messages::MessagePtr &msg);
private: private:
bool initialized = false; bool initialized = false;
+6 -4
View File
@@ -1,6 +1,7 @@
#include "twitchserver.hpp" #include "twitchserver.hpp"
#include "application.hpp" #include "application.hpp"
#include "controllers/highlights/highlightcontroller.hpp"
#include "providers/twitch/ircmessagehandler.hpp" #include "providers/twitch/ircmessagehandler.hpp"
#include "providers/twitch/twitchaccount.hpp" #include "providers/twitch/twitchaccount.hpp"
#include "providers/twitch/twitchhelpers.hpp" #include "providers/twitch/twitchhelpers.hpp"
@@ -93,12 +94,13 @@ void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
TwitchMessageBuilder builder(chan.get(), message, args); TwitchMessageBuilder builder(chan.get(), message, args);
if (!builder.isIgnored()) { if (!builder.isIgnored()) {
messages::MessagePtr _message = builder.build(); messages::MessagePtr msg = builder.build();
if (_message->flags & messages::Message::Highlighted) { if (msg->flags & messages::Message::Highlighted) {
this->mentionsChannel->addMessage(_message); this->mentionsChannel->addMessage(msg);
getApp()->highlights->addHighlight(msg);
} }
chan->addMessage(_message); chan->addMessage(msg);
} }
} }
+1 -1
View File
@@ -26,7 +26,7 @@ public:
QSize getScaleIndependantSize() const; QSize getScaleIndependantSize() const;
int getScaleIndependantWidth() const; int getScaleIndependantWidth() const;
int getScaleIndependantHeight() const; int getScaleIndependantHeight() const;
void setScaleIndependantSize(int width, int yOffset); void setScaleIndependantSize(int width, int height);
void setScaleIndependantSize(QSize); void setScaleIndependantSize(QSize);
void setScaleIndependantWidth(int value); void setScaleIndependantWidth(int value);
void setScaleIndependantHeight(int value); void setScaleIndependantHeight(int value);
+19 -3
View File
@@ -32,10 +32,16 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
BaseWindow::BaseWindow(QWidget *parent, bool _enableCustomFrame) BaseWindow::BaseWindow(QWidget *parent, Flags flags)
: BaseWidget(parent, Qt::Window) : BaseWidget(parent, Qt::Window)
, enableCustomFrame(_enableCustomFrame) , enableCustomFrame(flags & EnableCustomFrame)
, frameless(flags & FrameLess)
{ {
if (this->frameless) {
this->enableCustomFrame = false;
this->setWindowFlag(Qt::FramelessWindowHint);
}
this->init(); this->init();
} }
@@ -53,6 +59,7 @@ void BaseWindow::init()
layout->setSpacing(0); layout->setSpacing(0);
this->setLayout(layout); this->setLayout(layout);
{ {
if (!this->frameless) {
QHBoxLayout *buttonLayout = this->ui.titlebarBox = new QHBoxLayout(); QHBoxLayout *buttonLayout = this->ui.titlebarBox = new QHBoxLayout();
buttonLayout->setMargin(0); buttonLayout->setMargin(0);
layout->addLayout(buttonLayout); layout->addLayout(buttonLayout);
@@ -103,6 +110,7 @@ void BaseWindow::init()
buttonLayout->addWidget(_exitButton); buttonLayout->addWidget(_exitButton);
buttonLayout->setSpacing(0); buttonLayout->setSpacing(0);
} }
}
this->ui.layoutBase = new BaseWidget(this); this->ui.layoutBase = new BaseWidget(this);
layout->addWidget(this->ui.layoutBase); layout->addWidget(this->ui.layoutBase);
} }
@@ -165,10 +173,12 @@ void BaseWindow::themeRefreshEvent()
palette.setColor(QPalette::Foreground, this->themeManager->window.text); palette.setColor(QPalette::Foreground, this->themeManager->window.text);
this->setPalette(palette); this->setPalette(palette);
if (this->ui.titleLabel) {
QPalette palette_title; QPalette palette_title;
palette_title.setColor(QPalette::Foreground, palette_title.setColor(QPalette::Foreground,
this->themeManager->isLightTheme() ? "#333" : "#ccc"); this->themeManager->isLightTheme() ? "#333" : "#ccc");
this->ui.titleLabel->setPalette(palette_title); this->ui.titleLabel->setPalette(palette_title);
}
for (RippleEffectButton *button : this->ui.buttons) { for (RippleEffectButton *button : this->ui.buttons) {
button->setMouseEffectColor(this->themeManager->window.text); button->setMouseEffectColor(this->themeManager->window.text);
@@ -212,7 +222,7 @@ void BaseWindow::changeEvent(QEvent *)
TooltipWidget::getInstance()->hide(); TooltipWidget::getInstance()->hide();
#ifdef USEWINSDK #ifdef USEWINSDK
if (this->hasCustomWindowFrame()) { if (this->ui.maxButton) {
this->ui.maxButton->setButtonStyle(this->windowState() & Qt::WindowMaximized this->ui.maxButton->setButtonStyle(this->windowState() & Qt::WindowMaximized
? TitleBarButton::Unmaximize ? TitleBarButton::Unmaximize
: TitleBarButton::Maximize); : TitleBarButton::Maximize);
@@ -449,12 +459,18 @@ void BaseWindow::calcButtonsSizes()
return; return;
} }
if ((this->width() / this->getScale()) < 300) { if ((this->width() / this->getScale()) < 300) {
if (this->ui.minButton)
this->ui.minButton->setScaleIndependantSize(30, 30); this->ui.minButton->setScaleIndependantSize(30, 30);
if (this->ui.maxButton)
this->ui.maxButton->setScaleIndependantSize(30, 30); this->ui.maxButton->setScaleIndependantSize(30, 30);
if (this->ui.exitButton)
this->ui.exitButton->setScaleIndependantSize(30, 30); this->ui.exitButton->setScaleIndependantSize(30, 30);
} else { } else {
if (this->ui.minButton)
this->ui.minButton->setScaleIndependantSize(46, 30); this->ui.minButton->setScaleIndependantSize(46, 30);
if (this->ui.maxButton)
this->ui.maxButton->setScaleIndependantSize(46, 30); this->ui.maxButton->setScaleIndependantSize(46, 30);
if (this->ui.exitButton)
this->ui.exitButton->setScaleIndependantSize(46, 30); this->ui.exitButton->setScaleIndependantSize(46, 30);
} }
} }
+7 -4
View File
@@ -19,7 +19,9 @@ class BaseWindow : public BaseWidget
Q_OBJECT Q_OBJECT
public: public:
explicit BaseWindow(QWidget *parent = nullptr, bool enableCustomFrame = false); enum Flags { None = 0, EnableCustomFrame = 1, FrameLess = 2 };
explicit BaseWindow(QWidget *parent = nullptr, Flags flags = None);
QWidget *getLayoutContainer(); QWidget *getLayoutContainer();
bool hasCustomWindowFrame(); bool hasCustomWindowFrame();
@@ -51,16 +53,17 @@ private:
void calcButtonsSizes(); void calcButtonsSizes();
bool enableCustomFrame; bool enableCustomFrame;
bool frameless;
bool stayInScreenRect = false; bool stayInScreenRect = false;
bool shown = false; bool shown = false;
struct { struct {
QHBoxLayout *titlebarBox; QHBoxLayout *titlebarBox = nullptr;
QWidget *titleLabel; QWidget *titleLabel = nullptr;
TitleBarButton *minButton = nullptr; TitleBarButton *minButton = nullptr;
TitleBarButton *maxButton = nullptr; TitleBarButton *maxButton = nullptr;
TitleBarButton *exitButton = nullptr; TitleBarButton *exitButton = nullptr;
QWidget *layoutBase; QWidget *layoutBase = nullptr;
std::vector<RippleEffectButton *> buttons; std::vector<RippleEffectButton *> buttons;
} ui; } ui;
}; };
+1 -1
View File
@@ -17,7 +17,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
EmotePopup::EmotePopup() EmotePopup::EmotePopup()
: BaseWindow(nullptr, true) : BaseWindow(nullptr, BaseWindow::EnableCustomFrame)
{ {
this->viewEmotes = new ChannelView(); this->viewEmotes = new ChannelView();
this->viewEmojis = new ChannelView(); this->viewEmojis = new ChannelView();
+50
View File
@@ -0,0 +1,50 @@
#include "notificationpopup.hpp"
#include "widgets/helper/channelview.hpp"
#include <QApplication>
#include <QDesktopWidget>
#include <QScreen>
namespace chatterino {
namespace widgets {
NotificationPopup::NotificationPopup()
: BaseWindow((QWidget *)nullptr, BaseWindow::FrameLess)
, channel(std::make_shared<Channel>("notifications", Channel::None))
{
this->channelView = new ChannelView(this);
auto *layout = new QVBoxLayout(this);
this->setLayout(layout);
layout->addWidget(this->channelView);
this->channelView->setChannel(this->channel);
this->setScaleIndependantSize(300, 150);
}
void NotificationPopup::updatePosition()
{
Location location = BottomRight;
QDesktopWidget *desktop = QApplication::desktop();
const QRect rect = desktop->availableGeometry();
switch (location) {
case BottomRight: {
this->move(rect.right() - this->width(), rect.bottom() - this->height());
} break;
}
}
void NotificationPopup::addMessage(messages::MessagePtr msg)
{
this->channel->addMessage(msg);
// QTimer::singleShot(5000, this, [this, msg] { this->channel->remove });
}
} // namespace widgets
} // namespace chatterino
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include "channel.hpp"
#include "messages/message.hpp"
#include "widgets/basewindow.hpp"
namespace chatterino {
namespace widgets {
class ChannelView;
class NotificationPopup : public BaseWindow
{
public:
enum Location { TopLeft, TopRight, BottomLeft, BottomRight };
NotificationPopup();
void addMessage(messages::MessagePtr msg);
void updatePosition();
private:
ChannelView *channelView;
ChannelPtr channel;
};
} // namespace widgets
} // namespace chatterino
+1 -1
View File
@@ -17,7 +17,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
SelectChannelDialog::SelectChannelDialog() SelectChannelDialog::SelectChannelDialog()
: BaseWindow((QWidget *)nullptr, true) : BaseWindow((QWidget *)nullptr, BaseWindow::EnableCustomFrame)
, selectedChannel(Channel::getEmpty()) , selectedChannel(Channel::getEmpty())
{ {
this->setWindowTitle("Select a channel to join"); this->setWindowTitle("Select a channel to join");
+1 -1
View File
@@ -24,7 +24,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
Window::Window(WindowType _type) Window::Window(WindowType _type)
: BaseWindow(nullptr, true) : BaseWindow(nullptr, BaseWindow::EnableCustomFrame)
, type(_type) , type(_type)
, dpi(this->getScale()) , dpi(this->getScale())
, notebook(this) , notebook(this)