HAL
content_frame.cpp
Go to the documentation of this file.
2 
5 #include "gui/toolbar/toolbar.h"
6 
7 #include <QAction>
8 #include <QChildEvent>
9 #include <QShortcut>
10 
11 namespace hal
12 {
13  ContentFrame::ContentFrame(ContentWidget* widget, bool attached, QWidget* parent)
14  : QWidget(parent), mVerticalLayout(new QVBoxLayout()), mHorizontalLayout(new QHBoxLayout()), mLeftToolbar(new Toolbar()), mRightToolbar(new Toolbar()), mWidget(widget),
15  mNameLabel(new QLabel())
16 
17  {
18  setWindowTitle(widget->name());
19  setFocusPolicy(Qt::FocusPolicy::StrongFocus);
20 
21  mVerticalLayout->setContentsMargins(0, 0, 0, 0);
22  mVerticalLayout->setSpacing(0);
23 
24  mHorizontalLayout->setContentsMargins(0, 0, 0, 0);
25  mHorizontalLayout->setSpacing(0);
26 
28  mLeftToolbar->setIconSize(QSize(18, 18));
30  mRightToolbar->setIconSize(QSize(18, 18));
31 
32  QAction* action = new QAction(this);
33 
34  mDetachIconStyle = "all->#969696";
35  mDetachIconPath = ":/icons/detach";
36 
37  if (attached)
38  {
39  mNameLabel->setText(widget->name());
40  mLeftToolbar->addWidget(mNameLabel);
41  mLeftToolbar->addSeparator();
42  action->setText("Detach");
43  action->setIcon(gui_utility::getStyledSvgIcon(mDetachIconStyle, mDetachIconPath));
45  }
46  else
47  {
48  action->setText("Reattach");
50  }
51  widget->setupToolbar(mLeftToolbar);
52  mRightToolbar->addAction(action);
53 
54  for (QShortcut* s : widget->createShortcuts())
55  {
56  s->setParent(this);
57  s->setContext(Qt::WidgetWithChildrenShortcut);
58  s->setEnabled(true);
59  }
60 
61  setLayout(mVerticalLayout);
62  mVerticalLayout->addLayout(mHorizontalLayout, Qt::AlignTop);
63  mHorizontalLayout->addWidget(mLeftToolbar);
64  mHorizontalLayout->addWidget(mRightToolbar);
65  mVerticalLayout->addWidget(widget, Qt::AlignBottom);
66  widget->show();
68  }
69 
71  {
72  if (event->removed() && event->child() == mWidget)
73  {
74  hide();
75  setParent(nullptr);
76  deleteLater();
77  }
78  }
79 
81  {
82  return mWidget;
83  }
84 
86  {
87  hide();
88  mWidget->detach();
89  }
90 
92  {
93  hide();
94  mWidget->reattach();
95  }
96 
98  {
99  mNameLabel->setText(name);
101  }
102 
103  void ContentFrame::closeEvent(QCloseEvent* event)
104  {
105  Q_UNUSED(event)
106  reattachWidget();
107  }
108 }
void handleNameChanged(const QString &name)
ContentFrame(ContentWidget *widget, bool attached, QWidget *parent=nullptr)
void childEvent(QChildEvent *event) override
ContentWidget * content()
Abstract class for Widgets within HAL's ContentArea.
virtual void setupToolbar(Toolbar *Toolbar)
void name_changed(const QString &name)
virtual QList< QShortcut * > createShortcuts()
Toolbar for all ContentFrames and ContentWidgets.
Definition: toolbar.h:39
void show()
Definition: widget.cpp:21
action
Definition: control.py:16
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
std::string name
void triggered(bool checked)
void addLayout(QLayout *layout, int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
void setText(const QString &)
void setContentsMargins(int left, int top, int right, int bottom)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void deleteLater()
void setParent(QObject *parent)
AlignTop
WidgetWithChildrenShortcut
QAction * addAction(const QString &text)
QAction * addSeparator()
QAction * addWidget(QWidget *widget)
void setIconSize(const QSize &iconSize)
virtual bool event(QEvent *event) override
void setFocusPolicy(Qt::FocusPolicy policy)
void hide()
void setLayout(QLayout *layout)
void setParent(QWidget *parent)
void setSizePolicy(QSizePolicy)
void setWindowTitle(const QString &)