office-gobmx/include/sfx2/namedcolor.hxx

62 lines
1.6 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 <sal/config.h>
#include <sfx2/dllapi.h>
#include <docmodel/color/ComplexColor.hxx>
#include <docmodel/theme/ThemeColorType.hxx>
struct SFX2_DLLPUBLIC NamedColor
{
Color m_aColor;
OUString m_aName;
sal_Int16 m_nThemeIndex = -1;
sal_Int16 m_nLumMod = 10000;
sal_Int16 m_nLumOff = 0;
NamedColor() = default;
NamedColor(Color const& rColor, OUString const& rName)
: m_aColor(rColor)
, m_aName(rName)
{
}
tdf#34804 sw: enable keyboard shortcut for CharColor and CharBackColor The result of this patch is that a keyboard shortcut can now set the font fore-/back-ground color using the color shown in the toolbar/sidebar. This is now possible thanks to Maxim's work in 7.6.2 tdf#154270 Sync toolbar button recent colors and Andreas Heinisch's 24.8 commit 8c822b764b35a0116a0865e991a87c8315e0 tdf#72991 - Remember last used color depending in cui This patch does 3 things: 1. SetRecentColor when the app initializes 2. Uses SID_ATTR_CHAR_COLOR's recentColor for .uno:FontColor if no pItem was provided (i.e. a keyboard shortcut called it) 3. Uses SID_ATTR_CHAR_BACK_COLOR's recentColor for .uno:CharBackColor if no pItem was provided (Note that without a selection, CharBackColor isn't so useful for a keyboard shortcut, since it turns the drag-and-drop template on.) Setting the recent color right away is critical for user acceptance. Otherwise, it would only function after they first modified the color in the toolbar/sidebar. make CppunitTest_sw_uiwriter9 CPPUNIT_TEST_NAME=testTdf34804 Unfortunately, I can't reliably know if this request came from an awt::KeyEvent or not, because in that case we could just avoid CharBackColor's template altogether. [While there is rReq.GetModifiers() as a good hint, it is not a guarantee (in case assigned to a function key, or CTRL held while clicking the toolbar, etc.)] Change-Id: I7377f087dcdf7011205af005cd0d172100bade2b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174804 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2024-10-10 19:48:10 -05:00
model::ComplexColor getComplexColor() const
{
model::ComplexColor aComplexColor;
auto eThemeColorType = model::convertToThemeColorType(m_nThemeIndex);
if (eThemeColorType != model::ThemeColorType::Unknown)
{
aComplexColor.setThemeColor(eThemeColorType);
if (m_nLumMod != 10000)
aComplexColor.addTransformation({ model::TransformationType::LumMod, m_nLumMod });
if (m_nLumOff != 0)
aComplexColor.addTransformation({ model::TransformationType::LumOff, m_nLumOff });
aComplexColor.setFinalColor(m_aColor);
}
else
{
aComplexColor.setColor(m_aColor);
}
return aComplexColor;
}
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */