clean up chatwidgetheader more

This commit is contained in:
Rasmus Karlsson 2017-06-11 09:11:55 +02:00
parent 85356cdd6b
commit 961f22819e
4 changed files with 96 additions and 86 deletions

View file

@ -235,5 +235,28 @@ void ChatWidget::doChangeChannel()
this->showChangeChannelPopup(); this->showChangeChannelPopup();
} }
void ChatWidget::doPopup()
{
// TODO: Copy signals and stuff too
auto widget = new ChatWidget();
widget->setChannelName(this->getChannelName());
widget->show();
}
void ChatWidget::doClearChat()
{
qDebug() << "[UNIMPLEMENTED]: Clear chat";
}
void ChatWidget::doOpenChannel()
{
qDebug() << "[UNIMPLEMENTED]: Open twitch.tv/" << this->getChannelName();
}
void ChatWidget::doOpenPopupPlayer()
{
qDebug() << "[UNIMPLEMENTED]: Open twitch.tv/" << this->getChannelName() << "/popout";
}
} // namespace widgets } // namespace widgets
} // namespace chatterino } // namespace chatterino

View file

@ -82,6 +82,19 @@ public slots:
// Show a dialog for changing the current splits/chat widgets channel // Show a dialog for changing the current splits/chat widgets channel
void doChangeChannel(); void doChangeChannel();
// Open popup copy of this chat widget
// XXX: maybe make current chatwidget a popup instead?
void doPopup();
// Clear chat from all messages
void doClearChat();
// Open link to twitch channel in default browser
void doOpenChannel();
// Open popup player of twitch channel in default browser
void doOpenPopupPlayer();
}; };
} // namespace widgets } // namespace widgets

View file

@ -14,62 +14,55 @@ namespace widgets {
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget) ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
: QWidget(_chatWidget) : QWidget(_chatWidget)
, chatWidget(_chatWidget) , chatWidget(_chatWidget)
, _dragStart() , leftMenu(this)
, _dragging(false) , rightMenu(this)
, _leftLabel()
, _middleLabel()
, _rightLabel()
, _leftMenu(this)
, _rightMenu(this)
{ {
setFixedHeight(32); this->setFixedHeight(32);
updateColors(); this->updateColors();
updateChannelText(); this->updateChannelText();
setLayout(&_hbox); this->setLayout(&this->hbox);
_hbox.setMargin(0); this->hbox.setMargin(0);
_hbox.addWidget(&_leftLabel); this->hbox.addWidget(&this->leftLabel);
_hbox.addWidget(&_middleLabel, 1); this->hbox.addWidget(&this->channelNameLabel, 1);
_hbox.addWidget(&_rightLabel); this->hbox.addWidget(&this->rightLabel);
// left // left
_leftLabel.getLabel().setTextFormat(Qt::RichText); this->leftLabel.getLabel().setTextFormat(Qt::RichText);
_leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />"); this->leftLabel.getLabel().setText("<img src=':/images/tool_moreCollapser_off16.png' />");
QObject::connect(&_leftLabel, &ChatWidgetHeaderButton::clicked, this, connect(&this->leftLabel, &ChatWidgetHeaderButton::clicked, this,
&ChatWidgetHeader::leftButtonClicked); &ChatWidgetHeader::leftButtonClicked);
_leftMenu.addAction("Add new split", this->chatWidget, &ChatWidget::doAddSplit, this->leftMenu.addAction("Add new split", this->chatWidget, &ChatWidget::doAddSplit,
QKeySequence(tr("Ctrl+T"))); QKeySequence(tr("Ctrl+T")));
_leftMenu.addAction("Close split", this->chatWidget, &ChatWidget::doCloseSplit, this->leftMenu.addAction("Close split", this->chatWidget, &ChatWidget::doCloseSplit,
QKeySequence(tr("Ctrl+W"))); QKeySequence(tr("Ctrl+W")));
_leftMenu.addAction("Move split", this, SLOT(menuMoveSplit())); this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
_leftMenu.addAction("Popup", this, SLOT(menuPopup())); this->leftMenu.addAction("Popup", this->chatWidget, &ChatWidget::doPopup);
_leftMenu.addSeparator(); this->leftMenu.addSeparator();
_leftMenu.addAction("Change channel", this->chatWidget, &ChatWidget::doChangeChannel, this->leftMenu.addAction("Change channel", this->chatWidget, &ChatWidget::doChangeChannel,
QKeySequence(tr("Ctrl+R"))); QKeySequence(tr("Ctrl+R")));
_leftMenu.addAction("Clear chat", this, SLOT(menuClearChat())); this->leftMenu.addAction("Clear chat", this->chatWidget, &ChatWidget::doClearChat);
_leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel())); this->leftMenu.addAction("Open channel", this->chatWidget, &ChatWidget::doOpenChannel);
_leftMenu.addAction("Open pop-out player", this, SLOT(menuPopupPlayer())); this->leftMenu.addAction("Open popup player", this->chatWidget, &ChatWidget::doOpenPopupPlayer);
_leftMenu.addSeparator(); this->leftMenu.addSeparator();
_leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes())); this->leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
_leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect())); this->leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
_leftMenu.addSeparator(); this->leftMenu.addSeparator();
_leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog())); this->leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
// middle // middle
_middleLabel.setAlignment(Qt::AlignCenter); this->channelNameLabel.setAlignment(Qt::AlignCenter);
connect(&_middleLabel, &SignalLabel::mouseDoubleClick, this, connect(&this->channelNameLabel, &SignalLabel::mouseDoubleClick, this,
&ChatWidgetHeader::mouseDoubleClickEvent); &ChatWidgetHeader::mouseDoubleClickEvent);
// connect(&this->middleLabel, &SignalLabel::mouseDown, this,
// &ChatWidgetHeader::mouseDoubleClickEvent);
// right // right
_rightLabel.setMinimumWidth(height()); this->rightLabel.setMinimumWidth(this->height());
_rightLabel.getLabel().setTextFormat(Qt::RichText); this->rightLabel.getLabel().setTextFormat(Qt::RichText);
_rightLabel.getLabel().setText("ayy"); this->rightLabel.getLabel().setText("ayy");
} }
void ChatWidgetHeader::updateColors() void ChatWidgetHeader::updateColors()
@ -77,16 +70,16 @@ void ChatWidgetHeader::updateColors()
QPalette palette; QPalette palette;
palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text); palette.setColor(QPalette::Foreground, ColorScheme::getInstance().Text);
_leftLabel.setPalette(palette); this->leftLabel.setPalette(palette);
_middleLabel.setPalette(palette); this->channelNameLabel.setPalette(palette);
_rightLabel.setPalette(palette); this->rightLabel.setPalette(palette);
} }
void ChatWidgetHeader::updateChannelText() void ChatWidgetHeader::updateChannelText()
{ {
const QString &c = this->chatWidget->getChannelName(); const QString &c = this->chatWidget->getChannelName();
_middleLabel.setText(c.isEmpty() ? "<no channel>" : c); this->channelNameLabel.setText(c.isEmpty() ? "<no channel>" : c);
} }
void ChatWidgetHeader::paintEvent(QPaintEvent *) void ChatWidgetHeader::paintEvent(QPaintEvent *)
@ -100,16 +93,16 @@ void ChatWidgetHeader::paintEvent(QPaintEvent *)
void ChatWidgetHeader::mousePressEvent(QMouseEvent *event) void ChatWidgetHeader::mousePressEvent(QMouseEvent *event)
{ {
_dragging = true; this->dragging = true;
_dragStart = event->pos(); this->dragStart = event->pos();
} }
void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event) void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
{ {
if (_dragging) { if (this->dragging) {
if (std::abs(_dragStart.x() - event->pos().x()) > 12 || if (std::abs(this->dragStart.x() - event->pos().x()) > 12 ||
std::abs(_dragStart.y() - event->pos().y()) > 12) { std::abs(this->dragStart.y() - event->pos().y()) > 12) {
auto page = static_cast<NotebookPage *>(this->chatWidget->parentWidget()); auto page = static_cast<NotebookPage *>(this->chatWidget->parentWidget());
if (page != nullptr) { if (page != nullptr) {
@ -148,8 +141,8 @@ void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
void ChatWidgetHeader::leftButtonClicked() void ChatWidgetHeader::leftButtonClicked()
{ {
_leftMenu.move(_leftLabel.mapToGlobal(QPoint(0, _leftLabel.height()))); this->leftMenu.move(this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
_leftMenu.show(); this->leftMenu.show();
} }
void ChatWidgetHeader::rightButtonClicked() void ChatWidgetHeader::rightButtonClicked()
@ -160,25 +153,6 @@ void ChatWidgetHeader::menuMoveSplit()
{ {
} }
void ChatWidgetHeader::menuPopup()
{
auto widget = new ChatWidget();
widget->setChannelName(this->chatWidget->getChannelName());
widget->show();
}
void ChatWidgetHeader::menuClearChat()
{
}
void ChatWidgetHeader::menuOpenChannel()
{
}
void ChatWidgetHeader::menuPopupPlayer()
{
}
void ChatWidgetHeader::menuReloadChannelEmotes() void ChatWidgetHeader::menuReloadChannelEmotes()
{ {
} }

View file

@ -36,29 +36,29 @@ protected:
virtual void mouseDoubleClickEvent(QMouseEvent *event) override; virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
private: private:
ChatWidget *chatWidget; ChatWidget *const chatWidget;
QPoint _dragStart; QPoint dragStart;
bool _dragging; bool dragging = false;
QHBoxLayout _hbox; QHBoxLayout hbox;
ChatWidgetHeaderButton _leftLabel; // top left
SignalLabel _middleLabel; ChatWidgetHeaderButton leftLabel;
ChatWidgetHeaderButton _rightLabel; QMenu leftMenu;
QMenu _leftMenu; // center
QMenu _rightMenu; SignalLabel channelNameLabel;
// top right
ChatWidgetHeaderButton rightLabel;
QMenu rightMenu;
void leftButtonClicked(); void leftButtonClicked();
void rightButtonClicked(); void rightButtonClicked();
public slots: public slots:
void menuMoveSplit(); void menuMoveSplit();
void menuPopup();
void menuClearChat();
void menuOpenChannel();
void menuPopupPlayer();
void menuReloadChannelEmotes(); void menuReloadChannelEmotes();
void menuManualReconnect(); void menuManualReconnect();
void menuShowChangelog(); void menuShowChangelog();