Files
libreoffice/vcl/inc/qt5/QtInstanceMessageDialog.hxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2.1 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "QtInstanceButton.hxx"
#include "QtInstanceDialog.hxx"
#include <QtWidgets/QMessageBox>
class QtInstanceMessageDialog : public QtInstanceDialog, public virtual weld::MessageDialog
{
Q_OBJECT
private:
QMessageBox* m_pMessageDialog;
// the DialogController/Dialog/function passed to the runAsync variants
std::shared_ptr<weld::DialogController> m_xRunAsyncDialogController;
std::shared_ptr<weld::Dialog> m_xRunAsyncDialog;
std::function<void(sal_Int32)> m_aRunAsyncFunc;
public:
QtInstanceMessageDialog(QMessageBox* pMessageDialog);
virtual void set_primary_text(const rtl::OUString& rText) override;
virtual void set_secondary_text(const rtl::OUString& rText) override;
virtual Container* weld_message_area() override;
virtual OUString get_primary_text() const override;
virtual OUString get_secondary_text() const override;
tdf#154381 qt weld: Add button handling for message box Override the `QtInstanceDialog` methods `add_button` and `run` in `QtInstanceMessageDialog`, and implement handling for these buttons with the native `QMessageBox` that is used internally: Implement `QtInstanceMessageDialog::add_button` to make adding buttons to the welded message dialog work. Map the VCL response type to a corresponding `QMessageBox::ButtonRole`. Some mappings are straightforward, others are a bit more arbitrary, but the only essential thing is that the mapping back to the VCL response code is consistent. `QMessageBox::exec` [1] overrides `QDialog::exec` [2], and while the int returned by the latter corresponds to a `QDialog::DialogCode` code, the int returned by the former corresponds to a `QMessageBox::StandardButton` value. Since the current `QtInstanceDialog::run` implementation relies on the `QDialog` behaviour, override it for the message dialog case. Since the `QMessageBox::ButtonRole` is set in `QtInstanceMessageDialog::add_button`, retrieve the corresponding role from the clicked button instead of using the return value of the `QMessageBox::exec` to be able to get the correct VCL return code again. With this in place, the qt6 welded message dialog that shows up when opening a file that's already open in another instance of LibreOffice (s. `AlreadyOpenQueryBox::AlreadyOpenQueryBox`) shows buttons and clicking any of them behaves as expected, just as is the case for the non-welded one (whose use can be forced by setting env var `SAL_VCL_QT_NO_WELDED_WIDGETS=1`). [1] https://doc.qt.io/qt-6/qmessagebox.html#exec` [2] https://doc.qt.io/qt-6/qdialog.html#exec Change-Id: Ie37573951302f13eab758f889d478dc9351e9c07 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162440 Tested-by: Jenkins Reviewed-by: Omkar Acharekar <omkaracharekar12@gmail.com> Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-01-23 13:47:21 +01:00
// weld::Dialog overrides
virtual void add_button(const OUString& rText, int nResponse,
const OUString& rHelpId = {}) override;
virtual void set_default_response(int nResponse) override;
QtInstanceButton* weld_widget_for_response(int nResponse) override;
tdf#154381 qt weld: Add button handling for message box Override the `QtInstanceDialog` methods `add_button` and `run` in `QtInstanceMessageDialog`, and implement handling for these buttons with the native `QMessageBox` that is used internally: Implement `QtInstanceMessageDialog::add_button` to make adding buttons to the welded message dialog work. Map the VCL response type to a corresponding `QMessageBox::ButtonRole`. Some mappings are straightforward, others are a bit more arbitrary, but the only essential thing is that the mapping back to the VCL response code is consistent. `QMessageBox::exec` [1] overrides `QDialog::exec` [2], and while the int returned by the latter corresponds to a `QDialog::DialogCode` code, the int returned by the former corresponds to a `QMessageBox::StandardButton` value. Since the current `QtInstanceDialog::run` implementation relies on the `QDialog` behaviour, override it for the message dialog case. Since the `QMessageBox::ButtonRole` is set in `QtInstanceMessageDialog::add_button`, retrieve the corresponding role from the clicked button instead of using the return value of the `QMessageBox::exec` to be able to get the correct VCL return code again. With this in place, the qt6 welded message dialog that shows up when opening a file that's already open in another instance of LibreOffice (s. `AlreadyOpenQueryBox::AlreadyOpenQueryBox`) shows buttons and clicking any of them behaves as expected, just as is the case for the non-welded one (whose use can be forced by setting env var `SAL_VCL_QT_NO_WELDED_WIDGETS=1`). [1] https://doc.qt.io/qt-6/qmessagebox.html#exec` [2] https://doc.qt.io/qt-6/qdialog.html#exec Change-Id: Ie37573951302f13eab758f889d478dc9351e9c07 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162440 Tested-by: Jenkins Reviewed-by: Omkar Acharekar <omkaracharekar12@gmail.com> Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-01-23 13:47:21 +01:00
virtual int run() override;
virtual bool runAsync(std::shared_ptr<weld::DialogController> const& rxOwner,
const std::function<void(sal_Int32)>& func) override;
virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
const std::function<void(sal_Int32)>& func) override;
virtual void response(int nResponse) override;
private:
virtual QPushButton* buttonForResponseCode(int nResponse);
private slots:
void dialogFinished(int nResult);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */