LibreOffice Module vcl (master)  1
Qt5Graphics_Controls.hxx
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 
20 #pragma once
21 
22 #include <vclpluginapi.h>
23 #include <WidgetDrawInterface.hxx>
24 
25 #include <memory>
26 
27 #include <QtGui/QImage>
28 #include <QtGui/QPainter>
29 #include <QtGui/QRegion>
30 #include <QtWidgets/QPushButton>
31 #include <QtWidgets/QStyle>
32 #include <QtWidgets/QStyleOption>
33 
34 class Qt5GraphicsBase;
35 
37 {
38  std::unique_ptr<QImage> m_image;
41 
42 public:
43  Qt5Graphics_Controls(const Qt5GraphicsBase& rGraphics);
44 
45  QImage* getImage() { return m_image.get(); }
46 
47  bool isNativeControlSupported(ControlType nType, ControlPart nPart) override;
49  const tools::Rectangle& rControlRegion, const Point& aPos,
50  bool& rIsInside) override;
51  bool drawNativeControl(ControlType nType, ControlPart nPart,
52  const tools::Rectangle& rControlRegion, ControlState nState,
53  const ImplControlValue& aValue, const OUString& aCaption) override;
55  const tools::Rectangle& rControlRegion, ControlState nState,
56  const ImplControlValue& aValue, const OUString& aCaption,
57  tools::Rectangle& rNativeBoundingRegion,
58  tools::Rectangle& rNativeContentRegion) override;
59 
60 private:
61  static int pixelMetric(QStyle::PixelMetric metric, const QStyleOption* option = nullptr);
62  static QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption* option,
63  const QSize& contentsSize);
64  static QRect subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex* option,
65  QStyle::SubControl subControl);
66  static QRect subElementRect(QStyle::SubElement element, const QStyleOption* option);
67 
68  void draw(QStyle::ControlElement element, QStyleOption* option, QImage* image,
69  QStyle::State const state = QStyle::State_None, QRect rect = QRect());
70  void draw(QStyle::PrimitiveElement element, QStyleOption* option, QImage* image,
71  QStyle::State const state = QStyle::State_None, QRect rect = QRect());
72  void draw(QStyle::ComplexControl element, QStyleOptionComplex* option, QImage* image,
73  QStyle::State const state = QStyle::State_None);
74  void drawFrame(QStyle::PrimitiveElement element, QImage* image, QStyle::State const& state,
75  bool bClip = true,
76  QStyle::PixelMetric eLineMetric = QStyle::PM_DefaultFrameWidth);
77 
78  static void fillQStyleOptionTab(const ImplControlValue& value, QStyleOptionTab& sot);
79  void fullQStyleOptionTabWidgetFrame(QStyleOptionTabWidgetFrame& option, bool bDownscale);
80 
81  enum class Round
82  {
83  Floor,
84  Ceil,
85  };
86 
87  int downscale(int value, Round eRound);
88  int upscale(int value, Round eRound);
89  QRect downscale(const QRect& rect);
90  QRect upscale(const QRect& rect);
91  QSize downscale(const QSize& size, Round eRound);
92  QSize upscale(const QSize& size, Round eRound);
93  QPoint upscale(const QPoint& point, Round eRound);
94 };
95 
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void draw(QStyle::ControlElement element, QStyleOption *option, QImage *image, QStyle::State const state=QStyle::State_None, QRect rect=QRect())
int upscale(int value, Round eRound)
JCOPY_OPTION option
Definition: transupp.h:208
static QRect subElementRect(QStyle::SubElement element, const QStyleOption *option)
void fullQStyleOptionTabWidgetFrame(QStyleOptionTabWidgetFrame &option, bool bDownscale)
static QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize)
bool getNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) override
Get the native control regions for the control part.
bool drawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption) override
Draw the requested control.
static void fillQStyleOptionTab(const ImplControlValue &value, QStyleOptionTab &sot)
Qt5GraphicsBase const & m_rGraphics
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
void drawFrame(QStyle::PrimitiveElement element, QImage *image, QStyle::State const &state, bool bClip=true, QStyle::PixelMetric eLineMetric=QStyle::PM_DefaultFrameWidth)
Qt5Graphics_Controls(const Qt5GraphicsBase &rGraphics)
std::unique_ptr< QImage > m_image
bool isNativeControlSupported(ControlType nType, ControlPart nPart) override
Query the platform layer for native control support.
bool hitTestNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, const Point &aPos, bool &rIsInside) override
Query if a position is inside the native widget part.
static QRect subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex *option, QStyle::SubControl subControl)
static int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option=nullptr)
int downscale(int value, Round eRound)