refactored SplitInput

This commit is contained in:
fourtf 2018-01-25 20:49:49 +01:00
parent 8ab0fa4378
commit 0a8073d0e5
27 changed files with 296 additions and 180 deletions

3
.vs/ProjectSettings.json Normal file
View file

@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}

View file

@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\ISSUE_TEMPLATE.md",
"PreviewInSolutionExplorer": false
}

BIN
.vs/slnx.sqlite Normal file

Binary file not shown.

View file

@ -155,7 +155,7 @@ AccountPopupWidget::AccountPopupWidget(ChannelPtr _channel)
this->hide(); // this->hide(); //
}); });
this->dpiMultiplierChanged(this->getDpiMultiplier(), this->getDpiMultiplier()); this->scaleChangedEvent(this->getScale());
} }
void AccountPopupWidget::setName(const QString &name) void AccountPopupWidget::setName(const QString &name)
@ -247,7 +247,7 @@ void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
} }
} }
void AccountPopupWidget::dpiMultiplierChanged(float /*oldDpi*/, float newDpi) void AccountPopupWidget::scaleChangedEvent(float newDpi)
{ {
this->setStyleSheet(QString("* { font-size: <font-size>px; }") this->setStyleSheet(QString("* { font-size: <font-size>px; }")
.replace("<font-size>", QString::number((int)(12 * newDpi)))); .replace("<font-size>", QString::number((int)(12 * newDpi))));

View file

@ -35,7 +35,7 @@ signals:
void refreshButtons(); void refreshButtons();
protected: protected:
virtual void dpiMultiplierChanged(float oldDpi, float newDpi) override; virtual void scaleChangedEvent(float newDpi) override;
private: private:
Ui::AccountPopup *ui; Ui::AccountPopup *ui;

View file

@ -2,6 +2,7 @@
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp" #include "singletons/thememanager.hpp"
#include <QChildEvent>
#include <QDebug> #include <QDebug>
#include <QIcon> #include <QIcon>
#include <QLayout> #include <QLayout>
@ -25,13 +26,7 @@ BaseWidget::BaseWidget(BaseWidget *parent, Qt::WindowFlags f)
this->init(); this->init();
} }
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f) float BaseWidget::getScale() const
: QWidget(parent, f)
, themeManager(singletons::ThemeManager::getInstance())
{
}
float BaseWidget::getDpiMultiplier()
{ {
// return 1.f; // return 1.f;
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window()); BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
@ -39,17 +34,14 @@ float BaseWidget::getDpiMultiplier()
if (baseWidget == nullptr) { if (baseWidget == nullptr) {
return 1.f; return 1.f;
} else { } else {
return baseWidget->dpiMultiplier; return baseWidget->scale;
// int screenNr = QApplication::desktop()->screenNumber(this);
// QScreen *screen = QApplication::screens().at(screenNr);
// return screen->logicalDotsPerInch() / 96.f;
} }
} }
void BaseWidget::init() void BaseWidget::init()
{ {
auto connection = this->themeManager.updated.connect([this]() { auto connection = this->themeManager.updated.connect([this]() {
this->refreshTheme(); this->themeRefreshEvent();
this->update(); this->update();
}); });
@ -59,7 +51,66 @@ void BaseWidget::init()
}); });
} }
void BaseWidget::refreshTheme() void BaseWidget::childEvent(QChildEvent *event)
{
if (event->added()) {
BaseWidget *widget = dynamic_cast<BaseWidget *>(event->child());
if (widget) {
this->widgets.push_back(widget);
}
} else if (event->removed()) {
for (auto it = this->widgets.begin(); it != this->widgets.end(); it++) {
if (*it == event->child()) {
this->widgets.erase(it);
break;
}
}
}
}
void BaseWidget::setScale(float value)
{
// update scale value
this->scale = value;
this->scaleChangedEvent(value);
this->scaleChanged.invoke(value);
// set scale for all children
BaseWidget::setScaleRecursive(value, this);
}
void BaseWidget::setScaleRecursive(float scale, QObject *object)
{
for (QObject *child : object->children()) {
BaseWidget *widget = dynamic_cast<BaseWidget *>(child);
if (widget != nullptr) {
widget->setScale(scale);
continue;
}
// QLayout *layout = nullptr;
// QWidget *widget = dynamic_cast<QWidget *>(child);
// if (widget != nullptr) {
// layout = widget->layout();
// }
// else {
QLayout *layout = dynamic_cast<QLayout *>(object);
if (layout != nullptr) {
setScaleRecursive(scale, layout);
}
// }
}
}
void BaseWidget::scaleChangedEvent(float newDpi)
{
}
void BaseWidget::themeRefreshEvent()
{ {
// Do any color scheme updates here // Do any color scheme updates here
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <pajlada/signals/signal.hpp>
namespace chatterino { namespace chatterino {
namespace singletons { namespace singletons {
@ -8,6 +9,7 @@ class ThemeManager;
} }
namespace widgets { namespace widgets {
class BaseWindow;
class BaseWidget : public QWidget class BaseWidget : public QWidget
{ {
@ -17,23 +19,30 @@ public:
explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent, explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent,
Qt::WindowFlags f = Qt::WindowFlags()); Qt::WindowFlags f = Qt::WindowFlags());
explicit BaseWidget(BaseWidget *parent, Qt::WindowFlags f = Qt::WindowFlags()); explicit BaseWidget(BaseWidget *parent, Qt::WindowFlags f = Qt::WindowFlags());
explicit BaseWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
singletons::ThemeManager &themeManager; singletons::ThemeManager &themeManager;
float getDpiMultiplier(); float getScale() const;
pajlada::Signals::Signal<float> scaleChanged;
protected: protected:
virtual void dpiMultiplierChanged(float /*oldDpi*/, float /*newDpi*/) virtual void childEvent(QChildEvent *) override;
{
}
float dpiMultiplier = 1.f; virtual void scaleChangedEvent(float newScale);
virtual void themeRefreshEvent();
virtual void refreshTheme(); void setScale(float value);
private: private:
void init(); void init();
float scale = 1.f;
std::vector<BaseWidget *> widgets;
static void setScaleRecursive(float scale, QObject *object);
friend class BaseWindow;
}; };
} // namespace widgets } // namespace widgets

View file

@ -44,7 +44,7 @@ BaseWindow::BaseWindow(BaseWidget *parent, bool _enableCustomFrame)
} }
BaseWindow::BaseWindow(QWidget *parent, bool _enableCustomFrame) BaseWindow::BaseWindow(QWidget *parent, bool _enableCustomFrame)
: BaseWidget(parent, Qt::Window) : BaseWidget(singletons::ThemeManager::getInstance(), parent, Qt::Window)
, enableCustomFrame(_enableCustomFrame) , enableCustomFrame(_enableCustomFrame)
{ {
this->init(); this->init();
@ -57,12 +57,12 @@ void BaseWindow::init()
#ifdef USEWINSDK #ifdef USEWINSDK
if (this->hasCustomWindowFrame()) { if (this->hasCustomWindowFrame()) {
// CUSTOM WINDOW FRAME // CUSTOM WINDOW FRAME
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout();
layout->setMargin(1); layout->setMargin(1);
layout->setSpacing(0); layout->setSpacing(0);
this->setLayout(layout); this->setLayout(layout);
{ {
QHBoxLayout *buttonLayout = this->titlebarBox = new QHBoxLayout; QHBoxLayout *buttonLayout = this->titlebarBox = new QHBoxLayout();
buttonLayout->setMargin(0); buttonLayout->setMargin(0);
layout->addLayout(buttonLayout); layout->addLayout(buttonLayout);
@ -107,7 +107,7 @@ void BaseWindow::init()
buttonLayout->addWidget(_exitButton); buttonLayout->addWidget(_exitButton);
buttonLayout->setSpacing(0); buttonLayout->setSpacing(0);
} }
this->layoutBase = new QWidget(this); this->layoutBase = new BaseWidget(this);
layout->addWidget(this->layoutBase); layout->addWidget(this->layoutBase);
} }
@ -115,10 +115,10 @@ void BaseWindow::init()
auto dpi = util::getWindowDpi(this->winId()); auto dpi = util::getWindowDpi(this->winId());
if (dpi) { if (dpi) {
this->dpiMultiplier = dpi.value() / 96.f; this->scale = dpi.value() / 96.f;
} }
this->dpiMultiplierChanged(1, this->dpiMultiplier); this->scaleChangedEvent(this->scale);
#endif #endif
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) { if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
@ -155,7 +155,7 @@ bool BaseWindow::hasCustomWindowFrame()
#endif #endif
} }
void BaseWindow::refreshTheme() void BaseWindow::themeRefreshEvent()
{ {
QPalette palette; QPalette palette;
palette.setColor(QPalette::Background, this->themeManager.windowBg); palette.setColor(QPalette::Background, this->themeManager.windowBg);
@ -249,14 +249,14 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
qDebug() << "dpi changed"; qDebug() << "dpi changed";
int dpi = HIWORD(msg->wParam); int dpi = HIWORD(msg->wParam);
float oldDpiMultiplier = this->dpiMultiplier; float oldScale = this->scale;
this->dpiMultiplier = dpi / 96.f; float _scale = dpi / 96.f;
float scale = this->dpiMultiplier / oldDpiMultiplier; float resizeScale = _scale / oldScale;
this->dpiMultiplierChanged(oldDpiMultiplier, this->dpiMultiplier); this->resize(static_cast<int>(this->width() * resizeScale),
static_cast<int>(this->height() * resizeScale));
this->resize(static_cast<int>(this->width() * scale), this->setScale(_scale);
static_cast<int>(this->height() * scale));
return true; return true;
} }

View file

@ -40,7 +40,7 @@ protected:
virtual void leaveEvent(QEvent *) override; virtual void leaveEvent(QEvent *) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual void refreshTheme() override; virtual void themeRefreshEvent() override;
private: private:
void init(); void init();

View file

@ -25,8 +25,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#define LAYOUT_WIDTH \ #define LAYOUT_WIDTH (this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getScale())
(this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getDpiMultiplier())
using namespace chatterino::messages; using namespace chatterino::messages;
@ -115,9 +114,9 @@ ChannelView::~ChannelView()
this->messageReplacedConnection.disconnect(); this->messageReplacedConnection.disconnect();
} }
void ChannelView::refreshTheme() void ChannelView::themeRefreshEvent()
{ {
BaseWidget::refreshTheme(); BaseWidget::themeRefreshEvent();
this->layoutMessages(); this->layoutMessages();
} }
@ -175,7 +174,7 @@ void ChannelView::actuallyLayoutMessages()
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
auto message = messagesSnapshot[i]; auto message = messagesSnapshot[i];
redrawRequired |= message->layout(layoutWidth, this->getDpiMultiplier(), flags); redrawRequired |= message->layout(layoutWidth, this->getScale(), flags);
y += message->getHeight(); y += message->getHeight();
@ -191,7 +190,7 @@ void ChannelView::actuallyLayoutMessages()
for (int i = (int)messagesSnapshot.getLength() - 1; i >= 0; i--) { for (int i = (int)messagesSnapshot.getLength() - 1; i >= 0; i--) {
auto *message = messagesSnapshot[i].get(); auto *message = messagesSnapshot[i].get();
message->layout(layoutWidth, this->getDpiMultiplier(), flags); message->layout(layoutWidth, this->getScale(), flags);
h -= message->getHeight(); h -= message->getHeight();
@ -582,8 +581,7 @@ void ChannelView::wheelEvent(QWheelEvent *event)
if (i == 0) { if (i == 0) {
desired = 0; desired = 0;
} else { } else {
snapshot[i - 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier(), snapshot[i - 1]->layout(LAYOUT_WIDTH, this->getScale(), this->getFlags());
this->getFlags());
scrollFactor = 1; scrollFactor = 1;
currentScrollLeft = snapshot[i - 1]->getHeight(); currentScrollLeft = snapshot[i - 1]->getHeight();
} }
@ -605,8 +603,7 @@ void ChannelView::wheelEvent(QWheelEvent *event)
if (i == snapshotLength - 1) { if (i == snapshotLength - 1) {
desired = snapshot.getLength(); desired = snapshot.getLength();
} else { } else {
snapshot[i + 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier(), snapshot[i + 1]->layout(LAYOUT_WIDTH, this->getScale(), this->getFlags());
this->getFlags());
scrollFactor = 1; scrollFactor = 1;
currentScrollLeft = snapshot[i + 1]->getHeight(); currentScrollLeft = snapshot[i + 1]->getHeight();

View file

@ -53,7 +53,7 @@ public:
pajlada::Signals::Signal<const messages::Link &> linkClicked; pajlada::Signals::Signal<const messages::Link &> linkClicked;
protected: protected:
virtual void refreshTheme() override; virtual void themeRefreshEvent() override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;

View file

@ -25,7 +25,6 @@ NotebookTab::NotebookTab(Notebook *_notebook, const std::string &_uuid)
, useDefaultBehaviour(fS("{}/useDefaultBehaviour", this->settingRoot), true) , useDefaultBehaviour(fS("{}/useDefaultBehaviour", this->settingRoot), true)
, menu(this) , menu(this)
{ {
this->calcSize();
this->setAcceptDrops(true); this->setAcceptDrops(true);
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic)); this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
@ -65,22 +64,25 @@ NotebookTab::NotebookTab(Notebook *_notebook, const std::string &_uuid)
this->menu.addAction(enableHighlightsOnNewMessageAction); this->menu.addAction(enableHighlightsOnNewMessageAction);
connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [this](bool newValue) { QObject::connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [this](bool newValue) {
debug::Log("New value is {}", newValue); // debug::Log("New value is {}", newValue); //
}); });
} }
void NotebookTab::calcSize() void NotebookTab::themeRefreshEvent()
{ {
float scale = getDpiMultiplier(); this->update();
}
void NotebookTab::updateSize()
{
float scale = getScale();
QString qTitle(qS(this->title)); QString qTitle(qS(this->title));
if (singletons::SettingManager::getInstance().hideTabX) { if (singletons::SettingManager::getInstance().hideTabX) {
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 16) * scale), this->resize((int)((fontMetrics().width(qTitle) + 16) * scale), (int)(24 * scale));
static_cast<int>(24 * scale));
} else { } else {
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 8 + 24) * scale), this->resize((int)((fontMetrics().width(qTitle) + 8 + 24) * scale), (int)(24 * scale));
static_cast<int>(24 * scale));
} }
if (this->parent() != nullptr) { if (this->parent() != nullptr) {
@ -97,7 +99,7 @@ void NotebookTab::setTitle(const QString &newTitle)
{ {
this->title = newTitle.toStdString(); this->title = newTitle.toStdString();
this->calcSize(); this->updateSize();
} }
bool NotebookTab::isSelected() const bool NotebookTab::isSelected() const
@ -134,7 +136,7 @@ QRect NotebookTab::getDesiredRect() const
void NotebookTab::hideTabXChanged(bool) void NotebookTab::hideTabXChanged(bool)
{ {
this->calcSize(); this->updateSize();
this->update(); this->update();
} }
@ -197,7 +199,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
painter.setPen(colors.text); painter.setPen(colors.text);
// set area for text // set area for text
float scale = this->getDpiMultiplier(); float scale = this->getScale();
int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale); int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale);
QRect rect(0, 0, this->width() - rectW, this->height()); QRect rect(0, 0, this->width() - rectW, this->height());

View file

@ -25,7 +25,7 @@ class NotebookTab : public BaseWidget
public: public:
explicit NotebookTab(Notebook *_notebook, const std::string &_uuid); explicit NotebookTab(Notebook *_notebook, const std::string &_uuid);
void calcSize(); void updateSize();
SplitContainer *page; SplitContainer *page;
@ -42,16 +42,18 @@ public:
void hideTabXChanged(bool); void hideTabXChanged(bool);
protected: protected:
void paintEvent(QPaintEvent *) override; virtual void themeRefreshEvent() override;
void mousePressEvent(QMouseEvent *event) override; virtual void paintEvent(QPaintEvent *) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
void dragEnterEvent(QDragEnterEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
void mouseMoveEvent(QMouseEvent *event) override; virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
private: private:
std::vector<pajlada::Signals::ScopedConnection> managedConnections; std::vector<pajlada::Signals::ScopedConnection> managedConnections;
@ -80,7 +82,7 @@ private:
QRect getXRect() QRect getXRect()
{ {
float scale = this->getDpiMultiplier(); float scale = this->getScale();
return QRect(this->width() - static_cast<int>(20 * scale), static_cast<int>(4 * scale), return QRect(this->width() - static_cast<int>(20 * scale), static_cast<int>(4 * scale),
static_cast<int>(16 * scale), static_cast<int>(16 * scale)); static_cast<int>(16 * scale), static_cast<int>(16 * scale));
} }

View file

@ -44,7 +44,7 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
if (this->pixmap != nullptr) { if (this->pixmap != nullptr) {
QRect rect = this->rect(); QRect rect = this->rect();
int xD = 6 * this->getDpiMultiplier(); int xD = 6 * this->getScale();
rect.moveLeft(xD); rect.moveLeft(xD);
rect.setRight(rect.right() - xD - xD); rect.setRight(rect.right() - xD - xD);

View file

@ -66,7 +66,7 @@ SplitHeader::SplitHeader(Split *_split)
// ---- misc // ---- misc
this->layout()->setMargin(0); this->layout()->setMargin(0);
this->refreshTheme(); this->themeRefreshEvent();
this->updateChannelText(); this->updateChannelText();
@ -135,7 +135,7 @@ void SplitHeader::initializeChannelSignals()
void SplitHeader::resizeEvent(QResizeEvent *event) void SplitHeader::resizeEvent(QResizeEvent *event)
{ {
int w = 28 * getDpiMultiplier(); int w = 28 * getScale();
this->setFixedHeight(w); this->setFixedHeight(w);
this->dropdownButton->setFixedWidth(w); this->dropdownButton->setFixedWidth(w);
@ -242,7 +242,7 @@ void SplitHeader::rightButtonClicked()
{ {
} }
void SplitHeader::refreshTheme() void SplitHeader::themeRefreshEvent()
{ {
QPalette palette; QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager.splits.header.text); palette.setColor(QPalette::Foreground, this->themeManager.splits.header.text);

View file

@ -57,7 +57,7 @@ private:
void rightButtonClicked(); void rightButtonClicked();
virtual void refreshTheme() override; virtual void themeRefreshEvent() override;
void initializeChannelSignals(); void initializeChannelSignals();

View file

@ -4,6 +4,7 @@
#include "singletons/ircmanager.hpp" #include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp" #include "singletons/thememanager.hpp"
#include "util/layoutcreator.hpp"
#include "widgets/notebook.hpp" #include "widgets/notebook.hpp"
#include "widgets/split.hpp" #include "widgets/split.hpp"
#include "widgets/splitcontainer.hpp" #include "widgets/splitcontainer.hpp"
@ -17,41 +18,59 @@ namespace widgets {
SplitInput::SplitInput(Split *_chatWidget) SplitInput::SplitInput(Split *_chatWidget)
: BaseWidget(_chatWidget) : BaseWidget(_chatWidget)
, chatWidget(_chatWidget) , chatWidget(_chatWidget)
, emotesLabel(this)
{ {
this->setLayout(&this->hbox); this->initLayout();
this->hbox.setMargin(4); // auto completion
auto completer = new QCompleter(
singletons::CompletionManager::getInstance().createModel(this->chatWidget->channelName));
this->hbox.addLayout(&this->editContainer); this->ui.textEdit->setCompleter(completer);
this->hbox.addLayout(&this->vbox);
// misc
this->installKeyPressedEvent();
this->themeRefreshEvent();
this->scaleChangedEvent(this->getScale());
}
void SplitInput::initLayout()
{
auto &fontManager = singletons::FontManager::getInstance(); auto &fontManager = singletons::FontManager::getInstance();
util::LayoutCreator<SplitInput> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(&this->ui.hbox);
// input
auto textEdit = layout.emplace<ResizingTextEdit>().assign(&this->ui.textEdit);
connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this,
&SplitInput::editTextChanged);
// right box
auto box = layout.emplace<QVBoxLayout>().withoutMargin();
box->setSpacing(0);
{
auto textEditLength = box.emplace<QLabel>().assign(&this->ui.textEditLength);
textEditLength->setAlignment(Qt::AlignRight);
box->addStretch(1);
box.emplace<RippleEffectLabel>().assign(&this->ui.emoteButton);
}
this->ui.emoteButton->getLabel().setTextFormat(Qt::RichText);
// ---- misc
// set edit font
this->ui.textEdit->setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getScale()));
this->textInput.setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getDpiMultiplier()));
this->managedConnections.emplace_back(fontManager.fontChanged.connect([this, &fontManager]() { this->managedConnections.emplace_back(fontManager.fontChanged.connect([this, &fontManager]() {
this->textInput.setFont( this->ui.textEdit->setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getDpiMultiplier())); fontManager.getFont(singletons::FontManager::Type::Medium, this->getScale()));
})); }));
this->editContainer.addWidget(&this->textInput); // open emote popup
this->editContainer.setMargin(2); QObject::connect(this->ui.emoteButton, &RippleEffectLabel::clicked, [this] {
this->emotesLabel.setMinimumHeight(24);
this->vbox.addWidget(&this->textLengthLabel);
this->vbox.addStretch(1);
this->vbox.addWidget(&this->emotesLabel);
this->textLengthLabel.setText("");
this->textLengthLabel.setAlignment(Qt::AlignRight);
this->emotesLabel.getLabel().setTextFormat(Qt::RichText);
this->emotesLabel.getLabel().setText("<img src=':/images/emote.svg' width='12' height='12' "
"/>");
connect(&this->emotesLabel, &RippleEffectLabel::clicked, [this] {
if (!this->emotePopup) { if (!this->emotePopup) {
this->emotePopup = std::make_unique<EmotePopup>(this->themeManager); this->emotePopup = std::make_unique<EmotePopup>(this->themeManager);
this->emotePopup->linkClicked.connect([this](const messages::Link &link) { this->emotePopup->linkClicked.connect([this](const messages::Link &link) {
@ -61,29 +80,62 @@ SplitInput::SplitInput(Split *_chatWidget)
}); });
} }
this->emotePopup->resize((int)(300 * this->emotePopup->getDpiMultiplier()), this->emotePopup->resize((int)(300 * this->emotePopup->getScale()),
(int)(500 * this->emotePopup->getDpiMultiplier())); (int)(500 * this->emotePopup->getScale()));
this->emotePopup->loadChannel(this->chatWidget->getChannel()); this->emotePopup->loadChannel(this->chatWidget->getChannel());
this->emotePopup->show(); this->emotePopup->show();
}); });
connect(&textInput, &ResizingTextEdit::textChanged, this, &SplitInput::editTextChanged); // clear channelview selection when selecting in the input
QObject::connect(this->ui.textEdit, &QTextEdit::copyAvailable, [this](bool available) {
if (available) {
this->chatWidget->view.clearSelection();
}
});
this->refreshTheme(); // textEditLength visibility
textLengthLabel.setHidden(!singletons::SettingManager::getInstance().showMessageLength); singletons::SettingManager::getInstance().showMessageLength.connect(
[this](const bool &value, auto) { this->ui.textEditLength->setHidden(!value); },
this->managedConnections);
}
auto completer = new QCompleter( void SplitInput::scaleChangedEvent(float scale)
singletons::CompletionManager::getInstance().createModel(this->chatWidget->channelName)); {
// update the icon size of the emote button
QString text = "<img src=':/images/emote.svg' width='xD' height='xD' />";
text.replace("xD", QString::number((int)12 * scale));
this->textInput.setCompleter(completer); this->ui.emoteButton->getLabel().setText(text);
this->ui.emoteButton->setFixedHeight((int)18 * scale);
this->textInput.keyPressed.connect([this](QKeyEvent *event) { // set maximum height
this->setMaximumHeight((int)(150 * this->getScale()));
this->themeRefreshEvent();
}
void SplitInput::themeRefreshEvent()
{
QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager.splits.input.text);
this->ui.textEditLength->setPalette(palette);
this->ui.textEdit->setStyleSheet(this->themeManager.splits.input.styleSheet);
this->ui.hbox->setMargin((this->themeManager.isLightTheme() ? 4 : 2) * this->getScale());
}
void SplitInput::installKeyPressedEvent()
{
this->ui.textEdit->keyPressed.connect([this](QKeyEvent *event) {
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
auto c = this->chatWidget->getChannel(); auto c = this->chatWidget->getChannel();
if (c == nullptr) { if (c == nullptr) {
return; return;
} }
QString message = textInput.toPlainText(); QString message = ui.textEdit->toPlainText();
QString sendMessage = QString sendMessage =
singletons::CommandManager::getInstance().execCommand(message, c, false); singletons::CommandManager::getInstance().execCommand(message, c, false);
@ -94,9 +146,9 @@ SplitInput::SplitInput(Split *_chatWidget)
event->accept(); event->accept();
if (!(event->modifiers() == Qt::ControlModifier)) { if (!(event->modifiers() == Qt::ControlModifier)) {
this->textInput.setText(QString()); this->ui.textEdit->setText(QString());
this->prevIndex = 0; this->prevIndex = 0;
} else if (this->textInput.toPlainText() == } else if (this->ui.textEdit->toPlainText() ==
this->prevMsg.at(this->prevMsg.size() - 1)) { this->prevMsg.at(this->prevMsg.size() - 1)) {
this->prevMsg.removeLast(); this->prevMsg.removeLast();
} }
@ -115,7 +167,7 @@ SplitInput::SplitInput(Split *_chatWidget)
} else { } else {
if (this->prevMsg.size() && this->prevIndex) { if (this->prevMsg.size() && this->prevIndex) {
this->prevIndex--; this->prevIndex--;
this->textInput.setText(this->prevMsg.at(this->prevIndex)); this->ui.textEdit->setText(this->prevMsg.at(this->prevIndex));
} }
} }
} else if (event->key() == Qt::Key_Down) { } else if (event->key() == Qt::Key_Down) {
@ -133,10 +185,10 @@ SplitInput::SplitInput(Split *_chatWidget)
if (this->prevIndex != (this->prevMsg.size() - 1) && if (this->prevIndex != (this->prevMsg.size() - 1) &&
this->prevIndex != this->prevMsg.size()) { this->prevIndex != this->prevMsg.size()) {
this->prevIndex++; this->prevIndex++;
this->textInput.setText(this->prevMsg.at(this->prevIndex)); this->ui.textEdit->setText(this->prevMsg.at(this->prevIndex));
} else { } else {
this->prevIndex = this->prevMsg.size(); this->prevIndex = this->prevMsg.size();
this->textInput.setText(QString()); this->ui.textEdit->setText(QString());
} }
} }
} else if (event->key() == Qt::Key_Left) { } else if (event->key() == Qt::Key_Left) {
@ -188,54 +240,32 @@ SplitInput::SplitInput(Split *_chatWidget)
} }
} }
}); });
singletons::SettingManager::getInstance().showMessageLength.connect(
[this](const bool &value, auto) { this->textLengthLabel.setHidden(!value); },
this->managedConnections);
QObject::connect(&this->textInput, &QTextEdit::copyAvailable, [this](bool available) {
if (available) {
this->chatWidget->view.clearSelection();
}
});
} }
void SplitInput::clearSelection() void SplitInput::clearSelection()
{ {
QTextCursor c = this->textInput.textCursor(); QTextCursor c = this->ui.textEdit->textCursor();
c.setPosition(c.position()); c.setPosition(c.position());
c.setPosition(c.position(), QTextCursor::KeepAnchor); c.setPosition(c.position(), QTextCursor::KeepAnchor);
this->textInput.setTextCursor(c); this->ui.textEdit->setTextCursor(c);
} }
QString SplitInput::getInputText() const QString SplitInput::getInputText() const
{ {
return this->textInput.toPlainText(); return this->ui.textEdit->toPlainText();
} }
void SplitInput::insertText(const QString &text) void SplitInput::insertText(const QString &text)
{ {
this->textInput.insertPlainText(text); this->ui.textEdit->insertPlainText(text);
}
void SplitInput::refreshTheme()
{
QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager.splits.input.text);
this->textLengthLabel.setPalette(palette);
this->textInput.setStyleSheet(this->themeManager.splits.input.styleSheet);
this->hbox.setMargin((this->themeManager.isLightTheme() ? 4 : 2) * this->getDpiMultiplier());
} }
void SplitInput::editTextChanged() void SplitInput::editTextChanged()
{ {
QString text = this->textInput.toPlainText(); // set textLengthLabel value
QString text = this->ui.textEdit->toPlainText();
this->textChanged.invoke(text); this->textChanged.invoke(text);
@ -254,7 +284,7 @@ void SplitInput::editTextChanged()
labelText = QString::number(text.length()); labelText = QString::number(text.length());
} }
this->textLengthLabel.setText(labelText); this->ui.textEditLength->setText(labelText);
} }
void SplitInput::paintEvent(QPaintEvent *) void SplitInput::paintEvent(QPaintEvent *)
@ -265,7 +295,7 @@ void SplitInput::paintEvent(QPaintEvent *)
QPen pen(this->themeManager.splits.input.border); QPen pen(this->themeManager.splits.input.border);
if (this->themeManager.isLightTheme()) { if (this->themeManager.isLightTheme()) {
pen.setWidth((int)(6 * this->getDpiMultiplier())); pen.setWidth((int)(6 * this->getScale()));
} }
painter.setPen(pen); painter.setPen(pen);
painter.drawRect(0, 0, this->width() - 1, this->height() - 1); painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
@ -274,14 +304,10 @@ void SplitInput::paintEvent(QPaintEvent *)
void SplitInput::resizeEvent(QResizeEvent *) void SplitInput::resizeEvent(QResizeEvent *)
{ {
if (this->height() == this->maximumHeight()) { if (this->height() == this->maximumHeight()) {
this->textInput.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); this->ui.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
} else { } else {
this->textInput.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->ui.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
} }
this->setMaximumHeight((int)(150 * this->getDpiMultiplier()));
this->refreshTheme();
} }
void SplitInput::mousePressEvent(QMouseEvent *) void SplitInput::mousePressEvent(QMouseEvent *)

View file

@ -32,6 +32,8 @@ public:
pajlada::Signals::Signal<const QString &> textChanged; pajlada::Signals::Signal<const QString &> textChanged;
protected: protected:
virtual void scaleChangedEvent(float scale) override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
@ -41,16 +43,27 @@ private:
Split *const chatWidget; Split *const chatWidget;
std::unique_ptr<EmotePopup> emotePopup; std::unique_ptr<EmotePopup> emotePopup;
struct {
ResizingTextEdit *textEdit;
QLabel *textEditLength;
RippleEffectLabel *emoteButton;
QHBoxLayout *hbox;
} ui;
std::vector<pajlada::Signals::ScopedConnection> managedConnections; std::vector<pajlada::Signals::ScopedConnection> managedConnections;
QHBoxLayout hbox; // QHBoxLayout hbox;
QVBoxLayout vbox; // QVBoxLayout vbox;
QHBoxLayout editContainer; // QHBoxLayout editContainer;
ResizingTextEdit textInput; // ResizingTextEdit textInput;
QLabel textLengthLabel; // QLabel textLengthLabel;
RippleEffectLabel emotesLabel; // RippleEffectLabel emotesLabel;
QStringList prevMsg; QStringList prevMsg;
int prevIndex = 0; int prevIndex = 0;
virtual void refreshTheme() override;
void initLayout();
void installKeyPressedEvent();
virtual void themeRefreshEvent() override;
private slots: private slots:
void editTextChanged(); void editTextChanged();

View file

@ -53,6 +53,8 @@ Notebook::Notebook(Window *parent, bool _showButtons, const std::string &setting
closeConfirmDialog.setIcon(QMessageBox::Icon::Question); closeConfirmDialog.setIcon(QMessageBox::Icon::Question);
closeConfirmDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); closeConfirmDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
closeConfirmDialog.setDefaultButton(QMessageBox::Yes); closeConfirmDialog.setDefaultButton(QMessageBox::Yes);
// this->scaleChangedEvent(this->getScale());
} }
SplitContainer *Notebook::addNewPage() SplitContainer *Notebook::addNewPage()
@ -212,7 +214,7 @@ void Notebook::performLayout(bool animated)
singletons::SettingManager &settings = singletons::SettingManager::getInstance(); singletons::SettingManager &settings = singletons::SettingManager::getInstance();
int x = 0, y = 0; int x = 0, y = 0;
float scale = this->getDpiMultiplier(); float scale = this->getScale();
bool customFrame = this->parentWindow->hasCustomWindowFrame(); bool customFrame = this->parentWindow->hasCustomWindowFrame();
if (!this->showButtons || settings.hidePreferencesButton || customFrame) { if (!this->showButtons || settings.hidePreferencesButton || customFrame) {
@ -262,17 +264,20 @@ void Notebook::performLayout(bool animated)
void Notebook::resizeEvent(QResizeEvent *) void Notebook::resizeEvent(QResizeEvent *)
{ {
float scale = this->getDpiMultiplier(); this->performLayout(false);
}
this->settingsButton.resize(static_cast<int>(24 * scale), static_cast<int>(24 * scale)); void Notebook::scaleChangedEvent(float)
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)); float h = 24 * this->getScale();
this->settingsButton.setFixedSize(h, h);
this->userButton.setFixedSize(h, h);
this->addButton.setFixedSize(h, h);
for (auto &i : this->pages) { for (auto &i : this->pages) {
i->getTab()->calcSize(); i->getTab()->updateSize();
} }
this->performLayout(false);
} }
void Notebook::settingsButtonClicked() void Notebook::settingsButtonClicked()

View file

@ -48,6 +48,7 @@ public:
void previousTab(); void previousTab();
protected: protected:
void scaleChangedEvent(float scale);
void resizeEvent(QResizeEvent *); void resizeEvent(QResizeEvent *);
void settingsButtonMouseReleased(QMouseEvent *event); void settingsButtonMouseReleased(QMouseEvent *event);

View file

@ -18,7 +18,7 @@ Scrollbar::Scrollbar(ChannelView *parent)
, currentValueAnimation(this, "currentValue") , currentValueAnimation(this, "currentValue")
, smoothScrollingSetting(singletons::SettingManager::getInstance().enableSmoothScrolling) , smoothScrollingSetting(singletons::SettingManager::getInstance().enableSmoothScrolling)
{ {
resize((int)(16 * this->getDpiMultiplier()), 100); resize((int)(16 * this->getScale()), 100);
this->currentValueAnimation.setDuration(150); this->currentValueAnimation.setDuration(150);
this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic)); this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic));
@ -29,7 +29,7 @@ Scrollbar::Scrollbar(ChannelView *parent)
timer->setSingleShot(true); timer->setSingleShot(true);
connect(timer, &QTimer::timeout, [=]() { connect(timer, &QTimer::timeout, [=]() {
resize((int)(16 * this->getDpiMultiplier()), 100); resize((int)(16 * this->getScale()), 100);
timer->deleteLater(); timer->deleteLater();
}); });
@ -194,7 +194,7 @@ void Scrollbar::printCurrentState(const QString &prefix) const
void Scrollbar::paintEvent(QPaintEvent *) void Scrollbar::paintEvent(QPaintEvent *)
{ {
bool mouseOver = this->mouseOverIndex != -1; bool mouseOver = this->mouseOverIndex != -1;
int xOffset = mouseOver ? 0 : width() - (int)(4 * this->getDpiMultiplier()); int xOffset = mouseOver ? 0 : width() - (int)(4 * this->getScale());
QPainter painter(this); QPainter painter(this);
// painter.fillRect(rect(), this->themeManager.ScrollbarBG); // painter.fillRect(rect(), this->themeManager.ScrollbarBG);
@ -248,7 +248,7 @@ void Scrollbar::paintEvent(QPaintEvent *)
void Scrollbar::resizeEvent(QResizeEvent *) void Scrollbar::resizeEvent(QResizeEvent *)
{ {
this->resize((int)(16 * this->getDpiMultiplier()), this->height()); this->resize((int)(16 * this->getScale()), this->height());
} }
void Scrollbar::mouseMoveEvent(QMouseEvent *event) void Scrollbar::mouseMoveEvent(QMouseEvent *event)

View file

@ -29,7 +29,7 @@ SettingsDialog::SettingsDialog()
this->addTabs(); this->addTabs();
this->dpiMultiplierChanged(this->getDpiMultiplier(), this->getDpiMultiplier()); this->scaleChangedEvent(this->getScale());
} }
void SettingsDialog::initUi() void SettingsDialog::initUi()
@ -149,7 +149,7 @@ void SettingsDialog::refresh()
singletons::SettingManager::getInstance().saveSnapshot(); singletons::SettingManager::getInstance().saveSnapshot();
} }
void SettingsDialog::dpiMultiplierChanged(float oldDpi, float newDpi) void SettingsDialog::scaleChangedEvent(float newDpi)
{ {
QFile file(":/qss/settings.qss"); QFile file(":/qss/settings.qss");
file.open(QFile::ReadOnly); file.open(QFile::ReadOnly);

View file

@ -32,7 +32,7 @@ public:
static void showDialog(PreferredTab preferredTab = PreferredTab::NoPreference); static void showDialog(PreferredTab preferredTab = PreferredTab::NoPreference);
protected: protected:
virtual void dpiMultiplierChanged(float oldDpi, float newDpi) override; virtual void scaleChangedEvent(float newDpi) override;
private: private:
void refresh(); void refresh();

View file

@ -87,7 +87,7 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
this->channelNameUpdated(this->channelName.getValue()); this->channelNameUpdated(this->channelName.getValue());
this->input.textInput.installEventFilter(parent); this->input.ui.textEdit->installEventFilter(parent);
this->view.mouseDown.connect([this](QMouseEvent *) { this->giveFocus(Qt::MouseFocusReason); }); this->view.mouseDown.connect([this](QMouseEvent *) { this->giveFocus(Qt::MouseFocusReason); });
this->view.selectionChanged.connect([this]() { this->view.selectionChanged.connect([this]() {
@ -259,12 +259,12 @@ void Split::updateLastReadMessage()
void Split::giveFocus(Qt::FocusReason reason) void Split::giveFocus(Qt::FocusReason reason)
{ {
this->input.textInput.setFocus(reason); this->input.ui.textEdit->setFocus(reason);
} }
bool Split::hasFocus() const bool Split::hasFocus() const
{ {
return this->input.textInput.hasFocus(); return this->input.ui.textEdit->hasFocus();
} }
void Split::paintEvent(QPaintEvent *) void Split::paintEvent(QPaintEvent *)

View file

@ -40,7 +40,7 @@ TooltipWidget::~TooltipWidget()
this->fontChangedConnection.disconnect(); this->fontChangedConnection.disconnect();
} }
void TooltipWidget::dpiMultiplierChanged(float, float) void TooltipWidget::scaleChangedEvent(float)
{ {
this->updateFont(); this->updateFont();
} }
@ -48,7 +48,7 @@ void TooltipWidget::dpiMultiplierChanged(float, float)
void TooltipWidget::updateFont() void TooltipWidget::updateFont()
{ {
this->setFont(singletons::FontManager::getInstance().getFont( this->setFont(singletons::FontManager::getInstance().getFont(
singletons::FontManager::Type::MediumSmall, this->getDpiMultiplier())); singletons::FontManager::Type::MediumSmall, this->getScale()));
} }
void TooltipWidget::setText(QString text) void TooltipWidget::setText(QString text)

View file

@ -29,7 +29,7 @@ public:
protected: protected:
virtual void changeEvent(QEvent *) override; virtual void changeEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override; virtual void leaveEvent(QEvent *) override;
virtual void dpiMultiplierChanged(float, float) override; virtual void scaleChangedEvent(float) override;
private: private:
QLabel *displayText; QLabel *displayText;

View file

@ -23,7 +23,7 @@ Window::Window(const QString &windowName, singletons::ThemeManager &_themeManage
: BaseWindow(_themeManager, nullptr, true) : BaseWindow(_themeManager, nullptr, true)
, settingRoot(fS("/windows/{}", windowName)) , settingRoot(fS("/windows/{}", windowName))
, windowGeometry(this->settingRoot) , windowGeometry(this->settingRoot)
, dpi(this->getDpiMultiplier()) , dpi(this->getScale())
, themeManager(_themeManager) , themeManager(_themeManager)
, notebook(this, _isMainWindow, this->settingRoot) , notebook(this, _isMainWindow, this->settingRoot)
{ {
@ -58,7 +58,7 @@ Window::Window(const QString &windowName, singletons::ThemeManager &_themeManage
// set margin // set margin
layout->setMargin(0); layout->setMargin(0);
this->refreshTheme(); this->themeRefreshEvent();
this->loadGeometry(); this->loadGeometry();