BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SampleDesigner/ParticleView.cpp
6 //! @brief Implements class ParticleView
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
22 #include <QObject>
23 #include <QPainter>
24 #include <QStyleOptionGraphicsItem>
25 
26 ParticleView::ParticleView(QGraphicsItem* parent) : ConnectableView(parent)
27 {
28  setName("Particle");
32  ->setToolTip("Connect to the ParticleLayout");
34  ->setToolTip("Connect particle rotation to this port, if necessary");
35  m_label_vspace = StyleUtils::SizeOfLetterM().height() * 3.0;
36 }
37 
38 void ParticleView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
39 {
40  Q_UNUSED(widget);
41  painter->setRenderHint(QPainter::SmoothPixmapTransform);
42  painter->setRenderHint(QPainter::Antialiasing);
43 
44  painter->setPen(Qt::gray);
45  if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) {
46  painter->setPen(Qt::DashLine);
47  }
48 
50  painter->drawRoundedRect(getRectangle(), m_roundpar, m_roundpar);
51 
52  if (m_label.isEmpty())
53  return;
54 
55  painter->setPen(Qt::black);
56  double width = getRectangle().width() * 0.9;
57  double yoffset = 5; // space above the label
58  // double height = m_label_vspace - yoffset;
59  double height = 20;
60  QFont serifFont("Monospace", DesignerHelper::getLabelFontSize(), QFont::Normal);
61  painter->setFont(serifFont);
62  QRectF textRect(getRectangle().x() + (getRectangle().width() - width) / 2.,
63  getRectangle().y() + yoffset, width, height);
64  painter->drawText(textRect, Qt::AlignCenter, m_label);
65 
66  QRectF target(getRectangle().width() / 2 - 16, 25, 32, 32);
67  painter->drawPixmap(target, m_pixmap, QRectF(0.0, 0.0, m_pixmap.width(), m_pixmap.height()));
68  // painter->drawImage(target, m_pixmap);
69 }
70 
71 void ParticleView::onPropertyChange(const QString& propertyName)
72 {
73  if (propertyName == ParticleItem::P_FORM_FACTOR)
75 
76  IView::onPropertyChange(propertyName);
77 }
78 
79 void ParticleView::addView(IView* childView, int /*row*/)
80 {
81  if (childView->type() == ViewTypes::TRANSFORMATION) {
82  connectInputPort(dynamic_cast<ConnectableView*>(childView), 0);
83  } else {
84  throw GUIHelpers::Error("ParticleView::addView() -> Error. Unknown view");
85  }
86 }
87 
89 {
90  updatePixmap();
91  updateToolTip();
93 }
94 
96 {
97  if (!getItem())
98  return;
99 
100  QString ff_type = getItem()->item<GroupItem>(ParticleItem::P_FORM_FACTOR)->currentType();
101  QString filename = QString(":/widgetbox/images/ff_%1_64x64.png").arg(ff_type);
102  m_pixmap = QPixmap(filename);
103 }
104 
106 {
107  if (!getItem())
108  return;
109 
110  auto ffItem = getItem()->item<GroupItem>(ParticleItem::P_FORM_FACTOR)->currentItem();
111  setToolTip(ffItem->toolTip());
112 }
Defines class DesignerHelper.
Defines FormFactorItems classes.
Defines class GUIHelpers functions.
Defines class GroupItem.
Defines class ParticleItem.
Defines class ParticleView.
DefinesStyleUtils namespace.
view of ISampleNode's with rectangular shape and node functionality
void connectInputPort(ConnectableView *other, int port_number)
connects input port with given index with output port of other view
virtual void update_appearance()
updates visual appearance of the item (color, icons, size etc)
virtual void setColor(const QColor &color)
virtual void setRectangle(QRectF rect)
virtual QRectF getRectangle() const
virtual NodeEditorPort * addPort(const QString &name, NodeEditorPort::EPortDirection direction, NodeEditorPort::EPortType port_type)
adds port to view
virtual void setName(const QString &name)
static QRectF getParticleBoundingRect()
static QGradient getDecorationGradient(const QColor &color, const QRectF &rect)
static QColor getDefaultParticleColor()
static int getLabelFontSize()
parent class for graphic representation of all ISampleNode's
Definition: IView.h:25
virtual SessionItem * getItem()
Definition: IView.h:59
virtual void onPropertyChange(const QString &propertyName)
Definition: IView.cpp:75
int type() const
Definition: IView.h:54
static const QString P_FORM_FACTOR
Definition: ParticleItem.h:25
void addView(IView *childView, int row=0)
void updateToolTip()
void updatePixmap()
ParticleView(QGraphicsItem *parent=0)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void update_appearance()
updates visual appearance of the item (color, icons, size etc)
QPixmap m_pixmap
Definition: ParticleView.h:43
void onPropertyChange(const QString &propertyName)
T * item(const QString &tag) const
Definition: SessionItem.h:151
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:110
@ TRANSFORMATION
Definition: ViewTypes.h:40