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-04-12 17:46:44 +02: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-04-12 17:46:44 +02:00
|
|
|
setLayout(&_hbox);
|
|
|
|
_hbox.setMargin(0);
|
|
|
|
_hbox.addWidget(&_leftLabel);
|
|
|
|
_hbox.addWidget(&_middleLabel, 1);
|
|
|
|
_hbox.addWidget(&_rightLabel);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// left
|
2017-04-12 17:46:44 +02:00
|
|
|
_leftLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
_leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
QObject::connect(&_leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
2017-01-15 17:12:19 +01:00
|
|
|
&ChatWidgetHeader::leftButtonClicked);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()), QKeySequence(tr("Ctrl+T")));
|
|
|
|
_leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()), QKeySequence(tr("Ctrl+W")));
|
|
|
|
_leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
|
|
|
_leftMenu.addAction("Popup", this, SLOT(menuPopup()));
|
|
|
|
_leftMenu.addSeparator();
|
|
|
|
_leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()),
|
|
|
|
QKeySequence(tr("Ctrl+R")));
|
|
|
|
_leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
|
|
|
|
_leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
|
|
|
|
_leftMenu.addAction("Open pop-out player", this, SLOT(menuPopupPlayer()));
|
|
|
|
_leftMenu.addSeparator();
|
|
|
|
_leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
|
|
|
|
_leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
|
|
|
|
_leftMenu.addSeparator();
|
|
|
|
_leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// middle
|
2017-04-12 17:46:44 +02:00
|
|
|
_middleLabel.setAlignment(Qt::AlignCenter);
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
connect(&_middleLabel, &SignalLabel::mouseDoubleClick, this,
|
2017-01-18 21:30:23 +01:00
|
|
|
&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-04-12 17:46:44 +02:00
|
|
|
_rightLabel.setMinimumWidth(height());
|
|
|
|
_rightLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
_rightLabel.getLabel().setText("ayy");
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::updateColors()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
QPalette palette;
|
2017-01-24 20:15:12 +01:00
|
|
|
palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_leftLabel.setPalette(palette);
|
|
|
|
_middleLabel.setPalette(palette);
|
|
|
|
_rightLabel.setPalette(palette);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::updateChannelText()
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &c = _chatWidget->getChannelName();
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::paintEvent(QPaintEvent *)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2017-01-24 20:15:12 +01:00
|
|
|
painter.fillRect(rect(), ColorScheme::getInstance().ChatHeaderBackground);
|
|
|
|
painter.setPen(ColorScheme::getInstance().ChatHeaderBorder);
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.drawRect(0, 0, width() - 1, height() - 1);
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::mousePressEvent(QMouseEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
_dragging = true;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_dragStart = event->pos();
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
if (_dragging) {
|
|
|
|
if (std::abs(_dragStart.x() - event->pos().x()) > 12 ||
|
|
|
|
std::abs(_dragStart.y() - event->pos().y()) > 12) {
|
|
|
|
auto chatWidget = _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-26 07:10:46 +01:00
|
|
|
// page->update();
|
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-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2017-04-12 17:46:44 +02:00
|
|
|
_chatWidget->showChangeChannelPopup();
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::leftButtonClicked()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
_leftMenu.move(_leftLabel.mapToGlobal(QPoint(0, _leftLabel.height())));
|
|
|
|
_leftMenu.show();
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::rightButtonClicked()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuAddSplit()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuCloseSplit()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuMoveSplit()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuPopup()
|
2017-02-03 19:31:51 +01:00
|
|
|
{
|
|
|
|
auto widget = new ChatWidget();
|
2017-04-12 17:46:44 +02:00
|
|
|
widget->setChannelName(_chatWidget->getChannelName());
|
2017-02-03 19:31:51 +01:00
|
|
|
widget->show();
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuChangeChannel()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
_chatWidget->showChangeChannelPopup();
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuClearChat()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuOpenChannel()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuPopupPlayer()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuReloadChannelEmotes()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuManualReconnect()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuShowChangelog()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
|
|
|
}
|