diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2023-10-25 18:23:06 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2023-10-28 21:31:16 +0200 |
commit | 50abd90d739410ed34de5e7cd9c4308dc75f9ab6 (patch) | |
tree | b085c71389e7c7604b47ee63b0f6921a033eb903 | |
parent | 7269df74824bdea31b9d42d1e2d77b77e702b3ab (diff) |
Introduce easy to apply cond format styles
UNO commands for Data bars and Color scale conditional
formatting now can be called with parameter to apply
few predefined themes.
In the future it could be moved somewhere so it could
be configured from the UI maybe...
Change-Id: I080709709fcc0886dcaf6050a6c1ae621b6728c9
(cherry picked from commit c8d4a99082269c7008df5765232a93d19e7a3d84)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158539
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | sc/sdi/scalc.sdi | 4 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 155 |
2 files changed, 143 insertions, 16 deletions
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi index 4da6e21b162e..614293cc90bb 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -787,7 +787,7 @@ SfxVoidItem CurrentConditionalFormatDialog SID_OPENDLG_CURRENTCONDFRMT SfxVoidItem ColorScaleFormatDialog SID_OPENDLG_COLORSCALE -() +(SfxInt16Item IconSet FN_PARAM_1) [ AutoUpdate = FALSE, FastCall = FALSE, @@ -805,7 +805,7 @@ SfxVoidItem ColorScaleFormatDialog SID_OPENDLG_COLORSCALE SfxVoidItem DataBarFormatDialog SID_OPENDLG_DATABAR -() +(SfxInt16Item IconSet FN_PARAM_1) [ AutoUpdate = FALSE, FastCall = FALSE, diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index b35796ff0c2e..1b307963dc01 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2186,27 +2186,154 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) // do we have a parameter with the conditional formatting type? const SfxInt16Item* pParam = rReq.GetArg<SfxInt16Item>(FN_PARAM_1); - if (pParam && nSlot == SID_OPENDLG_ICONSET) + if (pParam) { auto pFormat = std::make_unique<ScConditionalFormat>(0, &rDoc); pFormat->SetRange(aRangeList); - ScIconSetType eIconSetType = limit_cast<ScIconSetType>(pParam->GetValue(), IconSet_3Arrows, IconSet_5Boxes); - const int nSteps = ScIconSetFormat::getIconSetElements(eIconSetType); + if (nSlot == SID_OPENDLG_ICONSET) + { + ScIconSetType eIconSetType = limit_cast<ScIconSetType>(pParam->GetValue(), IconSet_3Arrows, IconSet_5Boxes); + const int nSteps = ScIconSetFormat::getIconSetElements(eIconSetType); + + ScIconSetFormat* pEntry = new ScIconSetFormat(&rDoc); + ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData(eIconSetType); + + pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(0, COL_RED, COLORSCALE_PERCENT)); + pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(100. / nSteps), COL_BROWN, COLORSCALE_PERCENT)); + pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(200. / nSteps), COL_YELLOW, COLORSCALE_PERCENT)); + if (nSteps > 3) + pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(300. / nSteps), COL_WHITE, COLORSCALE_PERCENT)); + if (nSteps > 4) + pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(400. / nSteps), COL_GREEN, COLORSCALE_PERCENT)); + + pEntry->SetIconSetData(pIconSetFormatData); + pFormat->AddEntry(pEntry); + } + else if (nSlot == SID_OPENDLG_COLORSCALE) + { + typedef std::tuple<double, Color, ScColorScaleEntryType> ScaleEntry; + static std::vector<std::vector<ScaleEntry>> aScaleThemes = + { + { + { 0, Color(0xF8696B), COLORSCALE_MIN }, + { 0, Color(0x63BE7B), COLORSCALE_MAX }, + { 50, Color(0xFFEB84), COLORSCALE_PERCENTILE } + }, + { + { 0, Color(0x63BE7B), COLORSCALE_MIN }, + { 0, Color(0xF8696B), COLORSCALE_MAX }, + { 50, Color(0xFFEB84), COLORSCALE_PERCENTILE } + }, + { + { 0, Color(0xF8696B), COLORSCALE_MIN }, + { 0, Color(0x63BE7B), COLORSCALE_MAX }, + { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE } + }, + { + { 0, Color(0x63BE7B), COLORSCALE_MIN }, + { 0, Color(0xF8696B), COLORSCALE_MAX }, + { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE } + }, + { + { 0, Color(0xF8696B), COLORSCALE_MIN }, + { 0, Color(0x5A8AC6), COLORSCALE_MAX }, + { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE } + }, + { + { 0, Color(0x5A8AC6), COLORSCALE_MIN }, + { 0, Color(0xF8696B), COLORSCALE_MAX }, + { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE } + }, + { + { 0, Color(0xF8696B), COLORSCALE_MIN }, + { 0, Color(0xFCFCFF), COLORSCALE_MAX } + }, + { + { 0, Color(0xFCFCFF), COLORSCALE_MIN }, + { 0, Color(0xF8696B), COLORSCALE_MAX } + }, + { + { 0, Color(0x63BE7B), COLORSCALE_MIN }, + { 0, Color(0xFCFCFF), COLORSCALE_MAX } + }, + { + { 0, Color(0xFCFCFF), COLORSCALE_MIN }, + { 0, Color(0x63BE7B), COLORSCALE_MAX } + }, + { + { 0, Color(0x63BE7B), COLORSCALE_MIN }, + { 0, Color(0xFFEF9C), COLORSCALE_MAX } + }, + { + { 0, Color(0xFFEF9C), COLORSCALE_MIN }, + { 0, Color(0x63BE7B), COLORSCALE_MAX } + } + }; + + sal_uInt16 nTheme = pParam->GetValue(); + if (nTheme < aScaleThemes.size()) + { + ScColorScaleFormat* pFormatEntry = new ScColorScaleFormat(&rDoc); + + auto& aTheme = aScaleThemes[nTheme]; + + ScColorScaleEntry* pMin = new ScColorScaleEntry(std::get<0>(aTheme[0]), std::get<1>(aTheme[0]), std::get<2>(aTheme[0])); + ScColorScaleEntry* pMax = new ScColorScaleEntry(std::get<0>(aTheme[1]), std::get<1>(aTheme[1]), std::get<2>(aTheme[1])); + + pFormatEntry->AddEntry(pMin); + + // COLORSCALE_PERCENTILE has to be in the middle + if (aTheme.size() > 2) + { + ScColorScaleEntry* pPer = new ScColorScaleEntry(std::get<0>(aTheme[2]), std::get<1>(aTheme[2]), std::get<2>(aTheme[2])); + pFormatEntry->AddEntry(pPer); + } + + pFormatEntry->AddEntry(pMax); + + pFormat->AddEntry(pFormatEntry); + } - ScIconSetFormat* pEntry = new ScIconSetFormat(&rDoc); - ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData(eIconSetType); + } + else if (nSlot == SID_OPENDLG_DATABAR) + { + typedef std::tuple<Color, bool> DatabarEntry; + static std::vector<DatabarEntry> aDatabarThemes = + { + { Color(0x638EC6), true }, + { Color(0x63C384), true }, + { Color(0xFF555A), true }, + { Color(0xFFB628), true }, + { Color(0x008AEF), true }, + { Color(0xD6007B), true }, + { Color(0x638EC6), false }, + { Color(0x63C384), false }, + { Color(0xFF555A), false }, + { Color(0xFFB628), false }, + { Color(0x008AEF), false }, + { Color(0xD6007B), false } + }; + + sal_uInt16 nTheme = pParam->GetValue(); + if (nTheme < aDatabarThemes.size()) + { + ScDataBarFormat* pFormatEntry = new ScDataBarFormat(&rDoc); - pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(0, COL_RED, COLORSCALE_PERCENT)); - pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(100. / nSteps), COL_BROWN, COLORSCALE_PERCENT)); - pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(200. / nSteps), COL_YELLOW, COLORSCALE_PERCENT)); - if (nSteps > 3) - pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(300. / nSteps), COL_WHITE, COLORSCALE_PERCENT)); - if (nSteps > 4) - pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(400. / nSteps), COL_GREEN, COLORSCALE_PERCENT)); + auto& aTheme = aDatabarThemes[nTheme]; - pEntry->SetIconSetData(pIconSetFormatData); - pFormat->AddEntry(pEntry); + ScDataBarFormatData* pData = new ScDataBarFormatData(); + pData->maPositiveColor = std::get<0>(aTheme); + pData->mbGradient = std::get<1>(aTheme); + pData->mxNegativeColor = Color(0xFF0000); + pData->mpLowerLimit.reset(new ScColorScaleEntry(0, 0, COLORSCALE_AUTO)); + pData->mpUpperLimit.reset(new ScColorScaleEntry(0, 0, COLORSCALE_AUTO)); + + pFormatEntry->SetDataBarData(pData); + + pFormat->AddEntry(pFormatEntry); + } + } // use the new conditional formatting GetViewData().GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nIndex, std::move(pFormat), aPos.Tab(), aRangeList); |