mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
HiDPI commit
This commit is contained in:
parent
222eedcd21
commit
14511e10ef
13 changed files with 138 additions and 55 deletions
|
@ -163,7 +163,8 @@ HEADERS += \
|
|||
src/widgets/rippleeffectlabel.hpp \
|
||||
src/widgets/qualitypopup.hpp \
|
||||
src/widgets/emotepopup.hpp \
|
||||
src/messages/messagecolor.hpp
|
||||
src/messages/messagecolor.hpp \
|
||||
src/util/nativeeventhelper.hpp
|
||||
|
||||
PRECOMPILED_HEADER =
|
||||
|
||||
|
|
23
src/util/nativeeventhelper.hpp
Normal file
23
src/util/nativeeventhelper.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef USEWINSDK
|
||||
#include "windows.h"
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
static bool tryHandleDpiChangedMessage(void *message, int &dpi)
|
||||
{
|
||||
MSG *msg = reinterpret_cast<MSG *>(message);
|
||||
|
||||
// WM_DPICHANGED
|
||||
if (msg->message == 0x02E0) {
|
||||
dpi = HIWORD(msg->wParam);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,15 +1,21 @@
|
|||
#include "widgets/basewidget.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
|
||||
//#include <QApplication>
|
||||
#include <QDebug>
|
||||
//#include <QDesktopWidget>
|
||||
//#include <QScreen>
|
||||
#include <boost/signals2.hpp>
|
||||
#include "util/nativeeventhelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
// BaseWidget::BaseWidget(ColorScheme &_colorScheme, WindowManager &_windowManager, QWidget *parent)
|
||||
BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, colorScheme(_colorScheme)
|
||||
// , windowManager(_windowManager)
|
||||
{
|
||||
this->init();
|
||||
}
|
||||
|
@ -17,10 +23,25 @@ BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
|
|||
BaseWidget::BaseWidget(BaseWidget *parent)
|
||||
: QWidget(parent)
|
||||
, colorScheme(parent->colorScheme)
|
||||
// , windowManager(parent->windowManager)
|
||||
{
|
||||
this->init();
|
||||
}
|
||||
|
||||
float BaseWidget::getDpiMultiplier()
|
||||
{
|
||||
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
||||
|
||||
if (baseWidget == nullptr) {
|
||||
return 1.f;
|
||||
} else {
|
||||
return baseWidget->dpiMultiplier;
|
||||
// int screenNr = QApplication::desktop()->screenNumber(this);
|
||||
// QScreen *screen = QApplication::screens().at(screenNr);
|
||||
// return screen->logicalDotsPerInch() / 96.f;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseWidget::init()
|
||||
{
|
||||
this->colorScheme.updated.connect([this]() {
|
||||
|
@ -35,5 +56,28 @@ void BaseWidget::refreshTheme()
|
|||
// Do any color scheme updates here
|
||||
}
|
||||
|
||||
#ifdef USEWINSDK
|
||||
bool BaseWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||
{
|
||||
int dpi;
|
||||
|
||||
if (util::tryHandleDpiChangedMessage(message, dpi)) {
|
||||
qDebug() << "dpi changed";
|
||||
|
||||
float oldDpiMultiplier = this->dpiMultiplier;
|
||||
this->dpiMultiplier = dpi / 96.f;
|
||||
float scale = this->dpiMultiplier / oldDpiMultiplier;
|
||||
|
||||
qDebug() << scale;
|
||||
qDebug() << dpi;
|
||||
|
||||
this->resize(static_cast<int>(this->width() * scale),
|
||||
static_cast<int>(this->height() * scale));
|
||||
}
|
||||
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
//#include "windowmanager.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ColorScheme;
|
||||
|
@ -13,13 +15,27 @@ class BaseWidget : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// explicit BaseWidget(ColorScheme &_colorScheme, WindowManager &windowManager, QWidget
|
||||
// *parent);
|
||||
explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent);
|
||||
|
||||
explicit BaseWidget(BaseWidget *parent);
|
||||
|
||||
ColorScheme &colorScheme;
|
||||
|
||||
float getDpiMultiplier();
|
||||
|
||||
// protected:
|
||||
// WindowManager &windowManager;
|
||||
|
||||
protected:
|
||||
#ifdef USEWINSDK
|
||||
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
float dpiMultiplier = 1.f;
|
||||
|
||||
void init();
|
||||
|
||||
virtual void refreshTheme();
|
||||
|
|
|
@ -21,8 +21,6 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
|||
, rightLabel(this)
|
||||
, rightMenu(this)
|
||||
{
|
||||
this->setFixedHeight(32);
|
||||
|
||||
this->refreshTheme();
|
||||
|
||||
this->updateChannelText();
|
||||
|
@ -76,6 +74,11 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
|||
timer->start(60000);
|
||||
}
|
||||
|
||||
void ChatWidgetHeader::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
this->setFixedHeight(static_cast<float>(32 * getDpiMultiplier()));
|
||||
}
|
||||
|
||||
void ChatWidgetHeader::updateChannelText()
|
||||
{
|
||||
const std::string channelName = this->chatWidget->channelName;
|
||||
|
@ -85,14 +88,14 @@ void ChatWidgetHeader::updateChannelText()
|
|||
auto channel = this->chatWidget->getChannel();
|
||||
|
||||
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
||||
|
||||
|
||||
if (twitchChannel != nullptr && twitchChannel->isLive) {
|
||||
this->channelNameLabel.setText(QString::fromStdString(channelName) + " (live)");
|
||||
this->setToolTip("<style>.center { text-align: center; }</style>"
|
||||
"<p class = \"center\">" +
|
||||
twitchChannel->streamStatus + "<br><br>" +
|
||||
twitchChannel->streamGame + "<br>"
|
||||
"Live for " +
|
||||
twitchChannel->streamStatus + "<br><br>" + twitchChannel->streamGame +
|
||||
"<br>"
|
||||
"Live for " +
|
||||
twitchChannel->streamUptime + " with " +
|
||||
twitchChannel->streamViewerCount + " viewers"
|
||||
"</p>");
|
||||
|
|
|
@ -36,6 +36,7 @@ protected:
|
|||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private:
|
||||
ChatWidget *const chatWidget;
|
||||
|
@ -66,7 +67,6 @@ public slots:
|
|||
void menuReloadChannelEmotes();
|
||||
void menuManualReconnect();
|
||||
void menuShowChangelog();
|
||||
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#ifdef USEWINSDK
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
|
@ -27,6 +23,7 @@ MainWindow::MainWindow(ChannelManager &_channelManager, ColorScheme &_colorSchem
|
|||
, colorScheme(_colorScheme)
|
||||
, completionManager(_completionManager)
|
||||
, notebook(this->channelManager, this)
|
||||
, dpi(this->getDpiMultiplier())
|
||||
// , windowGeometry("/windows/0/geometry")
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
@ -71,19 +68,6 @@ MainWindow::~MainWindow()
|
|||
{
|
||||
}
|
||||
|
||||
#ifdef USEWINSDK
|
||||
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||
{
|
||||
MSG *msg = reinterpret_cast<MSG *>(message);
|
||||
|
||||
if (msg->message == 0x02E0) {
|
||||
qDebug() << "dpi changed";
|
||||
}
|
||||
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
void MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
||||
{
|
||||
auto *page = this->notebook.getSelectedPage();
|
||||
|
|
|
@ -42,11 +42,10 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
#ifdef USEWINSDK
|
||||
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
float dpi;
|
||||
|
||||
virtual void refreshTheme() override;
|
||||
|
||||
ChannelManager &channelManager;
|
||||
|
|
|
@ -31,15 +31,11 @@ Notebook::Notebook(ChannelManager &_channelManager, MainWindow *parent)
|
|||
this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
|
||||
this->connect(&this->addButton, SIGNAL(clicked()), this, SLOT(addPageButtonClicked()));
|
||||
|
||||
this->settingsButton.resize(24, 24);
|
||||
this->settingsButton.icon = NotebookButton::IconSettings;
|
||||
|
||||
this->userButton.resize(24, 24);
|
||||
this->userButton.move(24, 0);
|
||||
this->userButton.icon = NotebookButton::IconUser;
|
||||
|
||||
this->addButton.resize(24, 24);
|
||||
|
||||
SettingsManager::getInstance().hidePreferencesButton.valueChanged.connect(
|
||||
[this](const bool &) { this->performLayout(); });
|
||||
SettingsManager::getInstance().hideUserButton.valueChanged.connect(
|
||||
|
@ -163,27 +159,26 @@ void Notebook::previousTab()
|
|||
void Notebook::performLayout(bool animated)
|
||||
{
|
||||
int x = 0, y = 0;
|
||||
float scale = this->getDpiMultiplier();
|
||||
|
||||
if (SettingsManager::getInstance().hidePreferencesButton.get()) {
|
||||
this->settingsButton.hide();
|
||||
} else {
|
||||
this->settingsButton.show();
|
||||
x += 24;
|
||||
x += settingsButton.width();
|
||||
}
|
||||
if (SettingsManager::getInstance().hideUserButton.get()) {
|
||||
this->userButton.hide();
|
||||
} else {
|
||||
this->userButton.move(x, 0);
|
||||
this->userButton.show();
|
||||
x += 24;
|
||||
x += userButton.width();
|
||||
}
|
||||
|
||||
int tabHeight = 16;
|
||||
int tabHeight = static_cast<int>(24 * scale);
|
||||
bool first = true;
|
||||
|
||||
for (auto &i : this->pages) {
|
||||
tabHeight = i->getTab()->height();
|
||||
|
||||
if (!first &&
|
||||
(i == this->pages.last() ? tabHeight : 0) + x + i->getTab()->width() > width()) {
|
||||
y += i->getTab()->height();
|
||||
|
@ -207,6 +202,16 @@ void Notebook::performLayout(bool animated)
|
|||
|
||||
void Notebook::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
float scale = this->getDpiMultiplier();
|
||||
|
||||
this->settingsButton.resize(static_cast<int>(24 * scale), static_cast<int>(24 * scale));
|
||||
this->userButton.resize(static_cast<int>(24 * scale), static_cast<int>(24 * scale));
|
||||
this->addButton.resize(static_cast<int>(24 * scale), static_cast<int>(24 * scale));
|
||||
|
||||
for (auto &i : this->pages) {
|
||||
i->getTab()->calcSize();
|
||||
}
|
||||
|
||||
this->performLayout(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,10 +67,14 @@ NotebookTab::~NotebookTab()
|
|||
|
||||
void NotebookTab::calcSize()
|
||||
{
|
||||
float scale = getDpiMultiplier();
|
||||
|
||||
if (SettingsManager::getInstance().hideTabX.get()) {
|
||||
this->resize(fontMetrics().width(title) + 8, 24);
|
||||
this->resize(static_cast<int>((fontMetrics().width(title) + 16) * scale),
|
||||
static_cast<int>(24 * scale));
|
||||
} else {
|
||||
this->resize(fontMetrics().width(title) + 8 + 24, 24);
|
||||
this->resize(static_cast<int>((fontMetrics().width(title) + 8 + 24) * scale),
|
||||
static_cast<int>(24 * scale));
|
||||
}
|
||||
|
||||
if (this->parent() != nullptr) {
|
||||
|
@ -179,8 +183,9 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
|||
|
||||
painter.setPen(fg);
|
||||
|
||||
QRect rect(0, 0, this->width() - (SettingsManager::getInstance().hideTabX.get() ? 0 : 16),
|
||||
this->height());
|
||||
float scale = this->getDpiMultiplier();
|
||||
int rectW = (SettingsManager::getInstance().hideTabX.get() ? 0 : static_cast<int>(16) * scale);
|
||||
QRect rect(0, 0, this->width() - rectW, this->height());
|
||||
|
||||
painter.drawText(rect, title, QTextOption(Qt::AlignCenter));
|
||||
|
||||
|
@ -194,8 +199,10 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
|||
}
|
||||
}
|
||||
|
||||
painter.drawLine(xRect.topLeft() + QPoint(4, 4), xRect.bottomRight() + QPoint(-4, -4));
|
||||
painter.drawLine(xRect.topRight() + QPoint(-4, 4), xRect.bottomLeft() + QPoint(4, -4));
|
||||
int a = static_cast<int>(scale * 4);
|
||||
|
||||
painter.drawLine(xRect.topLeft() + QPoint(a, a), xRect.bottomRight() + QPoint(-a, -a));
|
||||
painter.drawLine(xRect.topRight() + QPoint(-a, a), xRect.bottomLeft() + QPoint(a, -a));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,9 @@ private:
|
|||
|
||||
QRect getXRect()
|
||||
{
|
||||
return QRect(this->width() - 20, 4, 16, 16);
|
||||
float scale = this->getDpiMultiplier();
|
||||
return QRect(this->width() - static_cast<int>(20 * scale), static_cast<int>(4 * scale),
|
||||
static_cast<int>(16 * scale), static_cast<int>(16 * scale));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -10,15 +10,16 @@ namespace widgets {
|
|||
|
||||
RippleEffectLabel::RippleEffectLabel(BaseWidget *parent, int spacing)
|
||||
: RippleEffectButton(parent)
|
||||
, label(this)
|
||||
{
|
||||
setLayout(&this->ui.hbox);
|
||||
setLayout(&this->hbox);
|
||||
|
||||
this->ui.label.setAlignment(Qt::AlignCenter);
|
||||
this->label.setAlignment(Qt::AlignCenter);
|
||||
|
||||
this->ui.hbox.setMargin(0);
|
||||
this->ui.hbox.addSpacing(spacing);
|
||||
this->ui.hbox.addWidget(&this->ui.label);
|
||||
this->ui.hbox.addSpacing(spacing);
|
||||
this->hbox.setMargin(0);
|
||||
this->hbox.addSpacing(spacing);
|
||||
this->hbox.addWidget(&this->label);
|
||||
this->hbox.addSpacing(spacing);
|
||||
|
||||
this->setMouseEffectColor(QColor(255, 255, 255, 63));
|
||||
}
|
||||
|
|
|
@ -22,14 +22,12 @@ public:
|
|||
|
||||
SignalLabel &getLabel()
|
||||
{
|
||||
return this->ui.label;
|
||||
return this->label;
|
||||
}
|
||||
|
||||
private:
|
||||
struct {
|
||||
QHBoxLayout hbox;
|
||||
SignalLabel label;
|
||||
} ui;
|
||||
QHBoxLayout hbox;
|
||||
SignalLabel label;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
|
Loading…
Reference in a new issue