Avoid misplaced/clipped dialogs when default dialog size doesn't fit screen
https://github.com/Martchus/syncthingtray/issues/89
This commit is contained in:
parent
4903927de9
commit
8c4e2168bc
|
@ -98,7 +98,7 @@ find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.6.0 REQUIRED)
|
|||
use_cpp_utilities()
|
||||
|
||||
# find qtutilities
|
||||
find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.0.0 REQUIRED)
|
||||
find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.4.0 REQUIRED)
|
||||
use_qt_utilities()
|
||||
|
||||
# find backend libraries
|
||||
|
|
|
@ -295,9 +295,9 @@ void TrayIcon::showNewDir(const QString &devId, const QString &dirId, const QStr
|
|||
|
||||
void TrayIcon::showInternalErrorsDialog()
|
||||
{
|
||||
auto *const errorViewDlg = InternalErrorsDialog::instance();
|
||||
connect(errorViewDlg, &InternalErrorsDialog::errorsCleared, this, &TrayIcon::handleErrorsCleared);
|
||||
centerWidget(errorViewDlg);
|
||||
errorViewDlg->show();
|
||||
if (!InternalErrorsDialog::hasInstance()) {
|
||||
connect(InternalErrorsDialog::instance(), &InternalErrorsDialog::errorsCleared, this, &TrayIcon::handleErrorsCleared);
|
||||
}
|
||||
trayMenu().widget().showInternalErrorsDialog();
|
||||
}
|
||||
} // namespace QtGui
|
||||
|
|
|
@ -3,16 +3,13 @@
|
|||
#include "./trayicon.h"
|
||||
#include "./traymenu.h"
|
||||
|
||||
#include <syncthingwidgets/misc/internalerrorsdialog.h>
|
||||
#include <syncthingwidgets/misc/otherdialogs.h>
|
||||
#include <syncthingwidgets/misc/syncthinglauncher.h>
|
||||
#include <syncthingwidgets/misc/textviewdialog.h>
|
||||
#include <syncthingwidgets/settings/settingsdialog.h>
|
||||
#include <syncthingwidgets/webview/webviewdialog.h>
|
||||
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
#include <syncthingwidgets/misc/internalerrorsdialog.h>
|
||||
#endif
|
||||
|
||||
#include <syncthingmodel/syncthingicons.h>
|
||||
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
|
@ -244,8 +241,9 @@ void TrayWidget::showSettingsDialog()
|
|||
// by simply saving the settings immediately.
|
||||
connect(s_settingsDlg, &SettingsDialog::applied, &Settings::save);
|
||||
}
|
||||
centerWidget(s_settingsDlg);
|
||||
showDialog(s_settingsDlg);
|
||||
|
||||
// show settings dialog centered or maximized if the relatively big windows would overflow
|
||||
showDialog(s_settingsDlg, centerWidgetAvoidingOverflow(s_settingsDlg));
|
||||
}
|
||||
|
||||
void TrayWidget::showAboutDialog()
|
||||
|
@ -292,24 +290,21 @@ void TrayWidget::showOwnDeviceId()
|
|||
{
|
||||
auto *const dlg = ownDeviceIdDialog(m_connection);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
centerWidget(dlg);
|
||||
showDialog(dlg);
|
||||
showDialog(dlg, centerWidgetAvoidingOverflow(dlg));
|
||||
}
|
||||
|
||||
void TrayWidget::showLog()
|
||||
{
|
||||
auto *const dlg = TextViewDialog::forLogEntries(m_connection);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
centerWidget(dlg);
|
||||
showDialog(dlg);
|
||||
showDialog(dlg, centerWidgetAvoidingOverflow(dlg));
|
||||
}
|
||||
|
||||
void TrayWidget::showNotifications()
|
||||
{
|
||||
auto *const dlg = TextViewDialog::forLogEntries(m_notifications, tr("New notifications"));
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
centerWidget(dlg);
|
||||
showDialog(dlg);
|
||||
showDialog(dlg, centerWidgetAvoidingOverflow(dlg));
|
||||
m_notifications.clear();
|
||||
dismissNotifications();
|
||||
}
|
||||
|
@ -329,15 +324,16 @@ void TrayWidget::showInternalErrorsButton()
|
|||
{
|
||||
m_internalErrorsButton->setVisible(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
void TrayWidget::showInternalErrorsDialog()
|
||||
{
|
||||
auto *const errorViewDlg = InternalErrorsDialog::instance();
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
connect(errorViewDlg, &InternalErrorsDialog::errorsCleared, this, &TrayWidget::handleErrorsCleared);
|
||||
centerWidget(errorViewDlg);
|
||||
errorViewDlg->show();
|
||||
}
|
||||
#endif
|
||||
showDialog(errorViewDlg, centerWidgetAvoidingOverflow(errorViewDlg));
|
||||
}
|
||||
|
||||
void TrayWidget::dismissNotifications()
|
||||
{
|
||||
|
@ -816,12 +812,19 @@ void TrayWidget::handleConnectionSelected(QAction *connectionAction)
|
|||
}
|
||||
}
|
||||
|
||||
void TrayWidget::showDialog(QWidget *dlg)
|
||||
void TrayWidget::showDialog(QWidget *dlg, bool maximized)
|
||||
{
|
||||
if (m_menu) {
|
||||
m_menu->close();
|
||||
}
|
||||
dlg->show();
|
||||
if (maximized) {
|
||||
// assign the minimum size so when the window is "de-maximized" again it doesn't overflow again and is not misplaced
|
||||
dlg->resize(dlg->minimumSize());
|
||||
centerWidget(dlg);
|
||||
dlg->showMaximized();
|
||||
} else {
|
||||
dlg->show();
|
||||
}
|
||||
dlg->activateWindow();
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ public Q_SLOTS:
|
|||
void showUsingPositioningSettings();
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
void showInternalErrorsButton();
|
||||
void showInternalErrorsDialog();
|
||||
#endif
|
||||
void showInternalErrorsDialog();
|
||||
void dismissNotifications();
|
||||
void restartSyncthing();
|
||||
void quitTray();
|
||||
|
@ -103,7 +103,7 @@ private Q_SLOTS:
|
|||
#endif
|
||||
void handleNewNotification(CppUtilities::DateTime when, const QString &msg);
|
||||
void handleConnectionSelected(QAction *connectionAction);
|
||||
void showDialog(QWidget *dlg);
|
||||
void showDialog(QWidget *dlg, bool maximized = false);
|
||||
|
||||
private:
|
||||
TrayMenu *m_menu;
|
||||
|
|
|
@ -15,6 +15,7 @@ class SYNCTHINGWIDGETS_EXPORT InternalErrorsDialog : public TextViewDialog {
|
|||
public:
|
||||
~InternalErrorsDialog() override;
|
||||
static InternalErrorsDialog *instance();
|
||||
static bool hasInstance();
|
||||
static void addError(InternalError &&newError);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -43,6 +44,11 @@ inline InternalErrorsDialog *InternalErrorsDialog::instance()
|
|||
return s_instance ? s_instance : (s_instance = new InternalErrorsDialog);
|
||||
}
|
||||
|
||||
inline bool InternalErrorsDialog::hasInstance()
|
||||
{
|
||||
return s_instance != nullptr;
|
||||
}
|
||||
|
||||
inline void InternalErrorsDialog::showInstance()
|
||||
{
|
||||
instance()->show();
|
||||
|
|
Loading…
Reference in New Issue