dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
popupwidget.cpp
Go to the documentation of this file.
1 #include "popupwidget.h"
2 #include <QVBoxLayout>
3 #include <QHBoxLayout>
4 #include <QtGui>
5 #include <QGroupBox>
6 
7 PopupWidget::PopupWidget(QWidget *parent)
8  : QDialog(parent)
9 {
10  m_widget = nullptr;
11 
12  QVBoxLayout *mainLayout = new QVBoxLayout();
13 
14  m_layout = new QHBoxLayout();
15  mainLayout->addLayout(m_layout);
16 
17  QHBoxLayout *buttonLayout = new QHBoxLayout();
18 
19  m_closeButton = new QPushButton(tr("Close"));
20  buttonLayout->addWidget(m_closeButton);
21 
22  mainLayout->addLayout(buttonLayout);
23 
24  setLayout(mainLayout);
25 
26  connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close()));
27  connect(this, SIGNAL(accepted()), this, SLOT(close()));
28  connect(this, SIGNAL(rejected()), this, SLOT(close()));
29 }
30 
31 void PopupWidget::popUp(QWidget *widget)
32 {
33  setWidget(widget);
34  exec();
35 }
36 
37 void PopupWidget::setWidget(QWidget *widget)
38 {
39  m_widget = widget;
40  m_widgetParent = widget->parentWidget();
41 
42  // save the current width,height so we can restore when closed
43  m_widgetWidth = m_widget->width();
44  m_widgetHeight = m_widget->height();
45 
46  // double the size of the widget for the dialog
47  m_widget->resize(m_widgetWidth * 2, m_widgetHeight * 2);
48  m_layout->addWidget(m_widget);
49 }
50 
52 {
53  closePopup();
54 
55  return QDialog::close();
56 }
57 
58 void PopupWidget::done(int result)
59 {
60  closePopup();
61 
62  QDialog::done(result);
63 }
64 
65 void PopupWidget::closePopup()
66 {
67  if (m_widget && m_widgetParent) {
68  if (QGroupBox *w = qobject_cast<QGroupBox *>(m_widgetParent)) {
69  m_widget->resize(m_widgetWidth, m_widgetHeight);
70  w->layout()->addWidget(m_widget);
71  }
72  }
73 }
bool close()
Definition: popupwidget.cpp:51
void setWidget(QWidget *widget)
Definition: popupwidget.cpp:37
PopupWidget(QWidget *parent=nullptr)
Definition: popupwidget.cpp:7
void popUp(QWidget *widget=nullptr)
Definition: popupwidget.cpp:31
void done(int result)
Definition: popupwidget.cpp:58