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

View File

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

View File

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