1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

GCS/core: Preliminary support for more than 2 workspaces in GCS.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@692 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-05-30 18:57:33 +00:00 committed by ephy
parent c53aa219d5
commit cea963e96b
6 changed files with 490 additions and 25 deletions

View File

@ -59,7 +59,8 @@ SOURCES += mainwindow.cpp \
iuavgadgetconfiguration.cpp \
uavgadgetinstancemanager.cpp \
uavgadgetoptionspagedecorator.cpp \
uavgadgetdecorator.cpp
uavgadgetdecorator.cpp \
workspacesettings.cpp
HEADERS += mainwindow.h \
tabpositionindicator.h \
fancyactionbar.h \
@ -115,11 +116,13 @@ HEADERS += mainwindow.h \
iuavgadgetconfiguration.h \
uavgadgetinstancemanager.h \
uavgadgetoptionspagedecorator.h \
uavgadgetdecorator.h
uavgadgetdecorator.h \
workspacesettings.h
FORMS += dialogs/settingsdialog.ui \
dialogs/shortcutsettings.ui \
generalsettings.ui \
uavgadgetoptionspage.ui
uavgadgetoptionspage.ui \
workspacesettings.ui
RESOURCES += core.qrc \
fancyactionbar.qrc
unix:!macx {

View File

@ -40,6 +40,7 @@
#include "outputpane.h"
#include "plugindialog.h"
#include "shortcutsettings.h"
#include "workspacesettings.h"
#include "modemanager.h"
#include "uavgadgetmode.h"
#include "uavgadgetmanager.h"
@ -123,6 +124,7 @@ MainWindow::MainWindow() :
m_activeContext(0),
m_generalSettings(new GeneralSettings),
m_shortcutSettings(new ShortcutSettings),
m_workspaceSettings(new WorkspaceSettings),
m_focusToEditor(0),
m_newAction(0),
m_openAction(0),
@ -206,12 +208,15 @@ MainWindow::~MainWindow()
}
pm->removeObject(m_shortcutSettings);
pm->removeObject(m_generalSettings);
pm->removeObject(m_workspaceSettings);
delete m_messageManager;
m_messageManager = 0;
delete m_shortcutSettings;
m_shortcutSettings = 0;
delete m_generalSettings;
m_generalSettings = 0;
delete m_workspaceSettings;
m_workspaceSettings = 0;
delete m_settings;
m_settings = 0;
delete m_uniqueIDManager;
@ -245,6 +250,7 @@ bool MainWindow::init(QString *errorMessage)
pm->addObject(m_generalSettings);
pm->addObject(m_shortcutSettings);
pm->addObject(m_workspaceSettings);
return true;
}
@ -256,32 +262,11 @@ void MainWindow::modeChanged(Core::IMode */*mode*/)
void MainWindow::extensionsInitialized()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
m_uavGadgetInstanceManager = new UAVGadgetInstanceManager(this);
m_uavGadgetInstanceManager->readConfigurations();
// Workspace 1
UAVGadgetMode *uavGadgetMode;
Core::UAVGadgetManager *m_uavGadgetManager;
m_uavGadgetManager = new Core::UAVGadgetManager(CoreImpl::instance(), this);
m_uavGadgetManager->hide();
uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, QString(tr("Workspace 1")),
QIcon(":/core/images/openpilot_logo_64.png"), 90, QString("Mode1"));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode);
pm->addObject(uavGadgetMode);
addUAVGadgetManager(m_uavGadgetManager);
// Workspace 2
m_uavGadgetManager = new Core::UAVGadgetManager(CoreImpl::instance(), this);
m_uavGadgetManager->hide();
uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, QString(tr("Workspace 2")),
QIcon(":/core/images/plus.png"), 60, QString("Mode2"));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode);
pm->addObject(uavGadgetMode);
addUAVGadgetManager(m_uavGadgetManager);
createWorkspaces();
m_viewManager->extensionsInitalized();
@ -904,6 +889,35 @@ void MainWindow::shutdown()
m_activeContext = 0;
}
void MainWindow::createWorkspaces() {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
m_settings->beginGroup(QLatin1String("Workspace"));
const int numberOfWorkspaces = m_settings->value(QLatin1String("NumberOfWorkspaces"), 2).toInt();
UAVGadgetMode *uavGadgetMode;
Core::UAVGadgetManager *m_uavGadgetManager;
for (int i = 1; i <= numberOfWorkspaces; ++i) {
m_uavGadgetManager = new Core::UAVGadgetManager(CoreImpl::instance(), this);
m_uavGadgetManager->hide();
QString numberString = QString::number(i);
QString defaultName = "Workspace" + numberString;
QString defaultIconName = "Icon" + numberString;
const QString name = m_settings->value(defaultName, defaultName).toString();
const QString iconName = m_settings->value(defaultIconName, ":/core/images/openpilot_logo_64.png").toString();
uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, name,
QIcon(iconName), 90-i, QString("Mode" + numberString));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode);
pm->addObject(uavGadgetMode);
addUAVGadgetManager(m_uavGadgetManager);
}
m_settings->endGroup();
}
static const char *settingsGroup = "MainWindow";
static const char *geometryKey = "Geometry";
static const char *colorKey = "Color";

View File

@ -69,6 +69,7 @@ class CoreImpl;
class FancyTabWidget;
class GeneralSettings;
class ShortcutSettings;
class WorkspaceSettings;
class ViewManager;
class VersionDialog;
class UAVGadgetMode;
@ -157,6 +158,7 @@ private:
void registerDefaultContainers();
void registerDefaultActions();
void createWorkspaces();
void readSettings();
void writeSettings();
@ -187,6 +189,7 @@ private:
GeneralSettings *m_generalSettings;
ShortcutSettings *m_shortcutSettings;
WorkspaceSettings *m_workspaceSettings;
// actions
QShortcut *m_focusToEditor;

View File

@ -0,0 +1,164 @@
/**
******************************************************************************
*
* @file workspacesettings.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup coreplugin
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "workspacesettings.h"
#include <coreplugin/icore.h>
#include <QtCore/QSettings>
#include "ui_workspacesettings.h"
using namespace Core;
using namespace Core::Internal;
const int WorkspaceSettings::MAX_WORKSPACES = 10;
WorkspaceSettings::WorkspaceSettings(QObject *parent) :
IOptionsPage(parent)
{
}
WorkspaceSettings::~WorkspaceSettings()
{
}
// IOptionsPage
QString WorkspaceSettings::id() const
{
return QLatin1String("Workspaces");
}
QString WorkspaceSettings::trName() const
{
return tr("Workspaces");
}
QString WorkspaceSettings::category() const
{
return QLatin1String("GCS");
}
QString WorkspaceSettings::trCategory() const
{
return tr("GCS");
}
QWidget *WorkspaceSettings::createPage(QWidget *parent)
{
m_page = new Ui::WorkspaceSettings();
QWidget *w = new QWidget(parent);
m_page->setupUi(w);
m_page->numberOfWorkspacesSpinBox->setMaximum(MAX_WORKSPACES);
m_settings = Core::ICore::instance()->settings();
m_settings->beginGroup(QLatin1String("Workspace"));
const int numberOfWorkspaces = m_settings->value(QLatin1String("NumberOfWorkspaces"), 2).toInt();
m_page->numberOfWorkspacesSpinBox->setValue(numberOfWorkspaces);
for (int i = 1; i <= MAX_WORKSPACES; ++i) {
QString numberString = QString::number(i);
QString defaultName = "Workspace" + numberString;
QString defaultIconName = "Icon" + numberString;
const QString name = m_settings->value(defaultName, defaultName).toString();
const QString iconName = m_settings->value(defaultIconName, ":/core/images/openpilot_logo_64.png").toString();
m_iconNames.append(iconName);
m_names.append(name);
if (i <= numberOfWorkspaces)
m_page->workspaceComboBox->addItem(QIcon(iconName), name);
}
m_settings->endGroup();
connect(m_page->workspaceComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectWorkspace(int)));
connect(m_page->numberOfWorkspacesSpinBox, SIGNAL(valueChanged(int)), this, SLOT(numberOfWorkspacesChanged(int)));
connect(m_page->nameEdit, SIGNAL(textEdited(QString)), this, SLOT(textEdited(QString)));
m_currentIndex = 0;
QString iconName = m_iconNames.at(m_currentIndex);
m_page->iconEdit->setText(iconName);
m_page->iconLabel->setPixmap(QIcon(iconName).pixmap(16, 16));
m_page->nameEdit->setText(m_names.at(m_currentIndex));
return w;
}
void WorkspaceSettings::apply()
{
m_iconNames.replace(m_currentIndex, m_page->iconEdit->text());
m_names.replace(m_currentIndex, m_page->nameEdit->text());
m_settings->beginGroup(QLatin1String("Workspace"));
m_settings->setValue(QLatin1String("NumberOfWorkspaces"), m_page->numberOfWorkspacesSpinBox->value());
for (int i = 1; i <= MAX_WORKSPACES; ++i) {
QString numberString = QString::number(i);
QString defaultName = "Workspace" + numberString;
QString defaultIconName = "Icon" + numberString;
m_settings->setValue(defaultName, m_names.at(i-1));
m_settings->setValue(defaultIconName, m_iconNames.at(i-1));
}
m_settings->endGroup();
}
void WorkspaceSettings::finish()
{
delete m_page;
}
void WorkspaceSettings::textEdited(QString name)
{
m_page->workspaceComboBox->setItemText(m_currentIndex, m_page->nameEdit->text());
}
void WorkspaceSettings::numberOfWorkspacesChanged(int value)
{
int count = m_page->workspaceComboBox->count();
if (value > count) {
for (int i = count; i < value; ++i) {
m_page->workspaceComboBox->addItem(QIcon(m_iconNames.at(i)), m_names.at(i));
}
} else if (value < count){
for (int i = count-1; i >= value; --i) {
m_page->workspaceComboBox->removeItem(i);
}
}
}
void WorkspaceSettings::selectWorkspace(int index)
{
// write old values of workspace not shown anymore
m_iconNames.replace(m_currentIndex, m_page->iconEdit->text());
m_names.replace(m_currentIndex, m_page->nameEdit->text());
m_page->workspaceComboBox->setItemIcon(m_currentIndex, QIcon(m_page->iconEdit->text()));
m_page->workspaceComboBox->setItemText(m_currentIndex, m_page->nameEdit->text());
// display current workspace
QString iconName = m_iconNames.at(index);
m_page->iconEdit->setText(iconName);
m_page->iconLabel->setPixmap(QIcon(iconName).pixmap(16, 16));
m_page->nameEdit->setText(m_names.at(index));
m_currentIndex = index;
}

View File

@ -0,0 +1,81 @@
/**
******************************************************************************
*
* @file workspacesettings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup coreplugin
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef WORKSPACESETTINGS_H
#define WORKSPACESETTINGS_H
#include <coreplugin/dialogs/ioptionspage.h>
#include <QtCore/QObject>
#include <QtCore/QStringList>
class QSettings;
namespace Core {
namespace Internal {
namespace Ui {
class WorkspaceSettings;
}
class WorkspaceSettings : public IOptionsPage
{
Q_OBJECT
public:
WorkspaceSettings(QObject *parent = 0);
~WorkspaceSettings();
// IOptionsPage
QString id() const;
QString trName() const;
QString category() const;
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void apply();
void finish();
signals:
public slots:
void selectWorkspace(int index);
void numberOfWorkspacesChanged(int value);
void textEdited(QString string);
private:
Ui::WorkspaceSettings *m_page;
QSettings *m_settings;
QStringList m_iconNames;
QStringList m_names;
int m_currentIndex;
static const int MAX_WORKSPACES;
};
} // namespace Internal
} // namespace Core
#endif // WORKSPACESETTINGS_H

View File

@ -0,0 +1,200 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Core::Internal::WorkspaceSettings</class>
<widget class="QWidget" name="Core::Internal::WorkspaceSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>371</width>
<height>101</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Workspaces</string>
</property>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>331</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Number of workspaces:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="numberOfWorkspacesSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="value">
<number>2</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget_2">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>331</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="workspaceComboBox"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<zorder>horizontalLayoutWidget</zorder>
<zorder>horizontalLayoutWidget_2</zorder>
<zorder>horizontalLayoutWidget_3</zorder>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>371</width>
<height>111</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Details</string>
</property>
<widget class="QWidget" name="horizontalLayoutWidget_3">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>331</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Icon:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="iconEdit"/>
</item>
<item>
<widget class="QLabel" name="iconLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="chooseIconButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Choose</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget_4">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>331</width>
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="nameEdit"/>
</item>
</layout>
</widget>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>20</x>
<y>240</y>
<width>311</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt; A restart is needed for changes to take effect.</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>