CollapsiblePanel.h 1.73 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9

#include <QLabel>
LamarMoore's avatar
LamarMoore committed
10
#include <QWidget>
11
12
13

class QVBoxLayout;

14
15
16
17
18
19
20
21
22
23
24
25
namespace MantidQt {
namespace MantidWidgets {
class CaptionLabel : public QLabel {
  Q_OBJECT
public:
  CaptionLabel(const QString &caption, QWidget *parent);
  void mousePressEvent(QMouseEvent *e) override;
  void paintEvent(QPaintEvent *event) override;
  bool isCollapsed() const { return m_collapsed; }
  void collapse();
  void expand();
signals:
26
  void collapseOrExpand(bool /*_t1*/);
27

28
29
30
private:
  bool m_collapsed;
};
31

32
/**
LamarMoore's avatar
LamarMoore committed
33
34
 * Implements a collapsible panel.
 */
35
36
37
38
39
40
class CollapsiblePanel : public QWidget {
  Q_OBJECT
public:
  CollapsiblePanel(const QString &caption, QWidget *parent);
  void setWidget(QWidget *widget);
  void setCaption(const QString &caption);
Mathieu Tillet's avatar
Mathieu Tillet committed
41
  void collapseCaption() { m_label->collapse(); }
42
  void expandCaption() { m_label->expand(); }
43
44
45
46
47
48
49
50
  bool isCollapsed() const;
signals:
  void collapsed();
  void expanded();
public slots:
  void collapse();
  void expand();
private slots:
51
  void collapseOrExpand(bool /*collapse*/);
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
private:
  QWidget *m_widget;
  QVBoxLayout *m_layout;
  CaptionLabel *m_label;
};

class CollapsibleStack : public QWidget {
  Q_OBJECT
public:
  explicit CollapsibleStack(QWidget *parent);
  CollapsiblePanel *addPanel(const QString &caption, QWidget *widget);
private slots:
  void updateStretch();

private:
  bool allCollapsed() const;
  QVBoxLayout *m_layout;
};

LamarMoore's avatar
LamarMoore committed
72
73
} // namespace MantidWidgets
} // namespace MantidQt