added stuff related to scaling

This commit is contained in:
fourtf 2018-06-11 21:57:17 +02:00
parent 66e1952603
commit 866f868b54
9 changed files with 48 additions and 27 deletions

View file

@ -115,8 +115,9 @@ void NotebookButton::mouseReleaseEvent(QMouseEvent *event)
void NotebookButton::dragEnterEvent(QDragEnterEvent *event) void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
{ {
if (!event->mimeData()->hasFormat("chatterino/split")) if (!event->mimeData()->hasFormat("chatterino/split")) {
return; return;
}
event->acceptProposedAction(); event->acceptProposedAction();

View file

@ -22,7 +22,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
NotebookTab::NotebookTab(Notebook *notebook) NotebookTab::NotebookTab(Notebook *notebook)
: BaseWidget(notebook) : RippleEffectButton(notebook)
, positionChangedAnimation_(this, "pos") , positionChangedAnimation_(this, "pos")
, notebook_(notebook) , notebook_(notebook)
, menu_(this) , menu_(this)
@ -68,6 +68,9 @@ NotebookTab::NotebookTab(Notebook *notebook)
void NotebookTab::themeRefreshEvent() void NotebookTab::themeRefreshEvent()
{ {
this->update(); this->update();
// this->setMouseEffectColor(QColor("#999"));
this->setMouseEffectColor(this->themeManager->tabs.regular.text);
} }
void NotebookTab::updateSize() void NotebookTab::updateSize()
@ -234,9 +237,9 @@ void NotebookTab::paintEvent(QPaintEvent *)
bool windowFocused = this->window() == QApplication::activeWindow(); bool windowFocused = this->window() == QApplication::activeWindow();
// || SettingsDialog::getHandle() == QApplication::activeWindow(); // || SettingsDialog::getHandle() == QApplication::activeWindow();
QBrush tabBackground = this->mouseOver_ ? colors.backgrounds.hover QBrush tabBackground = /*this->mouseOver_ ? colors.backgrounds.hover
: (windowFocused ? colors.backgrounds.regular :*/ (windowFocused ? colors.backgrounds.regular
: colors.backgrounds.unfocused); : colors.backgrounds.unfocused);
// painter.fillRect(rect(), this->mouseOver_ ? regular.backgrounds.hover // painter.fillRect(rect(), this->mouseOver_ ? regular.backgrounds.hover
// : (windowFocused ? regular.backgrounds.regular // : (windowFocused ? regular.backgrounds.regular
@ -312,6 +315,8 @@ void NotebookTab::paintEvent(QPaintEvent *)
// draw line at bottom // draw line at bottom
if (!this->selected_) { if (!this->selected_) {
painter.fillRect(0, this->height() - 1, this->width(), 1, app->themes->window.background); painter.fillRect(0, this->height() - 1, this->width(), 1, app->themes->window.background);
this->fancyPaint(painter);
} }
} }
@ -373,19 +378,23 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
} }
} }
void NotebookTab::enterEvent(QEvent *) void NotebookTab::enterEvent(QEvent *event)
{ {
this->mouseOver_ = true; this->mouseOver_ = true;
this->update(); this->update();
RippleEffectButton::enterEvent(event);
} }
void NotebookTab::leaveEvent(QEvent *) void NotebookTab::leaveEvent(QEvent *event)
{ {
this->mouseOverX_ = false; this->mouseOverX_ = false;
this->mouseOver_ = false; this->mouseOver_ = false;
this->update(); this->update();
RippleEffectButton::leaveEvent(event);
} }
void NotebookTab::dragEnterEvent(QDragEnterEvent *event) void NotebookTab::dragEnterEvent(QDragEnterEvent *event)
@ -429,6 +438,8 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event)
this->notebook_->rearrangePage(this->page, index); this->notebook_->rearrangePage(this->page, index);
} }
} }
RippleEffectButton::mouseMoveEvent(event);
} }
QRect NotebookTab::getXRect() QRect NotebookTab::getXRect()

View file

@ -2,6 +2,7 @@
#include "common.hpp" #include "common.hpp"
#include "widgets/basewidget.hpp" #include "widgets/basewidget.hpp"
#include "widgets/helper/rippleeffectbutton.hpp"
#include <QMenu> #include <QMenu>
#include <QPropertyAnimation> #include <QPropertyAnimation>
@ -17,7 +18,7 @@ namespace widgets {
class Notebook; class Notebook;
class SplitContainer; class SplitContainer;
class NotebookTab : public BaseWidget class NotebookTab : public RippleEffectButton
{ {
Q_OBJECT Q_OBJECT

View file

@ -88,7 +88,7 @@ void RippleEffectButton::fancyPaint(QPainter &painter)
QRadialGradient gradient(QPointF(mousePos_), this->width() / 2); QRadialGradient gradient(QPointF(mousePos_), this->width() / 2);
gradient.setColorAt(0, gradient.setColorAt(0,
QColor(c.red(), c.green(), c.blue(), int(60 * this->hoverMultiplier_))); QColor(c.red(), c.green(), c.blue(), int(50 * this->hoverMultiplier_)));
gradient.setColorAt(1, gradient.setColorAt(1,
QColor(c.red(), c.green(), c.blue(), int(40 * this->hoverMultiplier_))); QColor(c.red(), c.green(), c.blue(), int(40 * this->hoverMultiplier_)));
@ -97,7 +97,7 @@ void RippleEffectButton::fancyPaint(QPainter &painter)
for (auto effect : this->clickEffects_) { for (auto effect : this->clickEffects_) {
QRadialGradient gradient(effect.position.x(), effect.position.y(), QRadialGradient gradient(effect.position.x(), effect.position.y(),
effect.progress * float(width()) * 2, effect.position.x(), effect.progress * qreal(width()) * 2, effect.position.x(),
effect.position.y()); effect.position.y());
gradient.setColorAt(0, gradient.setColorAt(0,

View file

@ -91,7 +91,7 @@ void Label::paintEvent(QPaintEvent *)
painter.setFont( painter.setFont(
app->fonts->getFont(this->getFontStyle(), this->getScale() * this->devicePixelRatioF())); app->fonts->getFont(this->getFontStyle(), this->getScale() * this->devicePixelRatioF()));
int offset = this->hasOffset_ ? int(8 * this->getScale()) : 0; int offset = this->getOffset();
// draw text // draw text
QRect textRect(offset, 0, this->width() - offset - offset, this->height()); QRect textRect(offset, 0, this->width() - offset - offset, this->height());
@ -112,10 +112,17 @@ void Label::updateSize()
QFontMetrics metrics = app->fonts->getFontMetrics(this->fontStyle_, this->getScale()); QFontMetrics metrics = app->fonts->getFontMetrics(this->fontStyle_, this->getScale());
this->preferedSize_ = QSize(metrics.width(this->text_), metrics.height()); int width = metrics.width(this->text_) + (2 * this->getOffset());
int height = metrics.height();
this->preferedSize_ = QSize(width, height);
this->updateGeometry(); this->updateGeometry();
} }
int Label::getOffset()
{
return this->hasOffset_ ? int(8 * this->getScale()) : 0;
}
} // namespace widgets } // namespace widgets
} // namespace chatterino } // namespace chatterino

View file

@ -40,6 +40,7 @@ private:
bool hasOffset_ = true; bool hasOffset_ = true;
void updateSize(); void updateSize();
int getOffset();
}; };
} // namespace widgets } // namespace widgets

View file

@ -340,7 +340,7 @@ void Notebook::performLayout(bool animated)
x += i->tab->width(); x += i->tab->width();
} }
x += int(scale * 2); x += int(scale * 1);
first = false; first = false;
} }

View file

@ -8,6 +8,7 @@
#include "util/urlfetch.hpp" #include "util/urlfetch.hpp"
#include "widgets/helper/line.hpp" #include "widgets/helper/line.hpp"
#include "widgets/helper/rippleeffectlabel.hpp" #include "widgets/helper/rippleeffectlabel.hpp"
#include "widgets/label.hpp"
#include <QCheckBox> #include <QCheckBox>
#include <QDesktopServices> #include <QDesktopServices>
@ -32,9 +33,8 @@ UserInfoPopup::UserInfoPopup()
auto head = layout.emplace<QHBoxLayout>().withoutMargin(); auto head = layout.emplace<QHBoxLayout>().withoutMargin();
{ {
// avatar // avatar
// auto avatar = head.emplace<QLabel>("Avatar").assign(&this->ui_.avatarButtoAn);
auto avatar = head.emplace<RippleEffectButton>(nullptr).assign(&this->ui_.avatarButton); auto avatar = head.emplace<RippleEffectButton>(nullptr).assign(&this->ui_.avatarButton);
avatar->setFixedSize(100, 100); avatar->setScaleIndependantSize(100, 100);
QObject::connect(*avatar, &RippleEffectButton::clicked, [this] { QObject::connect(*avatar, &RippleEffectButton::clicked, [this] {
QDesktopServices::openUrl(QUrl("https://twitch.tv/" + this->userName_)); QDesktopServices::openUrl(QUrl("https://twitch.tv/" + this->userName_));
}); });
@ -42,14 +42,14 @@ UserInfoPopup::UserInfoPopup()
// items on the right // items on the right
auto vbox = head.emplace<QVBoxLayout>(); auto vbox = head.emplace<QVBoxLayout>();
{ {
auto name = vbox.emplace<QLabel>().assign(&this->ui_.nameLabel); auto name = vbox.emplace<Label>().assign(&this->ui_.nameLabel);
auto font = name->font(); auto font = name->font();
font.setBold(true); font.setBold(true);
name->setFont(font); name->setFont(font);
vbox.emplace<QLabel>(TEXT_VIEWS).assign(&this->ui_.viewCountLabel); vbox.emplace<Label>(TEXT_VIEWS).assign(&this->ui_.viewCountLabel);
vbox.emplace<QLabel>(TEXT_FOLLOWERS).assign(&this->ui_.followerCountLabel); vbox.emplace<Label>(TEXT_FOLLOWERS).assign(&this->ui_.followerCountLabel);
vbox.emplace<QLabel>(TEXT_CREATED).assign(&this->ui_.createdDateLabel); vbox.emplace<Label>(TEXT_CREATED).assign(&this->ui_.createdDateLabel);
} }
} }
@ -302,7 +302,6 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
QColor color2(255, 255, 255, 0); QColor color2(255, 255, 255, 0);
int buttonWidth = 32; int buttonWidth = 32;
int buttonWidth2 = 24;
int buttonHeight = 32; int buttonHeight = 32;
layout->setSpacing(16); layout->setSpacing(16);
@ -312,7 +311,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
{ {
auto title = vbox.emplace<QHBoxLayout>().withoutMargin(); auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1); title->addStretch(1);
auto label = title.emplace<QLabel>(text); auto label = title.emplace<Label>(text);
label->setStyleSheet("color: #BBB"); label->setStyleSheet("color: #BBB");
title->addStretch(1); title->addStretch(1);
@ -337,7 +336,7 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
{ {
auto title = vbox.emplace<QHBoxLayout>().withoutMargin(); auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
title->addStretch(1); title->addStretch(1);
auto label = title.emplace<QLabel>(title_); auto label = title.emplace<Label>(title_);
label->setStyleSheet("color: #BBB"); label->setStyleSheet("color: #BBB");
title->addStretch(1); title->addStretch(1);

View file

@ -5,12 +5,13 @@
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
class QLabel;
class QCheckBox; class QCheckBox;
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
class Label;
class UserInfoPopup final : public BaseWindow class UserInfoPopup final : public BaseWindow
{ {
Q_OBJECT Q_OBJECT
@ -43,10 +44,10 @@ private:
struct { struct {
RippleEffectButton *avatarButton = nullptr; RippleEffectButton *avatarButton = nullptr;
QLabel *nameLabel = nullptr; Label *nameLabel = nullptr;
QLabel *viewCountLabel = nullptr; Label *viewCountLabel = nullptr;
QLabel *followerCountLabel = nullptr; Label *followerCountLabel = nullptr;
QLabel *createdDateLabel = nullptr; Label *createdDateLabel = nullptr;
QCheckBox *follow = nullptr; QCheckBox *follow = nullptr;
QCheckBox *ignore = nullptr; QCheckBox *ignore = nullptr;