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 
54 class SymbolPreviewGraphicsItem final : public QGraphicsItem,
55  public AttributeProvider {
56 public:
57  // Constructors / Destructor
59  const IF_GraphicsLayerProvider& layerProvider,
60  const QStringList& localeOrder, const Symbol& symbol,
61  const Component* cmp = nullptr,
62  const tl::optional<Uuid>& symbVarUuid = tl::nullopt,
63  const tl::optional<Uuid>& symbVarItemUuid = tl::nullopt) noexcept;
64  ~SymbolPreviewGraphicsItem() noexcept;
65 
66  // Setters
67  void setDrawBoundingRect(bool enable) noexcept;
68 
69  // General Methods
70  void updateCacheAndRepaint() noexcept;
71 
72  // Inherited from QGraphicsItem
73  QRectF boundingRect() const noexcept override { return mBoundingRect; }
74  QPainterPath shape() const noexcept override { return mShape; }
75  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
76  QWidget* widget = 0) noexcept override;
77 
78 signals:
79 
81  void attributesChanged() override {}
82 
83 private:
84  // make some methods inaccessible...
85  SymbolPreviewGraphicsItem() = delete;
88  delete;
89 
90  // Inherited from AttributeProvider
92  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
93 
94  // Types
95 
97  QString text;
98  qreal fontSize;
99  bool rotate180;
100  Qt::Alignment align;
101  QRectF textRect;
102  };
103 
104  // General Attributes
106  const Symbol& mSymbol;
109  QFont mFont;
111  QStringList mLocaleOrder;
112 
113  // Cached Attributes
115  QPainterPath mShape;
116  QHash<const Text*, CachedTextProperties_t> mCachedTextProperties;
117 };
118 
119 /*******************************************************************************
120  * End of File
121  ******************************************************************************/
122 
123 } // namespace library
124 } // namespace librepcb
125 
126 #endif // LIBREPCB_LIBRARY_SYMBOLPREVIEWGRAPHICSITEM_H
void updateCacheAndRepaint() noexcept
Definition: symbolpreviewgraphicsitem.cpp:117
QStringList mLocaleOrder
Definition: symbolpreviewgraphicsitem.h:111
QRectF textRect
Definition: symbolpreviewgraphicsitem.h:101
The SymbolPreviewGraphicsItem class.
Definition: symbolpreviewgraphicsitem.h:54
qreal fontSize
Definition: symbolpreviewgraphicsitem.h:98
bool mDrawBoundingRect
Definition: symbolpreviewgraphicsitem.h:110
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: symbolpreviewgraphicsitem.cpp:218
QPainterPath shape() const noexceptoverride
Definition: symbolpreviewgraphicsitem.h:74
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
QFont mFont
Definition: symbolpreviewgraphicsitem.h:109
QPainterPath mShape
Definition: symbolpreviewgraphicsitem.h:115
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:81
Qt::Alignment align
Definition: symbolpreviewgraphicsitem.h:100
const Component * mComponent
Definition: symbolpreviewgraphicsitem.h:107
QRectF boundingRect() const noexceptoverride
Definition: symbolpreviewgraphicsitem.h:73
const ComponentSymbolVariantItem * mSymbVarItem
Definition: symbolpreviewgraphicsitem.h:108
const Symbol & mSymbol
Definition: symbolpreviewgraphicsitem.h:106
QRectF mBoundingRect
Definition: symbolpreviewgraphicsitem.h:114
bool rotate180
Definition: symbolpreviewgraphicsitem.h:99
QString text
Definition: symbolpreviewgraphicsitem.h:97
~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:105
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:58
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:116
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59