improved user popup

This commit is contained in:
fourtf 2018-06-19 18:55:45 +02:00
parent 73a067f42f
commit 78b20776a8
7 changed files with 72 additions and 10 deletions

View file

@ -165,6 +165,8 @@ void BaseWindow::init()
void BaseWindow::setStayInScreenRect(bool value)
{
this->stayInScreenRect_ = value;
this->moveIntoDesktopRect(this);
}
bool BaseWindow::getStayInScreenRect() const
@ -231,6 +233,10 @@ bool BaseWindow::event(QEvent *event)
void BaseWindow::wheelEvent(QWheelEvent *event)
{
if (event->orientation() != Qt::Vertical) {
return;
}
if (event->modifiers() & Qt::ControlModifier) {
if (event->delta() > 0) {
getApp()->settings->uiScale.setValue(singletons::WindowManager::clampUiScale(
@ -316,7 +322,7 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent)
// move the widget into the screen geometry if it's not already in there
QDesktopWidget *desktop = QApplication::desktop();
QRect s = desktop->screenGeometry(parent);
QRect s = desktop->availableGeometry(parent);
QPoint p = this->pos();
if (p.x() < s.left()) {

View file

@ -563,7 +563,8 @@ messages::MessageElement::Flags ChannelView::getFlags() const
bool ChannelView::isPaused()
{
return this->pausedTemporarily_ || this->pausedBySelection_ || this->pausedByScrollingUp_;
return false;
// return this->pausedTemporarily_ || this->pausedBySelection_ || this->pausedByScrollingUp_;
}
void ChannelView::updatePauseStatus()
@ -659,6 +660,10 @@ void ChannelView::drawMessages(QPainter &painter)
void ChannelView::wheelEvent(QWheelEvent *event)
{
if (event->orientation() != Qt::Vertical) {
return;
}
this->pausedBySelection_ = false;
this->pausedTemporarily_ = false;
this->updatePauseStatus();

View file

@ -22,5 +22,26 @@ RippleEffectLabel::RippleEffectLabel(BaseWidget *parent, int spacing)
this->hbox.addSpacing(spacing);
}
RippleEffectLabel2::RippleEffectLabel2(BaseWidget *parent, int padding)
: RippleEffectButton(parent)
, label_(this)
{
auto *hbox = new QHBoxLayout(this);
this->setLayout(hbox);
// this->label_.setAlignment(Qt::AlignCenter);
this->label_.setCentered(true);
hbox->setMargin(0);
// hbox.addSpacing(spacing);
hbox->addWidget(&this->label_);
// hbox.addSpacing(spacing);
}
Label &RippleEffectLabel2::getLabel()
{
return this->label_;
}
} // namespace widgets
} // namespace chatterino

View file

@ -3,6 +3,7 @@
#include "widgets/basewidget.hpp"
#include "widgets/helper/rippleeffectbutton.hpp"
#include "widgets/helper/signallabel.hpp"
#include "widgets/label.hpp"
#include <QHBoxLayout>
#include <QLabel>
@ -27,5 +28,16 @@ private:
SignalLabel label;
};
class RippleEffectLabel2 : public RippleEffectButton
{
public:
explicit RippleEffectLabel2(BaseWidget *parent = nullptr, int padding = 6);
Label &getLabel();
private:
Label label_;
};
} // namespace widgets
} // namespace chatterino

View file

@ -104,6 +104,11 @@ void Label::paintEvent(QPaintEvent *)
QTextOption option(alignment);
option.setWrapMode(QTextOption::NoWrap);
painter.drawText(textRect, this->text_, option);
#if 0
painter.setPen(QColor(255, 0, 0));
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
#endif
}
void Label::updateSize()

View file

@ -23,7 +23,7 @@ public:
void setCentered(bool centered);
bool getHasOffset() const;
void setHasOffset(bool centered);
void setHasOffset(bool hasOffset);
protected:
virtual void scaleChangedEvent(float scale) override;

View file

@ -25,6 +25,8 @@ UserInfoPopup::UserInfoPopup()
: BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless | BaseWindow::DeleteOnFocusOut))
, hack_(new bool)
{
this->setStayInScreenRect(true);
auto app = getApp();
auto layout = util::LayoutCreator<UserInfoPopup>(this).setLayoutType<QVBoxLayout>();
@ -67,12 +69,17 @@ UserInfoPopup::UserInfoPopup()
auto mod = user.emplace<RippleEffectButton>(this);
mod->setPixmap(app->resources->buttons.mod);
mod->setScaleIndependantSize(30, 30);
auto unmod = user.emplace<RippleEffectLabel>();
auto unmod = user.emplace<RippleEffectButton>(this);
unmod->setPixmap(app->resources->buttons.unmod);
unmod->setScaleIndependantSize(30, 30);
user->addStretch(1);
QObject::connect(mod.getElement(), &RippleEffectButton::clicked,
[this] { this->channel_->sendMessage("/mod " + this->userName_); });
QObject::connect(unmod.getElement(), &RippleEffectButton::clicked,
[this] { this->channel_->sendMessage("/unmod " + this->userName_); });
// userstate
this->userStateChanged.connect([this, mod, unmod]() mutable {
providers::twitch::TwitchChannel *twitchChannel =
@ -301,7 +308,8 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
QColor color1(255, 255, 255, 80);
QColor color2(255, 255, 255, 0);
int buttonWidth = 32;
int buttonWidth = 24;
int buttonWidth2 = 32;
int buttonHeight = 32;
layout->setSpacing(16);
@ -312,6 +320,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1);
auto label = title.emplace<Label>(text);
label->setHasOffset(false);
label->setStyleSheet("color: #BBB");
title->addStretch(1);
@ -338,21 +347,25 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
title->addStretch(1);
auto label = title.emplace<Label>(title_);
label->setStyleSheet("color: #BBB");
label->setHasOffset(false);
title->addStretch(1);
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
hbox->setSpacing(0);
for (const auto &item : items) {
auto a = hbox.emplace<RippleEffectLabel>();
auto a = hbox.emplace<RippleEffectLabel2>();
a->getLabel().setText(std::get<0>(item));
a->setScaleIndependantSize(buttonWidth, buttonHeight);
if (std::get<0>(item).length() > 1) {
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
} else {
a->setScaleIndependantSize(buttonWidth, buttonHeight);
}
a->setBorderColor(color1);
// connect
QObject::connect(
*a, &RippleEffectLabel::clicked, [ this, timeout = std::get<1>(item) ] {
*a, &RippleEffectLabel2::clicked, [ this, timeout = std::get<1>(item) ] {
this->buttonClicked.invoke(std::make_pair(Action::Timeout, timeout));
});
}