1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

OP-9 GCS/uavobjectbrowser: Options to change colors.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@510 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-04-16 09:49:05 +00:00 committed by ephy
parent d08e801e37
commit fdb15257f0
11 changed files with 163 additions and 22 deletions

View File

@ -40,7 +40,7 @@ EmptyGadgetWidget::EmptyGadgetWidget(QWidget *parent) : QLabel(parent)
this-> this->
setText(tr("Choose a gadget to display in this view.\n") + setText(tr("Choose a gadget to display in this view.\n") +
tr("You can also split this view in two.\n\n") + tr("You can also split this view in two.\n\n") +
tr("Maybe you first have to choose Show Toolbars in the Window menu.")); tr("Maybe you first have to choose Edit Gadgets Mode in the Window menu."));
} }
EmptyGadgetWidget::~EmptyGadgetWidget() EmptyGadgetWidget::~EmptyGadgetWidget()

View File

@ -53,7 +53,7 @@ public:
int childCount() const; int childCount() const;
int columnCount() const; int columnCount() const;
QVariant data(int column = 1) const; QVariant data(int column = 1) const;
// only column 1 is changed with setData currently // only column 1 (TreeItem::dataColumn) is changed with setData currently
// other columns are initialized in constructor // other columns are initialized in constructor
virtual void setData(QVariant value, int column = 1); virtual void setData(QVariant value, int column = 1);
int row() const; int row() const;

View File

@ -42,5 +42,8 @@ UAVObjectBrowser::~UAVObjectBrowser()
void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config) void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config)
{ {
UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config); UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config);
m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor());
m_widget->setManuallyChangedColor(m->manuallyChangedColor());
m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout());
} }

View File

@ -29,17 +29,31 @@
#include <QtCore/QDataStream> #include <QtCore/QDataStream>
UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) : UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent) IUAVGadgetConfiguration(classId, parent),
m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255)),
m_recentlyUpdatedTimeout(500)
{ {
if (state.count() > 0) { if (state.count() > 0) {
QDataStream stream(state); QDataStream stream(state);
QColor recent;
QColor manual;
int timeout;
stream >> recent;
stream >> manual;
stream >> timeout;
m_recentlyUpdatedColor = recent;
m_manuallyChangedColor = manual;
m_recentlyUpdatedTimeout = timeout;
} }
} }
IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone() IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
{ {
UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId()); UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId());
m->m_recentlyUpdatedColor = m_recentlyUpdatedColor;
m->m_manuallyChangedColor = m_manuallyChangedColor;
m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout;
return m; return m;
} }
@ -47,7 +61,9 @@ QByteArray UAVObjectBrowserConfiguration::saveState() const
{ {
QByteArray bytes; QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly); QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << m_recentlyUpdatedColor;
stream << m_manuallyChangedColor;
stream << m_recentlyUpdatedTimeout;
return bytes; return bytes;
} }

View File

@ -29,22 +29,36 @@
#define UAVOBJECTBROWSERCONFIGURATION_H #define UAVOBJECTBROWSERCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h> #include <coreplugin/iuavgadgetconfiguration.h>
#include <QtGui/QColor>
using namespace Core; using namespace Core;
class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor)
Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor)
Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout)
public: public:
explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
QByteArray saveState() const; QByteArray saveState() const;
IUAVGadgetConfiguration *clone(); IUAVGadgetConfiguration *clone();
QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; }
QColor manuallyChangedColor() const { return m_manuallyChangedColor; }
int recentlyUpdatedTimeout() const { return m_recentlyUpdatedTimeout; }
signals: signals:
public slots: public slots:
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; }
private: private:
QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor;
int m_recentlyUpdatedTimeout;
}; };
#endif // UAVOBJECTBROWSERCONFIGURATION_H #endif // UAVOBJECTBROWSERCONFIGURATION_H

View File

@ -53,6 +53,6 @@ IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByt
IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config) IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{ {
return 0;// new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config)); return new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config));
} }

View File

@ -27,11 +27,13 @@
#include "uavobjectbrowseroptionspage.h" #include "uavobjectbrowseroptionspage.h"
#include "uavobjectbrowserconfiguration.h" #include "uavobjectbrowserconfiguration.h"
#include "ui_uavobjectbrowseroptionspage.h"
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QSpinBox> #include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox> #include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QColorDialog>
UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) : UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) :
@ -43,17 +45,102 @@ UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfigu
QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent) QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
{ {
QWidget *widget = new QWidget; QWidget *widget = new QWidget;
QVBoxLayout *vl = new QVBoxLayout();
widget->setLayout(vl);
QHBoxLayout *recentColorLayout = new QHBoxLayout();
QWidget *ru = new QWidget;
ru->setLayout(recentColorLayout);
QWidget *label = new QLabel(tr("Recently updated highlight color:"));
QHBoxLayout *rubLayout = new QHBoxLayout();
QWidget *rub = new QWidget;
rub->setLayout(rubLayout);
m_ruLabel = new QLabel(" ");
m_ruLabel->setMinimumWidth(40);
m_ruButton = new QPushButton(tr("Choose"));
rubLayout->addWidget(m_ruLabel);
rubLayout->addWidget(m_ruButton);
recentColorLayout->addWidget(label);
recentColorLayout->addWidget(rub);
QHBoxLayout *manualColorLayout = new QHBoxLayout();
QWidget *mc = new QWidget;
mc->setLayout(manualColorLayout);
label = new QLabel(tr("Manually changed color:"));
QHBoxLayout *mcbLayout = new QHBoxLayout();
QWidget *mcb = new QWidget;
mcb->setLayout(mcbLayout);
m_mcLabel = new QLabel(" ");
m_mcLabel->setMinimumWidth(40);
m_mcButton = new QPushButton(tr("Choose"));
mcbLayout->addWidget(m_mcLabel);
mcbLayout->addWidget(m_mcButton);
manualColorLayout->addWidget(label);
manualColorLayout->addWidget(mcb);
QHBoxLayout *timeoutLayout = new QHBoxLayout();
QWidget *x = new QWidget;
x->setLayout(timeoutLayout);
label = new QLabel("Recently updated highlight timeout (ms):");
m_timeoutSpin = new QSpinBox();
m_timeoutSpin->setSingleStep(100);
m_timeoutSpin->setMaximum(1000000000);
timeoutLayout->addWidget(label);
timeoutLayout->addWidget(m_timeoutSpin);
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
vl->addWidget(ru);
vl->addWidget(mc);
vl->addWidget(x);
vl->addSpacerItem(spacer);
m_ruColor = m_config->recentlyUpdatedColor();
QString s = QString("background-color: %1").arg(m_ruColor.name());
m_ruLabel->setStyleSheet(s);
m_mcColor = m_config->manuallyChangedColor();
s = QString("background-color: %1").arg(m_mcColor.name());
m_mcLabel->setStyleSheet(s);
m_timeoutSpin->setValue(m_config->recentlyUpdatedTimeout());
connect(m_ruButton, SIGNAL(clicked()), this, SLOT(ruButtonClicked()));
connect(m_mcButton, SIGNAL(clicked()), this, SLOT(mcButtonClicked()));
return widget; return widget;
} }
void UAVObjectBrowserOptionsPage::apply() void UAVObjectBrowserOptionsPage::apply()
{ {
m_config->setRecentlyUpdatedColor(m_ruColor);
m_config->setManuallyChangedColor(m_mcColor);
m_config->setRecentlyUpdatedTimeout(m_timeoutSpin->value());
} }
void UAVObjectBrowserOptionsPage::finish() void UAVObjectBrowserOptionsPage::finish()
{ {
disconnect(m_ruButton, SIGNAL(clicked()), this, SLOT(ruButtonClicked()));
disconnect(m_mcButton, SIGNAL(clicked()), this, SLOT(mcButtonClicked()));
delete m_ruButton;
delete m_mcButton;
delete m_ruLabel;
delete m_mcLabel;
delete m_timeoutSpin;
}
void UAVObjectBrowserOptionsPage::ruButtonClicked()
{
QColor c = QColorDialog::getColor(m_ruColor);
m_ruColor = c.isValid() ? c : m_ruColor;
QString s = QString("background-color: %1").arg(m_ruColor.name());
m_ruLabel->setStyleSheet(s);
}
void UAVObjectBrowserOptionsPage::mcButtonClicked()
{
QColor c = QColorDialog::getColor(m_mcColor);
m_mcColor = c.isValid() ? c : m_mcColor;
QString s = QString("background-color: %1").arg(m_mcColor.name());
m_mcLabel->setStyleSheet(s);
} }

View File

@ -29,13 +29,15 @@
#define UAVOBJECTBROWSEROPTIONSPAGE_H #define UAVOBJECTBROWSEROPTIONSPAGE_H
#include "coreplugin/dialogs/ioptionspage.h" #include "coreplugin/dialogs/ioptionspage.h"
#include <QtGui/QColor>
namespace Core { namespace Core {
class IUAVGadgetConfiguration; class IUAVGadgetConfiguration;
} }
class UAVObjectBrowserConfiguration; class UAVObjectBrowserConfiguration;
class QLabel;
class QPushButton;
class QSpinBox; class QSpinBox;
class QDoubleSpinBox;
using namespace Core; using namespace Core;
@ -51,9 +53,18 @@ public:
signals: signals:
public slots: private slots:
void ruButtonClicked();
void mcButtonClicked();
private: private:
UAVObjectBrowserConfiguration *m_config; UAVObjectBrowserConfiguration *m_config;
QColor m_ruColor;
QColor m_mcColor;
QLabel *m_ruLabel;
QLabel *m_mcLabel;
QPushButton *m_ruButton;
QPushButton *m_mcButton;
QSpinBox *m_timeoutSpin;
}; };

View File

@ -31,6 +31,7 @@
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include "uavobjects/settingspersistence.h" #include "uavobjects/settingspersistence.h"
#include "uavobjecttreemodel.h"
class QPushButton; class QPushButton;
class ObjectTreeItem; class ObjectTreeItem;
@ -44,21 +45,25 @@ class UAVObjectBrowserWidget : public QWidget
public: public:
UAVObjectBrowserWidget(QWidget *parent = 0); UAVObjectBrowserWidget(QWidget *parent = 0);
~UAVObjectBrowserWidget(); ~UAVObjectBrowserWidget();
void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); }
void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); }
void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); }
public slots:
void showMetaData(bool show);
private slots: private slots:
void sendUpdate(); void sendUpdate();
void requestUpdate(); void requestUpdate();
void showMetaData(bool show);
void saveSettings(); void saveSettings();
void readSettings(); void readSettings();
void currentChanged(const QModelIndex &current, const QModelIndex &previous); void currentChanged(const QModelIndex &current, const QModelIndex &previous);
private: private:
QPushButton *m_requestUpdate; QPushButton *m_requestUpdate;
QPushButton *m_sendUpdate; QPushButton *m_sendUpdate;
Ui_UAVObjectBrowser *m_browser; Ui_UAVObjectBrowser *m_browser;
QAbstractItemModel *m_model; UAVObjectTreeModel *m_model;
void updateSettings(SettingsPersistence::OperationEnum op); void updateSettings(SettingsPersistence::OperationEnum op);
void enableSendRequest(bool enable); void enableSendRequest(bool enable);

View File

@ -26,7 +26,6 @@
*/ */
#include "uavobjecttreemodel.h" #include "uavobjecttreemodel.h"
#include "treeitem.h"
#include "fieldtreeitem.h" #include "fieldtreeitem.h"
#include "uavobjects/uavobjectmanager.h" #include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavdataobject.h" #include "uavobjects/uavdataobject.h"
@ -290,7 +289,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (index.column() == 1 && role == Qt::EditRole) { if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(index.column()); return item->data(index.column());
} }
@ -304,7 +303,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
if (objItem && objItem->highlighted()) if (objItem && objItem->highlighted())
return QVariant(m_recentlyUpdatedColor); return QVariant(m_recentlyUpdatedColor);
} }
if (index.column() == 1 && role == Qt::BackgroundRole) { if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item); FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
if (fieldItem && fieldItem->highlighted()) if (fieldItem && fieldItem->highlighted())
return QVariant(m_recentlyUpdatedColor); return QVariant(m_recentlyUpdatedColor);
@ -315,7 +314,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
if (index.column() == 1) { if (index.column() == TreeItem::dataColumn) {
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item); EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
if (fieldItem) { if (fieldItem) {
int enumIndex = fieldItem->data(index.column()).toInt(); int enumIndex = fieldItem->data(index.column()).toInt();
@ -339,7 +338,7 @@ Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const
if (!index.isValid()) if (!index.isValid())
return 0; return 0;
if (index.column() == 1) { if (index.column() == TreeItem::dataColumn) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (item->isEditable()) if (item->isEditable())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;

View File

@ -28,11 +28,11 @@
#ifndef UAVOBJECTTREEMODEL_H #ifndef UAVOBJECTTREEMODEL_H
#define UAVOBJECTTREEMODEL_H #define UAVOBJECTTREEMODEL_H
#include "treeitem.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtGui/QColor> #include <QtGui/QColor>
class TreeItem;
class TopTreeItem; class TopTreeItem;
class ObjectTreeItem; class ObjectTreeItem;
class DataObjectTreeItem; class DataObjectTreeItem;
@ -62,6 +62,12 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
void setRecentlyUpdatedTimeout(int timeout) {
m_recentlyUpdatedTimeout = timeout;
TreeItem::setHighlightTime(timeout);
}
signals: signals: