LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / uavobjectwidgetutils / popupwidget.cpp
blob59beacf67de6cbc1c6f705f62dc786ad6bb52240
1 #include "popupwidget.h"
3 #include <QtGui>
4 #include <QVBoxLayout>
5 #include <QHBoxLayout>
6 #include <QPushButton>
7 #include <QGroupBox>
9 PopupWidget::PopupWidget(QWidget *parent) :
10 QDialog(parent)
12 m_widget = 0;
14 QVBoxLayout *mainLayout = new QVBoxLayout();
16 m_layout = new QHBoxLayout();
17 mainLayout->addLayout(m_layout);
19 QHBoxLayout *buttonLayout = new QHBoxLayout();
21 m_closeButton = new QPushButton(tr("Close"));
22 buttonLayout->addWidget(m_closeButton);
24 mainLayout->addLayout(buttonLayout);
26 setLayout(mainLayout);
28 connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close()));
29 connect(this, SIGNAL(accepted()), this, SLOT(close()));
30 connect(this, SIGNAL(rejected()), this, SLOT(close()));
33 void PopupWidget::popUp(QWidget *widget)
35 setWidget(widget);
36 exec();
39 void PopupWidget::setWidget(QWidget *widget)
41 m_widget = widget;
42 m_widgetParent = widget->parentWidget();
44 // save the current width,height so we can restore when closed
45 m_widgetWidth = m_widget->width();
46 m_widgetHeight = m_widget->height();
48 // double the size of the widget for the dialog
49 m_widget->resize(m_widgetWidth * 2, m_widgetHeight * 2);
50 m_layout->addWidget(m_widget);
53 bool PopupWidget::close()
55 closePopup();
57 return QDialog::close();
60 void PopupWidget::done(int result)
62 closePopup();
64 QDialog::done(result);
67 void PopupWidget::closePopup()
69 if (m_widget && m_widgetParent) {
70 if (QGroupBox * w = qobject_cast<QGroupBox *>(m_widgetParent)) {
71 m_widget->resize(m_widgetWidth, m_widgetHeight);
72 w->layout()->addWidget(m_widget);