Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chatterino7
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed May 19, 2024
2 parents a4c3831 + 8689bdb commit a3ef8a1
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: clang-tidy review
timeout-minutes: 20
uses: ZedThree/clang-tidy-review@v0.18.0
uses: ZedThree/clang-tidy-review@v0.19.0
with:
build_dir: build-clang-tidy
config_file: ".clang-tidy"
Expand All @@ -62,4 +62,4 @@ jobs:
libxkbcommon-x11-0, libxcb-xkb-dev, libxcb-cursor0
- name: clang-tidy-review upload
uses: ZedThree/clang-tidy-review/upload@v0.18.0
uses: ZedThree/clang-tidy-review/upload@v0.19.0
2 changes: 1 addition & 1 deletion .github/workflows/post-clang-tidy-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- uses: ZedThree/clang-tidy-review/post@v0.18.0
- uses: ZedThree/clang-tidy-review/post@v0.19.0
with:
lgtm_comment_body: ""
num_comments_as_exitcode: false
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
- Major: Improve high-DPI support on Windows. (#4868, #5391)
- Minor: Add option to customise Moderation buttons with images. (#5369)
- Minor: Colored usernames now update on the fly when changing the "Color @usernames" setting. (#5300)
- Minor: Added `flags.action` filter variable, allowing you to filter on `/me` messages. (#5397)
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
- Dev: Use Qt's high DPI scaling. (#4868)
- Dev: Use Qt's high DPI scaling. (#4868, #5400)
- Dev: Add doxygen build target. (#5377)
- Dev: Make printing of strings in tests easier. (#5379)
- Dev: Refactor and document `Scrollbar`. (#5334, #5393)
- Dev: Reduced the amount of scale events. (#5404)

## 2.5.1

Expand Down
1 change: 1 addition & 0 deletions src/controllers/filters/lang/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
{"channel.name", m->channelName},
{"channel.watching", watching},

{"flags.action", m->flags.has(MessageFlag::Action)},
{"flags.highlighted", m->flags.has(MessageFlag::Highlighted)},
{"flags.points_redeemed", m->flags.has(MessageFlag::RedeemedHighlight)},
{"flags.sub_message", m->flags.has(MessageFlag::Subscription)},
Expand Down
1 change: 1 addition & 0 deletions src/controllers/filters/lang/Filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static const QMap<QString, Type> MESSAGE_TYPING_CONTEXT = {
{"channel.name", Type::String},
{"channel.watching", Type::Bool},
{"channel.live", Type::Bool},
{"flags.action", Type::Bool},
{"flags.highlighted", Type::Bool},
{"flags.points_redeemed", Type::Bool},
{"flags.sub_message", Type::Bool},
Expand Down
1 change: 1 addition & 0 deletions src/controllers/filters/lang/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const QMap<QString, QString> validIdentifiersMap = {
{"channel.name", "channel name"},
{"channel.watching", "/watching channel?"},
{"channel.live", "channel live?"},
{"flags.action", "action/me message?"},
{"flags.highlighted", "highlighted?"},
{"flags.points_redeemed", "redeemed points?"},
{"flags.sub_message", "sub/resub message?"},
Expand Down
6 changes: 5 additions & 1 deletion src/widgets/BaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ float BaseWidget::scale() const

void BaseWidget::setScale(float value)
{
// update scale value
if (this->scale_ == value)
{
return;
}

this->scale_ = value;

this->scaleChangedEvent(this->scale());
Expand Down
23 changes: 20 additions & 3 deletions src/widgets/BaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ BaseWindow::BaseWindow(FlagsEnum<Flags> _flags, QWidget *parent)
[this]() {
postToThread([this] {
this->updateScale();
this->updateScale();
});
},
this->connections_, false);
Expand Down Expand Up @@ -931,9 +930,27 @@ void BaseWindow::updateScale()

this->setScale(scale);

for (auto *child : this->findChildren<BaseWidget *>())
BaseWindow::applyScaleRecursive(this, scale);
}

// NOLINTNEXTLINE(misc-no-recursion)
void BaseWindow::applyScaleRecursive(QObject *root, float scale)
{
for (QObject *obj : root->children())
{
child->setScale(scale);
auto *base = dynamic_cast<BaseWidget *>(obj);
if (base)
{
auto *window = dynamic_cast<BaseWindow *>(obj);
if (window)
{
// stop here, the window will get the event as well (via uiScale)
continue;
}
base->setScale(scale);
}

applyScaleRecursive(obj, scale);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/widgets/BaseWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class BaseWindow : public BaseWidget
void drawCustomWindowFrame(QPainter &painter);
void onFocusLost();

static void applyScaleRecursive(QObject *root, float scale);

bool handleSHOWWINDOW(MSG *msg);
bool handleSIZE(MSG *msg);
bool handleMOVE(MSG *msg);
Expand Down
15 changes: 14 additions & 1 deletion src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@ void Notebook::showTabVisibilityInfoPopup()

void Notebook::refresh()
{
if (this->refreshPaused_)
{
this->refreshRequested_ = true;
return;
}

this->performLayout();
this->updateTabVisibility();
}
Expand Down Expand Up @@ -652,13 +658,20 @@ void Notebook::resizeAddButton()
this->addButton_->setFixedSize(h, h);
}

void Notebook::scaleChangedEvent(float)
void Notebook::scaleChangedEvent(float /*scale*/)
{
this->resizeAddButton();
this->refreshPaused_ = true;
this->refreshRequested_ = false;
for (auto &i : this->items_)
{
i.tab->updateSize();
}
this->refreshPaused_ = false;
if (this->refreshRequested_)
{
this->refresh();
}
}

void Notebook::resizeEvent(QResizeEvent *)
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ class Notebook : public BaseWidget
bool showAddButton_ = false;
int lineOffset_ = 20;
bool lockNotebookLayout_ = false;

bool refreshPaused_ = false;
bool refreshRequested_ = false;

NotebookTabLocation tabLocation_ = NotebookTabLocation::Top;

QAction *lockNotebookLayoutAction_;
QAction *showTabsAction_;
QAction *toggleTopMostAction_;
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void SettingsDialog::filterElements(const QString &text)
auto *item = this->ui_.tabContainer->itemAt(i);
if (auto *x = dynamic_cast<QSpacerItem *>(item); x)
{
x->changeSize(10, shouldShowSpace ? int(16 * this->scale()) : 0);
x->changeSize(10, shouldShowSpace ? 16 : 0);
shouldShowSpace = false;
}
else if (item->widget())
Expand Down Expand Up @@ -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 "
"always be 1");

Expand Down
37 changes: 20 additions & 17 deletions src/widgets/helper/NotebookTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
#include "util/Clamp.hpp"
#include "util/Helpers.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/Notebook.hpp"
Expand All @@ -25,6 +24,8 @@
#include <QMimeData>
#include <QPainter>

#include <algorithm>

namespace chatterino {
namespace {
// Translates the given rectangle by an amount in the direction to appear like the tab is selected.
Expand Down Expand Up @@ -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();
int width;
int width = 0;

QFontMetrics metrics =
getIApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
Expand All @@ -199,13 +205,13 @@ int NotebookTab::normalTabWidth()
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
{
width = clamp(width, this->height(), int(150 * scale));
width = std::clamp(width, height, static_cast<int>(150 * scale));
}

return width;
Expand All @@ -214,8 +220,8 @@ int NotebookTab::normalTabWidth()
void NotebookTab::updateSize()
{
float scale = this->scale();
int width = this->normalTabWidth();
auto height = int(NOTEBOOK_TAB_HEIGHT * scale);
auto height = static_cast<int>(NOTEBOOK_TAB_HEIGHT * scale);
int width = this->normalTabWidthForHeight(height);

if (width < this->growWidth_)
{
Expand Down Expand Up @@ -628,13 +634,13 @@ void NotebookTab::paintEvent(QPaintEvent *)
}
}

bool NotebookTab::hasXButton()
bool NotebookTab::hasXButton() const
{
return getSettings()->showTabCloseButton &&
this->notebook_->getAllowUserTabManagement();
}

bool NotebookTab::shouldDrawXButton()
bool NotebookTab::shouldDrawXButton() const
{
return this->hasXButton() && (this->mouseOver_ || this->selected_);
}
Expand Down Expand Up @@ -820,18 +826,15 @@ void NotebookTab::update()
Button::update();
}

QRect NotebookTab::getXRect()
QRect NotebookTab::getXRect() const
{
QRect rect = this->rect();
float s = this->scale();
int size = static_cast<int>(16 * s);

int centerAdjustment =
this->tabLocation_ ==
(NotebookTabLocation::Top ||
this->tabLocation_ == NotebookTabLocation::Bottom)
? (size / 3) // slightly off true center
: (size / 2); // true center
int centerAdjustment = this->tabLocation_ == NotebookTabLocation::Top
? (size / 3) // slightly off true center
: (size / 2); // true center

QRect xRect(rect.right() - static_cast<int>(20 * s),
rect.center().y() - centerAdjustment, size, size);
Expand Down
10 changes: 6 additions & 4 deletions src/widgets/helper/NotebookTab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NotebookTab : public Button
void hideTabXChanged();

void growWidth(int width);
int normalTabWidth();
int normalTabWidth() const;

protected:
void themeChangedEvent() override;
Expand Down Expand Up @@ -100,11 +100,13 @@ class NotebookTab : public Button
private:
void showRenameDialog();

bool hasXButton();
bool shouldDrawXButton();
QRect getXRect();
bool hasXButton() const;
bool shouldDrawXButton() const;
QRect getXRect() const;
void titleUpdated();

int normalTabWidthForHeight(int height) const;

QPropertyAnimation positionChangedAnimation_;
bool positionChangedAnimationRunning_ = false;
QPoint positionAnimationDesiredPoint_;
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/splits/SplitHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ SplitHeader::SplitHeader(Split *split)
}
});
}

this->scaleChangedEvent(this->scale());
}

void SplitHeader::initializeLayout()
Expand Down

0 comments on commit a3ef8a1

Please sign in to comment.