Commit 483f6293 authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #400 from johnflux/config

A hefty commit to try to clean up MainWindow
parents a353542a 403104dd
......@@ -301,7 +301,8 @@ FORMS += src/ui/MainWindow.ui \
src/ui/configuration/ApmFirmwareConfig.ui \
src/ui/px4_configuration/QGCPX4AirframeConfig.ui \
src/ui/px4_configuration/QGCPX4MulticopterConfig.ui \
src/ui/px4_configuration/QGCPX4SensorCalibration.ui
src/ui/px4_configuration/QGCPX4SensorCalibration.ui \
src/ui/designer/QGCXYPlot.ui
INCLUDEPATH += src \
src/ui \
......@@ -449,7 +450,6 @@ HEADERS += src/MG.h \
src/ui/designer/QGCComboBox.h \
src/ui/designer/QGCTextLabel.h \
src/ui/submainwindow.h \
src/ui/dockwidgettitlebareventfilter.h \
src/ui/uas/UASQuickView.h \
src/ui/uas/UASQuickViewItem.h \
src/ui/linechart/ChartPlot.h \
......@@ -507,7 +507,8 @@ HEADERS += src/MG.h \
src/ui/QGCBaseParamWidget.h \
src/ui/px4_configuration/QGCPX4MulticopterConfig.h \
src/ui/px4_configuration/QGCPX4SensorCalibration.h \
src/ui/dockwidgeteventfilter.h
src/ui/designer/QGCXYPlot.h \
src/ui/menuactionhelper.h
# Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h
......@@ -672,7 +673,6 @@ SOURCES += src/main.cc \
src/ui/designer/QGCComboBox.cc \
src/ui/designer/QGCTextLabel.cc \
src/ui/submainwindow.cpp \
src/ui/dockwidgettitlebareventfilter.cpp \
src/ui/uas/UASQuickViewItem.cc \
src/ui/uas/UASQuickView.cc \
src/ui/linechart/ChartPlot.cc \
......@@ -730,7 +730,8 @@ SOURCES += src/main.cc \
src/ui/QGCBaseParamWidget.cc \
src/ui/px4_configuration/QGCPX4MulticopterConfig.cc \
src/ui/px4_configuration/QGCPX4SensorCalibration.cc \
src/ui/dockwidgeteventfilter.cpp
src/ui/designer/QGCXYPlot.cc \
src/ui/menuactionhelper.cpp
# Enable Google Earth only on Mac OS and Windows with Visual Studio compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
......
......@@ -27,7 +27,7 @@
#include "MainWindow.h"
#include <QDebug>
HDDisplay::HDDisplay(QStringList* plotList, QString title, QWidget *parent) :
HDDisplay::HDDisplay(const QStringList &plotList, QString title, QWidget *parent) :
QGraphicsView(parent),
uas(NULL),
xCenterOffset(0.0f),
......@@ -60,11 +60,8 @@ HDDisplay::HDDisplay(QStringList* plotList, QString title, QWidget *parent) :
setAutoFillBackground(true);
// Add all items in accept list to gauge
if (plotList) {
for(int i = 0; i < plotList->length(); ++i) {
addGauge(plotList->at(i));
}
}
for(int i = 0; i < plotList.length(); ++i)
addGauge(plotList.at(i));
restoreState();
// Set preferred size
......
......@@ -60,7 +60,7 @@ class HDDisplay : public QGraphicsView
{
Q_OBJECT
public:
HDDisplay(QStringList* plotList, QString title="", QWidget *parent = 0);
HDDisplay(const QStringList& plotList, QString title="", QWidget *parent = 0);
~HDDisplay();
public slots:
......
......@@ -49,7 +49,7 @@ This file is part of the QGROUNDCONTROL project
HSIDisplay::HSIDisplay(QWidget *parent) :
HDDisplay(NULL, "HSI", parent),
HDDisplay(QStringList(), "HSI", parent),
dragStarted(false),
leftDragStarted(false),
mouseHasMoved(false),
......
This diff is collapsed.
......@@ -86,6 +86,7 @@ class QGCStatusBar;
class Linecharts;
class QGCDataPlot2D;
class JoystickWidget;
class MenuActionHelper;
/**
* @brief Main Application Window
......@@ -142,41 +143,38 @@ public:
static const QString defaultLightStyle;
/** @brief Get current visual style */
QGC_MAINWINDOW_STYLE getStyle()
QGC_MAINWINDOW_STYLE getStyle() const
{
return currentStyle;
}
/** @brief Get current light visual stylesheet */
QString getLightStyleSheet()
QString getLightStyleSheet() const
{
return lightStyleFileName;
}
/** @brief Get current dark visual stylesheet */
QString getDarkStyleSheet()
QString getDarkStyleSheet() const
{
return darkStyleFileName;
}
/** @brief Get auto link reconnect setting */
bool autoReconnectEnabled()
bool autoReconnectEnabled() const
{
return autoReconnect;
}
/** @brief Get title bar mode setting */
bool dockWidgetTitleBarsEnabled()
{
return dockWidgetTitleBarEnabled;
}
bool dockWidgetTitleBarsEnabled() const;
/** @brief Get low power mode setting */
bool lowPowerModeEnabled()
bool lowPowerModeEnabled() const
{
return lowPowerMode;
}
void setCustomMode(enum MainWindow::CUSTOM_MODE mode)
void setCustomMode(MainWindow::CUSTOM_MODE mode)
{
if (mode != CUSTOM_MODE_UNCHANGED)
{
......@@ -184,12 +182,12 @@ public:
}
}
enum MainWindow::CUSTOM_MODE getCustomMode()
MainWindow::CUSTOM_MODE getCustomMode() const
{
return customMode;
}
QList<QAction*> listLinkMenuActions(void);
QList<QAction*> listLinkMenuActions();
public slots:
/** @brief Shows a status message on the bottom status bar */
......@@ -224,7 +222,7 @@ public slots:
void saveScreen();
/** @brief Sets advanced mode, allowing for editing of tool widget locations */
void setAdvancedMode();
void setAdvancedMode(bool isAdvancedMode);
/** @brief Load configuration views */
void loadHardwareConfigView();
void loadSoftwareConfigView();
......@@ -283,16 +281,6 @@ public slots:
/** @brief Load data view, allowing to plot flight data */
// void loadDataView(QString fileName);
/**
* @brief Shows a Docked Widget based on the action sender
*
* This slot is written to be used in conjunction with the addTool() function
* It shows the QDockedWidget based on the action sender
*
*/
void showTool(bool visible);
/**
* @brief Shows a Widget from the center stack based on the action sender
*
......@@ -308,13 +296,14 @@ public slots:
void commsWidgetDestroyed(QObject *obj);
protected slots:
/** @brief Called by a dock widget when it is has been deleted */
void dockWidgetDestroyed();
void showDockWidget(const QString &name, bool show);
signals:
void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE newTheme);
void styleChanged();
void initStatusChanged(const QString& message, int alignment, const QColor &color);
/** Emitted when any value changes from any source */
void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec);
#ifdef MOUSE_ENABLED_LINUX
/** @brief Forward X11Event to catch 3DMouse inputs */
void x11EventOccured(XEvent *event);
......@@ -362,8 +351,9 @@ protected:
* @param location The default location for the QDockedWidget in case there is no previous key in the settings
*/
void addTool(SubMainWindow *parent,VIEW_SECTIONS view,QDockWidget* widget, const QString& title, Qt::DockWidgetArea area);
void loadDockWidget(QString name);
QDockWidget* createDockWidget(QWidget *parent,QWidget *child,QString title,QString objectname,VIEW_SECTIONS view,Qt::DockWidgetArea area,int minwidth=0,int minheight=0);
void loadDockWidget(const QString &name);
QDockWidget* createDockWidget(QWidget *subMainWindowParent,QWidget *child,const QString& title,const QString& objectname,VIEW_SECTIONS view,Qt::DockWidgetArea area,const QSize& minSize = QSize());
/**
* @brief Adds an already instantiated QWidget to the center stack
*
......@@ -514,11 +504,7 @@ protected:
private:
QList<QObject*> commsWidgetList;
QMap<QString,QString> customWidgetNameToFilenameMap;
QMap<QAction*,QString > menuToDockNameMap;
QList<QDockWidget*> dockWidgets;
QMap<VIEW_SECTIONS,QMap<QString,QWidget*> > centralWidgetToDockWidgetsMap;
bool isAdvancedMode; ///< If enabled dock widgets can be moved and floated.
bool dockWidgetTitleBarEnabled; ///< If enabled, dock widget titlebars are displayed when NOT in advanced mode.
MenuActionHelper *menuActionHelper;
Ui::MainWindow ui;
/** @brief Set the appropriate titlebar for a given dock widget.
......@@ -529,6 +515,7 @@ private:
QString getWindowStateKey();
QString getWindowGeometryKey();
friend class MenuActionHelper; //For VIEW_SECTIONS
};
#endif /* _MAINWINDOW_H_ */
......@@ -576,7 +576,7 @@ void QGCPX4VehicleConfig::loadQgcConfig(bool primary)
{
if (file.toLower().endsWith(".qgw")) {
QWidget* parent = left?ui->generalLeftContents:ui->generalRightContents;
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget("", "", parent);
if (tool->loadSettings(generaldir.absoluteFilePath(file), false))
{
toolWidgets.append(tool);
......@@ -651,7 +651,7 @@ void QGCPX4VehicleConfig::loadQgcConfig(bool primary)
foreach (QString file,newdir.entryList(QDir::Files| QDir::NoDotAndDotDot))
{
if (file.toLower().endsWith(".qgw")) {
tool = new QGCToolWidget("", tab);
tool = new QGCToolWidget("", "", tab);
if (tool->loadSettings(newdir.absoluteFilePath(file), false))
{
toolWidgets.append(tool);
......@@ -698,7 +698,7 @@ void QGCPX4VehicleConfig::loadQgcConfig(bool primary)
foreach (QString file,newdir.entryList(QDir::Files| QDir::NoDotAndDotDot))
{
if (file.toLower().endsWith(".qgw")) {
tool = new QGCToolWidget("", tab);
tool = new QGCToolWidget("", "", tab);
tool->addUAS(mav);
if (tool->loadSettings(newdir.absoluteFilePath(file), false))
{
......@@ -953,10 +953,8 @@ void QGCPX4VehicleConfig::loadConfig()
{
parent = ui->generalRightContents;
}
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget(parametersname, parametersname, parent);
tool->addUAS(mav);
tool->setTitle(parametersname);
tool->setObjectName(parametersname);
tool->setSettings(genset);
QList<QString> paramlist = tool->getParamList();
for (int i=0;i<paramlist.size();i++)
......@@ -1007,10 +1005,8 @@ void QGCPX4VehicleConfig::loadConfig()
{
parent = ui->generalRightContents;
}
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget(parametersname, parametersname, parent);
tool->addUAS(mav);
tool->setTitle(parametersname);
tool->setObjectName(parametersname);
tool->setSettings(advset);
QList<QString> paramlist = tool->getParamList();
for (int i=0;i<paramlist.size();i++)
......
......@@ -261,7 +261,7 @@ void QGCVehicleConfig::loadQgcConfig(bool primary)
{
if (file.toLower().endsWith(".qgw")) {
QWidget* parent = left?ui->generalLeftContents:ui->generalRightContents;
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget("", "", parent);
if (tool->loadSettings(generaldir.absoluteFilePath(file), false))
{
toolWidgets.append(tool);
......@@ -291,7 +291,7 @@ void QGCVehicleConfig::loadQgcConfig(bool primary)
{
if (file.toLower().endsWith(".qgw")) {
QWidget* parent = left?ui->advancedLeftContents:ui->advancedRightContents;
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget("", "", parent);
if (tool->loadSettings(vehicledir.absoluteFilePath(file), false))
{
toolWidgets.append(tool);
......@@ -342,7 +342,7 @@ void QGCVehicleConfig::loadQgcConfig(bool primary)
foreach (QString file,newdir.entryList(QDir::Files| QDir::NoDotAndDotDot))
{
if (file.toLower().endsWith(".qgw")) {
tool = new QGCToolWidget("", tab);
tool = new QGCToolWidget("", "", tab);
if (tool->loadSettings(newdir.absoluteFilePath(file), false))
{
toolWidgets.append(tool);
......@@ -389,7 +389,7 @@ void QGCVehicleConfig::loadQgcConfig(bool primary)
foreach (QString file,newdir.entryList(QDir::Files| QDir::NoDotAndDotDot))
{
if (file.toLower().endsWith(".qgw")) {
tool = new QGCToolWidget("", tab);
tool = new QGCToolWidget("","", tab);
tool->addUAS(mav);
if (tool->loadSettings(newdir.absoluteFilePath(file), false))
{
......@@ -411,7 +411,7 @@ void QGCVehicleConfig::loadQgcConfig(bool primary)
// Load general calibration for autopilot
//TODO: Handle this more gracefully, maybe have it scan the directory for multiple calibration entries?
tool = new QGCToolWidget("", ui->sensorContents);
tool = new QGCToolWidget("", "", ui->sensorContents);
tool->addUAS(mav);
if (tool->loadSettings(autopilotdir.absolutePath() + "/general/calibration/calibration.qgw", false))
{
......@@ -426,7 +426,7 @@ void QGCVehicleConfig::loadQgcConfig(bool primary)
}
// Load vehicle-specific autopilot configuration
tool = new QGCToolWidget("", ui->sensorContents);
tool = new QGCToolWidget("", "", ui->sensorContents);
tool->addUAS(mav);
if (tool->loadSettings(autopilotdir.absolutePath() + "/" + mav->getSystemTypeName().toLower() + "/calibration/calibration.qgw", false))
{
......@@ -681,10 +681,8 @@ void QGCVehicleConfig::loadConfig()
{
parent = ui->generalRightContents;
}
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget(parametersname, parametersname, parent);
tool->addUAS(mav);
tool->setTitle(parametersname);
tool->setObjectName(parametersname);
tool->setSettings(genset);
QList<QString> paramlist = tool->getParamList();
for (int i=0;i<paramlist.size();i++)
......@@ -735,10 +733,8 @@ void QGCVehicleConfig::loadConfig()
{
parent = ui->generalRightContents;
}
tool = new QGCToolWidget("", parent);
tool = new QGCToolWidget(parametersname, parametersname, parent);
tool->addUAS(mav);
tool->setTitle(parametersname);
tool->setObjectName(parametersname);
tool->setSettings(advset);
QList<QString> paramlist = tool->getParamList();
for (int i=0;i<paramlist.size();i++)
......@@ -1175,14 +1171,12 @@ void QGCVehicleConfig::parameterChanged(int uas, int component, QString paramete
}
// Create the tool, attaching it to the QGroupBox
QGCToolWidget *tool = new QGCToolWidget("", parent);
QString tooltitle = parameterName;
if (parameterName.split("_").size() > 1)
{
tooltitle = parameterName.split("_")[0] + "_";
}
tool->setTitle(tooltitle);
tool->setObjectName(tooltitle);
QGCToolWidget *tool = new QGCToolWidget(tooltitle, tooltitle, parent);
//tool->setSettings(set);
libParamToWidgetMap.insert(parameterName,tool);
toolWidgets.append(tool);
......
......@@ -167,70 +167,42 @@ void QGCComboBox::selectParameter(int paramIndex)
}
}
void QGCComboBox::startEditMode()
void QGCComboBox::setEditMode(bool editMode)
{
ui->nameLabel->hide();
ui->writeButton->hide();
ui->readButton->hide();
ui->editInfoCheckBox->show();
ui->editDoneButton->show();
ui->editNameLabel->show();
ui->editRefreshParamsButton->show();
ui->editSelectParamComboBox->show();
ui->editSelectComponentComboBox->show();
ui->editStatusLabel->show();
ui->writeButton->hide();
ui->readButton->hide();
ui->editLine1->show();
ui->editLine2->show();
ui->editAddItemButton->show();
ui->editRemoveItemButton->show();
ui->editItemValueSpinBox->show();
ui->editItemNameLabel->show();
ui->itemValueLabel->show();
ui->itemNameLabel->show();
if (isDisabled)
{
ui->editOptionComboBox->setEnabled(true);
if(!editMode) {
// Store component id
selectComponent(ui->editSelectComponentComboBox->currentIndex());
// Store parameter name and id
selectParameter(ui->editSelectParamComboBox->currentIndex());
}
isInEditMode = true;
}
void QGCComboBox::endEditMode()
{
// Store component id
selectComponent(ui->editSelectComponentComboBox->currentIndex());
// Store parameter name and id
selectParameter(ui->editSelectParamComboBox->currentIndex());
// Min/max
ui->editInfoCheckBox->hide();
ui->editDoneButton->hide();
ui->editNameLabel->hide();
ui->editRefreshParamsButton->hide();
ui->editSelectParamComboBox->hide();
ui->editSelectComponentComboBox->hide();
ui->editStatusLabel->hide();
ui->editLine1->hide();
ui->editLine2->hide();
ui->writeButton->show();
ui->readButton->show();
ui->editAddItemButton->hide();
ui->editRemoveItemButton->hide();
ui->editItemValueSpinBox->hide();
ui->editItemNameLabel->hide();
ui->itemValueLabel->hide();
ui->itemNameLabel->hide();
ui->nameLabel->show();
ui->nameLabel->setVisible(!editMode);
ui->writeButton->setVisible(!editMode);
ui->readButton->setVisible(!editMode);
ui->editInfoCheckBox->setVisible(editMode);
ui->editDoneButton->setVisible(editMode);
ui->editNameLabel->setVisible(editMode);
ui->editRefreshParamsButton->setVisible(editMode);
ui->editSelectParamComboBox->setVisible(editMode);
ui->editSelectComponentComboBox->setVisible(editMode);
ui->editStatusLabel->setVisible(editMode);
ui->writeButton->setVisible(!editMode);
ui->readButton->setVisible(!editMode);
ui->editLine1->setVisible(editMode);
ui->editLine2->setVisible(editMode);
ui->editAddItemButton->setVisible(editMode);
ui->editRemoveItemButton->setVisible(editMode);
ui->editItemValueSpinBox->setVisible(editMode);
ui->editItemNameLabel->setVisible(editMode);
ui->itemValueLabel->setVisible(editMode);
ui->itemNameLabel->setVisible(editMode);
if (isDisabled)
{
ui->editOptionComboBox->setEnabled(false);
ui->editOptionComboBox->setEnabled(editMode);
}
isInEditMode = false;
emit editingFinished();
QGCToolWidgetItem::setEditMode(editMode);
}
void QGCComboBox::setParamPending()
......
......@@ -22,9 +22,9 @@ public:
explicit QGCComboBox(QWidget *parent = 0);
~QGCComboBox();
virtual void setEditMode(bool editMode) override;
public slots:
void startEditMode();
void endEditMode();
/** @brief Queue parameter for sending to the MAV (add to pending list)*/
void setParamPending();
/** @brief Update the UI with the new parameter value */
......
......@@ -159,93 +159,33 @@ void QGCCommandButton::setCommandButtonName(QString text)
ui->commandButton->setText(text);
}
void QGCCommandButton::startEditMode()
void QGCCommandButton::setEditMode(bool editMode)
{
// Hide elements
ui->commandButton->hide();
ui->nameLabel->hide();
ui->editCommandComboBox->blockSignals(false);
ui->editCommandComboBox->show();
ui->editFinishButton->show();
ui->editNameLabel->show();
ui->editButtonName->show();
ui->editConfirmationCheckBox->show();
ui->editComponentSpinBox->show();
ui->editParamsVisibleCheckBox->show();
ui->editParam1SpinBox->show();
ui->editParam2SpinBox->show();
ui->editParam3SpinBox->show();
ui->editParam4SpinBox->show();
ui->editParam5SpinBox->show();
ui->editParam6SpinBox->show();
ui->editParam7SpinBox->show();
ui->editLine1->show();
ui->editLine2->show();
// Attempt to undock the dock widget
QWidget* p = this;
QDockWidget* dock;
do {
p = p->parentWidget();
dock = dynamic_cast<QDockWidget*>(p);
if (dock)
{
dock->setFloating(true);
break;
}
} while (p && !dock);
isInEditMode = true;
}
void QGCCommandButton::endEditMode()
{
ui->editCommandComboBox->blockSignals(true);
ui->editCommandComboBox->hide();
ui->editFinishButton->hide();
ui->editNameLabel->hide();
ui->editButtonName->hide();
ui->editConfirmationCheckBox->hide();
ui->editComponentSpinBox->hide();
ui->editParamsVisibleCheckBox->hide();
ui->editLine1->hide();
ui->editLine2->hide();
if (!ui->editParamsVisibleCheckBox->isChecked())
{
ui->editParam1SpinBox->hide();
ui->editParam2SpinBox->hide();
ui->editParam3SpinBox->hide();
ui->editParam4SpinBox->hide();
ui->editParam5SpinBox->hide();
ui->editParam6SpinBox->hide();
ui->editParam7SpinBox->hide();
}
ui->commandButton->show();
ui->nameLabel->show();
// Write to settings
emit editingFinished();
// Attempt to dock the dock widget
QWidget* p = this;
QDockWidget* dock;
do {
p = p->parentWidget();
dock = dynamic_cast<QDockWidget*>(p);
if (dock)
{
dock->setFloating(false);
break;
}
} while (p && !dock);
isInEditMode = false;
ui->commandButton->setVisible(!editMode);
ui->nameLabel->setVisible(!editMode);
ui->editCommandComboBox->blockSignals(!editMode);
ui->editCommandComboBox->setVisible(editMode);
ui->editFinishButton->setVisible(editMode);
ui->editNameLabel->setVisible(editMode);
ui->editButtonName->setVisible(editMode);
ui->editConfirmationCheckBox->setVisible(editMode);
ui->editComponentSpinBox->setVisible(editMode);
ui->editParamsVisibleCheckBox->setVisible(editMode);
bool showParams = editMode || ui->editParamsVisibleCheckBox->isChecked();
ui->editParam1SpinBox->setVisible(showParams);
ui->editParam2SpinBox->setVisible(showParams);
ui->editParam3SpinBox->setVisible(showParams);
ui->editParam4SpinBox->setVisible(showParams);
ui->editParam5SpinBox->setVisible(showParams);
ui->editParam6SpinBox->setVisible(showParams);
ui->editParam7SpinBox->setVisible(showParams);
ui->editLine1->setVisible(editMode);
ui->editLine2->setVisible(editMode);
QGCToolWidgetItem::setEditMode(editMode);
}
void QGCCommandButton::writeSettings(QSettings& settings)
......
......@@ -18,11 +18,11 @@ public:
explicit QGCCommandButton(QWidget *parent = 0);
~QGCCommandButton();
virtual void setEditMode(bool editMode) override;
public slots:
void sendCommand();
void setCommandButtonName(QString text);
void startEditMode();
void endEditMode();
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
......
......@@ -207,74 +207,57 @@ void QGCParamSlider::selectParameter(int paramIndex)
}
}
void QGCParamSlider::startEditMode()
void QGCParamSlider::setEditMode(bool editMode)
{
ui->valueSlider->hide();
ui->doubleValueSpinBox->hide();
ui->intValueSpinBox->hide();
ui->nameLabel->hide();
ui->writeButton->hide();
ui->readButton->hide();
ui->editInfoCheckBox->show();
ui->editDoneButton->show();
ui->editNameLabel->show();
ui->editRefreshParamsButton->show();
ui->editSelectParamComboBox->show();
ui->editSelectComponentComboBox->show();
ui->editStatusLabel->show();
ui->editMinSpinBox->show();
ui->editMaxSpinBox->show();
ui->writeButton->hide();
ui->readButton->hide();
ui->editLine1->show();
ui->editLine2->show();
isInEditMode = true;
}
if(!editMode) {
// Store component id
selectComponent(ui->editSelectComponentComboBox->currentIndex());
void QGCParamSlider::endEditMode()
{
// Store component id
selectComponent(ui->editSelectComponentComboBox->currentIndex());
// Store parameter name and id
selectParameter(ui->editSelectParamComboBox->currentIndex());
// Store parameter name and id
selectParameter(ui->editSelectParamComboBox->currentIndex());
// Min/max
parameterMin = ui->editMinSpinBox->value();
parameterMax = ui->editMaxSpinBox->value();
// Min/max
parameterMin = ui->editMinSpinBox->value();
parameterMax = ui->editMaxSpinBox->value();
ui->editInfoCheckBox->hide();
ui->editDoneButton->hide();
ui->editNameLabel->hide();
ui->editRefreshParamsButton->hide();
ui->editSelectParamComboBox->hide();
ui->editSelectComponentComboBox->hide();
ui->editStatusLabel->hide();
ui->editMinSpinBox->hide();
ui->editMaxSpinBox->hide();
ui->editLine1->hide();
ui->editLine2->hide();
ui->writeButton->show();
ui->readButton->show();
ui->valueSlider->show();
switch ((int)parameterValue.type())
{
case QVariant::Char:
case QVariant::Int:
case QVariant::UInt:
ui->intValueSpinBox->show();
break;
case QMetaType::Float:
ui->doubleValueSpinBox->show();
break;
default:
qCritical() << "ERROR: NO VALID PARAM TYPE";
return;
switch ((int)parameterValue.type())
{
case QVariant::Char:
case QVariant::Int:
case QVariant::UInt:
ui->intValueSpinBox->show();
break;
case QMetaType::Float:
ui->doubleValueSpinBox->show();
break;
default:
qCritical() << "ERROR: NO VALID PARAM TYPE";
return;
}
} else {
ui->doubleValueSpinBox->hide();
ui->intValueSpinBox->hide();
}
ui->nameLabel->show();
isInEditMode = false;
emit editingFinished();
ui->valueSlider->setVisible(!editMode);
ui->nameLabel->setVisible(!editMode);
ui->writeButton->setVisible(!editMode);
ui->readButton->setVisible(!editMode);
ui->editInfoCheckBox->setVisible(editMode);
ui->editDoneButton->setVisible(editMode);
ui->editNameLabel->setVisible(editMode);
ui->editRefreshParamsButton->setVisible(editMode);
ui->editSelectParamComboBox->setVisible(editMode);
ui->editSelectComponentComboBox->setVisible(editMode);
ui->editStatusLabel->setVisible(editMode);
ui->editMinSpinBox->setVisible(editMode);
ui->editMaxSpinBox->setVisible(editMode);
ui->writeButton->setVisible(!editMode);
ui->readButton->setVisible(!editMode);
ui->editLine1->setVisible(editMode);
ui->editLine2->setVisible(editMode);
QGCToolWidgetItem::setEditMode(editMode);
}
void QGCParamSlider::setParamPending()
......
......@@ -20,9 +20,9 @@ public:
explicit QGCParamSlider(QWidget *parent = 0);
~QGCParamSlider();
virtual void setEditMode(bool editMode) override;
public slots:
void startEditMode();
void endEditMode();
/** @brief Queue parameter for sending to the MAV (add to pending list)*/
void setParamPending();
/** @brief Set the slider value as parameter value */
......
......@@ -20,6 +20,7 @@ public:
int value() { return m_value; }
int min() { return m_min; }
int max() { return m_max; }
protected:
void paintEvent(QPaintEvent *event);
private:
......
......@@ -31,61 +31,17 @@ QGCTextLabel::~QGCTextLabel()
delete ui;
}
void QGCTextLabel::startEditMode()
void QGCTextLabel::setEditMode(bool editMode)
{
// Hide elements
ui->editFinishButton->show();
ui->editNameLabel->show();
ui->editLine1->show();
ui->editLine2->show();
ui->isMavCommand->show();
// Attempt to undock the dock widget
QWidget* p = this;
QDockWidget* dock;
do {
p = p->parentWidget();
dock = dynamic_cast<QDockWidget*>(p);
if (dock)
{
dock->setFloating(true);
break;
}
} while (p && !dock);
isInEditMode = true;
}
void QGCTextLabel::endEditMode()
{
update_isMavCommand();
ui->editFinishButton->hide();
ui->editNameLabel->hide();
ui->editLine1->hide();
ui->editLine2->hide();
ui->isMavCommand->hide();
// Write to settings
emit editingFinished();
// Attempt to dock the dock widget
QWidget* p = this;
QDockWidget* dock;
do {
p = p->parentWidget();
dock = dynamic_cast<QDockWidget*>(p);
if (dock)
{
dock->setFloating(false);
break;
}
} while (p && !dock);
isInEditMode = false;
if(!editMode)
update_isMavCommand();
ui->editFinishButton->setVisible(editMode);
ui->editNameLabel->setVisible(editMode);
ui->editLine1->setVisible(editMode);
ui->editLine2->setVisible(editMode);
ui->isMavCommand->setVisible(editMode);
QGCToolWidgetItem::setEditMode(editMode);
}
void QGCTextLabel::writeSettings(QSettings& settings)
......
......@@ -19,9 +19,8 @@ public:
~QGCTextLabel();
void setActiveUAS(UASInterface *uas);
void enableText(int num);
virtual void setEditMode(bool editMode) override;
public slots:
void startEditMode();
void endEditMode();
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
......
This diff is collapsed.
......@@ -19,7 +19,7 @@ class QGCToolWidget : public QWidget
Q_OBJECT
public:
explicit QGCToolWidget(const QString& title=QString("Unnamed Tool"), QWidget *parent = 0, QSettings* settings = 0);
explicit QGCToolWidget(const QString& objectName, const QString& title, QWidget *parent = 0, QSettings* settings = 0);
~QGCToolWidget();
/** @brief Factory method to instantiate all tool widgets */
......@@ -29,12 +29,15 @@ public:
/** @brief All instances of this class */
static QMap<QString, QGCToolWidget*>* instances();
/** @brief Get title of widget */
const QString getTitle();
QString getTitle() const;
int isVisible(int view) { return viewVisible.value(view, false); }
int isVisible(int view) const { return viewVisible.value(view, false); }
Qt::DockWidgetArea getDockWidgetArea(int view) { return dockWidgetArea.value(view, Qt::BottomDockWidgetArea); }
void setParent(QWidget *parent);
/** @brief Store all widgets of this type to QSettings */
static void storeWidgetsToSettings(QSettings &settingsFile);
public slots:
void addUAS(UASInterface* uas);
/** @brief Delete this widget */
......@@ -44,27 +47,24 @@ public slots:
/** @brief Import settings for this widget from a file */
void importWidget();
/** @brief Store all widgets of this type to QSettings */
static void storeWidgetsToSettings(QString settingsFile=QString());
void storeWidgetsToSettings() { QSettings settings; QGCToolWidget::storeWidgetsToSettings(settings); }
public:
void loadSettings(QVariantMap& settings);
/** @brief Load this widget from a QSettings object */
void loadSettings(QSettings& settings);
/** @brief Load this widget from a settings file */
bool loadSettings(const QString& settings, bool singleinstance=false);
/** @brief Store this widget to a QSettings object */
void storeSettings(QSettings& settings);
/** @brief Store this widget to a settings file */
void storeSettings(const QString& settingsFile);
/** @brief Store this widget to a settings file */
void storeSettings();
/** @brief Store the view id and dock widget area */
void setViewVisibilityAndDockWidgetArea(int view, bool visible, Qt::DockWidgetArea area);
void setSettings(QVariantMap& settings);
QList<QString> getParamList();
void setParameterValue(int uas, int component, QString parameterName, const QVariant value);
bool fromMetaData() { return isFromMetaData; }
bool fromMetaData() const { return isFromMetaData; }
void showLabel(QString name,int num);
signals:
void titleChanged(QString);
void titleChanged(const QString &title);
protected:
bool isFromMetaData;
......@@ -74,6 +74,7 @@ protected:
QVariantMap settingsMap;
QAction* addParamAction;
QAction* addCommandAction;
QAction* addPlotAction;
QAction* addLabelAction;
QAction* setTitleAction;
QAction* deleteAction;
......@@ -85,13 +86,13 @@ protected:
QMap<int, Qt::DockWidgetArea> dockWidgetArea; ///< Dock widget area desired by this widget
QMap<int, bool> viewVisible; ///< Visibility in one view
QString widgetTitle;
static int instanceCount; ///< Number of instances around
void contextMenuEvent(QContextMenuEvent* event);
void createActions();
QList<QGCToolWidgetItem* >* itemList();
/** @brief Add an existing tool widget */
void addToolWidget(QGCToolWidgetItem* widget);
/** @brief Add an existing tool widget and set it to edit mode */
void addToolWidgetAndEdit(QGCToolWidgetItem* widget);
void hideEvent(QHideEvent* event);
public slots:
......@@ -100,10 +101,21 @@ public slots:
protected slots:
void addParam();
void addCommand();
void addPlot();
void addLabel();
void setTitle();
void widgetRemoved();
private:
/** Do not use this from outside the class to set the object name,
* because we cannot track changes to the object name, and the
* QObject::setObjectName() function is not virtual. Instead only
* pass in the object name to the constructor, or use the , then
* never change it again. */
void setObjectName(const QString &name) { QWidget::setObjectName(name); }
/** Helper for storeWidgetsToSettings() */
void storeSettings(QSettings& settings);
Ui::QGCToolWidget *ui;
};
......
......@@ -5,12 +5,13 @@
#include "QGCToolWidget.h"
#include "UASManager.h"
#include <QDockWidget>
QGCToolWidgetItem::QGCToolWidgetItem(const QString& name, QWidget *parent) :
QWidget(parent),
uas(NULL),
isInEditMode(false),
qgcToolWidgetItemName(name),
uas(NULL),
_component(-1)
{
startEditAction = new QAction(tr("Edit %1").arg(qgcToolWidgetItemName), this);
......@@ -20,11 +21,6 @@ QGCToolWidgetItem::QGCToolWidgetItem(const QString& name, QWidget *parent) :
deleteAction = new QAction(tr("Delete %1").arg(qgcToolWidgetItemName), this);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteLater()));
QGCToolWidget* tool = dynamic_cast<QGCToolWidget*>(parent);
if (tool) {
connect(this, SIGNAL(editingFinished()), tool, SLOT(storeWidgetsToSettings()));
}
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
this, SLOT(setActiveUAS(UASInterface*)));
// Set first UAS if it exists
......@@ -54,3 +50,25 @@ void QGCToolWidgetItem::setActiveUAS(UASInterface *uas)
{
this->uas = uas;
}
void QGCToolWidgetItem::setEditMode(bool editMode)
{
isInEditMode = editMode;
// Attempt to undock the dock widget
QWidget* p = this;
QDockWidget* dock;
do {
p = p->parentWidget();
dock = dynamic_cast<QDockWidget*>(p);
if (dock)
{
dock->setFloating(editMode);
break;
}
} while (p && !dock);
emit editingFinished();
}
......@@ -18,9 +18,12 @@ public:
return _component;
}
virtual void setEditMode(bool editMode);
bool isEditMode() const { return isInEditMode; }
public slots:
virtual void startEditMode() {}
virtual void endEditMode() {}
void startEditMode() { setEditMode(true); }
void endEditMode() { setEditMode(false); }
virtual void setComponent(int comp) {
_component = comp;
}
......@@ -33,15 +36,18 @@ signals:
void editingFinished();
protected:
void contextMenuEvent (QContextMenuEvent* event);
UASInterface* uas;
private:
QAction* startEditAction;
QAction* stopEditAction;
QAction* deleteAction;
bool isInEditMode;
QString qgcToolWidgetItemName;
UASInterface* uas;
int _component; ///< The MAV component (the process or device ID)
void contextMenuEvent (QContextMenuEvent* event);
};
......
This diff is collapsed.
#ifndef QGCXYPLOT_H
#define QGCXYPLOT_H
#include "QGCToolWidgetItem.h"
#include "MainWindow.h"
namespace Ui
{
class QGCXYPlot;
}
class UASInterface;
class QwtPlot;
class XYPlotCurve;
class QGCXYPlot : public QGCToolWidgetItem
{
Q_OBJECT
public:
explicit QGCXYPlot(QWidget *parent = 0);
~QGCXYPlot();
virtual void setEditMode(bool editMode);
public slots:
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void appendData(int uasId, const QString& curve, const QString& unit, const QVariant& variant, quint64 usec);
void clearPlot();
void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE style);
void updateMinMaxSettings();
private slots:
void on_maxDataShowSpinBox_valueChanged(int value);
void on_stopStartButton_toggled(bool checked);
void on_timeScrollBar_valueChanged(int value);
private:
Ui::QGCXYPlot *ui;
QwtPlot *plot;
XYPlotCurve* xycurve;
double x; /**< Last unused value for the x-coordinate */
quint64 x_timestamp_us; /**< Timestamp that we last recieved a value for x */
bool x_valid; /**< Whether we have recieved an x value but so far no corresponding y value */
double y; /**< Last unused value for the x-coordinate */
quint64 y_timestamp_us; /**< Timestamp that we last recieved a value for x */
bool y_valid; /**< Whether we have recieved an x value but so far no corresponding y value */
int max_timestamp_diff_us; /**< Only combine x and y to a data point if the timestamp for both doesn't differ by more than this */
};
#endif // QGCXYPLOT_H
This diff is collapsed.
#include <QDockWidget>
#include <QEvent>
#include <QLabel>
#include "dockwidgeteventfilter.h"
DockWidgetEventFilter::DockWidgetEventFilter(QObject *parent) : QObject(parent) {}
bool DockWidgetEventFilter::eventFilter(QObject *object,QEvent *event)
{
if (event->type() == QEvent::WindowTitleChange)
{
QDockWidget *dock = dynamic_cast<QDockWidget *>(object);
if(dock) {
QLabel *label = dynamic_cast<QLabel *>(dock->titleBarWidget());
if(label)
label->setText(dock->windowTitle());
}
}
return QObject::eventFilter(object,event);
}
#ifndef DOCKWIDGETEVENTFILTER_H
#define DOCKWIDGETEVENTFILTER_H
#include <QObject>
/** Event filter to update a QLabel titleBarWidget if the window's title changes */
class DockWidgetEventFilter : public QObject
{
Q_OBJECT
public:
DockWidgetEventFilter(QObject *parent = 0);
protected:
virtual bool eventFilter(QObject *object,QEvent *event) override;
};
#endif // DOCKWIDGETEVENTFILTER_H
#include "dockwidgettitlebareventfilter.h"
#include <QDebug>
#include <QEvent>
DockWidgetTitleBarEventFilter::DockWidgetTitleBarEventFilter(QObject *parent) : QObject(parent)
{
}
bool DockWidgetTitleBarEventFilter::eventFilter(QObject *object,QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)
{
return true;
}
return QObject::eventFilter(object,event);
}
#ifndef DOCKWIDGETTITLEBAREVENTFILTER_H
#define DOCKWIDGETTITLEBAREVENTFILTER_H
#include <QObject>
class DockWidgetTitleBarEventFilter : public QObject
{
Q_OBJECT
public:
explicit DockWidgetTitleBarEventFilter(QObject *parent = 0);
protected:
bool eventFilter(QObject *object,QEvent *event);
signals:
public slots:
};
#endif // DOCKWIDGETTITLEBAREVENTFILTER_H
......@@ -157,36 +157,43 @@ void IncrementalPlot::showLegend(bool show)
*/
void IncrementalPlot::setStyleText(const QString &style)
{
styleText = style.toLower();
foreach (QwtPlotCurve* curve, curves) {
// Style of datapoints
if (style.toLower().contains("circles")) {
curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) );
} else if (style.toLower().contains("crosses")) {
curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(5, 5)) );
} else if (style.toLower().contains("rect")) {
curve->setSymbol(QwtSymbol(QwtSymbol::Rect,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) );
} else if (style.toLower().contains("line")) { // Show no symbol
curve->setSymbol(QwtSymbol(QwtSymbol::NoSymbol,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) );
}
updateStyle(curve);
}
replot();
}
// Style of lines
if (style.toLower().contains("dotted")) {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DotLine));
} else if (style.toLower().contains("dashed")) {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DashLine));
} else if (style.toLower().contains("line") || style.toLower().contains("solid")) {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::SolidLine));
} else {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::NoPen));
}
curve->setStyle(QwtPlotCurve::Lines);
void IncrementalPlot::updateStyle(QwtPlotCurve *curve)
{
if(styleText.isNull())
return;
// Style of datapoints
if (styleText.contains("circles")) {
curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) );
} else if (styleText.contains("crosses")) {
curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(5, 5)) );
} else if (styleText.contains("rect")) {
curve->setSymbol(QwtSymbol(QwtSymbol::Rect,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) );
} else if (styleText.contains("line")) { // Show no symbol
curve->setSymbol(QwtSymbol(QwtSymbol::NoSymbol,
Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) );
}
// Style of lines
if (styleText.contains("dotted")) {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DotLine));
} else if (styleText.contains("dashed")) {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DashLine));
} else if (styleText.contains("line") || styleText.contains("solid")) {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::SolidLine));
} else {
curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::NoPen));
}
replot();
curve->setStyle(QwtPlotCurve::Lines);
}
void IncrementalPlot::resetScaling()
......@@ -275,7 +282,7 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s
const QColor &c = getNextColor();
curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
QBrush(c), QPen(c, symbolWidth), QSize(5, 5)) );
updateStyle(curve); //Apply any user-set style
curve->attach(this);
} else {
curve = curves.value(key);
......@@ -374,7 +381,7 @@ void IncrementalPlot::showGrid(bool show)
replot();
}
bool IncrementalPlot::gridEnabled()
bool IncrementalPlot::gridEnabled() const
{
return grid->isVisible();
}
......
......@@ -81,7 +81,7 @@ public:
virtual ~IncrementalPlot();
/** @brief Get the state of the grid */
bool gridEnabled();
bool gridEnabled() const;
/** @brief Read out data from a curve */
int data(const QString &key, double* r_x, double* r_y, int maxSize);
......@@ -125,10 +125,12 @@ protected:
double xmax; ///< Maximum x value seen
double ymin; ///< Minimum y value seen
double ymax; ///< Maximum y value seen
QString styleText; ///< Curve style set by setStyleText
private:
QMap<QString, CurveData* > d_data; ///< Data points
/** Helper function to apply styleText style to the given curve */
void updateStyle(QwtPlotCurve *curve);
};
#endif /* INCREMENTALPLOT_H */
......@@ -140,7 +140,7 @@ LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent
createLayout();
// And make sure we're listening for future style changes
connect(MainWindow::instance(), SIGNAL(styleChanged()), this, SLOT(recolor()));
connect(MainWindow::instance(), SIGNAL(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE)), this, SLOT(recolor()));
updateTimer->setInterval(updateInterval);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(refresh()));
......
#include "menuactionhelper.h"
MenuActionHelper::MenuActionHelper(QObject *parent) : QObject(parent),
m_isAdvancedMode(false),
m_dockWidgetTitleBarsEnabled(true),
m_addedCustomSeperator(false)
{
}
QAction *MenuActionHelper::createToolAction(const QString &title, const QString &name)
{
QAction *action = m_menuToDockNameMap.key(name); //For sanity, check that the action is not NULL
if(action) {
qWarning() << "createToolAction was called for action" << name << "which already exists in the menu";
return action;
}
action = new QAction(title, NULL);
action->setCheckable(true);
connect(action,SIGNAL(triggered(bool)),this,SLOT(showTool(bool)));
m_menuToDockNameMap[action] = name;
m_menu->addAction(action);
return action;
}
void MenuActionHelper::removeDockWidget()
{
QObject *dockWidget = QObject::sender(); //Note that we can't cast to QDockWidget because we are in its destructor
Q_ASSERT(dockWidget);
qDebug() << "Dockwidget:" << dockWidget->objectName() << "of type" << dockWidget->metaObject()->className();
QAction *action = m_menuToDockNameMap.key(dockWidget->objectName());
if(action) {
m_menuToDockNameMap.remove(action);
action->deleteLater();
}
QMap<MainWindow::VIEW_SECTIONS,QMap<QString,QDockWidget*> >::iterator it;
for (it = m_centralWidgetToDockWidgetsMap.begin(); it != m_centralWidgetToDockWidgetsMap.end(); ++it) {
QMap<QString,QDockWidget*>::iterator it2 = it.value().begin();
while( it2 != it.value().end()) {
if(it2.value() == dockWidget)
it2 = it.value().erase(it2);
else
++it2;
}
}
//Don't delete the dockWidget because this could have been called from the dockWidget destructor
m_dockWidgets.removeAll(static_cast<QDockWidget*>(dockWidget));
}
QAction *MenuActionHelper::createToolActionForCustomDockWidget(const QString &title, const QString& name, QDockWidget* dockWidget, MainWindow::VIEW_SECTIONS view) {
bool found = false;
QAction *action = NULL;
foreach(QAction *act, m_menuToDockNameMap.keys()) {
if(act->text() == title) {
found = true;
action = act;
}
}
if(!found)
action = createToolAction(title, name);
else
m_menuToDockNameMap[action] = name;
m_centralWidgetToDockWidgetsMap[view][name] = dockWidget;
connect(dockWidget, SIGNAL(destroyed()), SLOT(removeDockWidget()),Qt::UniqueConnection); //Use UniqueConnection since we might have already created this connection in createDockWidget
connect(dockWidget, SIGNAL(visibilityChanged(bool)), action, SLOT(setChecked(bool)));
action->setChecked(dockWidget->isVisible());
return action;
}
QDockWidget* MenuActionHelper::createDockWidget(const QString& title,const QString& name)
{
QDockWidget *dockWidget = new QDockWidget(title);
m_dockWidgets.append(dockWidget);
setDockWidgetTitleBar(dockWidget);
dockWidget->setObjectName(name);
connect(dockWidget, SIGNAL(destroyed()), SLOT(removeDockWidget()));
return dockWidget;
}
bool MenuActionHelper::containsDockWidget(MainWindow::VIEW_SECTIONS view, const QString &name) const {
return m_centralWidgetToDockWidgetsMap.contains(view) && m_centralWidgetToDockWidgetsMap[view].contains(name);
}
QDockWidget *MenuActionHelper::getDockWidget(MainWindow::VIEW_SECTIONS view, const QString &name) const {
if(!m_centralWidgetToDockWidgetsMap.contains(view))
return NULL;
return m_centralWidgetToDockWidgetsMap[view].value(name);
}
void MenuActionHelper::showTool(bool show) {
//Called when a menu item is clicked on, regardless of view.
QAction* act = qobject_cast<QAction *>(sender());
Q_ASSERT(act);
if (m_menuToDockNameMap.contains(act)) {
QString name = m_menuToDockNameMap[act];
emit needToShowDockWidget(name, show);
}
}
void MenuActionHelper::setDockWidgetTitleBarsEnabled(bool enabled)
{
m_dockWidgetTitleBarsEnabled = enabled;
for (int i = 0; i < m_dockWidgets.size(); i++)
setDockWidgetTitleBar(m_dockWidgets[i]);
}
void MenuActionHelper::setAdvancedMode(bool advancedMode)
{
m_isAdvancedMode = advancedMode;
for (int i = 0; i < m_dockWidgets.size(); i++)
setDockWidgetTitleBar(m_dockWidgets[i]);
}
void MenuActionHelper::setDockWidgetTitleBar(QDockWidget* widget)
{
Q_ASSERT(widget);
QWidget* oldTitleBar = widget->titleBarWidget();
// In advanced mode, we use the default titlebar provided by Qt.
if (m_isAdvancedMode)
{
widget->setTitleBarWidget(0);
}
// Otherwise, if just a textlabel should be shown, make that the titlebar.
else if (m_dockWidgetTitleBarsEnabled)
{
QLabel* label = new QLabel(widget);
label->setText(widget->windowTitle());
label->installEventFilter(this); //Ignore mouse clicks
widget->installEventFilter(this); //Update label if window title changes. See eventFilter below
widget->setTitleBarWidget(label);
}
// And if nothing should be shown, use an empty widget.
else
{
QWidget* newTitleBar = new QWidget(widget);
widget->setTitleBarWidget(newTitleBar);
}
// Be sure to clean up the old titlebar. When using QDockWidget::setTitleBarWidget(),
// it doesn't delete the old titlebar object.
delete oldTitleBar;
}
bool MenuActionHelper::eventFilter(QObject *object,QEvent *event)
{
if (event->type() == QEvent::WindowTitleChange)
{
QDockWidget *dock = qobject_cast<QDockWidget *>(object);
if(dock) {
// Update the dock title bar label
QLabel *label = dynamic_cast<QLabel *>(dock->titleBarWidget());
if(label)
label->setText(dock->windowTitle());
// Now update the action label
QString oldObjectName = dock->objectName();
QAction *action = m_menuToDockNameMap.key(oldObjectName);
if(action)
action->setText(dock->windowTitle());
//Now modify the object name - it is a strange naming scheme..
}
} else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)
{
if(qobject_cast<QLabel *>(object))
return true;
}
return QObject::eventFilter(object,event);
}
#ifndef MENUACTIONHELPER_H
#define MENUACTIONHELPER_H
#include "MainWindow.h"
class MenuActionHelper : public QObject
{
Q_OBJECT
public:
MenuActionHelper(QObject *parent = NULL);
~MenuActionHelper() {}
/** @brief Get title bar mode setting */
bool dockWidgetTitleBarsEnabled() const { return m_dockWidgetTitleBarsEnabled; }
void setDockWidgetTitleBarsEnabled(bool enabled);
bool isAdvancedMode() const { return m_isAdvancedMode; }
void setAdvancedMode(bool advancedMode);
QAction *createToolAction(const QString &title, const QString &name = QString());
QAction *createToolActionForCustomDockWidget(const QString& title, const QString& name, QDockWidget* dockWidget, MainWindow::VIEW_SECTIONS view);
QDockWidget *createDockWidget(const QString& title, const QString& name);
bool containsDockWidget(MainWindow::VIEW_SECTIONS view, const QString &name) const;
QDockWidget *getDockWidget(MainWindow::VIEW_SECTIONS view, const QString &name) const;
/** QMenu to add QActions to */
void setMenu(QMenu *menu) { m_menu = menu; }
protected:
virtual bool eventFilter(QObject *object,QEvent *event);
private slots:
void removeDockWidget();
/** @brief Shows a Docked Widget based on the action sender */
void showTool(bool show);
signals:
void needToShowDockWidget(const QString& name, bool show);
private:
QMap<QAction*,QString > m_menuToDockNameMap;
QList<QDockWidget*> m_dockWidgets;
QMap<MainWindow::VIEW_SECTIONS,QMap<QString,QDockWidget*> > m_centralWidgetToDockWidgetsMap;
bool m_isAdvancedMode; ///< If enabled dock widgets can be moved and floated.
bool m_dockWidgetTitleBarsEnabled; ///< If enabled, dock widget titlebars are displayed when NOT in advanced mode.
QMenu *m_menu; ///< \see setMenu()
bool m_addedCustomSeperator; ///< Whether we have added a seperator between the actions and the custom actions
void setDockWidgetTitleBar(QDockWidget* widget);
};
#endif // MENUACTIONHELPER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment