mirror-chatterino2/src/widgets/chatwidgetheader.cpp

170 lines
5.1 KiB
C++
Raw Normal View History

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-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)
: QWidget(_chatWidget)
, chatWidget(_chatWidget)
2017-06-11 09:11:55 +02:00
, leftMenu(this)
, 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-06-11 09:11:55 +02:00
this->updateColors();
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-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::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-06-11 09:11:55 +02:00
this->leftLabel.setPalette(palette);
this->channelNameLabel.setPalette(palette);
this->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-06-10 22:48:28 +02:00
const QString &c = this->chatWidget->getChannelName();
2017-01-17 00:15:44 +01:00
2017-06-11 09:11:55 +02:00
this->channelNameLabel.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-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-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-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::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
{
}
} // namespace widgets
} // namespace chatterino