Seamly2D
Code documentation
nonscalingfill_pathitem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file nonscalingfill_pathitem.cpp
3  ** @author Douglas S Caskey
4  ** @date Jan 29, 2023
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2023 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. if not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file vnobrushscalepathitem.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 10 1, 2016
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2016 Valentina project
36  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
54 
55 #include <QBrush>
56 #include <QMatrix>
57 #include <QPainter>
58 
59 //---------------------------------------------------------------------------------------------------------------------
61  : QGraphicsPathItem(parent)
62 {
63 }
64 
65 //---------------------------------------------------------------------------------------------------------------------
66 void NonScalingFillPathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
67 {
68  /*
69  * How to avoid transformation of QBrush fill
70  * http://www.qtforum.org/article/23942/how-to-avoid-transformation-of-qbrush-texture.html
71  * ?s=b4ba78dd6758da78fe395d8f6bb7512511a0833e#post84983
72  *
73  * Non Scaling QBrush fill style for qgraphicspathitem
74  * http://www.qtcentre.org/archive/index.php/t-13950.html
75  *
76  * You'll have to scale the brush down. The QStyleOptionGraphicsItem option passed in paint() will give you the
77  * transform being used, and you can set a transform on a QBrush. Put the two together and you can scale the brush
78  * inversely of the item.
79  */
80  QBrush brush = this->brush();
81  brush.setTransform(painter->combinedTransform().inverted());
82  this->setBrush(brush);
83  QGraphicsPathItem::paint(painter, option, widget);
84 }
NonScalingFillPathItem(QGraphicsItem *parent=nullptr)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) Q_DECL_OVERRIDE