mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(UI): Centre message boxes on main window
Setting the parent of MessageBoxManager to Widget has a dual effect of centreing the QMessageBox's on Widget' window which we want, but also giving ownership of MessageBoxManager to Widget, which causes Widget to destroy it in Widget's destructor. Since the original MessageBoxManager must outlive Widget to be used in Settings and when loading Profiles before Widget is constructed, we don't want Widget to destroy it. Instead of juggling MessageBoxManager's parent around dynamically when Nexus changes the active Window, just construct a second one in Widget to be used by all its children with the parent set on Widget, centreing the window and allowing it to have ownership. Settings and Profile still use the original parent-less MessageBoxManager since they show popups before Widget is constructed.
This commit is contained in:
parent
25223119c9
commit
c5fdb78676
@ -237,7 +237,7 @@ int main(int argc, char* argv[])
|
||||
qWarning() << "Couldn't load font";
|
||||
}
|
||||
|
||||
messageBoxManager = std::unique_ptr<MessageBoxManager>(new MessageBoxManager());
|
||||
messageBoxManager = std::unique_ptr<MessageBoxManager>(new MessageBoxManager(nullptr));
|
||||
settings = std::unique_ptr<Settings>(new Settings(*messageBoxManager));
|
||||
|
||||
QString locale = settings->getTranslation();
|
||||
|
@ -235,7 +235,7 @@ void Nexus::showMainGUI()
|
||||
assert(profile);
|
||||
|
||||
// Create GUI
|
||||
widget = new Widget(*profile, *audioControl, *cameraSource, *settings, *style, *messageBoxManager);
|
||||
widget = new Widget(*profile, *audioControl, *cameraSource, *settings, *style);
|
||||
|
||||
// Start GUI
|
||||
widget->init();
|
||||
|
@ -295,14 +295,13 @@ void Profile::initCore(const QByteArray& toxsave, Settings& s, bool isNewProfile
|
||||
}
|
||||
|
||||
Profile::Profile(const QString& name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_,
|
||||
Settings& settings_, IMessageBoxManager& messageBoxManager_)
|
||||
Settings& settings_)
|
||||
: name{name_}
|
||||
, passkey{std::move(passkey_)}
|
||||
, isRemoved{false}
|
||||
, encrypted{passkey != nullptr}
|
||||
, paths{paths_}
|
||||
, settings{settings_}
|
||||
, messageBoxManager{messageBoxManager_}
|
||||
{}
|
||||
|
||||
/**
|
||||
@ -337,14 +336,14 @@ Profile* Profile::loadProfile(const QString& name, const QString& password, Sett
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Profile* p = new Profile(name, std::move(tmpKey), paths, settings, messageBoxManager);
|
||||
Profile* p = new Profile(name, std::move(tmpKey), paths, settings);
|
||||
|
||||
// Core settings are saved per profile, need to load them before starting Core
|
||||
constexpr bool isNewProfile = false;
|
||||
settings.updateProfileData(p, parser, isNewProfile);
|
||||
|
||||
p->initCore(toxsave, settings, isNewProfile, cameraSource);
|
||||
p->loadDatabase(password);
|
||||
p->loadDatabase(password, messageBoxManager);
|
||||
|
||||
return p;
|
||||
}
|
||||
@ -371,13 +370,13 @@ Profile* Profile::createProfile(const QString& name, const QString& password, Se
|
||||
}
|
||||
|
||||
settings.createPersonal(name);
|
||||
Profile* p = new Profile(name, std::move(tmpKey), paths, settings, messageBoxManager);
|
||||
Profile* p = new Profile(name, std::move(tmpKey), paths, settings);
|
||||
|
||||
constexpr bool isNewProfile = true;
|
||||
settings.updateProfileData(p, parser, isNewProfile);
|
||||
|
||||
p->initCore(QByteArray(), settings, isNewProfile, cameraSource);
|
||||
p->loadDatabase(password);
|
||||
p->loadDatabase(password, messageBoxManager);
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -621,7 +620,7 @@ QByteArray Profile::loadAvatarData(const ToxPk& owner)
|
||||
return pic;
|
||||
}
|
||||
|
||||
void Profile::loadDatabase(QString password)
|
||||
void Profile::loadDatabase(QString password, IMessageBoxManager& messageBoxManager)
|
||||
{
|
||||
assert(core);
|
||||
|
||||
|
@ -99,7 +99,7 @@ public slots:
|
||||
void onRequestSent(const ToxPk& friendPk, const QString& message);
|
||||
|
||||
private slots:
|
||||
void loadDatabase(QString password);
|
||||
void loadDatabase(QString password, IMessageBoxManager& messageBoxManager);
|
||||
void saveAvatar(const ToxPk& owner, const QByteArray& avatar);
|
||||
void removeAvatar(const ToxPk& owner);
|
||||
void onSaveToxSave();
|
||||
@ -108,7 +108,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Profile(const QString& name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_,
|
||||
Settings &settings_, IMessageBoxManager& messageBoxManager);
|
||||
Settings &settings_);
|
||||
static QStringList getFilesByExt(QString extension, Settings& settings);
|
||||
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
|
||||
bool saveToxSave(QByteArray data);
|
||||
@ -128,5 +128,4 @@ private:
|
||||
std::unique_ptr<BootstrapNodeUpdater> bootstrapNodes;
|
||||
Paths& paths;
|
||||
Settings& settings;
|
||||
IMessageBoxManager& messageBoxManager;
|
||||
};
|
||||
|
@ -27,6 +27,11 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
MessageBoxManager::MessageBoxManager(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show some text to the user.
|
||||
* @param title Title of information window.
|
||||
|
@ -30,6 +30,7 @@ class MessageBoxManager : public QWidget, public IMessageBoxManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MessageBoxManager(QWidget* parent);
|
||||
~MessageBoxManager() override = default;
|
||||
void showInfo(const QString& title, const QString& msg) override;
|
||||
void showWarning(const QString& title, const QString& msg) override;
|
||||
|
@ -78,7 +78,7 @@
|
||||
#include "src/widget/form/settingswidget.h"
|
||||
#include "src/widget/style.h"
|
||||
#include "src/widget/translator.h"
|
||||
#include "src/widget/tool/imessageboxmanager.h"
|
||||
#include "src/widget/tool/messageboxmanager.h"
|
||||
#include "tool/removechatdialog.h"
|
||||
#include "src/persistence/smileypack.h"
|
||||
|
||||
@ -142,7 +142,7 @@ void Widget::acceptFileTransfer(const ToxFile& file, const QString& path)
|
||||
Widget* Widget::instance{nullptr};
|
||||
|
||||
Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSource_,
|
||||
Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_, QWidget* parent)
|
||||
Settings& settings_, Style& style_, QWidget* parent)
|
||||
: QMainWindow(parent)
|
||||
, profile{profile_}
|
||||
, trayMenu{nullptr}
|
||||
@ -159,7 +159,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou
|
||||
, documentCache(new DocumentCache(*smileyPack, settings))
|
||||
, cameraSource{cameraSource_}
|
||||
, style{style_}
|
||||
, messageBoxManager(messageBoxManager_)
|
||||
, messageBoxManager(new MessageBoxManager(this))
|
||||
, friendList(new FriendList())
|
||||
, contentDialogManager(new ContentDialogManager(*friendList))
|
||||
{
|
||||
@ -268,7 +268,7 @@ void Widget::init()
|
||||
sharedMessageProcessorParams.reset(new MessageProcessor::SharedParams(core->getMaxMessageSize(), coreExt->getMaxExtendedMessageSize()));
|
||||
|
||||
chatListWidget = new FriendListWidget(*core, this, settings, style,
|
||||
messageBoxManager, *friendList, settings.getGroupchatPosition());
|
||||
*messageBoxManager, *friendList, settings.getGroupchatPosition());
|
||||
connect(chatListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle);
|
||||
connect(chatListWidget, &FriendListWidget::connectCircleWidget, this,
|
||||
&Widget::connectCircleWidget);
|
||||
@ -296,9 +296,9 @@ void Widget::init()
|
||||
style.setThemeColor(settings, settings.getThemeColor());
|
||||
|
||||
CoreFile* coreFile = core->getCoreFile();
|
||||
filesForm = new FilesForm(*coreFile, settings, style, messageBoxManager, *friendList);
|
||||
filesForm = new FilesForm(*coreFile, settings, style, *messageBoxManager, *friendList);
|
||||
addFriendForm = new AddFriendForm(core->getSelfId(), settings, style,
|
||||
messageBoxManager, *core);
|
||||
*messageBoxManager, *core);
|
||||
groupInviteForm = new GroupInviteForm(settings, *core);
|
||||
|
||||
#if UPDATE_CHECK_ENABLED
|
||||
@ -306,13 +306,13 @@ void Widget::init()
|
||||
connect(updateCheck.get(), &UpdateCheck::updateAvailable, this, &Widget::onUpdateAvailable);
|
||||
#endif
|
||||
settingsWidget = new SettingsWidget(updateCheck.get(), audio, core, *smileyPack,
|
||||
cameraSource, settings, style, messageBoxManager, this);
|
||||
cameraSource, settings, style, *messageBoxManager, this);
|
||||
#if UPDATE_CHECK_ENABLED
|
||||
updateCheck->checkForUpdate();
|
||||
#endif
|
||||
|
||||
profileInfo = new ProfileInfo(core, &profile, settings);
|
||||
profileForm = new ProfileForm(profileInfo, settings, style, messageBoxManager);
|
||||
profileForm = new ProfileForm(profileInfo, settings, style, *messageBoxManager);
|
||||
|
||||
#if DESKTOP_NOTIFICATIONS
|
||||
notificationGenerator.reset(new NotificationGenerator(settings, &profile));
|
||||
@ -1159,7 +1159,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
||||
auto rawChatroom = new FriendChatroom(newfriend, contentDialogManager.get(), *core, settings);
|
||||
std::shared_ptr<FriendChatroom> chatroom(rawChatroom);
|
||||
const auto compact = settings.getCompactLayout();
|
||||
auto widget = new FriendWidget(chatroom, compact, settings, style, messageBoxManager);
|
||||
auto widget = new FriendWidget(chatroom, compact, settings, style, *messageBoxManager);
|
||||
connectFriendWidget(*widget);
|
||||
auto history = profile.getHistory();
|
||||
|
||||
@ -1174,7 +1174,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
||||
*friendMessageDispatcher, *friendList);
|
||||
auto friendForm = new ChatForm(profile, newfriend, *chatHistory,
|
||||
*friendMessageDispatcher, *documentCache, *smileyPack, cameraSource,
|
||||
settings, style, messageBoxManager, *contentDialogManager, *friendList);
|
||||
settings, style, *messageBoxManager, *contentDialogManager, *friendList);
|
||||
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
|
||||
|
||||
friendMessageDispatchers[friendPk] = friendMessageDispatcher;
|
||||
@ -1831,7 +1831,7 @@ void Widget::onUpdateAvailable()
|
||||
ContentDialog* Widget::createContentDialog() const
|
||||
{
|
||||
ContentDialog* contentDialog = new ContentDialog(*core, settings, style,
|
||||
messageBoxManager, *friendList);
|
||||
*messageBoxManager, *friendList);
|
||||
|
||||
registerContentDialog(*contentDialog);
|
||||
return contentDialog;
|
||||
@ -2157,7 +2157,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
||||
groupAlertConnections.insert(groupId, notifyReceivedConnection);
|
||||
|
||||
auto form = new GroupChatForm(*core, newgroup, *chatHistory, *messageDispatcher,
|
||||
settings, *documentCache, *smileyPack, style, messageBoxManager, *friendList);
|
||||
settings, *documentCache, *smileyPack, style, *messageBoxManager, *friendList);
|
||||
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
|
||||
form->setColorizedNames(settings.getEnableGroupChatsColor());
|
||||
groupMessageDispatchers[groupId] = messageDispatcher;
|
||||
|
@ -124,8 +124,7 @@ private:
|
||||
|
||||
public:
|
||||
Widget(Profile& profile_, IAudioControl& audio_, CameraSource& cameraSource,
|
||||
Settings& settings, Style& style, IMessageBoxManager& messageBoxManager,
|
||||
QWidget* parent = nullptr);
|
||||
Settings& settings, Style& style, QWidget* parent = nullptr);
|
||||
~Widget() override;
|
||||
void init();
|
||||
void setCentralWidget(QWidget* widget, const QString& widgetName);
|
||||
@ -393,7 +392,7 @@ private:
|
||||
std::unique_ptr<DocumentCache> documentCache;
|
||||
CameraSource& cameraSource;
|
||||
Style& style;
|
||||
IMessageBoxManager& messageBoxManager;
|
||||
IMessageBoxManager* messageBoxManager = nullptr; // freed by Qt on destruction
|
||||
std::unique_ptr<FriendList> friendList;
|
||||
std::unique_ptr<ContentDialogManager> contentDialogManager;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user