ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvExpanderButton.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "cvExpanderButton.h"
9 
10 #include <QIcon>
11 #include <QMouseEvent>
12 
13 //-----------------------------------------------------------------------------
15  : QFrame(parent),
16  m_layout(nullptr),
17  m_iconLabel(nullptr),
18  m_textLabel(nullptr),
19  m_checked(false),
20  m_pressed(false) {
21  // Load icons from resources
22  m_checkedPixmap =
23  QIcon(":/Resources/images/svg/pqMinus.svg").pixmap(QSize(16, 16));
24  m_uncheckedPixmap =
25  QIcon(":/Resources/images/svg/pqPlus.svg").pixmap(QSize(16, 16));
26 
27  setupUi();
28  updateIcon();
29 
30 #if defined(Q_WS_WIN) || defined(Q_OS_WIN)
31  setFrameShadow(QFrame::Sunken);
32 #endif
33 }
34 
35 //-----------------------------------------------------------------------------
37 
38 //-----------------------------------------------------------------------------
39 void cvExpanderButton::setupUi() {
40  // Setup frame properties - ParaView style
41  setFrameShape(QFrame::StyledPanel);
42  setFrameShadow(QFrame::Raised);
43  setLineWidth(1);
44 
45  // Create layout
46  m_layout = new QHBoxLayout(this);
47  m_layout->setContentsMargins(6, 4, 6, 4);
48  m_layout->setSpacing(6);
49 
50  // Icon label
51  m_iconLabel = new QLabel(this);
52  m_iconLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
53  m_layout->addWidget(m_iconLabel, 0);
54 
55  // Text label
56  m_textLabel = new QLabel(this);
57  m_textLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
58  QFont font = m_textLabel->font();
59  font.setBold(true);
60  m_textLabel->setFont(font);
61  m_layout->addWidget(m_textLabel, 1);
62 
63  setLayout(m_layout);
64 
65  // Set cursor to indicate clickable
66  setCursor(Qt::PointingHandCursor);
67 
68  // Set minimum size
70 }
71 
72 //-----------------------------------------------------------------------------
73 void cvExpanderButton::updateIcon() {
74  if (m_iconLabel) {
75  m_iconLabel->setPixmap(m_checked ? m_checkedPixmap : m_uncheckedPixmap);
76  }
77 }
78 
79 //-----------------------------------------------------------------------------
80 void cvExpanderButton::toggle() { setChecked(!m_checked); }
81 
82 //-----------------------------------------------------------------------------
83 void cvExpanderButton::setChecked(bool checked) {
84  if (m_checked == checked) {
85  return;
86  }
87 
88  m_checked = checked;
89  updateIcon();
90  emit toggled(m_checked);
91 }
92 
93 //-----------------------------------------------------------------------------
94 void cvExpanderButton::setText(const QString& text) {
95  if (m_textLabel) {
96  m_textLabel->setText(text);
97  }
98 }
99 
100 //-----------------------------------------------------------------------------
101 QString cvExpanderButton::text() const {
102  return m_textLabel ? m_textLabel->text() : QString();
103 }
104 
105 //-----------------------------------------------------------------------------
106 void cvExpanderButton::mousePressEvent(QMouseEvent* evt) {
107  if (evt->button() == Qt::LeftButton && evt->buttons() == Qt::LeftButton) {
108  m_pressed = true;
109  }
110 }
111 
112 //-----------------------------------------------------------------------------
113 void cvExpanderButton::mouseReleaseEvent(QMouseEvent* evt) {
114  if (m_pressed && evt->button() == Qt::LeftButton) {
115  m_pressed = false;
116  toggle();
117  }
118 }
~cvExpanderButton() override
void setText(const QString &text)
This property holds the text shown on the button.
void setChecked(bool checked)
This property holds whether the button is checked. By default, the button is unchecked (collapsed).
cvExpanderButton(QWidget *parent=nullptr)
void toggle()
Toggles the state of the checkable button.
void mouseReleaseEvent(QMouseEvent *evt) override
void toggled(bool checked)
This signal is emitted whenever the button changes its state.
void mousePressEvent(QMouseEvent *evt) override
Tensor Minimum(const Tensor &input, const Tensor &other)
Computes the element-wise minimum of input and other. The tensors must have same data type and device...