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

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

54 lines
1.7 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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;
tdf#130857 qt weld: Add layout/widget for extra msg dialog controls weld::MessageDialog::weld_message_area needs to return a weld::Container that can be used to insert additional controls into a message dialog. In order to implement this for QtInstanceMessageDialog, insert an additional widget with a QVBoxLayout layout into the QMessageBox layout, and return that one. In order to ensure that the extra controls are inserted in between the labels holding the text in the message dialog and the button box, make use of the known implementation detail that Qt's QMessageBox uses QGridLayout for its layout (see QMessageBoxPrivate::setupLayout in qtbase [1]), find where the last label is positioned, shift everything after the last label down by one row in the grid layout, then insert the extra widget in the now empty row. If QMessageBox internals ever change to use a different layout,..., then this will have to be adjusted in the future, but it works fine in my tests with both, Qt 5.15 and current qtbase dev (as of commit 4c0b45553862d3eff35906d02ea5e2afd9252bbd). This will be needed e.g. by the "LibreOfficDev Help Not Installed" dialog that shows up when pressing F1 in a build not including the local help. [1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/dialogs/qmessagebox.cpp?id=4c0b45553862d3eff35906d02ea5e2afd9252bbd#n290 Change-Id: I2153add5145a4655800ca89f8e943610014b1021 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176091 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
2024-11-05 17:40:28 +01:00
// widget containing a layout to add additional items
QWidget* m_pExtraControlsContainer;
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 std::unique_ptr<weld::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;
std::unique_ptr<weld::Button> weld_button_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;
private:
tdf#130857 qt weld: Add layout/widget for extra msg dialog controls weld::MessageDialog::weld_message_area needs to return a weld::Container that can be used to insert additional controls into a message dialog. In order to implement this for QtInstanceMessageDialog, insert an additional widget with a QVBoxLayout layout into the QMessageBox layout, and return that one. In order to ensure that the extra controls are inserted in between the labels holding the text in the message dialog and the button box, make use of the known implementation detail that Qt's QMessageBox uses QGridLayout for its layout (see QMessageBoxPrivate::setupLayout in qtbase [1]), find where the last label is positioned, shift everything after the last label down by one row in the grid layout, then insert the extra widget in the now empty row. If QMessageBox internals ever change to use a different layout,..., then this will have to be adjusted in the future, but it works fine in my tests with both, Qt 5.15 and current qtbase dev (as of commit 4c0b45553862d3eff35906d02ea5e2afd9252bbd). This will be needed e.g. by the "LibreOfficDev Help Not Installed" dialog that shows up when pressing F1 in a build not including the local help. [1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/dialogs/qmessagebox.cpp?id=4c0b45553862d3eff35906d02ea5e2afd9252bbd#n290 Change-Id: I2153add5145a4655800ca89f8e943610014b1021 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176091 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
2024-11-05 17:40:28 +01:00
QWidget* addWidgetForExtraItems();
virtual QPushButton* buttonForResponseCode(int nResponse);
tdf#130857 qt weld: Move runAsync logic to QtInstanceDialog Refactor the handling for running a QtInstanceMessageDialog asynchronously, and reuse the logic for the QtInstanceDialog base class: Move implementations for both QtInstanceMessageDialog::runAsync methods and the involved class members from QtInstanceMessageDialog to QtInstanceDialog. Split the previous logic from QtInstanceMessageDialog::dialogFinished into two methods: * move most of the logic as is to a new virtual slot in the base class, QtInstanceDialog::dialogFinished * override the base class implementation to get the response code from the actually clicked button via the PROPERTY_VCL_RESPONSE_CODE property set on that button, and call the base class method with that one. For QtInstanceDialog, there's no QDialog::clickedButton method that could be used to retrieve the clicked button, but it's also not needed there, because there a slot connected to the QAbstractButton::clicked signal that triggers closing the dialog, and passes the proper response code of the corresponding button already, see commit 08b55df5c9e42c1ccb78a156261811875629342a Author: Michael Weghorn <m.weghorn@posteo.de> Date: Sat Sep 28 00:32:15 2024 +0200 tdf#130857 qt weld: Close dialog on button click With this commit in place, QtInstanceDialog can now also be run asynchronously, instead of the QtInstanceDialog::runAsync methods just returning true without doing anything. This will be needed e.g. when adding support for the "Tools" -> "Word Count" dialog in Writer. Change-Id: I4edb9443cb11d1dc831a18f708cdbdd67c239aa6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174374 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
2024-10-02 09:33:08 +02:00
protected slots:
virtual void dialogFinished(int nResult) override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */