mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
Changes to allow icons to be displayed for gadgets in the options page and in the gadget dropdown list.
Also, allow gadgets to have exactly one configuration only, which gives them a bit more real estate in the options page. For gadgets to use this, call functions setIcon(QIcon) and setSingleConfigurationGadgetTrue() in the constructor of the gadget factory, e.g.: SystemHealthGadgetFactory::SystemHealthGadgetFactory(QObject *parent) : IUAVGadgetFactory(QString("SystemHealthGadget"), tr("System Health Gadget"), parent) { setSingleConfigurationGadgetTrue(); setIcon(QIcon(":/core/images/openpilot_logo_64.png")); }
This commit is contained in:
parent
07a48573ea
commit
ba4a060c27
@ -32,6 +32,7 @@
|
||||
#include <coreplugin/core_global.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWidget;
|
||||
@ -43,9 +44,14 @@ class CORE_EXPORT IOptionsPage : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
IOptionsPage(QObject *parent = 0) : QObject(parent) {}
|
||||
IOptionsPage(QObject *parent = 0) :
|
||||
QObject(parent),
|
||||
m_icon(QIcon()) {}
|
||||
virtual ~IOptionsPage() {}
|
||||
|
||||
void setIcon(QIcon icon) { m_icon = icon; }
|
||||
QIcon icon() { return m_icon; }
|
||||
|
||||
/* gadget options pages can leave these 4 functions as is,
|
||||
since they are decorated by UAVGadgetOptionsPageDecorator,
|
||||
all other options pages must override these */
|
||||
@ -57,6 +63,8 @@ public:
|
||||
virtual QWidget *createPage(QWidget *parent) = 0;
|
||||
virtual void apply() = 0;
|
||||
virtual void finish() = 0;
|
||||
private:
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
@ -114,6 +114,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
||||
splitter->setCollapsible(0, false);
|
||||
splitter->setCollapsible(1, false);
|
||||
pageTree->header()->setVisible(false);
|
||||
// pageTree->setIconSize(QSize(24, 24));
|
||||
|
||||
connect(pageTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
|
||||
this, SLOT(pageSelected()));
|
||||
@ -150,6 +151,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
||||
}
|
||||
}
|
||||
categoryItem = new QTreeWidgetItem(pageTree);
|
||||
categoryItem->setIcon(0, page->icon());
|
||||
categoryItem->setText(0, trCategories);
|
||||
categoryItem->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
||||
categories.insert(currentCategory, categoryItem);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "core_global.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtGui/QIcon>
|
||||
#include <QSettings>
|
||||
#include "uavconfiginfo.h"
|
||||
|
||||
@ -51,7 +52,9 @@ public:
|
||||
IUAVGadgetFactory(QString classId, QString name, QObject *parent = 0) :
|
||||
QObject(parent),
|
||||
m_classId(classId),
|
||||
m_name(name) {}
|
||||
m_name(name),
|
||||
m_icon(QIcon()),
|
||||
m_singleConfigurationGadget(false) {}
|
||||
virtual ~IUAVGadgetFactory() {}
|
||||
|
||||
virtual IUAVGadget *createGadget(QWidget *parent) = 0;
|
||||
@ -60,9 +63,16 @@ public:
|
||||
virtual IOptionsPage *createOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; }
|
||||
QString classId() const { return m_classId; }
|
||||
QString name() const { return m_name; }
|
||||
QIcon icon() const { return m_icon; }
|
||||
bool isSingleConfigurationGadget() { return m_singleConfigurationGadget; }
|
||||
protected:
|
||||
void setIcon(QIcon icon) { m_icon = icon; }
|
||||
void setSingleConfigurationGadgetTrue() { m_singleConfigurationGadget = true; }
|
||||
private:
|
||||
QString m_classId; // unique class id
|
||||
QString m_name; // display name, should also be unique
|
||||
QIcon m_icon;
|
||||
bool m_singleConfigurationGadget; // true if there is exactly one configuration for this gadget
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
@ -56,7 +56,9 @@ UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
|
||||
m_factories.append(f);
|
||||
QString classId = f->classId();
|
||||
QString name = f->name();
|
||||
m_classIds.insert(classId, name);
|
||||
QIcon icon = f->icon();
|
||||
m_classIdNameMap.insert(classId, name);
|
||||
m_classIdIconMap.insert(classId, icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,7 +110,7 @@ void UAVGadgetInstanceManager::readConfigs_1_2_0(QSettings *qs)
|
||||
{
|
||||
UAVConfigInfo configInfo;
|
||||
|
||||
foreach (QString classId, m_classIds.keys())
|
||||
foreach (QString classId, m_classIdNameMap.keys())
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
qs->beginGroup(classId);
|
||||
@ -159,7 +161,7 @@ void UAVGadgetInstanceManager::readConfigs_1_1_0(QSettings *qs)
|
||||
{
|
||||
UAVConfigInfo configInfo;
|
||||
|
||||
foreach (QString classId, m_classIds.keys())
|
||||
foreach (QString classId, m_classIdNameMap.keys())
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
qs->beginGroup(classId);
|
||||
@ -242,7 +244,8 @@ void UAVGadgetInstanceManager::createOptionsPages()
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *p = f->createOptionsPage(config);
|
||||
if (p) {
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config, f->isSingleConfigurationGadget());
|
||||
page->setIcon(f->icon());
|
||||
m_optionsPages.append(page);
|
||||
m_pm->addObject(page);
|
||||
}
|
||||
@ -334,6 +337,7 @@ void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *conf
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *p = f->createOptionsPage(config);
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
|
||||
page->setIcon(f->icon());
|
||||
m_provisionalConfigs.append(config);
|
||||
m_provisionalOptionsPages.append(page);
|
||||
m_settingsDialog->insertPage(page);
|
||||
@ -452,7 +456,12 @@ QStringList UAVGadgetInstanceManager::configurationNames(QString classId) const
|
||||
|
||||
QString UAVGadgetInstanceManager::gadgetName(QString classId) const
|
||||
{
|
||||
return m_classIds.value(classId);
|
||||
return m_classIdNameMap.value(classId);
|
||||
}
|
||||
|
||||
QIcon UAVGadgetInstanceManager::gadgetIcon(QString classId) const
|
||||
{
|
||||
return m_classIdIconMap.value(classId);
|
||||
}
|
||||
|
||||
IUAVGadgetFactory *UAVGadgetInstanceManager::factory(QString classId) const
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <QSettings>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QIcon>
|
||||
#include "core_global.h"
|
||||
#include "uavconfiginfo.h"
|
||||
|
||||
@ -68,9 +69,10 @@ public:
|
||||
void cloneConfiguration(IUAVGadgetConfiguration *config);
|
||||
void applyChanges(IUAVGadgetConfiguration *config);
|
||||
void configurationNameEdited(QString text, bool hasText = true);
|
||||
QStringList classIds() const { return m_classIds.keys(); }
|
||||
QStringList classIds() const { return m_classIdNameMap.keys(); }
|
||||
QStringList configurationNames(QString classId) const;
|
||||
QString gadgetName(QString classId) const;
|
||||
QIcon gadgetIcon(QString classId) const;
|
||||
|
||||
signals:
|
||||
void configurationChanged(IUAVGadgetConfiguration* config);
|
||||
@ -91,7 +93,8 @@ private:
|
||||
QList<IUAVGadgetFactory*> m_factories;
|
||||
QList<IUAVGadgetConfiguration*> m_configurations;
|
||||
QList<IOptionsPage*> m_optionsPages;
|
||||
QMap<QString, QString> m_classIds;
|
||||
QMap<QString, QString> m_classIdNameMap;
|
||||
QMap<QString, QIcon> m_classIdIconMap;
|
||||
QMap<QString, QStringList> m_takenNames;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalConfigs;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalDeletes;
|
||||
|
@ -91,6 +91,7 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
m_defaultIndex = 0;
|
||||
startFromOne = true;
|
||||
m_uavGadgetList->insertItem(0, im->gadgetName(classId), classId);
|
||||
m_uavGadgetList->setItemIcon(0, im->gadgetIcon(classId));
|
||||
m_uavGadgetList->insertSeparator(1);
|
||||
} else {
|
||||
|
||||
@ -101,6 +102,7 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
break;
|
||||
}
|
||||
m_uavGadgetList->insertItem(i, im->gadgetName(classId), classId);
|
||||
m_uavGadgetList->setItemIcon(i, im->gadgetIcon(classId));
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
@ -34,10 +34,12 @@
|
||||
|
||||
using namespace Core;
|
||||
|
||||
UAVGadgetOptionsPageDecorator::UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config, QObject *parent) :
|
||||
UAVGadgetOptionsPageDecorator::UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config,
|
||||
bool isSingleConfigurationGadget, QObject *parent) :
|
||||
Core::IOptionsPage(parent),
|
||||
m_optionsPage(page),
|
||||
m_config(config),
|
||||
m_isSingleConfigurationGadget(isSingleConfigurationGadget),
|
||||
m_id(config->name()),
|
||||
m_category(config->classId())
|
||||
{
|
||||
@ -65,6 +67,11 @@ QWidget *UAVGadgetOptionsPageDecorator::createPage(QWidget *parent)
|
||||
wi->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
m_page->verticalLayout_4->addWidget(wi);
|
||||
|
||||
// For some gadgets it might not make sense to have multiple configurations
|
||||
if (m_isSingleConfigurationGadget) {
|
||||
m_page->configurationBox->hide();
|
||||
}
|
||||
|
||||
connect(m_page->cloneButton, SIGNAL(clicked()), this, SLOT(cloneConfiguration()));
|
||||
connect(m_page->deleteButton, SIGNAL(clicked()), this, SLOT(deleteConfiguration()));
|
||||
connect(m_page->nameLineEdit, SIGNAL(textEdited(QString)), this, SLOT(textEdited(QString)));
|
||||
|
@ -43,7 +43,7 @@ class CORE_EXPORT UAVGadgetOptionsPageDecorator : public Core::IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config, QObject *parent = 0);
|
||||
explicit UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config, bool isSingleConfigurationGadget = false, QObject *parent = 0);
|
||||
|
||||
QString id() const { return m_id; }
|
||||
QString trName() const { return m_id; }
|
||||
@ -66,6 +66,7 @@ private slots:
|
||||
private:
|
||||
IOptionsPage *m_optionsPage;
|
||||
IUAVGadgetConfiguration *m_config;
|
||||
bool m_isSingleConfigurationGadget;
|
||||
UAVGadgetInstanceManager *m_instanceManager;
|
||||
QString m_id;
|
||||
QString m_category;
|
||||
|
Loading…
x
Reference in New Issue
Block a user