This commit is contained in:
fourtf 2018-05-25 12:13:09 +02:00
commit d775123ed0
7 changed files with 54 additions and 13 deletions

View file

@ -26,6 +26,11 @@ equals(QMAKE_CXX, "clang++")|equals(QMAKE_CXX, "g++") {
macx:ICON = resources/images/chatterino2.icns macx:ICON = resources/images/chatterino2.icns
win32:RC_FILE = resources/windows.rc win32:RC_FILE = resources/windows.rc
macx {
LIBS += -L/usr/local/lib
}
# Submodules # Submodules
include(dependencies/rapidjson.pri) include(dependencies/rapidjson.pri)
include(dependencies/settings.pri) include(dependencies/settings.pri)

View file

@ -3,6 +3,7 @@
#include "application.hpp" #include "application.hpp"
#include "singletons/emotemanager.hpp" #include "singletons/emotemanager.hpp"
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
#include "util/benchmark.hpp"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
@ -47,6 +48,8 @@ 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()");
auto app = getApp(); auto app = getApp();
bool layoutRequired = false; bool layoutRequired = false;
@ -73,6 +76,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
// check if timestamp format changed // check if timestamp format changed
bool timestampFormatChanged = this->timestampFormat != app->settings->timestampFormat; bool timestampFormatChanged = this->timestampFormat != app->settings->timestampFormat;
this->timestampFormat = app->settings->timestampFormat.getValue();
layoutRequired |= timestampFormatChanged; layoutRequired |= timestampFormatChanged;
@ -83,6 +87,8 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
imagesChanged |= scaleChanged; imagesChanged |= scaleChanged;
textChanged |= scaleChanged; textChanged |= scaleChanged;
// assert(layoutRequired);
// update word sizes if needed // update word sizes if needed
if (imagesChanged) { if (imagesChanged) {
// this->container.updateImages(); // this->container.updateImages();
@ -97,6 +103,8 @@ 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

@ -115,10 +115,16 @@ FontManager::FontData FontManager::createFontData(Type type, float scale)
// normal Ui font (use pt size) // normal Ui font (use pt size)
{ {
#ifdef Q_OS_MAC
constexpr float multiplier = 0.8f;
#else
constexpr float multiplier = 1.f;
#endif
static std::unordered_map<Type, UiFontData> defaultSize{ static std::unordered_map<Type, UiFontData> defaultSize{
{Tiny, {8, "Monospace", false, QFont::Normal}}, {Tiny, {8, "Monospace", false, QFont::Normal}},
{UiMedium, {12, DEFAULT_FONT_FAMILY, false, QFont::Normal}}, {UiMedium, {int(12 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
{UiTabs, {9, "Segoe UI", false, QFont::Normal}}, {UiTabs, {int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
}; };
UiFontData &data = defaultSize[type]; UiFontData &data = defaultSize[type];

View file

@ -1,11 +1,12 @@
#pragma once #pragma once
#include "widgets/window.hpp" #include "widgets/window.hpp"
#include "widgets/splitcontainer.hpp"
namespace chatterino { namespace chatterino {
namespace widgets { //namespace widgets {
struct SplitContainer::Node; //struct SplitContainer::Node;
} //}
namespace singletons { namespace singletons {
class WindowManager class WindowManager

View file

@ -3,6 +3,7 @@
#include <QDebug> #include <QDebug>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <boost/current_function.hpp> #include <boost/current_function.hpp>
#include <boost/noncopyable.hpp>
#define BENCH(x) \ #define BENCH(x) \
QElapsedTimer x; \ QElapsedTimer x; \
@ -11,3 +12,23 @@
#define MARK(x) \ #define MARK(x) \
qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \ qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \
<< static_cast<float>(x.nsecsElapsed()) / 100000.0 << "ms"; << static_cast<float>(x.nsecsElapsed()) / 100000.0 << "ms";
class BenchmarkGuard : boost::noncopyable {
QElapsedTimer timer;
QString name;
public:
BenchmarkGuard(const QString &_name)
:name(_name)
{
timer.start();
}
~BenchmarkGuard() {
qDebug() << this->name << float(timer.nsecsElapsed()) / 100000.0 << "ms";
}
qreal getElapsedMs() {
return qreal(timer.nsecsElapsed()) / 100000.0;
}
};

View file

@ -177,7 +177,7 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
{ {
auto app = getApp(); auto app = getApp();
// BENCH(timer) BENCH(timer)
auto messagesSnapshot = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
if (messagesSnapshot.getLength() == 0) { if (messagesSnapshot.getLength() == 0) {
@ -264,7 +264,7 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
this->messageWasAdded = false; this->messageWasAdded = false;
} }
// MARK(timer); MARK(timer);
if (redrawRequired) { if (redrawRequired) {
this->queueUpdate(); this->queueUpdate();
@ -580,7 +580,7 @@ bool ChannelView::isPaused()
void ChannelView::paintEvent(QPaintEvent * /*event*/) void ChannelView::paintEvent(QPaintEvent * /*event*/)
{ {
// BENCH(timer); BENCH(timer);
QPainter painter(this); QPainter painter(this);
@ -589,7 +589,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
// draw messages // draw messages
this->drawMessages(painter); this->drawMessages(painter);
// MARK(timer); MARK(timer);
} }
// if overlays is false then it draws the message, if true then it draws things such as the grey // if overlays is false then it draws the message, if true then it draws things such as the grey

View file

@ -86,7 +86,7 @@ void NotebookTab::updateSize()
float scale = getScale(); float scale = getScale();
int width; int width;
QFontMetrics metrics = getApp()->fonts->getFontMetrics(FontStyle::UiTabs, this->getScale()); QFontMetrics metrics = getApp()->fonts->getFontMetrics(FontStyle::UiTabs, this->getScale() * this->devicePixelRatioF());
if (this->hasXButton()) { if (this->hasXButton()) {
width = (int)((metrics.width(this->title) + 32) * scale); width = (int)((metrics.width(this->title) + 32) * scale);
@ -188,7 +188,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
QPainter painter(this); QPainter painter(this);
float scale = this->getScale(); float scale = this->getScale();
painter.setFont(getApp()->fonts->getFont(FontStyle::UiTabs, scale)); painter.setFont(getApp()->fonts->getFont(FontStyle::UiTabs, scale * this->devicePixelRatioF()));
int height = (int)(scale * NOTEBOOK_TAB_HEIGHT); int height = (int)(scale * NOTEBOOK_TAB_HEIGHT);
// int fullHeight = (int)(scale * 48); // int fullHeight = (int)(scale * 48);
@ -248,13 +248,13 @@ void NotebookTab::paintEvent(QPaintEvent *)
if (true) { // legacy if (true) { // legacy
// painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter)); // painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter));
int offset = (int)(scale * 8); int offset = (int)(scale * 8);
QRect textRect(offset, this->selected ? 0 : 1, this->width() - offset - offset, height); QRect textRect(offset, this->selected ? 1 : 2, this->width() - offset - offset, height);
if (this->shouldDrawXButton()) { if (this->shouldDrawXButton()) {
textRect.setRight(textRect.right() - this->height() / 2); textRect.setRight(textRect.right() - this->height() / 2);
} }
QTextOption option(Qt::AlignLeft | Qt::AlignVCenter); QTextOption option(Qt::AlignHCenter | Qt::AlignVCenter);
option.setWrapMode(QTextOption::NoWrap); option.setWrapMode(QTextOption::NoWrap);
painter.drawText(textRect, this->getTitle(), option); painter.drawText(textRect, this->getTitle(), option);
} else { } else {