Remove unneeded QWindow from QGtk3Dialog
It seems QWindow here is only for making the dialog modal, but QDialog already handles that and this makes two modals block each other depending on the order they created with Task-number: QTBUG-98988 Pick-to: 6.4 6.3 6.2 5.15 Change-Id: I6847cfab480395f62eaa0ebf79acf8b024192178 Reviewed-by: David Edmundson <davidedmundson@kde.org> Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
This commit is contained in:
parent
e97b9ddcb0
commit
64e6233252
@ -35,12 +35,10 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class QGtk3Dialog : public QWindow
|
||||
class QGtk3Dialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QGtk3Dialog(GtkWidget *gtkWidget);
|
||||
QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper);
|
||||
~QGtk3Dialog();
|
||||
|
||||
GtkDialog *gtkDialog() const;
|
||||
@ -49,23 +47,20 @@ public:
|
||||
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
|
||||
void hide();
|
||||
|
||||
Q_SIGNALS:
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
protected:
|
||||
static void onResponse(QGtk3Dialog *dialog, int response);
|
||||
|
||||
private slots:
|
||||
void onParentWindowDestroyed();
|
||||
static void onResponse(QPlatformDialogHelper *helper, int response);
|
||||
|
||||
private:
|
||||
GtkWidget *gtkWidget;
|
||||
QPlatformDialogHelper *helper;
|
||||
Qt::WindowModality modality;
|
||||
};
|
||||
|
||||
QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget)
|
||||
QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper)
|
||||
: gtkWidget(gtkWidget)
|
||||
, helper(helper)
|
||||
{
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), this);
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), helper);
|
||||
g_signal_connect(G_OBJECT(gtkWidget), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
||||
}
|
||||
|
||||
@ -82,27 +77,22 @@ GtkDialog *QGtk3Dialog::gtkDialog() const
|
||||
|
||||
void QGtk3Dialog::exec()
|
||||
{
|
||||
if (modality() == Qt::ApplicationModal) {
|
||||
if (modality == Qt::ApplicationModal) {
|
||||
// block input to the whole app, including other GTK dialogs
|
||||
gtk_dialog_run(gtkDialog());
|
||||
} else {
|
||||
// block input to the window, allow input to other GTK dialogs
|
||||
QEventLoop loop;
|
||||
connect(this, SIGNAL(accept()), &loop, SLOT(quit()));
|
||||
connect(this, SIGNAL(reject()), &loop, SLOT(quit()));
|
||||
loop.connect(helper, SIGNAL(accept()), SLOT(quit()));
|
||||
loop.connect(helper, SIGNAL(reject()), SLOT(quit()));
|
||||
loop.exec();
|
||||
}
|
||||
}
|
||||
|
||||
bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
|
||||
{
|
||||
if (parent) {
|
||||
connect(parent, &QWindow::destroyed, this, &QGtk3Dialog::onParentWindowDestroyed,
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
setParent(parent);
|
||||
setFlags(flags);
|
||||
setModality(modality);
|
||||
Q_UNUSED(flags);
|
||||
this->modality = modality;
|
||||
|
||||
gtk_widget_realize(gtkWidget); // creates X window
|
||||
|
||||
@ -120,7 +110,6 @@ bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWind
|
||||
|
||||
if (modality != Qt::NonModal) {
|
||||
gdk_window_set_modal_hint(gdkWindow, true);
|
||||
QGuiApplicationPrivate::showModalWindow(this);
|
||||
}
|
||||
|
||||
gtk_widget_show(gtkWidget);
|
||||
@ -130,30 +119,20 @@ bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWind
|
||||
|
||||
void QGtk3Dialog::hide()
|
||||
{
|
||||
QGuiApplicationPrivate::hideModalWindow(this);
|
||||
gtk_widget_hide(gtkWidget);
|
||||
}
|
||||
|
||||
void QGtk3Dialog::onResponse(QGtk3Dialog *dialog, int response)
|
||||
void QGtk3Dialog::onResponse(QPlatformDialogHelper *helper, int response)
|
||||
{
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
emit dialog->accept();
|
||||
emit helper->accept();
|
||||
else
|
||||
emit dialog->reject();
|
||||
}
|
||||
|
||||
void QGtk3Dialog::onParentWindowDestroyed()
|
||||
{
|
||||
// The QGtk3*DialogHelper classes own this object. Make sure the parent doesn't delete it.
|
||||
setParent(nullptr);
|
||||
emit helper->reject();
|
||||
}
|
||||
|
||||
QGtk3ColorDialogHelper::QGtk3ColorDialogHelper()
|
||||
{
|
||||
d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr)));
|
||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
||||
connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
|
||||
|
||||
d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr), this));
|
||||
g_signal_connect_swapped(d->gtkDialog(), "notify::rgba", G_CALLBACK(onColorChanged), this);
|
||||
}
|
||||
|
||||
@ -198,11 +177,6 @@ QColor QGtk3ColorDialogHelper::currentColor() const
|
||||
return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
|
||||
}
|
||||
|
||||
void QGtk3ColorDialogHelper::onAccepted()
|
||||
{
|
||||
emit accept();
|
||||
}
|
||||
|
||||
void QGtk3ColorDialogHelper::onColorChanged(QGtk3ColorDialogHelper *dialog)
|
||||
{
|
||||
emit dialog->currentColorChanged(dialog->currentColor());
|
||||
@ -222,10 +196,7 @@ QGtk3FileDialogHelper::QGtk3FileDialogHelper()
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Cancel)), GTK_RESPONSE_CANCEL,
|
||||
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Ok)), GTK_RESPONSE_OK,
|
||||
NULL)));
|
||||
|
||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
||||
connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
|
||||
NULL), this));
|
||||
|
||||
g_signal_connect(GTK_FILE_CHOOSER(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
|
||||
g_signal_connect_swapped(GTK_FILE_CHOOSER(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
|
||||
@ -348,11 +319,6 @@ QString QGtk3FileDialogHelper::selectedNameFilter() const
|
||||
return _filterNames.value(gtkFilter);
|
||||
}
|
||||
|
||||
void QGtk3FileDialogHelper::onAccepted()
|
||||
{
|
||||
emit accept();
|
||||
}
|
||||
|
||||
void QGtk3FileDialogHelper::onSelectionChanged(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
|
||||
{
|
||||
QString selection;
|
||||
@ -508,10 +474,7 @@ void QGtk3FileDialogHelper::setNameFilters(const QStringList &filters)
|
||||
|
||||
QGtk3FontDialogHelper::QGtk3FontDialogHelper()
|
||||
{
|
||||
d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr)));
|
||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
||||
connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
|
||||
|
||||
d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr), this));
|
||||
g_signal_connect_swapped(d->gtkDialog(), "notify::font", G_CALLBACK(onFontChanged), this);
|
||||
}
|
||||
|
||||
@ -615,11 +578,6 @@ QFont QGtk3FontDialogHelper::currentFont() const
|
||||
return font;
|
||||
}
|
||||
|
||||
void QGtk3FontDialogHelper::onAccepted()
|
||||
{
|
||||
emit accept();
|
||||
}
|
||||
|
||||
void QGtk3FontDialogHelper::onFontChanged(QGtk3FontDialogHelper *dialog)
|
||||
{
|
||||
emit dialog->currentFontChanged(dialog->currentFont());
|
||||
|
@ -35,9 +35,6 @@ public:
|
||||
void setCurrentColor(const QColor &color) override;
|
||||
QColor currentColor() const override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onAccepted();
|
||||
|
||||
private:
|
||||
static void onColorChanged(QGtk3ColorDialogHelper *helper);
|
||||
void applyOptions();
|
||||
@ -66,9 +63,6 @@ public:
|
||||
void selectNameFilter(const QString &filter) override;
|
||||
QString selectedNameFilter() const override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onAccepted();
|
||||
|
||||
private:
|
||||
static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
|
||||
static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
|
||||
@ -102,9 +96,6 @@ public:
|
||||
void setCurrentFont(const QFont &font) override;
|
||||
QFont currentFont() const override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onAccepted();
|
||||
|
||||
private:
|
||||
static void onFontChanged(QGtk3FontDialogHelper *helper);
|
||||
void applyOptions();
|
||||
|
Loading…
Reference in New Issue
Block a user