fix: get rid of duplicate scale events (#5404)
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
- Dev: Add doxygen build target. (#5377)
|
- Dev: Add doxygen build target. (#5377)
|
||||||
- Dev: Make printing of strings in tests easier. (#5379)
|
- Dev: Make printing of strings in tests easier. (#5379)
|
||||||
- Dev: Refactor and document `Scrollbar`. (#5334, #5393)
|
- Dev: Refactor and document `Scrollbar`. (#5334, #5393)
|
||||||
|
- Dev: Reduced the amount of scale events. (#5404)
|
||||||
|
|
||||||
## 2.5.1
|
## 2.5.1
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ float BaseWidget::scale() const
|
|||||||
|
|
||||||
void BaseWidget::setScale(float value)
|
void BaseWidget::setScale(float value)
|
||||||
{
|
{
|
||||||
// update scale value
|
if (this->scale_ == value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->scale_ = value;
|
this->scale_ = value;
|
||||||
|
|
||||||
this->scaleChangedEvent(this->scale());
|
this->scaleChangedEvent(this->scale());
|
||||||
|
|||||||
@@ -227,7 +227,6 @@ BaseWindow::BaseWindow(FlagsEnum<Flags> _flags, QWidget *parent)
|
|||||||
[this]() {
|
[this]() {
|
||||||
postToThread([this] {
|
postToThread([this] {
|
||||||
this->updateScale();
|
this->updateScale();
|
||||||
this->updateScale();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
this->connections_, false);
|
this->connections_, false);
|
||||||
|
|||||||
@@ -593,6 +593,12 @@ void Notebook::showTabVisibilityInfoPopup()
|
|||||||
|
|
||||||
void Notebook::refresh()
|
void Notebook::refresh()
|
||||||
{
|
{
|
||||||
|
if (this->refreshPaused_)
|
||||||
|
{
|
||||||
|
this->refreshRequested_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->performLayout();
|
this->performLayout();
|
||||||
this->updateTabVisibility();
|
this->updateTabVisibility();
|
||||||
}
|
}
|
||||||
@@ -652,13 +658,20 @@ void Notebook::resizeAddButton()
|
|||||||
this->addButton_->setFixedSize(h, h);
|
this->addButton_->setFixedSize(h, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notebook::scaleChangedEvent(float)
|
void Notebook::scaleChangedEvent(float /*scale*/)
|
||||||
{
|
{
|
||||||
this->resizeAddButton();
|
this->resizeAddButton();
|
||||||
|
this->refreshPaused_ = true;
|
||||||
|
this->refreshRequested_ = false;
|
||||||
for (auto &i : this->items_)
|
for (auto &i : this->items_)
|
||||||
{
|
{
|
||||||
i.tab->updateSize();
|
i.tab->updateSize();
|
||||||
}
|
}
|
||||||
|
this->refreshPaused_ = false;
|
||||||
|
if (this->refreshRequested_)
|
||||||
|
{
|
||||||
|
this->refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notebook::resizeEvent(QResizeEvent *)
|
void Notebook::resizeEvent(QResizeEvent *)
|
||||||
|
|||||||
@@ -193,7 +193,12 @@ private:
|
|||||||
bool showAddButton_ = false;
|
bool showAddButton_ = false;
|
||||||
int lineOffset_ = 20;
|
int lineOffset_ = 20;
|
||||||
bool lockNotebookLayout_ = false;
|
bool lockNotebookLayout_ = false;
|
||||||
|
|
||||||
|
bool refreshPaused_ = false;
|
||||||
|
bool refreshRequested_ = false;
|
||||||
|
|
||||||
NotebookTabLocation tabLocation_ = NotebookTabLocation::Top;
|
NotebookTabLocation tabLocation_ = NotebookTabLocation::Top;
|
||||||
|
|
||||||
QAction *lockNotebookLayoutAction_;
|
QAction *lockNotebookLayoutAction_;
|
||||||
QAction *showTabsAction_;
|
QAction *showTabsAction_;
|
||||||
QAction *toggleTopMostAction_;
|
QAction *toggleTopMostAction_;
|
||||||
|
|||||||
@@ -397,9 +397,9 @@ void SettingsDialog::refresh()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::scaleChangedEvent(float newDpi)
|
void SettingsDialog::scaleChangedEvent(float newScale)
|
||||||
{
|
{
|
||||||
assert(newDpi == 1.F &&
|
assert(newScale == 1.F &&
|
||||||
"Scaling is disabled for the settings dialog - its scale should "
|
"Scaling is disabled for the settings dialog - its scale should "
|
||||||
"always be 1");
|
"always be 1");
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
#include "util/Clamp.hpp"
|
|
||||||
#include "util/Helpers.hpp"
|
#include "util/Helpers.hpp"
|
||||||
#include "widgets/dialogs/SettingsDialog.hpp"
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||||
#include "widgets/Notebook.hpp"
|
#include "widgets/Notebook.hpp"
|
||||||
@@ -25,6 +24,8 @@
|
|||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace {
|
namespace {
|
||||||
// Translates the given rectangle by an amount in the direction to appear like the tab is selected.
|
// Translates the given rectangle by an amount in the direction to appear like the tab is selected.
|
||||||
@@ -182,10 +183,15 @@ void NotebookTab::growWidth(int width)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int NotebookTab::normalTabWidth()
|
int NotebookTab::normalTabWidth() const
|
||||||
|
{
|
||||||
|
return this->normalTabWidthForHeight(this->height());
|
||||||
|
}
|
||||||
|
|
||||||
|
int NotebookTab::normalTabWidthForHeight(int height) const
|
||||||
{
|
{
|
||||||
float scale = this->scale();
|
float scale = this->scale();
|
||||||
int width;
|
int width = 0;
|
||||||
|
|
||||||
QFontMetrics metrics =
|
QFontMetrics metrics =
|
||||||
getIApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
|
getIApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
|
||||||
@@ -199,13 +205,13 @@ int NotebookTab::normalTabWidth()
|
|||||||
width = (metrics.horizontalAdvance(this->getTitle()) + int(16 * scale));
|
width = (metrics.horizontalAdvance(this->getTitle()) + int(16 * scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->height() > 150 * scale)
|
if (static_cast<float>(height) > 150 * scale)
|
||||||
{
|
{
|
||||||
width = this->height();
|
width = height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
width = clamp(width, this->height(), int(150 * scale));
|
width = std::clamp(width, height, static_cast<int>(150 * scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
@@ -214,8 +220,8 @@ int NotebookTab::normalTabWidth()
|
|||||||
void NotebookTab::updateSize()
|
void NotebookTab::updateSize()
|
||||||
{
|
{
|
||||||
float scale = this->scale();
|
float scale = this->scale();
|
||||||
int width = this->normalTabWidth();
|
auto height = static_cast<int>(NOTEBOOK_TAB_HEIGHT * scale);
|
||||||
auto height = int(NOTEBOOK_TAB_HEIGHT * scale);
|
int width = this->normalTabWidthForHeight(height);
|
||||||
|
|
||||||
if (width < this->growWidth_)
|
if (width < this->growWidth_)
|
||||||
{
|
{
|
||||||
@@ -628,13 +634,13 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotebookTab::hasXButton()
|
bool NotebookTab::hasXButton() const
|
||||||
{
|
{
|
||||||
return getSettings()->showTabCloseButton &&
|
return getSettings()->showTabCloseButton &&
|
||||||
this->notebook_->getAllowUserTabManagement();
|
this->notebook_->getAllowUserTabManagement();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotebookTab::shouldDrawXButton()
|
bool NotebookTab::shouldDrawXButton() const
|
||||||
{
|
{
|
||||||
return this->hasXButton() && (this->mouseOver_ || this->selected_);
|
return this->hasXButton() && (this->mouseOver_ || this->selected_);
|
||||||
}
|
}
|
||||||
@@ -820,18 +826,15 @@ void NotebookTab::update()
|
|||||||
Button::update();
|
Button::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect NotebookTab::getXRect()
|
QRect NotebookTab::getXRect() const
|
||||||
{
|
{
|
||||||
QRect rect = this->rect();
|
QRect rect = this->rect();
|
||||||
float s = this->scale();
|
float s = this->scale();
|
||||||
int size = static_cast<int>(16 * s);
|
int size = static_cast<int>(16 * s);
|
||||||
|
|
||||||
int centerAdjustment =
|
int centerAdjustment = this->tabLocation_ == NotebookTabLocation::Top
|
||||||
this->tabLocation_ ==
|
? (size / 3) // slightly off true center
|
||||||
(NotebookTabLocation::Top ||
|
: (size / 2); // true center
|
||||||
this->tabLocation_ == NotebookTabLocation::Bottom)
|
|
||||||
? (size / 3) // slightly off true center
|
|
||||||
: (size / 2); // true center
|
|
||||||
|
|
||||||
QRect xRect(rect.right() - static_cast<int>(20 * s),
|
QRect xRect(rect.right() - static_cast<int>(20 * s),
|
||||||
rect.center().y() - centerAdjustment, size, size);
|
rect.center().y() - centerAdjustment, size, size);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
void hideTabXChanged();
|
void hideTabXChanged();
|
||||||
|
|
||||||
void growWidth(int width);
|
void growWidth(int width);
|
||||||
int normalTabWidth();
|
int normalTabWidth() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void themeChangedEvent() override;
|
void themeChangedEvent() override;
|
||||||
@@ -100,11 +100,13 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void showRenameDialog();
|
void showRenameDialog();
|
||||||
|
|
||||||
bool hasXButton();
|
bool hasXButton() const;
|
||||||
bool shouldDrawXButton();
|
bool shouldDrawXButton() const;
|
||||||
QRect getXRect();
|
QRect getXRect() const;
|
||||||
void titleUpdated();
|
void titleUpdated();
|
||||||
|
|
||||||
|
int normalTabWidthForHeight(int height) const;
|
||||||
|
|
||||||
QPropertyAnimation positionChangedAnimation_;
|
QPropertyAnimation positionChangedAnimation_;
|
||||||
bool positionChangedAnimationRunning_ = false;
|
bool positionChangedAnimationRunning_ = false;
|
||||||
QPoint positionAnimationDesiredPoint_;
|
QPoint positionAnimationDesiredPoint_;
|
||||||
|
|||||||
@@ -271,6 +271,8 @@ SplitHeader::SplitHeader(Split *split)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->scaleChangedEvent(this->scale());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitHeader::initializeLayout()
|
void SplitHeader::initializeLayout()
|
||||||
|
|||||||
Reference in New Issue
Block a user