Skip to content

Commit

Permalink
FIX(client): Improve handling of the GlobalShortcutButtons dialog
Browse files Browse the repository at this point in the history
This commit makes the shortcut configuration dialog a modal window.
It also explicitly searches for a parent QDialog, such that the window
can be centered over the Mumble application instead of randomly out of bounds
of the screen. (This is most likely only necessary because of a bug in Qt, but
Qt is a pain to debug)

Fixes mumble-voip#5024
  • Loading branch information
Hartmnt committed Jun 1, 2024
1 parent 7a6274f commit 245bf7b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/mumble/GlobalShortcutButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,41 @@

#include "GlobalShortcut.h"

#include "MainWindow.h"
#include "Global.h"

#include <QDebug>
#include <QRect>
#include <QTimer>

GlobalShortcutButtons::GlobalShortcutButtons(QWidget *parent) : QDialog(parent), m_ui(new Ui::GlobalShortcutButtons) {
m_ui->setupUi(this);
setModal(true);

connect(m_ui->addButton, &QPushButton::toggled, this, &GlobalShortcutButtons::toggleCapture);
connect(m_ui->removeButton, &QPushButton::clicked, this, &GlobalShortcutButtons::removeItem);

// Due to what appears to be a Qt bug, this dialog will not take
// the parent geometry into account when spawning.
// Therefore, we search for a different parent or even fallback to the
// MainWindow and move this dialog to its center.
QWidget *searchWidget = parent;
while (searchWidget && !qobject_cast< QDialog * >(searchWidget)) {
searchWidget = searchWidget->parentWidget();
}
QWidget *effectiveParent = qobject_cast< QDialog * >(searchWidget);
if (Global::get().mw && Global::get().mw->isVisible()) { //! effectiveParent &&
effectiveParent = Global::get().mw;
}

QTimer::singleShot(0, [effectiveParent, this]() {
if (!effectiveParent) {
return;
}
QRect geometry = effectiveParent->geometry();
qDebug() << geometry;
move(geometry.center().x() - (width() / 2), geometry.center().y() - (height() / 2));
});
}

GlobalShortcutButtons::~GlobalShortcutButtons() {
Expand Down

0 comments on commit 245bf7b

Please sign in to comment.