added basic channel and fixed moving splits

This commit is contained in:
fourtf 2017-01-01 13:07:36 +01:00
parent 8b8b9706b3
commit a290f88685
8 changed files with 129 additions and 42 deletions

21
channel.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "channel.h"
const Channel Channel::whispers = Channel(QString("/whispers"));
const Channel Channel::mentions = Channel(QString("/mentions"));
Channel::Channel(QString channel)
{
name = (channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel;
subLink = "https://www.twitch.tv/" + name + "/subscribe?ref=in_chat_subscriber_link";
channelLink = "https://twitch.tv/" + name;
popoutPlayerLink = "https://player.twitch.tv/?channel=" + name;
}
QString Channel::getSubLink() { return subLink ; }
QString Channel::getChannelLink() { return channelLink ; }
QString Channel::getPopoutPlayerLink() { return popoutPlayerLink ; }
bool Channel::getIsLive() { return isLive ; }
int Channel::getStreamViewerCount() { return streamViewerCount; }
QString Channel::getStreamStatus() { return streamStatus ; }
QString Channel::getStreamGame() { return streamGame ; }

41
channel.h Normal file
View file

@ -0,0 +1,41 @@
#ifndef CHANNEL_H
#define CHANNEL_H
#include "QString"
class Channel
{
public:
static const Channel whispers;
static const Channel mentions;
public:
QString getSubLink();
QString getChannelLink();
QString getPopoutPlayerLink();
bool getIsLive();
int getStreamViewerCount();
QString getStreamStatus();
QString getStreamGame();
private:
Channel(QString channel);
int referenceCount = 0;
QString name;
int roomID;
QString subLink = "";
QString channelLink = "";
QString popoutPlayerLink = "";
bool isLive = false;
int streamViewerCount = 0;
QString streamStatus = "";
QString streamGame = "";
};
#endif // CHANNEL_H

View file

@ -34,7 +34,8 @@ SOURCES += main.cpp\
chatwidgetheader.cpp \ chatwidgetheader.cpp \
chatwidgetinput.cpp \ chatwidgetinput.cpp \
chatwidgetview.cpp \ chatwidgetview.cpp \
notebookpagedroppreview.cpp notebookpagedroppreview.cpp \
channel.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
chatwidget.h \ chatwidget.h \
@ -46,7 +47,8 @@ HEADERS += mainwindow.h \
chatwidgetheader.h \ chatwidgetheader.h \
chatwidgetinput.h \ chatwidgetinput.h \
chatwidgetview.h \ chatwidgetview.h \
notebookpagedroppreview.h notebookpagedroppreview.h \
channel.h
FORMS += FORMS +=

View file

@ -46,6 +46,8 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
auto originalLocation = page->removeFromLayout(chatWidget); auto originalLocation = page->removeFromLayout(chatWidget);
//page->repaint();
QDrag *drag = new QDrag(chatWidget); QDrag *drag = new QDrag(chatWidget);
QMimeData* mimeData = new QMimeData; QMimeData* mimeData = new QMimeData;

View file

@ -16,7 +16,7 @@ void ColorScheme::setColors(float hue, float multiplyer)
DropPreviewBackground = getColor(hue, 0.5, 0.5, 0.3); DropPreviewBackground = getColor(hue, 0.5, 0.5, 0.3);
TextCaret = IsLightTheme ? QColor(0, 0, 0) : QColor(255, 255, 255); Text = TextCaret = IsLightTheme ? QColor(0, 0, 0) : QColor(255, 255, 255);
// tab // tab
TabPanelBackground = QColor(255, 255, 255); TabPanelBackground = QColor(255, 255, 255);

View file

@ -29,30 +29,6 @@ NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab)
hbox.setSpacing(1); hbox.setSpacing(1);
hbox.setMargin(0); hbox.setMargin(0);
QVBoxLayout* vbox = new QVBoxLayout();
vbox->addWidget(new ChatWidget());
vbox->addWidget(new ChatWidget());
vbox->addWidget(new ChatWidget());
hbox.addLayout(vbox);
vbox = new QVBoxLayout();
vbox->addWidget(new ChatWidget());
hbox.addLayout(vbox);
vbox = new QVBoxLayout();
vbox->addWidget(new ChatWidget());
vbox->addWidget(new ChatWidget());
hbox.addLayout(vbox);
vbox = new QVBoxLayout();
vbox->addWidget(new ChatWidget());
vbox->addWidget(new ChatWidget());
hbox.addLayout(vbox);
} }
std::pair<int, int> NotebookPage::removeFromLayout(ChatWidget *widget) std::pair<int, int> NotebookPage::removeFromLayout(ChatWidget *widget)
@ -111,6 +87,32 @@ void NotebookPage::addToLayout(ChatWidget *widget, std::pair<int, int> position
vbox->insertWidget(std::max(0, std::min(vbox->count(), position.second)), widget); vbox->insertWidget(std::max(0, std::min(vbox->count(), position.second)), widget);
} }
void NotebookPage::enterEvent(QEvent *)
{
if (hbox.count() == 0)
{
setCursor(QCursor(Qt::PointingHandCursor));
}
else
{
setCursor(QCursor(Qt::ArrowCursor));
}
}
void NotebookPage::leaveEvent(QEvent *)
{
}
void NotebookPage::mouseReleaseEvent(QMouseEvent *event)
{
if (hbox.count() == 0 && event->button() == Qt::LeftButton)
{
addToLayout(new ChatWidget(), std::pair<int, int>(-1, -1));
setCursor(QCursor(Qt::ArrowCursor));
}
}
void NotebookPage::dragEnterEvent(QDragEnterEvent *event) void NotebookPage::dragEnterEvent(QDragEnterEvent *event)
{ {
if (!event->mimeData()->hasFormat("chatterino/split")) return; if (!event->mimeData()->hasFormat("chatterino/split")) return;
@ -119,6 +121,12 @@ void NotebookPage::dragEnterEvent(QDragEnterEvent *event)
{ {
dropRegions.clear(); dropRegions.clear();
if (hbox.count()==0)
{
dropRegions.push_back(DropRegion(rect(), std::pair<int, int>(-1, -1)));
}
else
{
for (int i = 0; i < hbox.count() + 1; ++i) for (int i = 0; i < hbox.count() + 1; ++i)
{ {
dropRegions.push_back(DropRegion(QRect(((i*4 - 1) * width() / hbox.count()) / 4, 0, width()/hbox.count()/2, height()), std::pair<int, int>(i, -1))); dropRegions.push_back(DropRegion(QRect(((i*4 - 1) * width() / hbox.count()) / 4, 0, width()/hbox.count()/2, height()), std::pair<int, int>(i, -1)));
@ -133,6 +141,7 @@ void NotebookPage::dragEnterEvent(QDragEnterEvent *event)
dropRegions.push_back(DropRegion(QRect(i*width()/hbox.count(), ((j*2 - 1) * height() / vbox->count()) / 2, width()/hbox.count(), height()/vbox->count()), std::pair<int, int>(i, j))); dropRegions.push_back(DropRegion(QRect(i*width()/hbox.count(), ((j*2 - 1) * height() / vbox->count()) / 2, width()/hbox.count(), height()/vbox->count()), std::pair<int, int>(i, j)));
} }
} }
}
setPreviewRect(event->pos()); setPreviewRect(event->pos());
@ -169,7 +178,7 @@ void NotebookPage::setPreviewRect(QPoint mousePos)
void NotebookPage::dragLeaveEvent(QDragLeaveEvent *event) void NotebookPage::dragLeaveEvent(QDragLeaveEvent *event)
{ {
preview.hide();
} }
void NotebookPage::dropEvent(QDropEvent *event) void NotebookPage::dropEvent(QDropEvent *event)
@ -190,11 +199,19 @@ void NotebookPage::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
// painter.fillRect(rect(), ColorScheme::getInstance().ChatBackground); if (hbox.count() == 0)
{
painter.fillRect(rect(), ColorScheme::getInstance().ChatBackground);
// painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground); painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground);
painter.setPen(ColorScheme::getInstance().Text);
painter.drawText(rect(), "Add Chat", QTextOption(Qt::AlignCenter));
}
else
{
painter.fillRect(rect(), ColorScheme::getInstance().TabSelectedBackground); painter.fillRect(rect(), ColorScheme::getInstance().TabSelectedBackground);
painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground); painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground);
} }
}

View file

@ -32,6 +32,10 @@ public:
protected: protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
void mouseReleaseEvent(QMouseEvent *event);
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;

View file

@ -5,12 +5,12 @@
NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent = 0) NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent = 0)
: QWidget(parent) : QWidget(parent)
{ {
setHidden(true);
} }
void NotebookPageDropPreview::paintEvent(QPaintEvent *) void NotebookPageDropPreview::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
painter.fillRect(rect(), ColorScheme::getInstance().DropPreviewBackground); painter.fillRect(8, 8, width()-17, height()-17, ColorScheme::getInstance().DropPreviewBackground);
} }