BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Utils::DetailsButton Class Reference
Inheritance diagram for Utils::DetailsButton:
[legend]
Collaboration diagram for Utils::DetailsButton:
[legend]

Public Member Functions

 DetailsButton (QWidget *parent=0)
 
float fader ()
 
void setFader (float value)
 
QSize sizeHint () const
 

Protected Member Functions

bool event (QEvent *e)
 
void paintEvent (QPaintEvent *e)
 

Properties

float fader
 

Private Member Functions

QPixmap cacheRendering (const QSize &size, bool checked)
 

Private Attributes

QPixmap m_checkedPixmap
 
float m_fader
 
QPixmap m_uncheckedPixmap
 

Detailed Description

Definition at line 55 of file detailsbutton.h.

Constructor & Destructor Documentation

◆ DetailsButton()

DetailsButton::DetailsButton ( QWidget *  parent = 0)

Definition at line 75 of file detailsbutton.cpp.

75  : QAbstractButton(parent), m_fader(0)
76 {
77  setCheckable(true);
78  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
79  setText(tr("Details"));
80 }

Member Function Documentation

◆ cacheRendering()

QPixmap DetailsButton::cacheRendering ( const QSize &  size,
bool  checked 
)
private

Definition at line 158 of file detailsbutton.cpp.

159 {
160  const qreal pixelRatio = devicePixelRatio();
161  QPixmap pixmap(size * pixelRatio);
162  pixmap.setDevicePixelRatio(pixelRatio);
163  pixmap.fill(Qt::transparent);
164  QPainter p(&pixmap);
165  p.setRenderHint(QPainter::Antialiasing, true);
166  p.translate(0.5, 0.5);
167 
168  if (!FlatProjectsMode) {
169  QLinearGradient lg;
170  lg.setCoordinateMode(QGradient::ObjectBoundingMode);
171  lg.setFinalStop(0, 1);
172  if (!checked) {
173  lg.setColorAt(0, QColor(0, 0, 0, 10));
174  lg.setColorAt(1, QColor(0, 0, 0, 16));
175  } else {
176  lg.setColorAt(0, QColor(255, 255, 255, 0));
177  lg.setColorAt(1, QColor(255, 255, 255, 50));
178  }
179  p.setBrush(lg);
180  p.setPen(QColor(255, 255, 255, 140));
181  p.drawRoundedRect(1, 1, size.width() - 3, size.height() - 3, 1, 1);
182  p.setPen(QPen(QColor(0, 0, 0, 40)));
183  p.drawLine(0, 1, 0, size.height() - 2);
184  if (checked)
185  p.drawLine(1, size.height() - 1, size.width() - 1, size.height() - 1);
186  } else {
187  p.setPen(Qt::NoPen);
188  p.drawRoundedRect(0, 0, size.width(), size.height(), 1, 1);
189  }
190 
191  p.setPen(palette().color(QPalette::Text));
192 
193  QRect textRect = p.fontMetrics().boundingRect(text());
194  textRect.setWidth(textRect.width() + 15);
195  textRect.setHeight(textRect.height() + 4);
196  textRect.moveCenter(rect().center());
197 
198  p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text());
199 
200  int arrowsize = 15;
201  QStyleOption arrowOpt;
202  arrowOpt.initFrom(this);
203  QPalette pal = arrowOpt.palette;
204  pal.setBrush(QPalette::All, QPalette::Text, QColor(0, 0, 0));
205  arrowOpt.rect =
206  QRect(size.width() - arrowsize - 6, height() / 2 - arrowsize / 2, arrowsize, arrowsize);
207  arrowOpt.palette = pal;
208  style()->drawPrimitive(checked ? QStyle::PE_IndicatorArrowUp : QStyle::PE_IndicatorArrowDown,
209  &arrowOpt, &p, this);
210  return pixmap;
211 }

Referenced by paintEvent().

◆ event()

bool DetailsButton::event ( QEvent *  e)
protected

Definition at line 96 of file detailsbutton.cpp.

97 {
98  switch (e->type()) {
99  case QEvent::Enter: {
100  QPropertyAnimation* animation = new QPropertyAnimation(this, "fader");
101  animation->setDuration(200);
102  animation->setEndValue(1.0);
103  animation->start(QAbstractAnimation::DeleteWhenStopped);
104  } break;
105  case QEvent::Leave: {
106  QPropertyAnimation* animation = new QPropertyAnimation(this, "fader");
107  animation->setDuration(200);
108  animation->setEndValue(0.0);
109  animation->start(QAbstractAnimation::DeleteWhenStopped);
110  } break;
111  default:
112  return QAbstractButton::event(e);
113  }
114  return false;
115 }

◆ fader()

float Utils::DetailsButton::fader ( )
inline

Definition at line 63 of file detailsbutton.h.

63 { return m_fader; }

References m_fader.

◆ paintEvent()

void DetailsButton::paintEvent ( QPaintEvent *  e)
protected

Definition at line 117 of file detailsbutton.cpp.

118 {
119  QWidget::paintEvent(e);
120 
121  QPainter p(this);
122 
123  // draw hover animation
124  if (!GUI_OS_Utils::HostOsInfo::isMacHost() && !isDown() && m_fader > 0) {
125  QColor c = DetailsButtonBackgroundColorHover;
126  c.setAlpha(int(m_fader * c.alpha()));
127 
128  QRect r = rect();
129  if (!FlatProjectsMode)
130  r.adjust(1, 1, -2, -2);
131  p.fillRect(r, c);
132  }
133 
134  if (isChecked()) {
135  if (m_checkedPixmap.isNull()
136  || m_checkedPixmap.size() / m_checkedPixmap.devicePixelRatio() != contentsRect().size())
137  m_checkedPixmap = cacheRendering(contentsRect().size(), true);
138  p.drawPixmap(contentsRect(), m_checkedPixmap);
139  } else {
140  if (m_uncheckedPixmap.isNull()
141  || m_uncheckedPixmap.size() / m_uncheckedPixmap.devicePixelRatio()
142  != contentsRect().size())
143  m_uncheckedPixmap = cacheRendering(contentsRect().size(), false);
144  p.drawPixmap(contentsRect(), m_uncheckedPixmap);
145  }
146  if (isDown()) {
147  p.setPen(Qt::NoPen);
148  p.setBrush(QColor(0, 0, 0, 20));
149  p.drawRoundedRect(rect().adjusted(1, 1, -1, -1), 1, 1);
150  }
151  if (hasFocus()) {
152  QStyleOptionFocusRect option;
153  option.initFrom(this);
154  style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
155  }
156 }
static bool isMacHost()
Definition: hostosinfo.h:69
QPixmap cacheRendering(const QSize &size, bool checked)

References cacheRendering(), GUI_OS_Utils::HostOsInfo::isMacHost(), m_checkedPixmap, m_fader, and m_uncheckedPixmap.

Here is the call graph for this function:

◆ setFader()

void Utils::DetailsButton::setFader ( float  value)
inline

Definition at line 64 of file detailsbutton.h.

65  {
66  m_fader = value;
67  update();
68  }

References m_fader.

◆ sizeHint()

QSize DetailsButton::sizeHint ( ) const

Definition at line 82 of file detailsbutton.cpp.

83 {
84  // TODO: Adjust this when icons become available!
85 
86 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
87  const int w = fontMetrics().horizontalAdvance(text()) + 32;
88 #else
89  const int w = fontMetrics().width(text()) + 32;
90 #endif
92  return QSize(w, 34);
93  return QSize(w, 22);
94 }

References GUI_OS_Utils::HostOsInfo::isMacHost().

Here is the call graph for this function:

Member Data Documentation

◆ m_checkedPixmap

QPixmap Utils::DetailsButton::m_checkedPixmap
private

Definition at line 76 of file detailsbutton.h.

Referenced by paintEvent().

◆ m_fader

float Utils::DetailsButton::m_fader
private

Definition at line 78 of file detailsbutton.h.

Referenced by fader(), paintEvent(), and setFader().

◆ m_uncheckedPixmap

QPixmap Utils::DetailsButton::m_uncheckedPixmap
private

Definition at line 77 of file detailsbutton.h.

Referenced by paintEvent().

Property Documentation

◆ fader

float Utils::DetailsButton::fader
readwrite

Definition at line 52 of file detailsbutton.h.


The documentation for this class was generated from the following files: