QElectroTech  0.70
templatevisualcell.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "templatevisualcell.h"
19 #include "titleblocktemplate.h"
20 #include "diagramcontext.h"
21 
27  QGraphicsLayoutItem(),
28  QGraphicsItem(parent),
29  template_(nullptr),
30  cell_(nullptr)
31 {
32  setGraphicsItem(this);
33  setFlag(QGraphicsItem::ItemIsSelectable, true);
34 
35 }
36 
41 }
42 
49  prepareGeometryChange();
50  QGraphicsLayoutItem::setGeometry(g);
51  setPos(g.topLeft());
52 }
53 
59 QSizeF TitleBlockTemplateVisualCell::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const {
60  Q_UNUSED(which);
61  return constraint;
62 }
63 
68  return QRectF(QPointF(0,0), geometry().size());
69 }
70 
77 void TitleBlockTemplateVisualCell::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
78  Q_UNUSED(option);
79  Q_UNUSED(widget);
80 
81  QRectF drawing_rectangle(QPointF(0, 0), geometry().size() /*- QSizeF(1, 1)*/);
82 
83  if (template_ && cell_) {
84  template_ -> renderCell(*painter, *cell_, DiagramContext(), drawing_rectangle.toRect());
85  }
86  if (isSelected()) {
87  QBrush selection_brush = QApplication::palette().highlight();
88  QColor selection_color = selection_brush.color();
89  selection_color.setAlpha(127);
90  selection_brush.setColor(selection_color);
91  painter -> setPen(Qt::NoPen);
92  painter -> setBrush(selection_brush);
93  painter -> drawRect(drawing_rectangle/*.adjusted(1, 1, -1, -1)*/);
94  }
95 }
96 
103  template_ = tbt;
104  cell_ = cell;
105 }
106 
111  return(template_);
112 }
113 
118  return(cell_);
119 }
120 
125 QSet<TitleBlockCell *> TitleBlockTemplateVisualCell::cells() const {
126  QSet<TitleBlockCell *> set;
127  if (cell_) {
128  if (template_) {
129  set = template_ -> spannedCells(cell_);
130  }
131 
132  // the TitleBlockCell rendered by this object
133  set << cell_;
134  }
135  return(set);
136 }
QSizeF sizeHint(Qt::SizeHint, const QSizeF &=QSizeF()) const override
void setTemplateCell(TitleBlockTemplate *, TitleBlockCell *)
TitleBlockTemplate * titleBlockTemplate() const
TitleBlockCell * cell_
Previewed cell.
QSet< TitleBlockCell * > cells() const
QRectF boundingRect() const override
void setGeometry(const QRectF &) override
TitleBlockTemplate * template_
Title block template of the previewed cell.
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
TitleBlockCell * cell() const
TitleBlockTemplateVisualCell(QGraphicsItem *parent=nullptr)