1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(settings): create ui when needed instead of show/hide

note: no change in "embedded window" mode yet, but doesn't harm either
This commit is contained in:
Nils Fenner 2016-08-19 11:00:06 +02:00 committed by Diadlo
parent 3dcb8a62a4
commit 12bcc26154
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
3 changed files with 34 additions and 28 deletions

View File

@ -37,8 +37,7 @@
SettingsWidget::SettingsWidget(QWidget* parent) SettingsWidget::SettingsWidget(QWidget* parent)
: QWidget(parent, Qt::Window) : QWidget(parent, Qt::Window)
{ {
// block all signals during initialization, including child widgets setAttribute(Qt::WA_DeleteOnClose);
blockSignals(true);
QVBoxLayout* bodyLayout = new QVBoxLayout(); QVBoxLayout* bodyLayout = new QVBoxLayout();
@ -60,8 +59,6 @@ SettingsWidget::SettingsWidget(QWidget* parent)
connect(settingsWidgets, &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged); connect(settingsWidgets, &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged);
Translator::registerHandler(std::bind(&SettingsWidget::retranslateUi, this), this); Translator::registerHandler(std::bind(&SettingsWidget::retranslateUi, this), this);
blockSignals(false);
} }
SettingsWidget::~SettingsWidget() SettingsWidget::~SettingsWidget()

View File

@ -225,7 +225,6 @@ void Widget::init()
addFriendForm = new AddFriendForm; addFriendForm = new AddFriendForm;
groupInviteForm = new GroupInviteForm; groupInviteForm = new GroupInviteForm;
profileForm = new ProfileForm(); profileForm = new ProfileForm();
settingsWidget = new SettingsWidget();
//connect logout tray menu action //connect logout tray menu action
connect(actionLogout, &QAction::triggered, profileForm, &ProfileForm::onLogoutClicked); connect(actionLogout, &QAction::triggered, profileForm, &ProfileForm::onLogoutClicked);
@ -234,12 +233,11 @@ void Widget::init()
Core* core = Nexus::getCore(); Core* core = Nexus::getCore();
connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete); connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete);
connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete); connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete);
connect(&s, &Settings::showSystemTrayChanged, this, &Widget::onSetShowSystemTray);
connect(core, &Core::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded); connect(core, &Core::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked); connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked);
connect(ui->groupButton, &QPushButton::clicked, this, &Widget::onGroupClicked); connect(ui->groupButton, &QPushButton::clicked, this, &Widget::onGroupClicked);
connect(ui->transferButton, &QPushButton::clicked, this, &Widget::onTransferClicked); connect(ui->transferButton, &QPushButton::clicked, this, &Widget::onTransferClicked);
connect(ui->settingsButton, &QPushButton::clicked, this, &Widget::onSettingsClicked); connect(ui->settingsButton, &QPushButton::clicked, this, &Widget::onShowSettings);
connect(profilePicture, &MaskablePixmapWidget::clicked, this, &Widget::showProfile); connect(profilePicture, &MaskablePixmapWidget::clicked, this, &Widget::showProfile);
connect(ui->nameLabel, &CroppingLabel::clicked, this, &Widget::showProfile); connect(ui->nameLabel, &CroppingLabel::clicked, this, &Widget::showProfile);
connect(ui->statusLabel, &CroppingLabel::editFinished, this, &Widget::onStatusMessageChanged); connect(ui->statusLabel, &CroppingLabel::editFinished, this, &Widget::onStatusMessageChanged);
@ -326,13 +324,13 @@ void Widget::init()
QAction* preferencesAction = viewMenu->menu()->addAction(QString()); QAction* preferencesAction = viewMenu->menu()->addAction(QString());
preferencesAction->setMenuRole(QAction::PreferencesRole); preferencesAction->setMenuRole(QAction::PreferencesRole);
connect(preferencesAction, &QAction::triggered, this, &Widget::onSettingsClicked); connect(preferencesAction, &QAction::triggered, this, &Widget::onShowSettings);
QAction* aboutAction = viewMenu->menu()->addAction(QString()); QAction* aboutAction = viewMenu->menu()->addAction(QString());
aboutAction->setMenuRole(QAction::AboutRole); aboutAction->setMenuRole(QAction::AboutRole);
connect(aboutAction, &QAction::triggered, [this]() connect(aboutAction, &QAction::triggered, [this]()
{ {
onSettingsClicked(); onShowSettings();
settingsWidget->showAbout(); settingsWidget->showAbout();
}); });
@ -374,9 +372,6 @@ void Widget::init()
ui->mainSplitter->setSizes(sizes); ui->mainSplitter->setSizes(sizes);
} }
connect(&s, &Settings::compactLayoutChanged, contactListWidget, &FriendListWidget::onCompactChanged);
connect(&s, &Settings::groupchatPositionChanged, contactListWidget, &FriendListWidget::onGroupchatPositionChanged);
connect(&s, &Settings::separateWindowChanged, this, &Widget::onSeparateWindowClicked);
#if (AUTOUPDATE_ENABLED) #if (AUTOUPDATE_ENABLED)
if (Settings::getInstance().getCheckUpdates()) if (Settings::getInstance().getCheckUpdates())
AutoUpdater::checkUpdatesAsyncInteractive(); AutoUpdater::checkUpdatesAsyncInteractive();
@ -392,6 +387,16 @@ void Widget::init()
connect(groupInviteForm, &GroupInviteForm::groupInvitesSeen, this, &Widget::groupInvitesClear); connect(groupInviteForm, &GroupInviteForm::groupInvitesSeen, this, &Widget::groupInvitesClear);
connect(groupInviteForm, &GroupInviteForm::groupInviteAccepted, this, &Widget::onGroupInviteAccepted); connect(groupInviteForm, &GroupInviteForm::groupInviteAccepted, this, &Widget::onGroupInviteAccepted);
// settings
connect(&s, &Settings::showSystemTrayChanged,
this, &Widget::onSetShowSystemTray);
connect(&s, &Settings::separateWindowChanged,
this, &Widget::onSeparateWindowClicked);
connect(&s, &Settings::compactLayoutChanged,
contactListWidget, &FriendListWidget::onCompactChanged);
connect(&s, &Settings::groupchatPositionChanged,
contactListWidget, &FriendListWidget::onGroupchatPositionChanged);
retranslateUi(); retranslateUi();
Translator::registerHandler(std::bind(&Widget::retranslateUi, this), this); Translator::registerHandler(std::bind(&Widget::retranslateUi, this), this);
@ -530,7 +535,6 @@ Widget::~Widget()
delete icon; delete icon;
delete profileForm; delete profileForm;
delete settingsWidget;
delete addFriendForm; delete addFriendForm;
delete groupInviteForm; delete groupInviteForm;
delete filesForm; delete filesForm;
@ -563,8 +567,8 @@ Widget* Widget::getInstance()
*/ */
void Widget::showUpdateDownloadProgress() void Widget::showUpdateDownloadProgress()
{ {
onShowSettings();
settingsWidget->showAbout(); settingsWidget->showAbout();
onSettingsClicked();
} }
void Widget::moveEvent(QMoveEvent *event) void Widget::moveEvent(QMoveEvent *event)
@ -659,7 +663,7 @@ void Widget::onBadProxyCore()
"settings and restart.", "popup text")); "settings and restart.", "popup text"));
critical.setIcon(QMessageBox::Critical); critical.setIcon(QMessageBox::Critical);
critical.exec(); critical.exec();
onSettingsClicked(); onShowSettings();
} }
void Widget::onStatusSet(Status status) void Widget::onStatusSet(Status status)
@ -724,12 +728,8 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
{ {
showNormal(); showNormal();
resize(width, height()); resize(width, height());
}
setWindowTitle(QString()); if (settingsWidget)
setActiveToolMenuButton(None);
if (clicked)
{ {
ContentLayout* contentLayout = createContentDialog((SettingDialog)); ContentLayout* contentLayout = createContentDialog((SettingDialog));
contentLayout->parentWidget()->resize(size); contentLayout->parentWidget()->resize(size);
@ -738,6 +738,10 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
setActiveToolMenuButton(Widget::None); setActiveToolMenuButton(Widget::None);
} }
} }
setWindowTitle(QString());
setActiveToolMenuButton(None);
}
} }
void Widget::setWindowTitle(const QString& title) void Widget::setWindowTitle(const QString& title)
@ -883,8 +887,13 @@ void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason)
} }
} }
void Widget::onSettingsClicked() void Widget::onShowSettings()
{ {
if (!settingsWidget)
{
settingsWidget = new SettingsWidget(this);
}
if (Settings::getInstance().getSeparateWindow()) if (Settings::getInstance().getSeparateWindow())
{ {
if (!settingsWidget->isShown()) if (!settingsWidget->isShown())
@ -1003,7 +1012,6 @@ void Widget::addFriend(int friendId, const ToxPk& friendPk)
ChatForm* friendForm = newfriend->getChatForm(); ChatForm* friendForm = newfriend->getChatForm();
friendWidgets[friendId] = widget; friendWidgets[friendId] = widget;
newfriend->loadHistory(); newfriend->loadHistory();
const Settings& s = Settings::getInstance(); const Settings& s = Settings::getInstance();

View File

@ -23,6 +23,7 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QMainWindow> #include <QMainWindow>
#include <QPointer>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QFileInfo> #include <QFileInfo>
@ -113,7 +114,7 @@ public:
void resetIcon(); void resetIcon();
public slots: public slots:
void onSettingsClicked(); void onShowSettings();
void onSeparateWindowClicked(bool separate); void onSeparateWindowClicked(bool separate);
void onSeparateWindowChanged(bool separate, bool clicked); void onSeparateWindowChanged(bool separate, bool clicked);
void setWindowTitle(const QString& title); void setWindowTitle(const QString& title);
@ -268,7 +269,7 @@ private:
AddFriendForm *addFriendForm; AddFriendForm *addFriendForm;
GroupInviteForm* groupInviteForm; GroupInviteForm* groupInviteForm;
ProfileForm *profileForm; ProfileForm *profileForm;
SettingsWidget *settingsWidget; QPointer<SettingsWidget> settingsWidget;
FilesForm *filesForm; FilesForm *filesForm;
static Widget *instance; static Widget *instance;
GenericChatroomWidget *activeChatroomWidget; GenericChatroomWidget *activeChatroomWidget;