fixed split header tooltips not showing

This commit is contained in:
fourtf 2018-05-26 16:31:43 +02:00
parent 08cf701af3
commit 6b24f249f7
8 changed files with 46 additions and 28 deletions

View file

@ -48,7 +48,7 @@ int MessageLayout::getHeight() const
// return true if redraw is required // return true if redraw is required
bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
{ {
BenchmarkGuard benchmark("MessageLayout::layout()"); // BenchmarkGuard benchmark("MessageLayout::layout()");
auto app = getApp(); auto app = getApp();
@ -107,7 +107,6 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
} }
// return if no layout is required // return if no layout is required
qDebug() << layoutRequired;
if (!layoutRequired) { if (!layoutRequired) {
return false; return false;

View file

@ -325,6 +325,11 @@ void TwitchChannel::refreshLiveStatus()
QString::number(diff / 3600) + "h " + QString::number(diff % 3600 / 60) + "m"; QString::number(diff / 3600) + "h " + QString::number(diff % 3600 / 60) + "m";
channel->streamStatus.rerun = false; channel->streamStatus.rerun = false;
if (stream.HasMember("stream_type")) {
channel->streamStatus.streamType = stream["stream_type"].GetString();
} else {
channel->streamStatus.streamType = QString();
}
if (stream.HasMember("broadcast_platform")) { if (stream.HasMember("broadcast_platform")) {
const auto &broadcastPlatformValue = stream["broadcast_platform"]; const auto &broadcastPlatformValue = stream["broadcast_platform"];

View file

@ -32,6 +32,7 @@ public:
QString title; QString title;
QString game; QString game;
QString uptime; QString uptime;
QString streamType;
}; };
struct UserState { struct UserState {

View file

@ -18,7 +18,7 @@ class BaseWidget : public QWidget
public: public:
explicit BaseWidget(QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags()); explicit BaseWidget(QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags());
virtual ~BaseWidget(); virtual ~BaseWidget() override;
float getScale() const; float getScale() const;
pajlada::Signals::Signal<float> scaleChanged; pajlada::Signals::Signal<float> scaleChanged;

View file

@ -253,8 +253,8 @@ void BaseWindow::leaveEvent(QEvent *)
void BaseWindow::moveTo(QWidget *parent, QPoint point) void BaseWindow::moveTo(QWidget *parent, QPoint point)
{ {
point.rx() += 16; // point.rx() += 16;
point.ry() += 16; // point.ry() += 16;
this->move(point); this->move(point);
this->moveIntoDesktopRect(parent); this->moveIntoDesktopRect(parent);

View file

@ -175,7 +175,7 @@ void ChannelView::layoutMessages()
void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
{ {
BenchmarkGuard benchmark("layout messages"); // BenchmarkGuard benchmark("layout messages");
auto app = getApp(); auto app = getApp();
@ -579,7 +579,7 @@ bool ChannelView::isPaused()
void ChannelView::paintEvent(QPaintEvent * /*event*/) void ChannelView::paintEvent(QPaintEvent * /*event*/)
{ {
BenchmarkGuard benchmark("paint event"); // BenchmarkGuard benchmark("paint event");
QPainter painter(this); QPainter painter(this);

View file

@ -31,7 +31,6 @@ SplitHeader::SplitHeader(Split *_split)
, split(_split) , split(_split)
{ {
auto app = getApp(); auto app = getApp();
this->setMouseTracking(true);
util::LayoutCreator<SplitHeader> layoutCreator(this); util::LayoutCreator<SplitHeader> layoutCreator(this);
auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin(); auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin();
@ -53,13 +52,13 @@ SplitHeader::SplitHeader(Split *_split)
// channel name label // channel name label
// auto title = layout.emplace<Label>(this).assign(&this->titleLabel); // auto title = layout.emplace<Label>(this).assign(&this->titleLabel);
auto title = layout.emplace<SignalLabel>().assign(&this->titleLabel); auto title = layout.emplace<QLabel>().assign(&this->titleLabel);
title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
title->setMouseTracking(true); // title->setMouseTracking(true);
QObject::connect(this->titleLabel, &SignalLabel::mouseDoubleClick, this, // QObject::connect(this->titleLabel, &SignalLabel::mouseDoubleClick, this,
&SplitHeader::mouseDoubleClickEvent); // &SplitHeader::mouseDoubleClickEvent);
QObject::connect(this->titleLabel, &SignalLabel::mouseMove, this, // QObject::connect(this->titleLabel, &SignalLabel::mouseMove, this,
&SplitHeader::mouseMoveEvent); // &SplitHeader::mouseMoveEvent);
layout->addStretch(1); layout->addStretch(1);
@ -94,6 +93,8 @@ SplitHeader::SplitHeader(Split *_split)
this->split->channelChanged.connect([this]() { this->split->channelChanged.connect([this]() {
this->initializeChannelSignals(); // this->initializeChannelSignals(); //
}); });
this->setMouseTracking(true);
} }
SplitHeader::~SplitHeader() SplitHeader::~SplitHeader()
@ -101,7 +102,7 @@ SplitHeader::~SplitHeader()
this->onlineStatusChangedConnection.disconnect(); this->onlineStatusChangedConnection.disconnect();
} }
void SplitHeader::addDropdownItems(RippleEffectButton *label) void SplitHeader::addDropdownItems(RippleEffectButton *)
{ {
// clang-format off // clang-format off
this->dropdownMenu.addAction("Add new split", this->split, &Split::doAddSplit, QKeySequence(tr("Ctrl+T"))); this->dropdownMenu.addAction("Add new split", this->split, &Split::doAddSplit, QKeySequence(tr("Ctrl+T")));
@ -178,7 +179,7 @@ void SplitHeader::updateChannelText()
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()); TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel != nullptr) { if (twitchChannel != nullptr) {
const auto &streamStatus = twitchChannel->getStreamStatus(); const auto streamStatus = twitchChannel->getStreamStatus();
if (streamStatus.live) { if (streamStatus.live) {
this->isLive = true; this->isLive = true;
@ -192,9 +193,13 @@ void SplitHeader::updateChannelText()
"</p>"; "</p>";
if (streamStatus.rerun) { if (streamStatus.rerun) {
title += " (rerun)"; title += " (rerun)";
} else if (streamStatus.streamType.isEmpty()) {
title += " (" + streamStatus.streamType + ")";
} else { } else {
title += " (live)"; title += " (live)";
} }
} else {
this->tooltip = QString();
} }
} }
@ -327,17 +332,9 @@ void SplitHeader::mouseReleaseEvent(QMouseEvent *event)
void SplitHeader::mouseMoveEvent(QMouseEvent *event) void SplitHeader::mouseMoveEvent(QMouseEvent *event)
{ {
if (!this->dragging && this->isLive) {
auto tooltipWidget = TooltipWidget::getInstance();
tooltipWidget->moveTo(this, event->globalPos());
tooltipWidget->setText(tooltip);
tooltipWidget->show();
tooltipWidget->raise();
}
if (this->dragging) { if (this->dragging) {
if (std::abs(this->dragStart.x() - event->pos().x()) > (int)(12 * this->getScale()) || if (std::abs(this->dragStart.x() - event->pos().x()) > int(12 * this->getScale()) ||
std::abs(this->dragStart.y() - event->pos().y()) > (int)(12 * this->getScale())) { std::abs(this->dragStart.y() - event->pos().y()) > int(12 * this->getScale())) {
this->split->drag(); this->split->drag();
this->dragging = false; this->dragging = false;
} }
@ -352,11 +349,26 @@ void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event)
this->doubleClicked = true; this->doubleClicked = true;
} }
void SplitHeader::enterEvent(QEvent *event)
{
if (!this->tooltip.isEmpty()) {
auto tooltipWidget = TooltipWidget::getInstance();
tooltipWidget->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()));
tooltipWidget->setText(this->tooltip);
tooltipWidget->show();
tooltipWidget->raise();
}
BaseWidget::enterEvent(event);
}
void SplitHeader::leaveEvent(QEvent *event) void SplitHeader::leaveEvent(QEvent *event)
{ {
TooltipWidget::getInstance()->hide(); TooltipWidget::getInstance()->hide();
BaseWidget::leaveEvent(event); BaseWidget::leaveEvent(event);
} }
void SplitHeader::rightButtonClicked() void SplitHeader::rightButtonClicked()
{ {
} }

View file

@ -29,7 +29,7 @@ class SplitHeader : public BaseWidget
public: public:
explicit SplitHeader(Split *_chatWidget); explicit SplitHeader(Split *_chatWidget);
virtual ~SplitHeader(); virtual ~SplitHeader() override;
// Update channel text from chat widget // Update channel text from chat widget
void updateChannelText(); void updateChannelText();
@ -44,6 +44,7 @@ protected:
virtual void mousePressEvent(QMouseEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override; virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override; virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *event) override; virtual void leaveEvent(QEvent *event) override;
virtual void mouseDoubleClickEvent(QMouseEvent *event) override; virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
@ -59,7 +60,7 @@ private:
RippleEffectButton *dropdownButton; RippleEffectButton *dropdownButton;
// Label *titleLabel; // Label *titleLabel;
SignalLabel *titleLabel; QLabel *titleLabel;
RippleEffectLabel *modeButton; RippleEffectLabel *modeButton;
RippleEffectButton *moderationButton; RippleEffectButton *moderationButton;