Add some tests for NotebookTab (#5070)

* EmptyApplication: Add asserts to rest of getters (except for getSeventvAPI)

* Theme: make getTheme call getIApp()->getThemes() instead

this allows it to be used in tests
realistically this should be deprecated & users of it should just call
getIApp()->getThemes() directly

* Use getIApp() instead of getApp() in a few places
This commit is contained in:
pajlada
2024-01-06 11:42:45 +01:00
committed by GitHub
parent 77eb9cc1e9
commit 99b537ffd9
8 changed files with 193 additions and 13 deletions
+1 -1
View File
@@ -476,7 +476,7 @@ void Theme::normalizeColor(QColor &color) const
Theme *getTheme()
{
return getApp()->themes;
return getIApp()->getThemes();
}
} // namespace chatterino
+2 -3
View File
@@ -1,5 +1,6 @@
#include "widgets/BaseWidget.hpp"
#include "Application.hpp"
#include "common/QLogging.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "singletons/Theme.hpp"
@@ -17,10 +18,8 @@ namespace chatterino {
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, theme(getIApp()->getThemes())
{
// REMOVED
this->theme = getTheme();
this->signalHolder_.managedConnect(this->theme->updated, [this]() {
this->themeChangedEvent();
+6 -4
View File
@@ -588,11 +588,13 @@ void Notebook::updateTabVisibility()
void Notebook::updateTabVisibilityMenuAction()
{
auto toggleSeq = getApp()->hotkeys->getDisplaySequence(
const auto *hotkeys = getIApp()->getHotkeys();
auto toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {std::vector<QString>()});
if (toggleSeq.isEmpty())
{
toggleSeq = getApp()->hotkeys->getDisplaySequence(
toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"toggle"}});
}
@@ -601,12 +603,12 @@ void Notebook::updateTabVisibilityMenuAction()
// show contextual shortcuts
if (this->getShowTabs())
{
toggleSeq = getApp()->hotkeys->getDisplaySequence(
toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"off"}});
}
else if (!this->getShowTabs())
{
toggleSeq = getApp()->hotkeys->getDisplaySequence(
toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"on"}});
}
}
+15 -5
View File
@@ -93,8 +93,8 @@ NotebookTab::NotebookTab(Notebook *notebook)
[this]() {
this->notebook_->removePage(this->page);
},
getApp()->hotkeys->getDisplaySequence(HotkeyCategory::Window,
"removeTab"));
getIApp()->getHotkeys()->getDisplaySequence(HotkeyCategory::Window,
"removeTab"));
this->menu_.addAction(
"Popup Tab",
@@ -104,8 +104,8 @@ NotebookTab::NotebookTab(Notebook *notebook)
container->popup();
}
},
getApp()->hotkeys->getDisplaySequence(HotkeyCategory::Window, "popup",
{{"window"}}));
getIApp()->getHotkeys()->getDisplaySequence(HotkeyCategory::Window,
"popup", {{"window"}}));
highlightNewMessagesAction_ =
new QAction("Mark Tab as Unread on New Messages", &this->menu_);
@@ -196,7 +196,7 @@ int NotebookTab::normalTabWidth()
float scale = this->scale();
int width;
QFontMetrics metrics = getApp()->fonts->getFontMetrics(
auto metrics = getIApp()->getFonts()->getFontMetrics(
FontStyle::UiTabs, float(qreal(this->scale()) * deviceDpi(this)));
if (this->hasXButton())
@@ -359,6 +359,11 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
}
}
HighlightState NotebookTab::highlightState() const
{
return this->highlightState_;
}
void NotebookTab::setHighlightsEnabled(const bool &newVal)
{
this->highlightNewMessagesAction_->setChecked(newVal);
@@ -783,6 +788,11 @@ void NotebookTab::wheelEvent(QWheelEvent *event)
}
}
void NotebookTab::update()
{
Button::update();
}
QRect NotebookTab::getXRect()
{
QRect rect = this->rect();
+6
View File
@@ -53,6 +53,8 @@ public:
bool isLive() const;
void setHighlightState(HighlightState style);
HighlightState highlightState() const;
void setHighlightsEnabled(const bool &newVal);
bool hasHighlightsEnabled() const;
@@ -84,6 +86,10 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
/// This exists as an alias to its base classes update, and is virtual
/// to allow for mocking
virtual void update();
private:
void showRenameDialog();