Fixed stuff in user popup

This commit is contained in:
fourtf 2019-09-01 13:06:56 +02:00
parent b441e3e159
commit 5c0f81defd
8 changed files with 65 additions and 54 deletions

View file

@ -161,6 +161,8 @@ Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
{FontStyle::Tiny, {8, "Monospace", false, QFont::Normal}},
{FontStyle::UiMedium,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
{FontStyle::UiMediumBold,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Bold}},
{FontStyle::UiTabs,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
};

View file

@ -28,6 +28,7 @@ enum class FontStyle : uint8_t {
ChatVeryLarge,
UiMedium,
UiMediumBold,
UiTabs,
// don't remove this value

View file

@ -100,6 +100,8 @@ void Label::paintEvent(QPaintEvent *)
? Qt::AlignLeft | Qt::AlignVCenter
: Qt::AlignCenter;
painter.setBrush(this->palette().windowText());
QTextOption option(alignment);
option.setWrapMode(QTextOption::NoWrap);
painter.drawText(textRect, this->text_, option);

View file

@ -38,14 +38,14 @@ const QPixmap &Button::getPixmap() const
return this->pixmap_;
}
void Button::setDim(bool value)
void Button::setDim(Dim value)
{
this->dimPixmap_ = value;
this->update();
}
bool Button::getDim() const
Button::Dim Button::getDim() const
{
return this->dimPixmap_;
}
@ -76,7 +76,12 @@ bool Button::getEnableMargin() const
qreal Button::getCurrentDimAmount() const
{
return this->dimPixmap_ && !this->mouseOver_ ? 0.7 : 1;
if (this->dimPixmap_ == Dim::None || this->mouseOver_)
return 1;
else if (this->dimPixmap_ == Dim::Some)
return 0.7;
else
return 0.15;
}
void Button::setBorderColor(const QColor &color)
@ -113,14 +118,14 @@ void Button::paintEvent(QPaintEvent *)
painter.setRenderHint(QPainter::SmoothPixmapTransform);
if (!this->pixmap_.isNull())
{
if (!this->mouseOver_ && this->dimPixmap_ && this->enabled_)
{
painter.setOpacity(this->getCurrentDimAmount());
}
QRect rect = this->rect();
int s = this->enableMargin_ ? int(6 * this->scale()) : 0;
int margin = this->height() < 22 * this->scale() ? 3 : 6;
int s = this->enableMargin_ ? int(margin * this->scale()) : 0;
rect.moveLeft(s);
rect.setRight(rect.right() - s - s);

View file

@ -28,14 +28,16 @@ class Button : public BaseWidget
};
public:
enum class Dim { None, Some, Lots };
Button(BaseWidget *parent = nullptr);
void setMouseEffectColor(boost::optional<QColor> color);
void setPixmap(const QPixmap &pixmap_);
const QPixmap &getPixmap() const;
void setDim(bool value);
bool getDim() const;
void setDim(Dim value);
Dim getDim() const;
qreal getCurrentDimAmount() const;
void setEnable(bool value);
@ -76,7 +78,7 @@ private:
QColor borderColor_{};
QPixmap pixmap_{};
bool dimPixmap_{true};
Dim dimPixmap_{Dim::Some};
bool enableMargin_{true};
QPoint mousePos_{};
double hoverMultiplier_{0.0};

View file

@ -24,9 +24,23 @@
#define TEXT_FOLLOWERS "Followers: "
#define TEXT_VIEWS "Views: "
#define TEXT_CREATED "Created: "
#define TEXT_USER_ID "User ID: "
#define TEXT_USER_ID "ID: "
namespace chatterino {
namespace {
void addCopyableLabel(LayoutCreator<QHBoxLayout> box, Label **assign)
{
auto label = box.emplace<Label>().assign(assign);
auto button = box.emplace<Button>();
button->setPixmap(getApp()->resources->buttons.copyDark);
button->setScaleIndependantSize(18, 18);
button->setDim(Button::Dim::Lots);
QObject::connect(button.getElement(), &Button::leftClicked,
[label = label.getElement()] {
qApp->clipboard()->setText(label->getText());
});
};
} // namespace
UserInfoPopup::UserInfoPopup()
: BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless |
@ -51,6 +65,7 @@ UserInfoPopup::UserInfoPopup()
auto avatar =
head.emplace<Button>(nullptr).assign(&this->ui_.avatarButton);
avatar->setScaleIndependantSize(100, 100);
avatar->setDim(Button::Dim::None);
QObject::connect(avatar.getElement(), &Button::leftClicked, [this] {
QDesktopServices::openUrl(
QUrl("https://twitch.tv/" + this->userName_.toLower()));
@ -59,50 +74,24 @@ UserInfoPopup::UserInfoPopup()
// items on the right
auto vbox = head.emplace<QVBoxLayout>();
{
auto name_box = vbox.emplace<QHBoxLayout>();
name_box.withoutMargin();
auto name = name_box.emplace<Label>().assign(&this->ui_.nameLabel);
LayoutCreator<EffectLabel2> copyUserName =
name_box.emplace<EffectLabel2>(this);
copyUserName->setPixmap(app->resources->buttons.copyDark);
// TODO(mm2pl): change this when the card get themed.
copyUserName->setScaleIndependantSize(32, 32);
auto font = name->font();
font.setBold(true);
name->setFont(font);
name_box->addStretch(1);
QObject::connect(
copyUserName.getElement(), &Button::leftClicked, [this] {
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(this->userName_);
});
{
auto box = vbox.emplace<QHBoxLayout>()
.withoutMargin()
.withoutSpacing();
addCopyableLabel(box, &this->ui_.nameLabel);
this->ui_.nameLabel->setFontStyle(FontStyle::UiMediumBold);
box->addStretch(1);
addCopyableLabel(box, &this->ui_.userIDLabel);
auto palette = QPalette();
palette.setColor(QPalette::WindowText, QColor("#aaa"));
this->ui_.userIDLabel->setPalette(palette);
}
vbox.emplace<Label>(TEXT_VIEWS).assign(&this->ui_.viewCountLabel);
vbox.emplace<Label>(TEXT_FOLLOWERS)
.assign(&this->ui_.followerCountLabel);
vbox.emplace<Label>(TEXT_CREATED)
.assign(&this->ui_.createdDateLabel);
auto userIDBox = vbox.emplace<QHBoxLayout>().withoutMargin();
userIDBox.emplace<Label>(TEXT_USER_ID)
.assign(&this->ui_.userIDLabel);
LayoutCreator<EffectLabel2> copyUserID =
userIDBox.emplace<EffectLabel2>(this);
copyUserID->setPixmap(app->resources->buttons.copyDark);
// this will need to be changed too if there will be theming.
copyUserID->setScaleIndependantSize(32, 32);
userIDBox->addStretch(1);
QObject::connect(
copyUserID.getElement(), &Button::leftClicked, [this] {
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(this->userId_);
});
}
}
@ -234,7 +223,7 @@ UserInfoPopup::UserInfoPopup()
});
}
this->setStyleSheet("font-size: 11pt;");
// this->setStyleSheet("font-size: 11pt;");
this->installEvents();
}
@ -243,7 +232,17 @@ void UserInfoPopup::themeChangedEvent()
{
BaseWindow::themeChangedEvent();
this->setStyleSheet("background: #333");
this->setStyleSheet(
"background: #333; font-size: " +
QString::number(getFonts()
->getFont(FontStyle::UiMediumBold, this->scale())
.pixelSize()) +
"px;");
}
void UserInfoPopup::scaleChangedEvent(float /*scale*/)
{
themeChangedEvent();
}
void UserInfoPopup::installEvents()

View file

@ -23,6 +23,7 @@ public:
protected:
virtual void themeChangedEvent() override;
virtual void scaleChangedEvent(float scale) override;
private:
void installEvents();

View file

@ -189,7 +189,6 @@ void SplitHeader::initializeLayout()
SettingsDialogPreference::
ModerationActions);
this->split_->setModerationMode(true);
w->setDim(true);
}
else
{
@ -198,7 +197,7 @@ void SplitHeader::initializeLayout()
this->split_->setModerationMode(
!moderationMode);
w->setDim(moderationMode);
w->setDim(Button::Dim(moderationMode));
}
break;