mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
put the update button code into it's own file
This commit is contained in:
parent
ef13aef7df
commit
59332270b5
|
@ -226,7 +226,8 @@ SOURCES += \
|
||||||
src/controllers/moderationactions/ModerationActionModel.cpp \
|
src/controllers/moderationactions/ModerationActionModel.cpp \
|
||||||
src/widgets/settingspages/LookPage.cpp \
|
src/widgets/settingspages/LookPage.cpp \
|
||||||
src/widgets/settingspages/FeelPage.cpp \
|
src/widgets/settingspages/FeelPage.cpp \
|
||||||
src/widgets/dialogs/UpdatePromptDialog.cpp
|
src/widgets/dialogs/UpdatePromptDialog.cpp \
|
||||||
|
src/util/InitUpdateButton.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/Application.hpp \
|
src/Application.hpp \
|
||||||
|
@ -400,7 +401,8 @@ HEADERS += \
|
||||||
src/controllers/moderationactions/ModerationActionModel.hpp \
|
src/controllers/moderationactions/ModerationActionModel.hpp \
|
||||||
src/widgets/settingspages/LookPage.hpp \
|
src/widgets/settingspages/LookPage.hpp \
|
||||||
src/widgets/settingspages/FeelPage.hpp \
|
src/widgets/settingspages/FeelPage.hpp \
|
||||||
src/widgets/dialogs/UpdatePromptDialog.hpp
|
src/widgets/dialogs/UpdatePromptDialog.hpp \
|
||||||
|
src/util/InitUpdateButton.hpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources/resources.qrc \
|
resources/resources.qrc \
|
||||||
|
|
48
src/util/InitUpdateButton.cpp
Normal file
48
src/util/InitUpdateButton.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include "InitUpdateButton.hpp"
|
||||||
|
|
||||||
|
#include "widgets/dialogs/UpdatePromptDialog.hpp"
|
||||||
|
#include "widgets/helper/RippleEffectButton.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
void initUpdateButton(RippleEffectButton &button, std::unique_ptr<UpdatePromptDialog> &handle,
|
||||||
|
pajlada::Signals::SignalHolder &signalHolder)
|
||||||
|
{
|
||||||
|
button.hide();
|
||||||
|
|
||||||
|
// show update prompt when clicking the button
|
||||||
|
QObject::connect(&button, &RippleEffectButton::clicked, [&button, &handle] {
|
||||||
|
auto dialog = new UpdatePromptDialog();
|
||||||
|
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
||||||
|
dialog->move(button.mapToGlobal(QPoint(int(-100 * button.getScale()), button.height())));
|
||||||
|
dialog->show();
|
||||||
|
dialog->raise();
|
||||||
|
|
||||||
|
dialog->buttonClicked.connect([&button](auto buttonType) {
|
||||||
|
switch (buttonType) {
|
||||||
|
case UpdatePromptDialog::Dismiss: {
|
||||||
|
button.hide();
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
handle.reset(dialog);
|
||||||
|
dialog->closing.connect([&handle] { handle.release(); });
|
||||||
|
});
|
||||||
|
|
||||||
|
// update image when state changes
|
||||||
|
auto updateChange = [&button](auto) {
|
||||||
|
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
|
||||||
|
|
||||||
|
auto imageUrl = Updates::getInstance().isError() ? ":/images/download_update_error.png"
|
||||||
|
: ":/images/download_update.png";
|
||||||
|
button.setPixmap(QPixmap(imageUrl));
|
||||||
|
};
|
||||||
|
|
||||||
|
updateChange(Updates::getInstance().getStatus());
|
||||||
|
|
||||||
|
signalHolder.managedConnect(Updates::getInstance().statusUpdated,
|
||||||
|
[updateChange](auto status) { updateChange(status); });
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
19
src/util/InitUpdateButton.hpp
Normal file
19
src/util/InitUpdateButton.hpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace pajlada {
|
||||||
|
namespace Signals {
|
||||||
|
class SignalHolder;
|
||||||
|
}
|
||||||
|
} // namespace pajlada
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
class RippleEffectButton;
|
||||||
|
class UpdatePromptDialog;
|
||||||
|
|
||||||
|
void initUpdateButton(RippleEffectButton &button, std::unique_ptr<UpdatePromptDialog> &handle,
|
||||||
|
pajlada::Signals::SignalHolder &signalHolder);
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -4,6 +4,7 @@
|
||||||
#include "debug/Log.hpp"
|
#include "debug/Log.hpp"
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
|
#include "util/InitUpdateButton.hpp"
|
||||||
#include "widgets/Window.hpp"
|
#include "widgets/Window.hpp"
|
||||||
#include "widgets/dialogs/SettingsDialog.hpp"
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||||
#include "widgets/helper/NotebookButton.hpp"
|
#include "widgets/helper/NotebookButton.hpp"
|
||||||
|
@ -416,41 +417,50 @@ SplitNotebook::SplitNotebook(Window *parent)
|
||||||
bool customFrame = parent->hasCustomWindowFrame();
|
bool customFrame = parent->hasCustomWindowFrame();
|
||||||
|
|
||||||
if (!customFrame) {
|
if (!customFrame) {
|
||||||
auto settingsBtn = this->addCustomButton();
|
this->addCustomButtons();
|
||||||
auto userBtn = this->addCustomButton();
|
|
||||||
auto updateBtn = this->addCustomButton();
|
|
||||||
updateBtn->setPixmap(QPixmap(":/images/download_update.png"));
|
|
||||||
|
|
||||||
settingsBtn->setVisible(!app->settings->hidePreferencesButton.getValue());
|
|
||||||
userBtn->setVisible(!app->settings->hideUserButton.getValue());
|
|
||||||
|
|
||||||
app->settings->hidePreferencesButton.connect(
|
|
||||||
[this, settingsBtn](bool hide, auto) {
|
|
||||||
settingsBtn->setVisible(!hide);
|
|
||||||
this->performLayout(true);
|
|
||||||
},
|
|
||||||
this->uniqueConnections);
|
|
||||||
|
|
||||||
app->settings->hideUserButton.connect(
|
|
||||||
[this, userBtn](bool hide, auto) {
|
|
||||||
userBtn->setVisible(!hide);
|
|
||||||
this->performLayout(true);
|
|
||||||
},
|
|
||||||
this->uniqueConnections);
|
|
||||||
|
|
||||||
settingsBtn->icon = NotebookButton::IconSettings;
|
|
||||||
userBtn->icon = NotebookButton::IconUser;
|
|
||||||
|
|
||||||
QObject::connect(settingsBtn, &NotebookButton::clicked,
|
|
||||||
[] { getApp()->windows->showSettingsDialog(); });
|
|
||||||
|
|
||||||
QObject::connect(userBtn, &NotebookButton::clicked, [this, userBtn] {
|
|
||||||
getApp()->windows->showAccountSelectPopup(
|
|
||||||
this->mapToGlobal(userBtn->rect().bottomRight()));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SplitNotebook::addCustomButtons()
|
||||||
|
{
|
||||||
|
// settings
|
||||||
|
auto settingsBtn = this->addCustomButton();
|
||||||
|
|
||||||
|
settingsBtn->setVisible(!getApp()->settings->hidePreferencesButton.getValue());
|
||||||
|
|
||||||
|
getApp()->settings->hidePreferencesButton.connect(
|
||||||
|
[this, settingsBtn](bool hide, auto) {
|
||||||
|
settingsBtn->setVisible(!hide);
|
||||||
|
this->performLayout(true);
|
||||||
|
},
|
||||||
|
this->uniqueConnections);
|
||||||
|
|
||||||
|
settingsBtn->icon = NotebookButton::IconSettings;
|
||||||
|
|
||||||
|
QObject::connect(settingsBtn, &NotebookButton::clicked,
|
||||||
|
[] { getApp()->windows->showSettingsDialog(); });
|
||||||
|
|
||||||
|
// account
|
||||||
|
auto userBtn = this->addCustomButton();
|
||||||
|
userBtn->setVisible(!getApp()->settings->hideUserButton.getValue());
|
||||||
|
getApp()->settings->hideUserButton.connect(
|
||||||
|
[this, userBtn](bool hide, auto) {
|
||||||
|
userBtn->setVisible(!hide);
|
||||||
|
this->performLayout(true);
|
||||||
|
},
|
||||||
|
this->uniqueConnections);
|
||||||
|
|
||||||
|
userBtn->icon = NotebookButton::IconUser;
|
||||||
|
QObject::connect(userBtn, &NotebookButton::clicked, [this, userBtn] {
|
||||||
|
getApp()->windows->showAccountSelectPopup(this->mapToGlobal(userBtn->rect().bottomRight()));
|
||||||
|
});
|
||||||
|
|
||||||
|
// updates
|
||||||
|
auto updateBtn = this->addCustomButton();
|
||||||
|
|
||||||
|
initUpdateButton(*updateBtn, this->updateDialogHandle_, this->signalHolder_);
|
||||||
|
}
|
||||||
|
|
||||||
SplitContainer *SplitNotebook::addPage(bool select)
|
SplitContainer *SplitNotebook::addPage(bool select)
|
||||||
{
|
{
|
||||||
SplitContainer *container = new SplitContainer(this);
|
SplitContainer *container = new SplitContainer(this);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "pajlada/signals/signal.hpp"
|
#include "pajlada/signals/signal.hpp"
|
||||||
#include "widgets/BaseWidget.hpp"
|
#include "widgets/BaseWidget.hpp"
|
||||||
|
#include "widgets/dialogs/UpdatePromptDialog.hpp"
|
||||||
#include "widgets/helper/NotebookButton.hpp"
|
#include "widgets/helper/NotebookButton.hpp"
|
||||||
#include "widgets/helper/NotebookTab.hpp"
|
#include "widgets/helper/NotebookTab.hpp"
|
||||||
#include "widgets/splits/SplitContainer.hpp"
|
#include "widgets/splits/SplitContainer.hpp"
|
||||||
|
@ -9,6 +10,7 @@
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <pajlada/signals/signalholder.hpp>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
@ -89,6 +91,11 @@ public:
|
||||||
SplitContainer *getOrAddSelectedPage();
|
SplitContainer *getOrAddSelectedPage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addCustomButtons();
|
||||||
|
|
||||||
|
pajlada::Signals::SignalHolder signalHolder_;
|
||||||
|
std::unique_ptr<UpdatePromptDialog> updateDialogHandle_;
|
||||||
|
|
||||||
std::vector<pajlada::Signals::ScopedConnection> uniqueConnections;
|
std::vector<pajlada::Signals::ScopedConnection> uniqueConnections;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "singletons/Updates.hpp"
|
#include "singletons/Updates.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
|
#include "util/InitUpdateButton.hpp"
|
||||||
#include "widgets/AccountSwitchPopupWidget.hpp"
|
#include "widgets/AccountSwitchPopupWidget.hpp"
|
||||||
#include "widgets/Notebook.hpp"
|
#include "widgets/Notebook.hpp"
|
||||||
#include "widgets/dialogs/SettingsDialog.hpp"
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||||
|
@ -184,37 +185,8 @@ void Window::addCustomTitlebarButtons()
|
||||||
|
|
||||||
// updates
|
// updates
|
||||||
auto update = this->addTitleBarButton(TitleBarButton::None, [] {});
|
auto update = this->addTitleBarButton(TitleBarButton::None, [] {});
|
||||||
update->hide();
|
|
||||||
QObject::connect(update, &TitleBarButton::clicked, this, [this, update] {
|
|
||||||
auto dialog = new UpdatePromptDialog();
|
|
||||||
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
|
||||||
dialog->move(update->mapToGlobal(QPoint(int(-100 * this->getScale()), update->height())));
|
|
||||||
dialog->show();
|
|
||||||
dialog->raise();
|
|
||||||
|
|
||||||
dialog->buttonClicked.connect([update](auto button) {
|
initUpdateButton(*update, this->updateDialogHandle_, this->signalHolder_);
|
||||||
switch (button) {
|
|
||||||
case UpdatePromptDialog::Dismiss: {
|
|
||||||
update->hide();
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this->updateDialogHandle_.reset(dialog);
|
|
||||||
dialog->closing.connect([this] { this->updateDialogHandle_.release(); });
|
|
||||||
});
|
|
||||||
|
|
||||||
auto updateChange = [update](auto) {
|
|
||||||
update->setVisible(Updates::getInstance().shouldShowUpdateButton());
|
|
||||||
|
|
||||||
auto imageUrl = Updates::getInstance().isError() ? ":/images/download_update_error.png"
|
|
||||||
: ":/images/download_update.png";
|
|
||||||
update->setPixmap(QPixmap(imageUrl));
|
|
||||||
};
|
|
||||||
|
|
||||||
updateChange(Updates::getInstance().getStatus());
|
|
||||||
this->signalHolder.managedConnect(Updates::getInstance().statusUpdated,
|
|
||||||
[updateChange](auto status) { updateChange(status); });
|
|
||||||
|
|
||||||
// account
|
// account
|
||||||
this->userLabel = this->addTitleBarLabel([this] {
|
this->userLabel = this->addTitleBarLabel([this] {
|
||||||
|
|
|
@ -53,7 +53,7 @@ private:
|
||||||
|
|
||||||
SplitNotebook notebook;
|
SplitNotebook notebook;
|
||||||
|
|
||||||
pajlada::Signals::SignalHolder signalHolder;
|
pajlada::Signals::SignalHolder signalHolder_;
|
||||||
|
|
||||||
friend class Notebook;
|
friend class Notebook;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue