From a290f8868564aa4875bc376fdcbc2950e6144949 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 1 Jan 2017 13:07:36 +0100 Subject: [PATCH] added basic channel and fixed moving splits --- channel.cpp | 21 +++++++++ channel.h | 41 +++++++++++++++++ chatterino.pro | 6 ++- chatwidgetheader.cpp | 2 + colorscheme.cpp | 2 +- notebookpage.cpp | 91 ++++++++++++++++++++++--------------- notebookpage.h | 4 ++ notebookpagedroppreview.cpp | 4 +- 8 files changed, 129 insertions(+), 42 deletions(-) create mode 100644 channel.cpp create mode 100644 channel.h diff --git a/channel.cpp b/channel.cpp new file mode 100644 index 000000000..2716da312 --- /dev/null +++ b/channel.cpp @@ -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 ; } diff --git a/channel.h b/channel.h new file mode 100644 index 000000000..fdac16c04 --- /dev/null +++ b/channel.h @@ -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 diff --git a/chatterino.pro b/chatterino.pro index ebe0a296d..cac094e77 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -34,7 +34,8 @@ SOURCES += main.cpp\ chatwidgetheader.cpp \ chatwidgetinput.cpp \ chatwidgetview.cpp \ - notebookpagedroppreview.cpp + notebookpagedroppreview.cpp \ + channel.cpp HEADERS += mainwindow.h \ chatwidget.h \ @@ -46,7 +47,8 @@ HEADERS += mainwindow.h \ chatwidgetheader.h \ chatwidgetinput.h \ chatwidgetview.h \ - notebookpagedroppreview.h + notebookpagedroppreview.h \ + channel.h FORMS += diff --git a/chatwidgetheader.cpp b/chatwidgetheader.cpp index 6d32676e6..8740f6c19 100644 --- a/chatwidgetheader.cpp +++ b/chatwidgetheader.cpp @@ -46,6 +46,8 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event) auto originalLocation = page->removeFromLayout(chatWidget); + //page->repaint(); + QDrag *drag = new QDrag(chatWidget); QMimeData* mimeData = new QMimeData; diff --git a/colorscheme.cpp b/colorscheme.cpp index fa4ff7f44..0356b9575 100644 --- a/colorscheme.cpp +++ b/colorscheme.cpp @@ -16,7 +16,7 @@ void ColorScheme::setColors(float hue, float multiplyer) 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 TabPanelBackground = QColor(255, 255, 255); diff --git a/notebookpage.cpp b/notebookpage.cpp index 4ca1ca943..3c185de83 100644 --- a/notebookpage.cpp +++ b/notebookpage.cpp @@ -29,30 +29,6 @@ NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab) hbox.setSpacing(1); 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 NotebookPage::removeFromLayout(ChatWidget *widget) @@ -111,6 +87,32 @@ void NotebookPage::addToLayout(ChatWidget *widget, std::pair position 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(-1, -1)); + setCursor(QCursor(Qt::ArrowCursor)); + } +} + void NotebookPage::dragEnterEvent(QDragEnterEvent *event) { if (!event->mimeData()->hasFormat("chatterino/split")) return; @@ -119,18 +121,25 @@ void NotebookPage::dragEnterEvent(QDragEnterEvent *event) { dropRegions.clear(); - for (int i = 0; i < hbox.count() + 1; ++i) + if (hbox.count()==0) { - dropRegions.push_back(DropRegion(QRect(((i*4 - 1) * width() / hbox.count()) / 4, 0, width()/hbox.count()/2, height()), std::pair(i, -1))); + dropRegions.push_back(DropRegion(rect(), std::pair(-1, -1))); } - - for (int i = 0; i < hbox.count(); ++i) + else { - auto vbox = static_cast(hbox.itemAt(i)); - - for (int j = 0; j < vbox->count() + 1; ++j) + for (int i = 0; i < hbox.count() + 1; ++i) { - dropRegions.push_back(DropRegion(QRect(i*width()/hbox.count(), ((j*2 - 1) * height() / vbox->count()) / 2, width()/hbox.count(), height()/vbox->count()), std::pair(i, j))); + dropRegions.push_back(DropRegion(QRect(((i*4 - 1) * width() / hbox.count()) / 4, 0, width()/hbox.count()/2, height()), std::pair(i, -1))); + } + + for (int i = 0; i < hbox.count(); ++i) + { + auto vbox = static_cast(hbox.itemAt(i)); + + for (int j = 0; j < vbox->count() + 1; ++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(i, j))); + } } } @@ -169,7 +178,7 @@ void NotebookPage::setPreviewRect(QPoint mousePos) void NotebookPage::dragLeaveEvent(QDragLeaveEvent *event) { - + preview.hide(); } void NotebookPage::dropEvent(QDropEvent *event) @@ -190,11 +199,19 @@ void NotebookPage::paintEvent(QPaintEvent *) { 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.fillRect(rect(), 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(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground); + painter.fillRect(0, 0, width(), 2, ColorScheme::getInstance().TabSelectedBackground); + } } diff --git a/notebookpage.h b/notebookpage.h index c69d499b2..43a6af234 100644 --- a/notebookpage.h +++ b/notebookpage.h @@ -32,6 +32,10 @@ public: protected: void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void enterEvent(QEvent *); + void leaveEvent(QEvent *); + void mouseReleaseEvent(QMouseEvent *event); + void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; diff --git a/notebookpagedroppreview.cpp b/notebookpagedroppreview.cpp index ef696e843..52b4ec194 100644 --- a/notebookpagedroppreview.cpp +++ b/notebookpagedroppreview.cpp @@ -5,12 +5,12 @@ NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent = 0) : QWidget(parent) { - + setHidden(true); } void NotebookPageDropPreview::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.fillRect(rect(), ColorScheme::getInstance().DropPreviewBackground); + painter.fillRect(8, 8, width()-17, height()-17, ColorScheme::getInstance().DropPreviewBackground); }