2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/chatwidgetheader.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include "colorscheme.h"
|
2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/chatwidget.h"
|
|
|
|
#include "widgets/notebookpage.h"
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QByteArray>
|
|
|
|
#include <QDrag>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-01-16 18:27:51 +01:00
|
|
|
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent)
|
2017-01-01 02:30:42 +01:00
|
|
|
: QWidget()
|
2017-01-18 04:33:30 +01:00
|
|
|
, chatWidget(parent)
|
|
|
|
, dragStart()
|
|
|
|
, dragging(false)
|
|
|
|
, leftLabel()
|
|
|
|
, middleLabel()
|
|
|
|
, rightLabel()
|
|
|
|
, leftMenu(this)
|
|
|
|
, rightMenu(this)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
setFixedHeight(32);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
updateColors();
|
2017-01-17 00:15:44 +01:00
|
|
|
updateChannelText();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
setLayout(&this->hbox);
|
|
|
|
this->hbox.setMargin(0);
|
|
|
|
this->hbox.addWidget(&this->leftLabel);
|
|
|
|
this->hbox.addWidget(&this->middleLabel, 1);
|
|
|
|
this->hbox.addWidget(&this->rightLabel);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// left
|
2017-01-18 04:33:30 +01:00
|
|
|
this->leftLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
this->leftLabel.getLabel().setText(
|
2017-01-15 16:38:30 +01:00
|
|
|
"<img src=':/images/tool_moreCollapser_off16.png' />");
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
QObject::connect(&this->leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
2017-01-15 17:12:19 +01:00
|
|
|
&ChatWidgetHeader::leftButtonClicked);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()),
|
|
|
|
QKeySequence(tr("Ctrl+T")));
|
|
|
|
this->leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()),
|
|
|
|
QKeySequence(tr("Ctrl+W")));
|
|
|
|
this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
|
|
|
this->leftMenu.addSeparator();
|
|
|
|
this->leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()),
|
|
|
|
QKeySequence(tr("Ctrl+R")));
|
|
|
|
this->leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
|
|
|
|
this->leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
|
|
|
|
this->leftMenu.addAction("Open pop-out player", this,
|
|
|
|
SLOT(menuPopupPlayer()));
|
|
|
|
this->leftMenu.addSeparator();
|
|
|
|
this->leftMenu.addAction("Reload channel emotes", this,
|
|
|
|
SLOT(menuReloadChannelEmotes()));
|
|
|
|
this->leftMenu.addAction("Manual reconnect", this,
|
|
|
|
SLOT(menuManualReconnect()));
|
|
|
|
this->leftMenu.addSeparator();
|
|
|
|
this->leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// middle
|
2017-01-18 04:33:30 +01:00
|
|
|
this->middleLabel.setAlignment(Qt::AlignCenter);
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
connect(&this->middleLabel, &SignalLabel::mouseDoubleClick, this,
|
|
|
|
&ChatWidgetHeader::mouseDoubleClickEvent);
|
2017-01-22 05:58:23 +01:00
|
|
|
// connect(&this->middleLabel, &SignalLabel::mouseDown, this,
|
|
|
|
// &ChatWidgetHeader::mouseDoubleClickEvent);
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
// right
|
2017-01-18 04:33:30 +01:00
|
|
|
this->rightLabel.setMinimumWidth(height());
|
|
|
|
this->rightLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
this->rightLabel.getLabel().setText("ayy");
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::updateColors()
|
|
|
|
{
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Foreground, ColorScheme::instance().Text);
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->leftLabel.setPalette(palette);
|
|
|
|
this->middleLabel.setPalette(palette);
|
|
|
|
this->rightLabel.setPalette(palette);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
void
|
|
|
|
ChatWidgetHeader::updateChannelText()
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
const QString &c = this->chatWidget->getChannelName();
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
ChatWidgetHeader::paintEvent(QPaintEvent *)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
painter.fillRect(rect(), ColorScheme::instance().ChatHeaderBackground);
|
|
|
|
painter.setPen(ColorScheme::instance().ChatHeaderBorder);
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.drawRect(0, 0, width() - 1, height() - 1);
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
ChatWidgetHeader::mousePressEvent(QMouseEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->dragging = true;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->dragStart = event->pos();
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->dragging) {
|
|
|
|
if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
|
|
|
|
std::abs(this->dragStart.y() - event->pos().y()) > 12) {
|
|
|
|
auto chatWidget = this->chatWidget;
|
2017-01-11 18:52:09 +01:00
|
|
|
auto page = static_cast<NotebookPage *>(chatWidget->parentWidget());
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (page != NULL) {
|
2017-01-01 02:30:42 +01:00
|
|
|
NotebookPage::isDraggingSplit = true;
|
|
|
|
NotebookPage::draggingSplit = chatWidget;
|
|
|
|
|
|
|
|
auto originalLocation = page->removeFromLayout(chatWidget);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
// page->repaint();
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2017-01-01 02:30:42 +01:00
|
|
|
QDrag *drag = new QDrag(chatWidget);
|
2017-01-11 18:52:09 +01:00
|
|
|
QMimeData *mimeData = new QMimeData;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
|
|
|
mimeData->setData("chatterino/split", "xD");
|
|
|
|
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
|
|
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (dropAction == Qt::IgnoreAction) {
|
2017-01-01 02:30:42 +01:00
|
|
|
page->addToLayout(chatWidget, originalLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
NotebookPage::isDraggingSplit = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
void
|
|
|
|
ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2017-01-18 04:33:30 +01:00
|
|
|
this->chatWidget->showChangeChannelPopup();
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
void
|
|
|
|
ChatWidgetHeader::leftButtonClicked()
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->leftMenu.move(
|
|
|
|
this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
|
|
|
|
this->leftMenu.show();
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::rightButtonClicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuAddSplit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuCloseSplit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuMoveSplit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuChangeChannel()
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->chatWidget->showChangeChannelPopup();
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuClearChat()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuOpenChannel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuPopupPlayer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuReloadChannelEmotes()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuManualReconnect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ChatWidgetHeader::menuShowChangelog()
|
|
|
|
{
|
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
|
|
|
}
|