From 0a8073d0e5fc4cb63c077683f23d10c47e27354d Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 25 Jan 2018 20:49:49 +0100 Subject: [PATCH] refactored SplitInput --- .vs/ProjectSettings.json | 3 + .vs/VSWorkspaceState.json | 7 + .vs/slnx.sqlite | Bin 0 -> 73728 bytes src/widgets/accountpopup.cpp | 4 +- src/widgets/accountpopup.hpp | 2 +- src/widgets/basewidget.cpp | 77 +++++++-- src/widgets/basewidget.hpp | 23 ++- src/widgets/basewindow.cpp | 26 ++-- src/widgets/basewindow.hpp | 2 +- src/widgets/helper/channelview.cpp | 17 +- src/widgets/helper/channelview.hpp | 2 +- src/widgets/helper/notebooktab.cpp | 24 +-- src/widgets/helper/notebooktab.hpp | 20 +-- src/widgets/helper/rippleeffectbutton.cpp | 2 +- src/widgets/helper/splitheader.cpp | 6 +- src/widgets/helper/splitheader.hpp | 2 +- src/widgets/helper/splitinput.cpp | 180 +++++++++++++--------- src/widgets/helper/splitinput.hpp | 27 +++- src/widgets/notebook.cpp | 21 ++- src/widgets/notebook.hpp | 1 + src/widgets/scrollbar.cpp | 8 +- src/widgets/settingsdialog.cpp | 4 +- src/widgets/settingsdialog.hpp | 2 +- src/widgets/split.cpp | 6 +- src/widgets/tooltipwidget.cpp | 4 +- src/widgets/tooltipwidget.hpp | 2 +- src/widgets/window.cpp | 4 +- 27 files changed, 296 insertions(+), 180 deletions(-) create mode 100644 .vs/ProjectSettings.json create mode 100644 .vs/VSWorkspaceState.json create mode 100644 .vs/slnx.sqlite diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 000000000..866f1e137 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 000000000..b23974898 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\ISSUE_TEMPLATE.md", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..e43235e20bc1d323a9dcfe3d8b2b214a77c57261 GIT binary patch literal 73728 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 literal 0 HcmV?d00001 diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index e1a84d732..7502a548a 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -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: px; }") .replace("", QString::number((int)(12 * newDpi)))); diff --git a/src/widgets/accountpopup.hpp b/src/widgets/accountpopup.hpp index aeac473b4..b2ec8b522 100644 --- a/src/widgets/accountpopup.hpp +++ b/src/widgets/accountpopup.hpp @@ -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; diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index 808a59412..c15ef9cbf 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -2,6 +2,7 @@ #include "singletons/settingsmanager.hpp" #include "singletons/thememanager.hpp" +#include #include #include #include @@ -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(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(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(child); + if (widget != nullptr) { + widget->setScale(scale); + continue; + } + + // QLayout *layout = nullptr; + // QWidget *widget = dynamic_cast(child); + + // if (widget != nullptr) { + // layout = widget->layout(); + // } + + // else { + QLayout *layout = dynamic_cast(object); + + if (layout != nullptr) { + setScaleRecursive(scale, layout); + } + // } + } +} + +void BaseWidget::scaleChangedEvent(float newDpi) +{ +} + +void BaseWidget::themeRefreshEvent() { // Do any color scheme updates here } diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index 0228418b1..86479ab15 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include 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 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 widgets; + + static void setScaleRecursive(float scale, QObject *object); + + friend class BaseWindow; }; } // namespace widgets diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index 9ef8cb871..3bf96fd6c 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -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(this->width() * resizeScale), + static_cast(this->height() * resizeScale)); - this->resize(static_cast(this->width() * scale), - static_cast(this->height() * scale)); + this->setScale(_scale); return true; } diff --git a/src/widgets/basewindow.hpp b/src/widgets/basewindow.hpp index 2ec8e196f..fc6ccd756 100644 --- a/src/widgets/basewindow.hpp +++ b/src/widgets/basewindow.hpp @@ -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(); diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 12944c25a..8d7525b2e 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -25,8 +25,7 @@ #include #include -#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(); diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index 113e3b981..9212e3368 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -53,7 +53,7 @@ public: pajlada::Signals::Signal linkClicked; protected: - virtual void refreshTheme() override; + virtual void themeRefreshEvent() override; virtual void resizeEvent(QResizeEvent *) override; diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index fc91dd4be..0034dc76e 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -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((fontMetrics().width(qTitle) + 16) * scale), - static_cast(24 * scale)); + this->resize((int)((fontMetrics().width(qTitle) + 16) * scale), (int)(24 * scale)); } else { - this->resize(static_cast((fontMetrics().width(qTitle) + 8 + 24) * scale), - static_cast(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(16) * scale); QRect rect(0, 0, this->width() - rectW, this->height()); diff --git a/src/widgets/helper/notebooktab.hpp b/src/widgets/helper/notebooktab.hpp index f51cc9977..f97171932 100644 --- a/src/widgets/helper/notebooktab.hpp +++ b/src/widgets/helper/notebooktab.hpp @@ -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 managedConnections; @@ -80,7 +82,7 @@ private: QRect getXRect() { - float scale = this->getDpiMultiplier(); + float scale = this->getScale(); return QRect(this->width() - static_cast(20 * scale), static_cast(4 * scale), static_cast(16 * scale), static_cast(16 * scale)); } diff --git a/src/widgets/helper/rippleeffectbutton.cpp b/src/widgets/helper/rippleeffectbutton.cpp index 6ce8d243f..9462cf118 100644 --- a/src/widgets/helper/rippleeffectbutton.cpp +++ b/src/widgets/helper/rippleeffectbutton.cpp @@ -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); diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index 1390845c0..b9f09925d 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -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); diff --git a/src/widgets/helper/splitheader.hpp b/src/widgets/helper/splitheader.hpp index 900f151dc..568b75158 100644 --- a/src/widgets/helper/splitheader.hpp +++ b/src/widgets/helper/splitheader.hpp @@ -57,7 +57,7 @@ private: void rightButtonClicked(); - virtual void refreshTheme() override; + virtual void themeRefreshEvent() override; void initializeChannelSignals(); diff --git a/src/widgets/helper/splitinput.cpp b/src/widgets/helper/splitinput.cpp index 8e17a0500..06c4638ed 100644 --- a/src/widgets/helper/splitinput.cpp +++ b/src/widgets/helper/splitinput.cpp @@ -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 layoutCreator(this); + + auto layout = layoutCreator.setLayoutType().withoutMargin().assign(&this->ui.hbox); + + // input + auto textEdit = layout.emplace().assign(&this->ui.textEdit); + connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this, + &SplitInput::editTextChanged); + + // right box + auto box = layout.emplace().withoutMargin(); + box->setSpacing(0); + { + auto textEditLength = box.emplace().assign(&this->ui.textEditLength); + textEditLength->setAlignment(Qt::AlignRight); + + box->addStretch(1); + box.emplace().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(""); - - 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(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 = ""; + 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 *) diff --git a/src/widgets/helper/splitinput.hpp b/src/widgets/helper/splitinput.hpp index 951efd9c2..9718b984e 100644 --- a/src/widgets/helper/splitinput.hpp +++ b/src/widgets/helper/splitinput.hpp @@ -32,6 +32,8 @@ public: pajlada::Signals::Signal 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; + struct { + ResizingTextEdit *textEdit; + QLabel *textEditLength; + RippleEffectLabel *emoteButton; + + QHBoxLayout *hbox; + } ui; + std::vector 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(); diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 1849f6341..3158c24b9 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -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(24 * scale), static_cast(24 * scale)); - this->userButton.resize(static_cast(24 * scale), static_cast(24 * scale)); - this->addButton.resize(static_cast(24 * scale), static_cast(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() diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index 4c24d19a8..082768afd 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -48,6 +48,7 @@ public: void previousTab(); protected: + void scaleChangedEvent(float scale); void resizeEvent(QResizeEvent *); void settingsButtonMouseReleased(QMouseEvent *event); diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index 08755bf6a..720c2e88e 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -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) diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 2b1f20c9c..039c6ee8b 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -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); diff --git a/src/widgets/settingsdialog.hpp b/src/widgets/settingsdialog.hpp index d870e1931..2feecfc99 100644 --- a/src/widgets/settingsdialog.hpp +++ b/src/widgets/settingsdialog.hpp @@ -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(); diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index d61fcebc2..6f5952b06 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -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 *) diff --git a/src/widgets/tooltipwidget.cpp b/src/widgets/tooltipwidget.cpp index fa7e9c5dc..3d4ed9e66 100644 --- a/src/widgets/tooltipwidget.cpp +++ b/src/widgets/tooltipwidget.cpp @@ -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) diff --git a/src/widgets/tooltipwidget.hpp b/src/widgets/tooltipwidget.hpp index 46fabbccb..96f3af2ca 100644 --- a/src/widgets/tooltipwidget.hpp +++ b/src/widgets/tooltipwidget.hpp @@ -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; diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index c7ecdb039..0b5f58bcc 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -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();