1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +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->
setText(tr("Choose a gadget to display in this view.\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()

View File

@ -53,7 +53,7 @@ public:
int childCount() const;
int columnCount() 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
virtual void setData(QVariant value, int column = 1);
int row() const;

View File

@ -42,5 +42,8 @@ UAVObjectBrowser::~UAVObjectBrowser()
void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* 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,25 +29,41 @@
#include <QtCore/QDataStream>
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) {
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()
{
UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId());
return m;
m->m_recentlyUpdatedColor = m_recentlyUpdatedColor;
m->m_manuallyChangedColor = m_manuallyChangedColor;
m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout;
return m;
}
QByteArray UAVObjectBrowserConfiguration::saveState() const
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << m_recentlyUpdatedColor;
stream << m_manuallyChangedColor;
stream << m_recentlyUpdatedTimeout;
return bytes;
}

View File

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

View File

@ -53,6 +53,6 @@ IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByt
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 "uavobjectbrowserconfiguration.h"
#include "ui_uavobjectbrowseroptionspage.h"
#include <QtGui/QLabel>
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QColorDialog>
UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) :
@ -43,17 +45,102 @@ UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfigu
QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
{
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;
}
void UAVObjectBrowserOptionsPage::apply()
{
m_config->setRecentlyUpdatedColor(m_ruColor);
m_config->setManuallyChangedColor(m_mcColor);
m_config->setRecentlyUpdatedTimeout(m_timeoutSpin->value());
}
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
#include "coreplugin/dialogs/ioptionspage.h"
#include <QtGui/QColor>
namespace Core {
class IUAVGadgetConfiguration;
}
class UAVObjectBrowserConfiguration;
class QLabel;
class QPushButton;
class QSpinBox;
class QDoubleSpinBox;
using namespace Core;
@ -51,9 +53,18 @@ public:
signals:
public slots:
private slots:
void ruButtonClicked();
void mcButtonClicked();
private:
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/QTreeView>
#include "uavobjects/settingspersistence.h"
#include "uavobjecttreemodel.h"
class QPushButton;
class ObjectTreeItem;
@ -44,21 +45,25 @@ class UAVObjectBrowserWidget : public QWidget
public:
UAVObjectBrowserWidget(QWidget *parent = 0);
~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:
void sendUpdate();
void requestUpdate();
void showMetaData(bool show);
void saveSettings();
void readSettings();
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
private:
QPushButton *m_requestUpdate;
QPushButton *m_sendUpdate;
Ui_UAVObjectBrowser *m_browser;
QAbstractItemModel *m_model;
UAVObjectTreeModel *m_model;
void updateSettings(SettingsPersistence::OperationEnum op);
void enableSendRequest(bool enable);

View File

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

View File

@ -28,11 +28,11 @@
#ifndef UAVOBJECTTREEMODEL_H
#define UAVOBJECTTREEMODEL_H
#include "treeitem.h"
#include <QAbstractItemModel>
#include <QtCore/QMap>
#include <QtGui/QColor>
class TreeItem;
class TopTreeItem;
class ObjectTreeItem;
class DataObjectTreeItem;
@ -62,6 +62,12 @@ public:
int rowCount(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: