QGCDockWidget.cc 1.65 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11 12 13

#include "QGCDockWidget.h"

#include <QCloseEvent>
14
#include <QSettings>
15

16 17 18 19 20 21
const char*  QGCDockWidget::_settingsGroup = "DockWidgets";

QGCDockWidget::QGCDockWidget(const QString& title, QAction* action, QWidget* parent)
    : QWidget(parent)
    , _title(title)
	, _action(action)
22
{
23 24 25 26 27
    if (action) {
        setWindowTitle(title);
        setWindowFlags(Qt::Tool);
        loadSettings();
    }
28 29 30 31 32
}

// Instead of destroying the widget just hide it
void QGCDockWidget::closeEvent(QCloseEvent* event)
{
33 34 35 36
    if (_action) {
        saveSettings();
        event->ignore();
        _action->trigger();
37 38
    } else {
        QWidget::closeEvent(event);
39 40 41 42 43
    }
}

void QGCDockWidget::loadSettings(void)
{
dogmaphobic's avatar
dogmaphobic committed
44 45
    // TODO: This is crashing for some reason. Disabled until sorted out.
    if (0 /*_action*/) {
46 47 48 49 50
        QSettings settings;
        settings.beginGroup(_settingsGroup);
        if (settings.contains(_title)) {
            restoreGeometry(settings.value(_title).toByteArray());
        }
51
        settings.endGroup();
52 53 54 55 56
    }
}

void QGCDockWidget::saveSettings(void)
{
dogmaphobic's avatar
dogmaphobic committed
57 58
    // TODO: This is crashing for some reason. Disabled until sorted out.
    if (0 /*_action*/) {
59 60 61
        QSettings settings;
        settings.beginGroup(_settingsGroup);
        settings.setValue(_title, saveGeometry());
62
        settings.endGroup();
63
    }
64
}