2017-06-11 09:31:45 +02:00
|
|
|
#include "widgets/chatwidgetheader.hpp"
|
|
|
|
#include "colorscheme.hpp"
|
|
|
|
#include "widgets/chatwidget.hpp"
|
|
|
|
#include "widgets/notebookpage.hpp"
|
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-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
2017-06-26 16:41:20 +02:00
|
|
|
: BaseWidget(_chatWidget)
|
2017-06-10 22:48:28 +02:00
|
|
|
, chatWidget(_chatWidget)
|
2017-06-26 16:41:20 +02:00
|
|
|
, leftLabel(this)
|
2017-06-11 09:11:55 +02:00
|
|
|
, leftMenu(this)
|
2017-06-26 16:41:20 +02:00
|
|
|
, rightLabel(this)
|
2017-06-11 09:11:55 +02:00
|
|
|
, rightMenu(this)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-06-11 09:11:55 +02:00
|
|
|
this->setFixedHeight(32);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-07-02 14:28:37 +02:00
|
|
|
this->refreshTheme();
|
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->updateChannelText();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->setLayout(&this->hbox);
|
|
|
|
this->hbox.setMargin(0);
|
|
|
|
this->hbox.addWidget(&this->leftLabel);
|
|
|
|
this->hbox.addWidget(&this->channelNameLabel, 1);
|
|
|
|
this->hbox.addWidget(&this->rightLabel);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
// left
|
2017-06-11 09:11:55 +02:00
|
|
|
this->leftLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
this->leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
|
|
|
|
|
|
|
|
connect(&this->leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
|
|
|
&ChatWidgetHeader::leftButtonClicked);
|
|
|
|
|
|
|
|
this->leftMenu.addAction("Add new split", this->chatWidget, &ChatWidget::doAddSplit,
|
|
|
|
QKeySequence(tr("Ctrl+T")));
|
|
|
|
this->leftMenu.addAction("Close split", this->chatWidget, &ChatWidget::doCloseSplit,
|
|
|
|
QKeySequence(tr("Ctrl+W")));
|
|
|
|
this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
|
|
|
this->leftMenu.addAction("Popup", this->chatWidget, &ChatWidget::doPopup);
|
|
|
|
this->leftMenu.addSeparator();
|
|
|
|
this->leftMenu.addAction("Change channel", this->chatWidget, &ChatWidget::doChangeChannel,
|
|
|
|
QKeySequence(tr("Ctrl+R")));
|
|
|
|
this->leftMenu.addAction("Clear chat", this->chatWidget, &ChatWidget::doClearChat);
|
|
|
|
this->leftMenu.addAction("Open channel", this->chatWidget, &ChatWidget::doOpenChannel);
|
|
|
|
this->leftMenu.addAction("Open popup player", this->chatWidget, &ChatWidget::doOpenPopupPlayer);
|
|
|
|
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-06-11 09:11:55 +02:00
|
|
|
this->channelNameLabel.setAlignment(Qt::AlignCenter);
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
connect(&this->channelNameLabel, &SignalLabel::mouseDoubleClick, this,
|
2017-01-18 21:30:23 +01:00
|
|
|
&ChatWidgetHeader::mouseDoubleClickEvent);
|
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
// right
|
2017-06-11 09:11:55 +02:00
|
|
|
this->rightLabel.setMinimumWidth(this->height());
|
|
|
|
this->rightLabel.getLabel().setTextFormat(Qt::RichText);
|
|
|
|
this->rightLabel.getLabel().setText("ayy");
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::updateChannelText()
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2017-07-09 17:49:02 +02:00
|
|
|
const std::string channelName = this->chatWidget->channelName;
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-07-09 17:49:02 +02:00
|
|
|
if (channelName.empty()) {
|
|
|
|
this->channelNameLabel.setText("<no channel>");
|
|
|
|
} else {
|
|
|
|
this->channelNameLabel.setText(QString::fromStdString(channelName));
|
|
|
|
}
|
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-06-26 16:41:20 +02:00
|
|
|
painter.fillRect(rect(), this->colorScheme.ChatHeaderBackground);
|
|
|
|
painter.setPen(this->colorScheme.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-06-11 09:11:55 +02:00
|
|
|
this->dragging = true;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-11 09:11:55 +02:00
|
|
|
this->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-06-11 09:11:55 +02:00
|
|
|
if (this->dragging) {
|
|
|
|
if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
|
|
|
|
std::abs(this->dragStart.y() - event->pos().y()) > 12) {
|
2017-06-10 22:48:28 +02:00
|
|
|
auto page = static_cast<NotebookPage *>(this->chatWidget->parentWidget());
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
if (page != nullptr) {
|
2017-01-01 02:30:42 +01:00
|
|
|
NotebookPage::isDraggingSplit = true;
|
2017-06-10 22:48:28 +02:00
|
|
|
NotebookPage::draggingSplit = this->chatWidget;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
auto originalLocation = page->removeFromLayout(this->chatWidget);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-26 07:10:46 +01:00
|
|
|
// page->update();
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2017-06-10 22:48:28 +02:00
|
|
|
QDrag *drag = new QDrag(this->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-06-10 22:48:28 +02:00
|
|
|
page->addToLayout(this->chatWidget, originalLocation);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-10 22:48:28 +02:00
|
|
|
this->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-06-11 09:11:55 +02:00
|
|
|
this->leftMenu.move(this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
|
|
|
|
this->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-07-02 14:28:37 +02:00
|
|
|
void ChatWidgetHeader::refreshTheme()
|
|
|
|
{
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Foreground, this->colorScheme.Text);
|
|
|
|
|
|
|
|
this->leftLabel.setPalette(palette);
|
|
|
|
this->channelNameLabel.setPalette(palette);
|
|
|
|
this->rightLabel.setPalette(palette);
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuMoveSplit()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuReloadChannelEmotes()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuManualReconnect()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-10 23:53:39 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ChatWidgetHeader::menuShowChangelog()
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|