LibreOffice Module svx (master) 1
LineWidthValueSet.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "LineWidthValueSet.hxx"
20
22#include <vcl/event.hxx>
23#include <vcl/settings.hxx>
24#include <vcl/svapp.hxx>
25
26namespace svx::sidebar {
27
29 : ValueSet(nullptr)
30 , nSelItem(0)
31 , bCusEnable(false)
32{
33}
34
36{
38 SetLineCount(9);
40}
41
43{
44}
45
46void LineWidthValueSet::SetUnit(std::array<OUString,9> const & strUnits)
47{
48 maStrUnits = strUnits;
49}
50
51void LineWidthValueSet::SetSelItem(sal_uInt16 nSel)
52{
53 nSelItem = nSel;
54 if(nSel == 0)
55 {
56 SelectItem(1); // ,false); // 'false' nut supported by AOO
58 }
59 else
60 {
62 GrabFocus();
63 }
64}
65
67{
68 imgCus = img;
69}
70
72{
73 bCusEnable = bEnable;
74}
75
77{
78 tools::Rectangle aRect = rUDEvt.GetRect();
79 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
80 sal_uInt16 nItemId = rUDEvt.GetItemId();
81
82 tools::Long nRectHeight = aRect.GetHeight();
83 tools::Long nRectWidth = aRect.GetWidth();
84 Point aBLPos = aRect.TopLeft();
85
86 //const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
87 //Color aBackColor(0,0,200);
88 //const Color aTextColor = rStyleSettings.GetFieldTextColor();
89 vcl::Font aOldFont = pDev->GetFont();
90 Color aOldColor = pDev->GetLineColor();
91 Color aOldFillColor = pDev->GetFillColor();
92
93 vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getConfiguredSystemLanguage(), GetDefaultFontFlags::OnlyOne));
94 Size aSize = aFont.GetFontSize();
95 aSize.setHeight( nRectHeight*3/5 );
96 aFont.SetFontSize( aSize );
97
98 Point aLineStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - nItemId )/2);
99 Point aLineEnd(aBLPos.X() + nRectWidth * 7 / 9 - 10, aBLPos.Y() + ( nRectHeight - nItemId )/2);
100 if (nItemId == 9)
101 {
102 Point aImgStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - 23 ) / 2);
103 pDev->DrawImage(aImgStart, imgCus);
104
105 tools::Rectangle aStrRect = aRect;
106 aStrRect.AdjustTop(nRectHeight/6 );
107 aStrRect.AdjustBottom( -(nRectHeight/6) );
108 aStrRect.AdjustLeft(imgCus.GetSizePixel().Width() + 20 );
109 if(bCusEnable)
110 aFont.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
111 else
112 aFont.SetColor(Application::GetSettings().GetStyleSettings().GetDisableColor());
113
114 pDev->SetFont(aFont);
115 pDev->DrawText(aStrRect, maStrUnits[ nItemId - 1 ], DrawTextFlags::EndEllipsis);
116 }
117 else
118 {
119 if( nSelItem == nItemId )
120 {
121 tools::Rectangle aBackRect = aRect;
122 aBackRect.AdjustTop(3 );
123 aBackRect.AdjustBottom( -2 );
124 pDev->SetFillColor(Color(50,107,197));
125 pDev->DrawRect(aBackRect);
126 }
127 else
128 {
130 pDev->DrawRect(aRect);
131 }
132
133 //draw text
134 if(nSelItem == nItemId )
135 aFont.SetColor(COL_WHITE);
136 else
137 aFont.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
138 pDev->SetFont(aFont);
139 Point aStart(aBLPos.X() + nRectWidth * 7 / 9 , aBLPos.Y() + nRectHeight/6);
140 pDev->DrawText(aStart, maStrUnits[ nItemId - 1 ]); //can't set DrawTextFlags::EndEllipsis here ,or the text will disappear
141
142 //draw line
143 if( nSelItem == nItemId )
144 pDev->SetLineColor(COL_WHITE);
145 else
146 pDev->SetLineColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
147
148 for(sal_uInt16 i = 1; i <= nItemId; i++)
149 {
150 pDev->DrawLine(aLineStart,aLineEnd );
151 aLineStart.setY(aLineStart.getY() + 1);
152 aLineEnd.setY (aLineEnd.getY() + 1);
153 }
154 }
155
156 Invalidate( aRect );
157 pDev->SetLineColor(aOldColor);
158 pDev->SetFillColor(aOldFillColor);
159 pDev->SetFont(aOldFont);
160}
161
163{
164 ValueSet::SetDrawingArea(pDrawingArea);
165 Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(80, 12 * 9), MapMode(MapUnit::MapAppFont)));
166 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
167 SetOutputSizePixel(aSize);
168}
169
170} // end of namespace svx::sidebar
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const AllSettings & GetSettings()
Size GetSizePixel() const
static LanguageType getConfiguredSystemLanguage()
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void SetLineColor()
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
void SetFillColor()
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const Color & GetLineColor() const
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const Color & GetFillColor() const
constexpr tools::Long Y() const
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long getY() const
constexpr tools::Long Height() const
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
sal_uInt16 GetItemId() const
void SelectItem(sal_uInt16 nItemId)
void SetLineCount(sal_uInt16 nNewLines=0)
void SetColCount(sal_uInt16 nNewCols=1)
virtual void Resize() override
void SetNoSelection()
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
std::array< OUString, 9 > maStrUnits
virtual void UserDraw(const UserDrawEvent &rUDEvt) override
void SetUnit(std::array< OUString, 9 > const &strUnits)
virtual void Resize() override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
constexpr tools::Long GetWidth() const
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
constexpr tools::Long GetHeight() const
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
void SetFontSize(const Size &)
void SetColor(const Color &)
const Size & GetFontSize() const
virtual OutputDevice & get_ref_device()=0
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
int i
long Long