mirror-chatterino2/chatwidgetheader.cpp

204 lines
5 KiB
C++
Raw Normal View History

2017-01-01 02:30:42 +01:00
#include "chatwidgetheader.h"
#include "chatwidget.h"
2017-01-11 18:52:09 +01:00
#include "colorscheme.h"
2017-01-01 02:30:42 +01:00
#include "notebookpage.h"
2017-01-15 16:38:30 +01:00
#include <QByteArray>
#include <QDrag>
#include <QMimeData>
#include <QPainter>
2017-01-16 18:27:51 +01:00
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent)
2017-01-01 02:30:42 +01:00
: QWidget()
2017-01-16 18:27:51 +01:00
, m_chatWidget(parent)
2017-01-15 16:38:30 +01:00
, m_dragStart()
, m_dragging(false)
2017-01-16 18:27:51 +01:00
, m_leftLabel()
, m_middleLabel()
, m_rightLabel()
, m_leftMenu(this)
, m_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-16 18:27:51 +01:00
setLayout(&m_hbox);
m_hbox.setMargin(0);
m_hbox.addWidget(&m_leftLabel);
m_hbox.addWidget(&m_middleLabel, 1);
m_hbox.addWidget(&m_rightLabel);
2017-01-15 16:38:30 +01:00
// left
2017-01-16 18:27:51 +01:00
m_leftLabel.label().setTextFormat(Qt::RichText);
m_leftLabel.label().setText(
2017-01-15 16:38:30 +01:00
"<img src=':/images/tool_moreCollapser_off16.png' />");
2017-01-16 18:27:51 +01:00
QObject::connect(&m_leftLabel, &ChatWidgetHeaderButton::clicked, this,
2017-01-15 17:12:19 +01:00
&ChatWidgetHeader::leftButtonClicked);
2017-01-15 16:38:30 +01:00
2017-01-17 00:15:44 +01:00
m_leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()),
QKeySequence(tr("Ctrl+T")));
m_leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()),
QKeySequence(tr("Ctrl+W")));
m_leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
m_leftMenu.addSeparator();
m_leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()),
QKeySequence(tr("Ctrl+R")));
m_leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
m_leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
m_leftMenu.addAction("Open pop-out player", this, SLOT(menuPopupPlayer()));
m_leftMenu.addSeparator();
m_leftMenu.addAction("Reload channel emotes", this,
SLOT(menuReloadChannelEmotes()));
m_leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
m_leftMenu.addSeparator();
m_leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
2017-01-15 16:38:30 +01:00
// middle
2017-01-16 18:27:51 +01:00
m_middleLabel.setAlignment(Qt::AlignCenter);
2017-01-17 00:15:44 +01:00
QObject::connect(&m_middleLabel, &m_middleLabel.mouseDoubleClickEvent, this,
&mouseDoubleClickEvent);
2017-01-15 16:38:30 +01:00
// right
2017-01-16 18:27:51 +01:00
m_rightLabel.setMinimumWidth(height());
m_rightLabel.label().setTextFormat(Qt::RichText);
m_rightLabel.label().setText("ayy");
2017-01-15 16:38:30 +01:00
}
void
ChatWidgetHeader::updateColors()
{
QPalette palette;
palette.setColor(QPalette::Foreground, ColorScheme::instance().Text);
2017-01-16 18:27:51 +01:00
m_leftLabel.setPalette(palette);
m_middleLabel.setPalette(palette);
m_rightLabel.setPalette(palette);
2017-01-01 02:30:42 +01:00
}
2017-01-17 00:15:44 +01:00
void
ChatWidgetHeader::updateChannelText()
{
const QString &c = m_chatWidget->channelName();
m_middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
}
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-15 16:38:30 +01:00
m_dragging = true;
2017-01-01 02:30:42 +01:00
2017-01-15 16:38:30 +01:00
m_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-15 16:38:30 +01:00
if (m_dragging) {
if (std::abs(m_dragStart.x() - event->pos().x()) > 12 ||
std::abs(m_dragStart.y() - event->pos().y()) > 12) {
2017-01-16 18:27:51 +01:00
auto chatWidget = m_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 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) {
chatWidget()->showChangeChannelPopup();
}
}
2017-01-15 16:38:30 +01:00
void
ChatWidgetHeader::leftButtonClicked()
{
2017-01-16 18:27:51 +01:00
m_leftMenu.move(m_leftLabel.mapToGlobal(QPoint(0, m_leftLabel.height())));
m_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-17 00:15:44 +01:00
m_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()
{
}