Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(settings): create ui when needed instead of show/hide
Browse files Browse the repository at this point in the history
note: no change in "embedded window" mode yet, but doesn't harm either
  • Loading branch information
antis81 authored and Diadlo committed Feb 25, 2017
1 parent 3dcb8a6 commit 12bcc26
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
5 changes: 1 addition & 4 deletions src/widget/form/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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()
Expand Down
52 changes: 30 additions & 22 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -530,7 +535,6 @@ Widget::~Widget()

delete icon;
delete profileForm;
delete settingsWidget;
delete addFriendForm;
delete groupInviteForm;
delete filesForm;
Expand Down Expand Up @@ -563,8 +567,8 @@ Widget* Widget::getInstance()
*/
void Widget::showUpdateDownloadProgress()
{
onShowSettings();
settingsWidget->showAbout();
onSettingsClicked();
}

void Widget::moveEvent(QMoveEvent *event)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -724,19 +728,19 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
{
showNormal();
resize(width, height());

if (settingsWidget)
{
ContentLayout* contentLayout = createContentDialog((SettingDialog));
contentLayout->parentWidget()->resize(size);
contentLayout->parentWidget()->move(pos);
settingsWidget->show(contentLayout);
setActiveToolMenuButton(Widget::None);
}
}

setWindowTitle(QString());
setActiveToolMenuButton(None);

if (clicked)
{
ContentLayout* contentLayout = createContentDialog((SettingDialog));
contentLayout->parentWidget()->resize(size);
contentLayout->parentWidget()->move(pos);
settingsWidget->show(contentLayout);
setActiveToolMenuButton(Widget::None);
}
}
}

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ui_mainwindow.h"

#include <QMainWindow>
#include <QPointer>
#include <QSystemTrayIcon>
#include <QFileInfo>

Expand Down Expand Up @@ -113,7 +114,7 @@ class Widget final : public QMainWindow
void resetIcon();

public slots:
void onSettingsClicked();
void onShowSettings();
void onSeparateWindowClicked(bool separate);
void onSeparateWindowChanged(bool separate, bool clicked);
void setWindowTitle(const QString& title);
Expand Down Expand Up @@ -268,7 +269,7 @@ private slots:
AddFriendForm *addFriendForm;
GroupInviteForm* groupInviteForm;
ProfileForm *profileForm;
SettingsWidget *settingsWidget;
QPointer<SettingsWidget> settingsWidget;
FilesForm *filesForm;
static Widget *instance;
GenericChatroomWidget *activeChatroomWidget;
Expand Down

0 comments on commit 12bcc26

Please sign in to comment.