mirror-chatterino2/chatwidgetheader.cpp

195 lines
4.8 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-01 02:30:42 +01:00
ChatWidgetHeader::ChatWidgetHeader()
: QWidget()
2017-01-15 16:38:30 +01:00
, m_dragStart()
, m_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();
setLayout(&hbox);
hbox.setMargin(0);
hbox.addWidget(&leftLabel);
hbox.addWidget(&middleLabel, 1);
hbox.addWidget(&rightLabel);
// left
leftLabel.label().setTextFormat(Qt::RichText);
leftLabel.label().setText(
"<img src=':/images/tool_moreCollapser_off16.png' />");
2017-01-15 17:12:19 +01:00
QObject::connect(&leftLabel, &ChatWidgetHeaderButton::clicked, this,
&ChatWidgetHeader::leftButtonClicked);
2017-01-15 16:38:30 +01:00
2017-01-15 17:12:19 +01:00
leftMenu.addAction("Add new split", this, &ChatWidgetHeader::menuAddSplit,
2017-01-15 16:38:30 +01:00
QKeySequence(tr("Ctrl+T")));
2017-01-15 17:12:19 +01:00
leftMenu.addAction("Close split", this, &ChatWidgetHeader::menuCloseSplit,
2017-01-15 16:38:30 +01:00
QKeySequence(tr("Ctrl+W")));
2017-01-15 17:12:19 +01:00
leftMenu.addAction("Move split", this, &ChatWidgetHeader::menuMoveSplit);
2017-01-15 16:38:30 +01:00
leftMenu.addSeparator();
leftMenu.addAction("Change channel", this,
2017-01-15 17:12:19 +01:00
&ChatWidgetHeader::menuChangeChannel,
2017-01-15 16:38:30 +01:00
QKeySequence(tr("Ctrl+R")));
2017-01-15 17:12:19 +01:00
leftMenu.addAction("Clear chat", this, &ChatWidgetHeader::menuClearChat);
leftMenu.addAction("Open channel", this,
&ChatWidgetHeader::menuOpenChannel);
2017-01-15 16:38:30 +01:00
leftMenu.addAction("Open pop-out player", this,
2017-01-15 17:12:19 +01:00
&ChatWidgetHeader::menuPopupPlayer);
2017-01-15 16:38:30 +01:00
leftMenu.addSeparator();
leftMenu.addAction("Reload channel emotes", this,
2017-01-15 17:12:19 +01:00
&ChatWidgetHeader::menuReloadChannelEmotes);
2017-01-15 16:38:30 +01:00
leftMenu.addAction("Manual reconnect", this,
2017-01-15 17:12:19 +01:00
&ChatWidgetHeader::menuManualReconnect);
2017-01-15 16:38:30 +01:00
leftMenu.addSeparator();
leftMenu.addAction("Show changelog", this,
2017-01-15 17:12:19 +01:00
&ChatWidgetHeader::menuShowChangelog);
2017-01-15 16:38:30 +01:00
// middle
middleLabel.setAlignment(Qt::AlignCenter);
middleLabel.setText("textString");
// right
rightLabel.setMinimumWidth(height());
rightLabel.label().setTextFormat(Qt::RichText);
rightLabel.label().setText("ayy");
}
void
ChatWidgetHeader::updateColors()
{
QPalette palette;
palette.setColor(QPalette::Foreground, ColorScheme::instance().Text);
leftLabel.setPalette(palette);
middleLabel.setPalette(palette);
rightLabel.setPalette(palette);
2017-01-01 02:30:42 +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-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-01 02:30:42 +01:00
auto chatWidget = getChatWidget();
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-11 18:52:09 +01:00
ChatWidget *
ChatWidgetHeader::getChatWidget()
2017-01-01 02:30:42 +01:00
{
2017-01-11 18:52:09 +01:00
return static_cast<ChatWidget *>(parentWidget());
2017-01-01 02:30:42 +01:00
}
2017-01-15 16:38:30 +01:00
void
ChatWidgetHeader::leftButtonClicked()
{
leftMenu.move(leftLabel.mapToGlobal(QPoint(0, leftLabel.height())));
leftMenu.show();
}
void
ChatWidgetHeader::rightButtonClicked()
{
}
void
ChatWidgetHeader::menuAddSplit()
{
}
void
ChatWidgetHeader::menuCloseSplit()
{
}
void
ChatWidgetHeader::menuMoveSplit()
{
}
void
ChatWidgetHeader::menuChangeChannel()
{
}
void
ChatWidgetHeader::menuClearChat()
{
}
void
ChatWidgetHeader::menuOpenChannel()
{
}
void
ChatWidgetHeader::menuPopupPlayer()
{
}
void
ChatWidgetHeader::menuReloadChannelEmotes()
{
}
void
ChatWidgetHeader::menuManualReconnect()
{
}
void
ChatWidgetHeader::menuShowChangelog()
{
}