Skip to content

Commit

Permalink
Main window and topbar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BowDown097 committed Nov 29, 2023
1 parent e79822e commit a8b724c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 68 deletions.
21 changes: 7 additions & 14 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ MainWindow::MainWindow(const QCommandLineParser& parser, QWidget* parent) : QMai

InnerTube::instance().createContext(InnertubeClient(InnertubeClient::ClientType::WEB, "2.20230718.01.00", "DESKTOP"));
tryRestoreData();
connect(InnerTube::instance().authStore(), &InnertubeAuthStore::authenticateSuccess, m_topbar, &TopBar::postSignInSetup);
connect(InnerTube::instance().authStore(), &InnertubeAuthStore::authenticateSuccess, m_topbar, [this] { m_topbar->postSignInSetup(); });

if (parser.isSet("channel"))
ViewController::loadChannel(parser.value("channel"));
Expand Down Expand Up @@ -264,7 +264,7 @@ void MainWindow::searchByLink(const QString& link)

void MainWindow::searchByQuery(const QString& query)
{
m_topbar->alwaysShow = true;
m_topbar->setAlwaysShow(true);
UIUtils::clearLayout(ui->additionalWidgets);
ui->historySearchWidget->clear();

Expand Down Expand Up @@ -350,13 +350,12 @@ void MainWindow::showAccountMenu()
{
if (AccountControllerWidget* accountController = findChild<AccountControllerWidget*>("accountController"))
{
if (ui->centralwidget->currentIndex() != 0)
m_topbar->alwaysShow = false;
m_topbar->setAlwaysShow(ui->centralwidget->currentIndex() == 0);
accountController->deleteLater();
return;
}

m_topbar->alwaysShow = true;
m_topbar->setAlwaysShow(true);

AccountControllerWidget* accountController = new AccountControllerWidget(this);
accountController->setObjectName("accountController");
Expand All @@ -375,14 +374,13 @@ void MainWindow::showNotifications()
{
if (notificationMenu->isVisible())
{
if (ui->centralwidget->currentIndex() != 0)
m_topbar->alwaysShow = false;
m_topbar->setAlwaysShow(ui->centralwidget->currentIndex() == 0);
notificationMenu->clear();
notificationMenu->setVisible(false);
return;
}

m_topbar->alwaysShow = true;
m_topbar->setAlwaysShow(true);
notificationMenu->setVisible(true);
BrowseHelper::instance()->browseNotificationMenu(notificationMenu);
}
Expand All @@ -391,12 +389,7 @@ void MainWindow::tryRestoreData()
{
qtTubeApp->creds().populateAuthStore(qtTubeApp->creds().activeLogin());
if (InnerTube::instance().hasAuthenticated())
{
m_topbar->avatarButton->setVisible(true);
m_topbar->signInButton->setVisible(false);
m_topbar->setUpAvatarButton();
m_topbar->setUpNotifications();
}
m_topbar->postSignInSetup(false);
}

void MainWindow::trySwitchGridStatus(QListWidget* listWidget)
Expand Down
42 changes: 5 additions & 37 deletions src/qttubeapplication.cpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
#include "qttubeapplication.h"
#include "eastereggs.h"
#include "mainwindow.h"
#include <QMouseEvent>
#include <QPropertyAnimation>

bool QtTubeApplication::notify(QObject* receiver, QEvent* event)
{
if (receiver->objectName() != "MainWindowWindow")
return QApplication::notify(receiver, event);

if (event->type() == QEvent::MouseMove)
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
TopBar* topbar = MainWindow::topbar();
if (!topbar->alwaysShow)
{
if (mouseEvent->pos().y() < topbar->height())
{
if (topbar->isHidden() && topbar->animation->state() != QAbstractAnimation::Running)
{
topbar->animation->setStartValue(QRect(0, 0, topbar->width(), 0));
topbar->animation->setEndValue(QRect(0, 0, topbar->width(), topbar->height()));
disconnect(topbar->animation, &QPropertyAnimation::finished, topbar, nullptr);
topbar->animation->start();
topbar->show();
}
}
else if (topbar->animation->state() != QAbstractAnimation::Running && !topbar->isHidden())
{
int height = topbar->height();
topbar->animation->setEndValue(QRect(0, 0, topbar->width(), 0));
topbar->animation->setStartValue(QRect(0, 0, topbar->width(), topbar->height()));
connect(topbar->animation, &QPropertyAnimation::finished, topbar, [height, topbar] {
topbar->hide();
topbar->resize(topbar->width(), height);
});
topbar->animation->start();
}
}
}
else if (event->type() == QEvent::KeyPress)
if (receiver->objectName() == "MainWindowWindow")
{
EasterEggs::checkEasterEggs(static_cast<QKeyEvent*>(event));
if (event->type() == QEvent::MouseMove)
MainWindow::topbar()->handleMouseEvent(static_cast<QMouseEvent*>(event));
else if (event->type() == QEvent::KeyPress)
EasterEggs::checkEasterEggs(static_cast<QKeyEvent*>(event));
}

return QApplication::notify(receiver, event);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/channelview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void ChannelView::setTabsAndStyles(const InnertubeEndpoints::ChannelResponse& ch

bool hasBanner = !channelResp.header.banners.isEmpty();
channelBanner->setFixedHeight(hasBanner ? 129 : 40);
MainWindow::topbar()->alwaysShow = !hasBanner;
MainWindow::topbar()->setAlwaysShow(!hasBanner);
MainWindow::topbar()->setVisible(!hasBanner);

if (hasBanner)
Expand Down
8 changes: 4 additions & 4 deletions src/ui/views/viewcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void ViewController::loadChannel(const QString& channelId)
if (channelView)
{
channelView->deleteLater();
MainWindow::topbar()->alwaysShow = true;
MainWindow::topbar()->setAlwaysShow(true);
}
}

Expand All @@ -45,7 +45,7 @@ void ViewController::loadChannel(const QString& channelId)
QObject::connect(MainWindow::topbar()->logo, &TubeLabel::clicked, channelView, [channelView]
{
channelView->deleteLater();
MainWindow::topbar()->alwaysShow = true;
MainWindow::topbar()->setAlwaysShow(true);
});
}

Expand All @@ -69,12 +69,12 @@ void ViewController::loadVideo(const QString& videoId, int progress)
QObject::connect(MainWindow::topbar()->logo, &TubeLabel::clicked, watchView, [watchView]
{
watchView->deleteLater();
MainWindow::topbar()->alwaysShow = true;
MainWindow::topbar()->setAlwaysShow(true);
});
QObject::connect(watchView, &WatchView::loadFailed, [watchView](const InnertubeException& ie)
{
QMessageBox::critical(nullptr, "Failed to load video", ie.message());
watchView->deleteLater();
MainWindow::topbar()->alwaysShow = true;
MainWindow::topbar()->setAlwaysShow(true);
});
}
2 changes: 1 addition & 1 deletion src/ui/views/watchview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ WatchView::~WatchView()

WatchView::WatchView(const QString& videoId, int progress, QWidget* parent) : QWidget(parent), ui(new Ui::WatchView)
{
MainWindow::topbar()->setAlwaysShow(false);
MainWindow::topbar()->setVisible(false);
MainWindow::topbar()->alwaysShow = false;

ui->setupUi(this);

Expand Down
1 change: 1 addition & 0 deletions src/ui/widgets/accountmenu/accountswitcherwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "mainwindow.h"
#include "qttubeapplication.h"
#include <QBoxLayout>
#include <QPushButton>

AccountSwitcherWidget::AccountSwitcherWidget(QWidget* parent)
: QWidget(parent), addAccountButton(new QPushButton(this)), backButton(new QPushButton(this)), layout(new QVBoxLayout(this))
Expand Down
36 changes: 34 additions & 2 deletions src/ui/widgets/topbar/topbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "ui/forms/settings/settingsform.h"
#include "utils/uiutils.h"
#include <QApplication>
#include <QMouseEvent>
#include <QPushButton>

#ifdef INNERTUBE_NO_WEBENGINE
#include <QMessageBox>
Expand Down Expand Up @@ -58,13 +60,43 @@ TopBar::TopBar(QWidget* parent)
connect(signInButton, &QPushButton::clicked, this, &TopBar::trySignIn);
}

void TopBar::postSignInSetup()
void TopBar::handleMouseEvent(QMouseEvent* event)
{
if (alwaysShow || animation->state() == QAbstractAnimation::Running)
return;

if (event->pos().y() < height())
{
if (isHidden())
{
animation->setStartValue(QRect(0, 0, width(), 0));
animation->setEndValue(QRect(0, 0, width(), height()));
disconnect(animation, &QPropertyAnimation::finished, this, nullptr);
animation->start();
show();
}
}
else if (isVisible())
{
animation->setStartValue(QRect(0, 0, width(), height()));
animation->setEndValue(QRect(0, 0, width(), 0));
connect(animation, &QPropertyAnimation::finished, this, [this] {
hide();
resize(width(), animation->startValue().toRect().height());
});
animation->start();
}
}

void TopBar::postSignInSetup(bool emitSignal)
{
avatarButton->setVisible(true);
signInButton->setVisible(false);
setUpAvatarButton();
setUpNotifications();
emit signInStatusChanged();

if (emitSignal)
emit signInStatusChanged();
}

void TopBar::scaleAppropriately()
Expand Down
22 changes: 13 additions & 9 deletions src/ui/widgets/topbar/topbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@
#include "searchbox.h"
#include "topbarbell.h"
#include "ui/widgets/labels/tubelabel.h"
#include <QPushButton>

class QPropertyAnimation;
class QPushButton;

class TopBar : public QWidget
{
Q_OBJECT
public:
bool alwaysShow = true;
QPropertyAnimation* animation;
TubeLabel* avatarButton;
TubeLabel* logo;
TopBarBell* notificationBell;
SearchBox* searchBox;
TubeLabel* settingsButton;
QPushButton* signInButton;

explicit TopBar(QWidget* parent);
void postSignInSetup();
void handleMouseEvent(QMouseEvent* event);
void postSignInSetup(bool emitSignal = true);
void scaleAppropriately();
void setAlwaysShow(bool alwaysShow) { this->alwaysShow = alwaysShow; }
void updatePalette(const QPalette& palette);
private:
bool alwaysShow = true;
QPropertyAnimation* animation;
TubeLabel* settingsButton;
QPushButton* signInButton;
public slots:
void setUpAvatarButton();
void setUpNotifications();
void showSettings();
void signOut();
void trySignIn();
void updateNotificationCount();
private slots:
void setUpAvatarButton();
void setUpNotifications();
void showSettings();
signals:
void signInStatusChanged();
};
Expand Down

0 comments on commit a8b724c

Please sign in to comment.