LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
symbolpreviewgraphicsitem.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_LIBRARY_SYMBOLPREVIEWGRAPHICSITEM_H
21 #define LIBREPCB_LIBRARY_SYMBOLPREVIEWGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 #include <librepcb/common/uuid.h>
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 class Text;
38 class GraphicsLayer;
39 class IF_GraphicsLayerProvider;
40 
41 namespace library {
42 
43 class Symbol;
44 class Component;
45 class ComponentSymbolVariantItem;
46 
47 /*******************************************************************************
48  * Class SymbolPreviewGraphicsItem
49  ******************************************************************************/
50 
57 class SymbolPreviewGraphicsItem final : public QGraphicsItem,
58  public AttributeProvider {
59 public:
60  // Constructors / Destructor
62  const IF_GraphicsLayerProvider& layerProvider,
63  const QStringList& localeOrder, const Symbol& symbol,
64  const Component* cmp = nullptr,
65  const tl::optional<Uuid>& symbVarUuid = tl::nullopt,
66  const tl::optional<Uuid>& symbVarItemUuid = tl::nullopt) noexcept;
67  ~SymbolPreviewGraphicsItem() noexcept;
68 
69  // Setters
70  void setDrawBoundingRect(bool enable) noexcept;
71 
72  // General Methods
73  void updateCacheAndRepaint() noexcept;
74 
75  // Inherited from QGraphicsItem
76  QRectF boundingRect() const noexcept override { return mBoundingRect; }
77  QPainterPath shape() const noexcept override { return mShape; }
78  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
79  QWidget* widget = 0) noexcept override;
80 
81 signals:
82 
84  void attributesChanged() override {}
85 
86 private:
87  // make some methods inaccessible...
88  SymbolPreviewGraphicsItem() = delete;
91  delete;
92 
93  // Inherited from AttributeProvider
95  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
96 
97  // Types
98 
100  QString text;
101  qreal fontSize;
102  bool rotate180;
103  Qt::Alignment align;
104  QRectF textRect;
105  };
106 
107  // General Attributes
109  const Symbol& mSymbol;
112  QFont mFont;
114  QStringList mLocaleOrder;
115 
116  // Cached Attributes
118  QPainterPath mShape;
119  QHash<const Text*, CachedTextProperties_t> mCachedTextProperties;
120 };
121 
122 /*******************************************************************************
123  * End of File
124  ******************************************************************************/
125 
126 } // namespace library
127 } // namespace librepcb
128 
129 #endif // LIBREPCB_LIBRARY_SYMBOLPREVIEWGRAPHICSITEM_H
void updateCacheAndRepaint() noexcept
Definition: symbolpreviewgraphicsitem.cpp:117
QStringList mLocaleOrder
Definition: symbolpreviewgraphicsitem.h:114
QRectF textRect
Definition: symbolpreviewgraphicsitem.h:104
The SymbolPreviewGraphicsItem class.
Definition: symbolpreviewgraphicsitem.h:57
qreal fontSize
Definition: symbolpreviewgraphicsitem.h:101
bool mDrawBoundingRect
Definition: symbolpreviewgraphicsitem.h:113
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: symbolpreviewgraphicsitem.cpp:218
QPainterPath shape() const noexceptoverride
Definition: symbolpreviewgraphicsitem.h:77
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
QFont mFont
Definition: symbolpreviewgraphicsitem.h:112
QPainterPath mShape
Definition: symbolpreviewgraphicsitem.h:118
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:57
void attributesChanged() override
This signal is emited when the value of attributes has changed.
Definition: symbolpreviewgraphicsitem.h:84
Qt::Alignment align
Definition: symbolpreviewgraphicsitem.h:103
const Component * mComponent
Definition: symbolpreviewgraphicsitem.h:110
QRectF boundingRect() const noexceptoverride
Definition: symbolpreviewgraphicsitem.h:76
const ComponentSymbolVariantItem * mSymbVarItem
Definition: symbolpreviewgraphicsitem.h:111
const Symbol & mSymbol
Definition: symbolpreviewgraphicsitem.h:109
QRectF mBoundingRect
Definition: symbolpreviewgraphicsitem.h:117
bool rotate180
Definition: symbolpreviewgraphicsitem.h:102
QString text
Definition: symbolpreviewgraphicsitem.h:100
~SymbolPreviewGraphicsItem() noexcept
Definition: symbolpreviewgraphicsitem.cpp:97
SymbolPreviewGraphicsItem & operator=(const SymbolPreviewGraphicsItem &rhs)=delete
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: symbolpreviewgraphicsitem.cpp:342
const IF_GraphicsLayerProvider & mLayerProvider
Definition: symbolpreviewgraphicsitem.h:108
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:61
void setDrawBoundingRect(bool enable) noexcept
Definition: symbolpreviewgraphicsitem.cpp:104
The Component class represents a "generic" device in the library.
Definition: component.h:73
QHash< const Text *, CachedTextProperties_t > mCachedTextProperties
Definition: symbolpreviewgraphicsitem.h:119
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:62