office-gobmx/vcl/qt5/QtTools.cxx
Michael Weghorn c038b4fd16 tdf#159323 qt weld: Set standard buttons via weld API
Instead of mapping the `VclButtonsType` to the corresponding
`QMessageBox::StandardButtons` and using that to set the
standard buttons for the `QMessageBox` using
`QMessageBox::setStandardButtons`, use
`weld::MessageDialog::add_button` to add all of the
buttons manually, using their standard button texts.

While the former is somewhat nicer, it depends on the
ability to map between the VCL response code and a
`QMessageBox::ButtonRole`.
While there is currently a mapping in place
(s. `lcl_vclResponseTypeToQtMessageBoxButtonRole` and
`lcl_qtMessageBoxButtonRoleToVclResponseType`), this
turned out to not be sufficient, since the VCL
return code cannot only be one of the enum values
in `VclResponseType` (which are currently handled)
but any int.

This commit is in preparation of an upcoming one
that will replace the current mapping to support
arbitrary int response codes.

Change-Id: Icca68f2ccec182f8ff6ae3c64680a4d28bd687d0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162559
Tested-by: Jenkins
Reviewed-by: Omkar Acharekar  <omkaracharekar12@gmail.com>
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-01-28 16:42:04 +01:00

192 lines
5.7 KiB
C++

/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <QtTools.hxx>
#include <cairo.h>
#include <tools/stream.hxx>
#include <vcl/event.hxx>
#include <vcl/image.hxx>
#include <vcl/filter/PngImageWriter.hxx>
#include <vcl/stdtext.hxx>
#include <vcl/svapp.hxx>
#include <QtGui/QImage>
void CairoDeleter::operator()(cairo_surface_t* pSurface) const { cairo_surface_destroy(pSurface); }
sal_uInt16 GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers)
{
sal_uInt16 nCode = 0;
if (eKeyModifiers & Qt::ShiftModifier)
nCode |= KEY_SHIFT;
if (eKeyModifiers & Qt::ControlModifier)
nCode |= KEY_MOD1;
if (eKeyModifiers & Qt::AltModifier)
nCode |= KEY_MOD2;
if (eKeyModifiers & Qt::MetaModifier)
nCode |= KEY_MOD3;
return nCode;
}
sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons)
{
sal_uInt16 nCode = 0;
if (eButtons & Qt::LeftButton)
nCode |= MOUSE_LEFT;
if (eButtons & Qt::MiddleButton)
nCode |= MOUSE_MIDDLE;
if (eButtons & Qt::RightButton)
nCode |= MOUSE_RIGHT;
return nCode;
}
Qt::DropActions toQtDropActions(sal_Int8 dragOperation)
{
Qt::DropActions eRet = Qt::IgnoreAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
eRet |= Qt::CopyAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
eRet |= Qt::MoveAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
eRet |= Qt::LinkAction;
return eRet;
}
sal_Int8 toVclDropActions(Qt::DropActions dragOperation)
{
sal_Int8 nRet(0);
if (dragOperation & Qt::CopyAction)
nRet |= css::datatransfer::dnd::DNDConstants::ACTION_COPY;
if (dragOperation & Qt::MoveAction)
nRet |= css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
if (dragOperation & Qt::LinkAction)
nRet |= css::datatransfer::dnd::DNDConstants::ACTION_LINK;
return nRet;
}
sal_Int8 toVclDropAction(Qt::DropAction dragOperation)
{
sal_Int8 nRet(0);
if (dragOperation == Qt::CopyAction)
nRet = css::datatransfer::dnd::DNDConstants::ACTION_COPY;
else if (dragOperation == Qt::MoveAction)
nRet = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
else if (dragOperation == Qt::LinkAction)
nRet = css::datatransfer::dnd::DNDConstants::ACTION_LINK;
return nRet;
}
Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation)
{
Qt::DropAction eAct = Qt::IgnoreAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
eAct = Qt::MoveAction;
else if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
eAct = Qt::CopyAction;
else if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
eAct = Qt::LinkAction;
return eAct;
}
QImage toQImage(const Image& rImage)
{
QImage aImage;
if (!!rImage)
{
SvMemoryStream aMemStm;
auto rBitmapEx = rImage.GetBitmapEx();
vcl::PngImageWriter aWriter(aMemStm);
aWriter.write(rBitmapEx);
aImage.loadFromData(static_cast<const uchar*>(aMemStm.GetData()), aMemStm.TellEnd());
}
return aImage;
}
QMessageBox::Icon vclMessageTypeToQtIcon(VclMessageType eType)
{
QMessageBox::Icon eRet = QMessageBox::Information;
switch (eType)
{
case VclMessageType::Info:
eRet = QMessageBox::Information;
break;
case VclMessageType::Warning:
eRet = QMessageBox::Warning;
break;
case VclMessageType::Question:
eRet = QMessageBox::Question;
break;
case VclMessageType::Error:
eRet = QMessageBox::Critical;
break;
case VclMessageType::Other:
eRet = QMessageBox::Information;
break;
}
return eRet;
}
QString vclMessageTypeToQtTitle(VclMessageType eType)
{
QString title;
switch (eType)
{
case VclMessageType::Info:
title = toQString(GetStandardInfoBoxText());
break;
case VclMessageType::Warning:
title = toQString(GetStandardWarningBoxText());
break;
case VclMessageType::Question:
title = toQString(GetStandardQueryBoxText());
break;
case VclMessageType::Error:
title = toQString(GetStandardErrorBoxText());
break;
case VclMessageType::Other:
title = toQString(Application::GetDisplayName());
break;
}
return title;
}
int qtResponseTypeToVclResponseType(int ret)
{
if (ret == QDialog::Accepted)
{
ret = RET_OK;
}
else
{
ret = RET_CANCEL;
}
return ret;
}
QString vclToQtStringWithAccelerator(const OUString& rText)
{
// preserve literal '&'s and use '&' instead of '~' for the accelerator
return toQString(rText.replaceAll("&", "&&").replace('~', '&'));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */