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->dpiMultiplierChanged(this->getDpiMultiplier(), this->getDpiMultiplier());
this->scaleChangedEvent(this->getScale());
}
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; }")
.replace("<font-size>", QString::number((int)(12 * newDpi))));

View file

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

View file

@ -2,6 +2,7 @@
#include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp"
#include <QChildEvent>
#include <QDebug>
#include <QIcon>
#include <QLayout>
@ -25,13 +26,7 @@ BaseWidget::BaseWidget(BaseWidget *parent, Qt::WindowFlags f)
this->init();
}
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, themeManager(singletons::ThemeManager::getInstance())
{
}
float BaseWidget::getDpiMultiplier()
float BaseWidget::getScale() const
{
// return 1.f;
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
@ -39,17 +34,14 @@ float BaseWidget::getDpiMultiplier()
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;
return baseWidget->scale;
}
}
void BaseWidget::init()
{
auto connection = this->themeManager.updated.connect([this]() {
this->refreshTheme();
this->themeRefreshEvent();
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
}

View file

@ -1,6 +1,7 @@
#pragma once
#include <QWidget>
#include <pajlada/signals/signal.hpp>
namespace chatterino {
namespace singletons {
@ -8,6 +9,7 @@ class ThemeManager;
}
namespace widgets {
class BaseWindow;
class BaseWidget : public QWidget
{
@ -17,23 +19,30 @@ public:
explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *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;
float getDpiMultiplier();
float getScale() const;
pajlada::Signals::Signal<float> scaleChanged;
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:
void init();
float scale = 1.f;
std::vector<BaseWidget *> widgets;
static void setScaleRecursive(float scale, QObject *object);
friend class BaseWindow;
};
} // namespace widgets

View file

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

View file

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

View file

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

View file

@ -53,7 +53,7 @@ public:
pajlada::Signals::Signal<const messages::Link &> linkClicked;
protected:
virtual void refreshTheme() override;
virtual void themeRefreshEvent() 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)
, menu(this)
{
this->calcSize();
this->setAcceptDrops(true);
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
@ -65,22 +64,25 @@ NotebookTab::NotebookTab(Notebook *_notebook, const std::string &_uuid)
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); //
});
}
void NotebookTab::calcSize()
void NotebookTab::themeRefreshEvent()
{
float scale = getDpiMultiplier();
this->update();
}
void NotebookTab::updateSize()
{
float scale = getScale();
QString qTitle(qS(this->title));
if (singletons::SettingManager::getInstance().hideTabX) {
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 16) * scale),
static_cast<int>(24 * scale));
this->resize((int)((fontMetrics().width(qTitle) + 16) * scale), (int)(24 * scale));
} else {
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 8 + 24) * scale),
static_cast<int>(24 * scale));
this->resize((int)((fontMetrics().width(qTitle) + 8 + 24) * scale), (int)(24 * scale));
}
if (this->parent() != nullptr) {
@ -97,7 +99,7 @@ void NotebookTab::setTitle(const QString &newTitle)
{
this->title = newTitle.toStdString();
this->calcSize();
this->updateSize();
}
bool NotebookTab::isSelected() const
@ -134,7 +136,7 @@ QRect NotebookTab::getDesiredRect() const
void NotebookTab::hideTabXChanged(bool)
{
this->calcSize();
this->updateSize();
this->update();
}
@ -197,7 +199,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
painter.setPen(colors.text);
// set area for text
float scale = this->getDpiMultiplier();
float scale = this->getScale();
int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale);
QRect rect(0, 0, this->width() - rectW, this->height());

View file

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

View file

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

View file

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

View file

@ -4,6 +4,7 @@
#include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp"
#include "util/layoutcreator.hpp"
#include "widgets/notebook.hpp"
#include "widgets/split.hpp"
#include "widgets/splitcontainer.hpp"
@ -17,41 +18,59 @@ namespace widgets {
SplitInput::SplitInput(Split *_chatWidget)
: BaseWidget(_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->hbox.addLayout(&this->vbox);
this->ui.textEdit->setCompleter(completer);
// misc
this->installKeyPressedEvent();
this->themeRefreshEvent();
this->scaleChangedEvent(this->getScale());
}
void SplitInput::initLayout()
{
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->textInput.setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getDpiMultiplier()));
this->ui.textEdit->setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getScale()));
}));
this->editContainer.addWidget(&this->textInput);
this->editContainer.setMargin(2);
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] {
// open emote popup
QObject::connect(this->ui.emoteButton, &RippleEffectLabel::clicked, [this] {
if (!this->emotePopup) {
this->emotePopup = std::make_unique<EmotePopup>(this->themeManager);
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()),
(int)(500 * this->emotePopup->getDpiMultiplier()));
this->emotePopup->resize((int)(300 * this->emotePopup->getScale()),
(int)(500 * this->emotePopup->getScale()));
this->emotePopup->loadChannel(this->chatWidget->getChannel());
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();
textLengthLabel.setHidden(!singletons::SettingManager::getInstance().showMessageLength);
// textEditLength visibility
singletons::SettingManager::getInstance().showMessageLength.connect(
[this](const bool &value, auto) { this->ui.textEditLength->setHidden(!value); },
this->managedConnections);
}
auto completer = new QCompleter(
singletons::CompletionManager::getInstance().createModel(this->chatWidget->channelName));
void SplitInput::scaleChangedEvent(float scale)
{
// 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) {
auto c = this->chatWidget->getChannel();
if (c == nullptr) {
return;
}
QString message = textInput.toPlainText();
QString message = ui.textEdit->toPlainText();
QString sendMessage =
singletons::CommandManager::getInstance().execCommand(message, c, false);
@ -94,9 +146,9 @@ SplitInput::SplitInput(Split *_chatWidget)
event->accept();
if (!(event->modifiers() == Qt::ControlModifier)) {
this->textInput.setText(QString());
this->ui.textEdit->setText(QString());
this->prevIndex = 0;
} else if (this->textInput.toPlainText() ==
} else if (this->ui.textEdit->toPlainText() ==
this->prevMsg.at(this->prevMsg.size() - 1)) {
this->prevMsg.removeLast();
}
@ -115,7 +167,7 @@ SplitInput::SplitInput(Split *_chatWidget)
} else {
if (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 if (event->key() == Qt::Key_Down) {
@ -133,10 +185,10 @@ SplitInput::SplitInput(Split *_chatWidget)
if (this->prevIndex != (this->prevMsg.size() - 1) &&
this->prevIndex != this->prevMsg.size()) {
this->prevIndex++;
this->textInput.setText(this->prevMsg.at(this->prevIndex));
this->ui.textEdit->setText(this->prevMsg.at(this->prevIndex));
} else {
this->prevIndex = this->prevMsg.size();
this->textInput.setText(QString());
this->ui.textEdit->setText(QString());
}
}
} 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()
{
QTextCursor c = this->textInput.textCursor();
QTextCursor c = this->ui.textEdit->textCursor();
c.setPosition(c.position());
c.setPosition(c.position(), QTextCursor::KeepAnchor);
this->textInput.setTextCursor(c);
this->ui.textEdit->setTextCursor(c);
}
QString SplitInput::getInputText() const
{
return this->textInput.toPlainText();
return this->ui.textEdit->toPlainText();
}
void SplitInput::insertText(const QString &text)
{
this->textInput.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());
this->ui.textEdit->insertPlainText(text);
}
void SplitInput::editTextChanged()
{
QString text = this->textInput.toPlainText();
// set textLengthLabel value
QString text = this->ui.textEdit->toPlainText();
this->textChanged.invoke(text);
@ -254,7 +284,7 @@ void SplitInput::editTextChanged()
labelText = QString::number(text.length());
}
this->textLengthLabel.setText(labelText);
this->ui.textEditLength->setText(labelText);
}
void SplitInput::paintEvent(QPaintEvent *)
@ -265,7 +295,7 @@ void SplitInput::paintEvent(QPaintEvent *)
QPen pen(this->themeManager.splits.input.border);
if (this->themeManager.isLightTheme()) {
pen.setWidth((int)(6 * this->getDpiMultiplier()));
pen.setWidth((int)(6 * this->getScale()));
}
painter.setPen(pen);
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
@ -274,14 +304,10 @@ void SplitInput::paintEvent(QPaintEvent *)
void SplitInput::resizeEvent(QResizeEvent *)
{
if (this->height() == this->maximumHeight()) {
this->textInput.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
this->ui.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
} else {
this->textInput.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->ui.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
this->setMaximumHeight((int)(150 * this->getDpiMultiplier()));
this->refreshTheme();
}
void SplitInput::mousePressEvent(QMouseEvent *)

View file

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

View file

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

View file

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

View file

@ -18,7 +18,7 @@ Scrollbar::Scrollbar(ChannelView *parent)
, currentValueAnimation(this, "currentValue")
, smoothScrollingSetting(singletons::SettingManager::getInstance().enableSmoothScrolling)
{
resize((int)(16 * this->getDpiMultiplier()), 100);
resize((int)(16 * this->getScale()), 100);
this->currentValueAnimation.setDuration(150);
this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic));
@ -29,7 +29,7 @@ Scrollbar::Scrollbar(ChannelView *parent)
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, [=]() {
resize((int)(16 * this->getDpiMultiplier()), 100);
resize((int)(16 * this->getScale()), 100);
timer->deleteLater();
});
@ -194,7 +194,7 @@ void Scrollbar::printCurrentState(const QString &prefix) const
void Scrollbar::paintEvent(QPaintEvent *)
{
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);
// painter.fillRect(rect(), this->themeManager.ScrollbarBG);
@ -248,7 +248,7 @@ void Scrollbar::paintEvent(QPaintEvent *)
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)

View file

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

View file

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

View file

@ -87,7 +87,7 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
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.selectionChanged.connect([this]() {
@ -259,12 +259,12 @@ void Split::updateLastReadMessage()
void Split::giveFocus(Qt::FocusReason reason)
{
this->input.textInput.setFocus(reason);
this->input.ui.textEdit->setFocus(reason);
}
bool Split::hasFocus() const
{
return this->input.textInput.hasFocus();
return this->input.ui.textEdit->hasFocus();
}
void Split::paintEvent(QPaintEvent *)

View file

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

View file

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

View file

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