tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / miscdlgs / tabbgcolordlg.cxx
blobf319c1d8b005a24f52b6442b6e7e32d2e677b3ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <tabbgcolordlg.hxx>
24 #include <tools/color.hxx>
25 #include <vcl/event.hxx>
27 #include <officecfg/Office/Common.hxx>
29 ScTabBgColorDlg::ScTabBgColorDlg(weld::Window* pParent, const OUString& rTitle,
30 const OUString& rTabBgColorNoColorText, const Color& rDefaultColor)
31 : GenericDialogController(pParent, u"modules/scalc/ui/tabcolordialog.ui"_ustr, u"TabColorDialog"_ustr)
32 , m_aTabBgColor(rDefaultColor)
33 , m_xSelectPalette(m_xBuilder->weld_combo_box(u"paletteselector"_ustr))
34 , m_xTabBgColorSet(new ScTabBgColorValueSet(m_xBuilder->weld_scrolled_window(u"colorsetwin"_ustr, true)))
35 , m_xTabBgColorSetWin(new weld::CustomWeld(*m_xBuilder, u"colorset"_ustr, *m_xTabBgColorSet))
36 , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr))
38 m_xTabBgColorSet->SetDialog(this);
39 m_xTabBgColorSet->SetColCount(SvxColorValueSet::getColumnCount());
41 m_xDialog->set_title(rTitle);
43 const WinBits nBits(m_xTabBgColorSet->GetStyle() | WB_NAMEFIELD | WB_ITEMBORDER | WB_NONEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT);
44 m_xTabBgColorSet->SetStyle(nBits);
45 m_xTabBgColorSet->SetText(rTabBgColorNoColorText);
47 const sal_uInt32 nColCount = SvxColorValueSet::getColumnCount();
48 const sal_uInt32 nRowCount(10);
49 const sal_uInt32 nLength = SvxColorValueSet::getEntryEdgeLength();
50 Size aSize(m_xTabBgColorSet->CalcWindowSizePixel(Size(nLength, nLength), nColCount, nRowCount));
51 m_xTabBgColorSetWin->set_size_request(aSize.Width() + 8, aSize.Height() + 8);
53 FillPaletteLB();
55 m_xSelectPalette->connect_changed(LINK(this, ScTabBgColorDlg, SelectPaletteLBHdl));
56 m_xTabBgColorSet->SetDoubleClickHdl(LINK(this, ScTabBgColorDlg, TabBgColorDblClickHdl_Impl));
57 m_xBtnOk->connect_clicked(LINK(this, ScTabBgColorDlg, TabBgColorOKHdl_Impl));
60 ScTabBgColorDlg::~ScTabBgColorDlg()
64 void ScTabBgColorDlg::GetSelectedColor( Color& rColor ) const
66 rColor = m_aTabBgColor;
69 void ScTabBgColorDlg::FillPaletteLB()
71 m_xSelectPalette->clear();
72 std::vector<OUString> aPaletteList = m_aPaletteManager.GetPaletteList();
73 for (auto const& palette : aPaletteList)
75 m_xSelectPalette->append_text(palette);
77 OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
78 m_xSelectPalette->set_active_text(aPaletteName);
79 if (m_xSelectPalette->get_active() != -1)
81 SelectPaletteLBHdl(*m_xSelectPalette);
85 IMPL_LINK_NOARG(ScTabBgColorDlg, SelectPaletteLBHdl, weld::ComboBox&, void)
87 m_xTabBgColorSet->Clear();
88 sal_Int32 nPos = m_xSelectPalette->get_active();
89 m_aPaletteManager.SetPalette( nPos );
90 m_aPaletteManager.ReloadColorSet(*m_xTabBgColorSet);
91 m_xTabBgColorSet->Resize();
92 m_xTabBgColorSet->SelectItem(0);
95 // Handler, called when color selection is changed
96 IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorDblClickHdl_Impl, ValueSet*, void)
98 sal_uInt16 nItemId = m_xTabBgColorSet->GetSelectedItemId();
99 Color aColor = nItemId ? ( m_xTabBgColorSet->GetItemColor( nItemId ) ) : COL_AUTO;
100 m_aTabBgColor = aColor;
101 m_xDialog->response(RET_OK);
104 // Handler, called when the OK button is pushed
105 IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorOKHdl_Impl, weld::Button&, void)
107 sal_uInt16 nItemId = m_xTabBgColorSet->GetSelectedItemId();
108 Color aColor = nItemId ? ( m_xTabBgColorSet->GetItemColor( nItemId ) ) : COL_AUTO;
109 m_aTabBgColor = aColor;
110 m_xDialog->response(RET_OK);
113 ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet(std::unique_ptr<weld::ScrolledWindow> pWindow)
114 : SvxColorValueSet(std::move(pWindow))
115 , m_pTabBgColorDlg(nullptr)
119 ScTabBgColorDlg::ScTabBgColorValueSet::~ScTabBgColorValueSet()
123 bool ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent& rKEvt )
125 switch ( rKEvt.GetKeyCode().GetCode() )
127 case KEY_SPACE:
128 case KEY_RETURN:
130 sal_uInt16 nItemId = GetSelectedItemId();
131 const Color aColor = nItemId ? ( GetItemColor( nItemId ) ) : COL_AUTO;
132 m_pTabBgColorDlg->m_aTabBgColor = aColor;
133 m_pTabBgColorDlg->response(RET_OK);
134 return true;
136 break;
138 return SvxColorValueSet::KeyInput(rKEvt);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */