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 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> (cherry picked from commit 64e6233252117415d6765b6f7a8f4df39490b678) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
861780151f
commit
fe1319a4c8
@ -35,12 +35,10 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
class QGtk3Dialog : public QWindow
|
class QGtk3Dialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QGtk3Dialog(GtkWidget *gtkWidget);
|
QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper);
|
||||||
~QGtk3Dialog();
|
~QGtk3Dialog();
|
||||||
|
|
||||||
GtkDialog *gtkDialog() const;
|
GtkDialog *gtkDialog() const;
|
||||||
@ -49,23 +47,20 @@ public:
|
|||||||
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
|
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void accept();
|
|
||||||
void reject();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void onResponse(QGtk3Dialog *dialog, int response);
|
static void onResponse(QPlatformDialogHelper *helper, int response);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onParentWindowDestroyed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GtkWidget *gtkWidget;
|
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);
|
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()
|
void QGtk3Dialog::exec()
|
||||||
{
|
{
|
||||||
if (modality() == Qt::ApplicationModal) {
|
if (modality == Qt::ApplicationModal) {
|
||||||
// block input to the whole app, including other GTK dialogs
|
// block input to the whole app, including other GTK dialogs
|
||||||
gtk_dialog_run(gtkDialog());
|
gtk_dialog_run(gtkDialog());
|
||||||
} else {
|
} else {
|
||||||
// block input to the window, allow input to other GTK dialogs
|
// block input to the window, allow input to other GTK dialogs
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(this, SIGNAL(accept()), &loop, SLOT(quit()));
|
loop.connect(helper, SIGNAL(accept()), SLOT(quit()));
|
||||||
connect(this, SIGNAL(reject()), &loop, SLOT(quit()));
|
loop.connect(helper, SIGNAL(reject()), SLOT(quit()));
|
||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
|
bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
|
||||||
{
|
{
|
||||||
if (parent) {
|
Q_UNUSED(flags);
|
||||||
connect(parent, &QWindow::destroyed, this, &QGtk3Dialog::onParentWindowDestroyed,
|
this->modality = modality;
|
||||||
Qt::UniqueConnection);
|
|
||||||
}
|
|
||||||
setParent(parent);
|
|
||||||
setFlags(flags);
|
|
||||||
setModality(modality);
|
|
||||||
|
|
||||||
gtk_widget_realize(gtkWidget); // creates X window
|
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) {
|
if (modality != Qt::NonModal) {
|
||||||
gdk_window_set_modal_hint(gdkWindow, true);
|
gdk_window_set_modal_hint(gdkWindow, true);
|
||||||
QGuiApplicationPrivate::showModalWindow(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_show(gtkWidget);
|
gtk_widget_show(gtkWidget);
|
||||||
@ -130,30 +119,20 @@ bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWind
|
|||||||
|
|
||||||
void QGtk3Dialog::hide()
|
void QGtk3Dialog::hide()
|
||||||
{
|
{
|
||||||
QGuiApplicationPrivate::hideModalWindow(this);
|
|
||||||
gtk_widget_hide(gtkWidget);
|
gtk_widget_hide(gtkWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGtk3Dialog::onResponse(QGtk3Dialog *dialog, int response)
|
void QGtk3Dialog::onResponse(QPlatformDialogHelper *helper, int response)
|
||||||
{
|
{
|
||||||
if (response == GTK_RESPONSE_OK)
|
if (response == GTK_RESPONSE_OK)
|
||||||
emit dialog->accept();
|
emit helper->accept();
|
||||||
else
|
else
|
||||||
emit dialog->reject();
|
emit helper->reject();
|
||||||
}
|
|
||||||
|
|
||||||
void QGtk3Dialog::onParentWindowDestroyed()
|
|
||||||
{
|
|
||||||
// The QGtk3*DialogHelper classes own this object. Make sure the parent doesn't delete it.
|
|
||||||
setParent(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QGtk3ColorDialogHelper::QGtk3ColorDialogHelper()
|
QGtk3ColorDialogHelper::QGtk3ColorDialogHelper()
|
||||||
{
|
{
|
||||||
d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr)));
|
d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr), this));
|
||||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
|
||||||
connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
|
|
||||||
|
|
||||||
g_signal_connect_swapped(d->gtkDialog(), "notify::rgba", G_CALLBACK(onColorChanged), 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);
|
return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGtk3ColorDialogHelper::onAccepted()
|
|
||||||
{
|
|
||||||
emit accept();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QGtk3ColorDialogHelper::onColorChanged(QGtk3ColorDialogHelper *dialog)
|
void QGtk3ColorDialogHelper::onColorChanged(QGtk3ColorDialogHelper *dialog)
|
||||||
{
|
{
|
||||||
emit dialog->currentColorChanged(dialog->currentColor());
|
emit dialog->currentColorChanged(dialog->currentColor());
|
||||||
@ -222,10 +196,7 @@ QGtk3FileDialogHelper::QGtk3FileDialogHelper()
|
|||||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Cancel)), GTK_RESPONSE_CANCEL,
|
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Cancel)), GTK_RESPONSE_CANCEL,
|
||||||
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Ok)), GTK_RESPONSE_OK,
|
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Ok)), GTK_RESPONSE_OK,
|
||||||
NULL)));
|
NULL), this));
|
||||||
|
|
||||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
|
||||||
connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
|
|
||||||
|
|
||||||
g_signal_connect(GTK_FILE_CHOOSER(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), 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);
|
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);
|
return _filterNames.value(gtkFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGtk3FileDialogHelper::onAccepted()
|
|
||||||
{
|
|
||||||
emit accept();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QGtk3FileDialogHelper::onSelectionChanged(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
|
void QGtk3FileDialogHelper::onSelectionChanged(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
|
||||||
{
|
{
|
||||||
QString selection;
|
QString selection;
|
||||||
@ -508,10 +474,7 @@ void QGtk3FileDialogHelper::setNameFilters(const QStringList &filters)
|
|||||||
|
|
||||||
QGtk3FontDialogHelper::QGtk3FontDialogHelper()
|
QGtk3FontDialogHelper::QGtk3FontDialogHelper()
|
||||||
{
|
{
|
||||||
d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr)));
|
d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr), this));
|
||||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
|
||||||
connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
|
|
||||||
|
|
||||||
g_signal_connect_swapped(d->gtkDialog(), "notify::font", G_CALLBACK(onFontChanged), this);
|
g_signal_connect_swapped(d->gtkDialog(), "notify::font", G_CALLBACK(onFontChanged), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,11 +578,6 @@ QFont QGtk3FontDialogHelper::currentFont() const
|
|||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGtk3FontDialogHelper::onAccepted()
|
|
||||||
{
|
|
||||||
emit accept();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QGtk3FontDialogHelper::onFontChanged(QGtk3FontDialogHelper *dialog)
|
void QGtk3FontDialogHelper::onFontChanged(QGtk3FontDialogHelper *dialog)
|
||||||
{
|
{
|
||||||
emit dialog->currentFontChanged(dialog->currentFont());
|
emit dialog->currentFontChanged(dialog->currentFont());
|
||||||
|
@ -35,9 +35,6 @@ public:
|
|||||||
void setCurrentColor(const QColor &color) override;
|
void setCurrentColor(const QColor &color) override;
|
||||||
QColor currentColor() const override;
|
QColor currentColor() const override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onAccepted();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onColorChanged(QGtk3ColorDialogHelper *helper);
|
static void onColorChanged(QGtk3ColorDialogHelper *helper);
|
||||||
void applyOptions();
|
void applyOptions();
|
||||||
@ -66,9 +63,6 @@ public:
|
|||||||
void selectNameFilter(const QString &filter) override;
|
void selectNameFilter(const QString &filter) override;
|
||||||
QString selectedNameFilter() const override;
|
QString selectedNameFilter() const override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onAccepted();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
|
static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
|
||||||
static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
|
static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
|
||||||
@ -102,9 +96,6 @@ public:
|
|||||||
void setCurrentFont(const QFont &font) override;
|
void setCurrentFont(const QFont &font) override;
|
||||||
QFont currentFont() const override;
|
QFont currentFont() const override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onAccepted();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onFontChanged(QGtk3FontDialogHelper *helper);
|
static void onFontChanged(QGtk3FontDialogHelper *helper);
|
||||||
void applyOptions();
|
void applyOptions();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user