added ui scaling

This commit is contained in:
fourtf
2018-06-11 15:04:54 +02:00
parent 9b26fce781
commit ea9f9e7f18
27 changed files with 488 additions and 271 deletions
+5
View File
@@ -660,6 +660,11 @@ void ChannelView::drawMessages(QPainter &painter)
void ChannelView::wheelEvent(QWheelEvent *event)
{
if (event->modifiers() & Qt::ControlModifier) {
event->ignore();
return;
}
this->pausedBySelection = false;
this->pausedTemporarily = false;
-86
View File
@@ -1,86 +0,0 @@
#include "label.hpp"
#include "application.hpp"
#include "singletons/fontmanager.hpp"
#include <QPainter>
namespace chatterino {
namespace widgets {
Label::Label(BaseWidget *parent)
: BaseWidget(parent)
{
auto app = getApp();
app->fonts->fontChanged.connect([=]() {
this->scaleChangedEvent(this->getScale()); //
});
}
const QString &Label::getText() const
{
return this->text;
}
void Label::setText(const QString &value)
{
this->text = value;
this->scaleChangedEvent(this->getScale());
}
FontStyle Label::getFontStyle() const
{
return this->fontStyle;
}
void Label::setFontStyle(FontStyle style)
{
this->fontStyle = style;
this->scaleChangedEvent(this->getScale());
}
void Label::scaleChangedEvent(float scale)
{
auto app = getApp();
QFontMetrics metrics = app->fonts->getFontMetrics(this->fontStyle, scale);
this->preferedSize = QSize(metrics.width(this->text), metrics.height());
this->updateGeometry();
}
QSize Label::sizeHint() const
{
return this->preferedSize;
}
QSize Label::minimumSizeHint() const
{
return this->preferedSize;
}
void Label::paintEvent(QPaintEvent *)
{
auto app = getApp();
QPainter painter(this);
painter.setFont(app->fonts->getFont(this->fontStyle,
this->getScale() / painter.device()->devicePixelRatioF()));
int width = app->fonts->getFontMetrics(this->fontStyle, this->getScale()).width(this->text);
int flags = Qt::TextSingleLine;
if (this->width() < width) {
flags |= Qt::AlignLeft | Qt::AlignVCenter;
} else {
flags |= Qt::AlignCenter;
}
painter.drawText(this->rect(), flags, this->text);
}
} // namespace widgets
} // namespace chatterino
-34
View File
@@ -1,34 +0,0 @@
#pragma once
#include "singletons/fontmanager.hpp"
#include "widgets/basewidget.hpp"
namespace chatterino {
namespace widgets {
class Label : public BaseWidget
{
public:
Label(BaseWidget *parent);
const QString &getText() const;
void setText(const QString &text);
FontStyle getFontStyle() const;
void setFontStyle(FontStyle style);
protected:
virtual void scaleChangedEvent(float scale) override;
virtual void paintEvent(QPaintEvent *event) override;
virtual QSize sizeHint() const override;
virtual QSize minimumSizeHint() const override;
private:
QSize preferedSize;
QString text;
FontStyle fontStyle = FontStyle::ChatMedium;
};
} // namespace widgets
} // namespace chatterino
+4 -3
View File
@@ -5,6 +5,7 @@
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp"
#include "util/clamp.hpp"
#include "util/helpers.hpp"
#include "widgets/notebook.hpp"
#include "widgets/settingsdialog.hpp"
@@ -78,12 +79,12 @@ void NotebookTab::updateSize()
FontStyle::UiTabs, float(qreal(this->getScale()) * this->devicePixelRatioF()));
if (this->hasXButton()) {
width = int((metrics.width(this->getTitle()) + 32) * scale);
width = (metrics.width(this->getTitle()) + int(32 * scale));
} else {
width = int((metrics.width(this->getTitle()) + 16) * scale);
width = (metrics.width(this->getTitle()) + int(16 * scale));
}
width = std::max<int>(this->height(), std::min(int(150 * scale), width));
width = util::clamp(width, this->height(), int(150 * scale));
if (this->width() != width) {
this->resize(width, int(NOTEBOOK_TAB_HEIGHT * scale));
+4 -12
View File
@@ -7,7 +7,7 @@
#include "singletons/thememanager.hpp"
#include "util/layoutcreator.hpp"
#include "util/urlfetch.hpp"
#include "widgets/helper/label.hpp"
#include "widgets/label.hpp"
#include "widgets/split.hpp"
#include "widgets/splitcontainer.hpp"
#include "widgets/tooltipwidget.hpp"
@@ -48,19 +48,11 @@ SplitHeader::SplitHeader(Split *_split)
});
});
layout->addStretch(1);
// channel name label
// auto title = layout.emplace<Label>(this).assign(&this->titleLabel);
auto title = layout.emplace<QLabel>().assign(&this->titleLabel);
auto title = layout.emplace<Label>().assign(&this->titleLabel);
title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// title->setMouseTracking(true);
// QObject::connect(this->titleLabel, &SignalLabel::mouseDoubleClick, this,
// &SplitHeader::mouseDoubleClickEvent);
// QObject::connect(this->titleLabel, &SignalLabel::mouseMove, this,
// &SplitHeader::mouseMoveEvent);
layout->addStretch(1);
title->setCentered(true);
title->setHasOffset(false);
// mode button
auto mode = layout.emplace<RippleEffectLabel>(this).assign(&this->modeButton);
+2 -2
View File
@@ -1,7 +1,6 @@
#pragma once
#include "widgets/basewidget.hpp"
#include "widgets/helper/label.hpp"
#include "widgets/helper/rippleeffectlabel.hpp"
#include "widgets/helper/signallabel.hpp"
@@ -23,6 +22,7 @@ namespace chatterino {
namespace widgets {
class Split;
class Label;
class SplitHeader : public BaseWidget, pajlada::Signals::SignalHolder
{
@@ -61,7 +61,7 @@ private:
RippleEffectButton *dropdownButton;
// Label *titleLabel;
QLabel *titleLabel;
Label *titleLabel;
RippleEffectLabel *modeButton;
RippleEffectButton *moderationButton;
+1
View File
@@ -112,6 +112,7 @@ void SplitInput::scaleChangedEvent(float scale)
// set maximum height
this->setMaximumHeight(int(150 * this->getScale()));
this->ui_.textEdit->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale()));
}
void SplitInput::themeRefreshEvent()