diff options
author | Rainer Keller <rainer.keller@nokia.com> | 2011-03-14 15:23:45 +0100 |
---|---|---|
committer | Rainer Keller <rainer.keller@nokia.com> | 2011-04-14 14:30:38 +0200 |
commit | 46c1b55b84ba7e681d068e502af0f29707bed8d5 (patch) | |
tree | 81bfda0416a1e62ed3f033a8643e4eee1479f653 | |
parent | 23dfe88fa96a3fc573c7010ee9ef05726a0143b5 (diff) |
Implement new UI behaviour
Task-number: QTSIM-160
Reviewed-by: owolff
-rw-r--r-- | src/ui/applicationui.cpp | 99 | ||||
-rw-r--r-- | src/ui/applicationui.h | 65 | ||||
-rw-r--r-- | src/ui/cameraui.cpp | 1 | ||||
-rw-r--r-- | src/ui/cameraui.h | 1 | ||||
-rw-r--r-- | src/ui/configurationwidget.cpp | 510 | ||||
-rw-r--r-- | src/ui/configurationwidget.h | 121 | ||||
-rw-r--r-- | src/ui/contactsui.h | 1 | ||||
-rw-r--r-- | src/ui/docgalleryui.cpp | 1 | ||||
-rw-r--r-- | src/ui/docgalleryui.h | 1 | ||||
-rw-r--r-- | src/ui/feedbackui.cpp | 1 | ||||
-rw-r--r-- | src/ui/mainwindow.cpp | 84 | ||||
-rw-r--r-- | src/ui/mainwindow.h | 5 | ||||
-rw-r--r-- | src/ui/messagingui.h | 1 | ||||
-rw-r--r-- | src/ui/nfcui.cpp | 3 | ||||
-rw-r--r-- | src/ui/organizerui.cpp | 3 | ||||
-rw-r--r-- | src/ui/sensorsui.cpp | 1 | ||||
-rw-r--r-- | src/ui/sensorsui.h | 1 | ||||
-rw-r--r-- | src/ui/systeminfogenericui.cpp | 1 | ||||
-rw-r--r-- | src/ui/systeminfonetworkui.cpp | 1 | ||||
-rw-r--r-- | src/ui/systeminfonetworkui.h | 1 | ||||
-rw-r--r-- | src/ui/systeminfostorageui.cpp | 1 | ||||
-rw-r--r-- | src/ui/ui.pri | 10 | ||||
-rw-r--r-- | src/ui/viewui.cpp | 489 | ||||
-rw-r--r-- | src/ui/viewui.h | 130 |
24 files changed, 849 insertions, 683 deletions
diff --git a/src/ui/applicationui.cpp b/src/ui/applicationui.cpp new file mode 100644 index 0000000..316b323 --- /dev/null +++ b/src/ui/applicationui.cpp @@ -0,0 +1,99 @@ +/************************************************************************** +** +** This file is part of Qt Simulator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "applicationui.h" + +#include <remotecontrolwidget/optionsitem.h> +#include <QtGui/QLineEdit> +#include <QtGui/QHBoxLayout> +#include <QtGui/QPushButton> +#include <QtGui/QMenuBar> +#include "widget.h" + +ApplicationUi::ApplicationUi(QWidget *parent) : + ToolBoxPage(parent) +{ + QStringList tags; + QList<OptionsItem *> optionsList; + OptionsItem *item; + + mWidgetTitle = new QLineEdit(); + mWidgetTitle->setReadOnly(true); + item = new OptionsItem(tr("Topmost widget's title"), mWidgetTitle); + item->setTags(QStringList() << "topmost" << "wigdet" << "title"); + optionsList << item; + + QWidget *widget = new QWidget; + mMenuLayout = new QHBoxLayout(); + widget->setLayout(mMenuLayout); + item = new OptionsItem(tr("Application's menubar"), widget); + item->setTags(QStringList() << "menubar"); + optionsList << item; + + QPushButton *exitButton = new QPushButton(tr("Quit")); + item->setTags(QStringList() << "quit"); + item = new OptionsItem(tr("Quit current application"), exitButton); + optionsList << item; + + connect(exitButton, SIGNAL(clicked()), SIGNAL(exitButtonClicked())); + + setTitle(tr("Application")); + setOptions(optionsList); +} + +void ApplicationUi::updateMenuBarWidget(Widget *menuBarWidget) +{ + QMenuBar *menuBar = 0; + if (menuBarWidget) { + menuBar = menuBarWidget->menuBar(); + mWidgetTitle->setText(menuBarWidget->title); + } else { + mWidgetTitle->setText(QString()); + } + + if (mMenuBar == menuBar) + return; + + if (mMenuBar) { + mMenuBar->hide(); + mMenuLayout->removeWidget(mMenuBar); + } + + mMenuBar = menuBar; + if (!menuBar) + return; + + mMenuLayout->insertWidget(0, mMenuBar); + mMenuBar->show(); +} + diff --git a/src/ui/applicationui.h b/src/ui/applicationui.h new file mode 100644 index 0000000..1785f2f --- /dev/null +++ b/src/ui/applicationui.h @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of Qt Simulator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef APPLICATIONUI_H +#define APPLICATIONUI_H + +#include <remotecontrolwidget/toolbox.h> +#include <QtCore/QPointer> + +class QLineEdit; +class QHBoxLayout; +class Widget; +class QMenuBar; + +class ApplicationUi : public ToolBoxPage +{ + Q_OBJECT +public: + explicit ApplicationUi(QWidget *parent = 0); + +public slots: + void updateMenuBarWidget(Widget *menuBarWidget); + +signals: + void exitButtonClicked(); + +private: + QLineEdit *mWidgetTitle; + QHBoxLayout *mMenuLayout; + QPointer<QMenuBar> mMenuBar; + + +}; + +#endif // APPLICATIONUI_H diff --git a/src/ui/cameraui.cpp b/src/ui/cameraui.cpp index 7943f2d..55da83d 100644 --- a/src/ui/cameraui.cpp +++ b/src/ui/cameraui.cpp @@ -33,6 +33,7 @@ #include "cameraui.h" #include "configurationwidget.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QMetaEnum> #include <QtGui/QComboBox> diff --git a/src/ui/cameraui.h b/src/ui/cameraui.h index 5f0eaf1..f05e0c1 100644 --- a/src/ui/cameraui.h +++ b/src/ui/cameraui.h @@ -39,7 +39,6 @@ #include <remotecontrolwidget/toolbox.h> -class ConfigurationWidget; class QComboBox; class QLineEdit; class QPushButton; diff --git a/src/ui/configurationwidget.cpp b/src/ui/configurationwidget.cpp index d8ca5f7..668fe44 100644 --- a/src/ui/configurationwidget.cpp +++ b/src/ui/configurationwidget.cpp @@ -32,528 +32,20 @@ **************************************************************************/ #include "configurationwidget.h" -#include "ui_inspector.h" -#include "configurationreader.h" -#include "qsimulatordata_p.h" -#include "viewconfiguration.h" -#include "widget.h" -#include "application.h" -#include "deviceitem.h" - -#include <qmath.h> -#include <QtCore/QSettings> -#include <QtCore/QThread> -#include <QtCore/QDir> -#include <QtCore/QMetaEnum> -#include <QtGui/QDesktopWidget> -#include <QtGui/QScrollBar> -#include <QtGui/QMessageBox> -#include <QtGui/QToolButton> #include <QtGui/QCloseEvent> -#include <QtGui/QMenuBar> -#include <QtGui/QPushButton> - -Q_DECLARE_METATYPE(Orientation); -ConfigurationWidget::ConfigurationWidget(const DeviceItem *deviceItem, QWidget *parent) +ConfigurationWidget::ConfigurationWidget(QWidget *parent) : RemoteControlWidget(parent) - , ui_inspector(new Ui_Inspector) - , mCorrectionFactor(1) - , mViewConfiguration(0) - , mDeviceItem(deviceItem) - , mOrientationLocked(false) { - qRegisterMetaType<Orientation>(); - - QDesktopWidget *desktop = QApplication::desktop(); - mLogicalDpi.setWidth(desktop->logicalDpiX()); - mLogicalDpi.setHeight(desktop->logicalDpiY()); - setWindowTitle(tr("Qt Simulator Control")); - - mScriptInterface = new SimulatorScriptInterface(this); - - initializeApplicationArea(); - initializeViewArea(); } ConfigurationWidget::~ConfigurationWidget() { } -void ConfigurationWidget::initializeViewArea() -{ - QWidget *target = new QWidget(); - ui_inspector->setupUi(target); - - mOrientationButtons = new QButtonGroup; - mOrientationButtons->setParent(ui_inspector->topUp->parent()); - mOrientationButtons->addButton(ui_inspector->topUp, static_cast<int>(topUp)); - mOrientationButtons->addButton(ui_inspector->rightUp, static_cast<int>(rightUp)); - mOrientationButtons->addButton(ui_inspector->topDown, static_cast<int>(topDown)); - mOrientationButtons->addButton(ui_inspector->leftUp, static_cast<int>(leftUp)); - connect(mOrientationButtons, SIGNAL(buttonClicked(int)), this, SLOT(changeOrientation(int))); - - updateOrientationsButtonsIcons(false); - - connect(ui_inspector->scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(changeScaleFactor(int))); - connect(ui_inspector->deviceListView, SIGNAL(currentIndexChanged(int)), this, SLOT(changeDeviceSelection(int))); - - connect(ui_inspector->rotateScreen, SIGNAL(toggled(bool)), - this, SLOT(rotateScreenToggled())); - - mViewPage = new PageWidget(tr("View"), target); - mViewPage->setHideable(true); - mViewPage->setHasAdvancedButton(true); - mViewPage->advancedButton()->setToolTip(tr("Configure DPI correction")); - - connect(mViewPage, SIGNAL(advancedButtonClicked()), SLOT(showViewConfiguration())); - addPage(mViewPage); -} - -void ConfigurationWidget::initializeApplicationArea() -{ - QWidget *target = new QWidget(); - QFormLayout *innerLayout = new QFormLayout(); - mWidgetTitle = new QLineEdit(); - mWidgetTitle->setReadOnly(true); - innerLayout->addRow(tr("Topmost widget's title"), mWidgetTitle); - mMenuLayout = new QHBoxLayout(); - innerLayout->addRow(tr("Application's menubar"), mMenuLayout); - QPushButton *exitButton = new QPushButton(tr("Quit")); - connect(exitButton, SIGNAL(clicked()), SIGNAL(exitButtonClicked())); - innerLayout->addRow(tr("Quit current application"), exitButton); - target->setLayout(innerLayout); - - mAppPage = new PageWidget(tr("Application"), target); - mAppPage->setHideable(true); - mAppPage->hideContent(); - addPage(mAppPage); -} - -int ConfigurationWidget::currentDeviceIndex() const -{ - return ui_inspector->deviceListView->currentIndex(); -} - -QString ConfigurationWidget::currentDeviceName() const -{ - return ui_inspector->deviceListView->currentText(); -} - -void ConfigurationWidget::changeDeviceSelection(int newIndex) -{ - ui_inspector->deviceListView->setCurrentIndex(newIndex); - const DeviceData &newData = deviceList.at(newIndex); - emit deviceSelectionChanged(newData); - updateOrientationButtons(newData); - changeScaleFactor(ui_inspector->scaleSlider->value()); -} - -void ConfigurationWidget::updateMenuBarWidget(Widget *menuBarWidget) -{ - QMenuBar *menuBar = 0; - if (menuBarWidget) { - menuBar = menuBarWidget->menuBar(); - mWidgetTitle->setText(menuBarWidget->title); - } else { - mWidgetTitle->setText(QString()); - } - - if (mMenuBar == menuBar) - return; - - if (mMenuBar) { - mMenuBar->hide(); - mMenuLayout->removeWidget(mMenuBar); - } - - mMenuBar = menuBar; - if (!menuBar) - return; - - mMenuLayout->insertWidget(0, mMenuBar); - mMenuBar->show(); -} - -void ConfigurationWidget::updateOrientationButtonsState(Orientation orientation) -{ - mOrientationButtons->button(orientation)->setChecked(true); -} - -void ConfigurationWidget::updateOrientationsButtonsIcons(bool standardOrientationPortrait) -{ - if (standardOrientationPortrait) { - ui_inspector->topUp->setIcon(QIcon(":/ui/icons/topup.png")); - ui_inspector->topDown->setIcon(QIcon(":/ui/icons/topdown.png")); - ui_inspector->leftUp->setIcon(QIcon(":/ui/icons/leftup.png")); - ui_inspector->rightUp->setIcon(QIcon(":/ui/icons/rightup.png")); - } else { - ui_inspector->topUp->setIcon(QIcon(":/ui/icons/topup_landscape.png")); - ui_inspector->topDown->setIcon(QIcon(":/ui/icons/topdown_landscape.png")); - ui_inspector->leftUp->setIcon(QIcon(":/ui/icons/leftup_landscape.png")); - ui_inspector->rightUp->setIcon(QIcon(":/ui/icons/rightup_landscape.png")); - } -} - -void ConfigurationWidget::updateOrientationButtons(const DeviceData &data) -{ - const bool rotateScreen = ui_inspector->rotateScreen->isChecked(); - - if (!rotateScreen || mOrientationLocked) { - ui_inspector->topUp->setEnabled(true); - ui_inspector->leftUp->setEnabled(true); - ui_inspector->rightUp->setEnabled(true); - ui_inspector->topDown->setEnabled(true); - } else { - ui_inspector->topUp->setEnabled(data.supportedOrientations & topUp); - ui_inspector->leftUp->setEnabled(data.supportedOrientations & leftUp); - ui_inspector->rightUp->setEnabled(data.supportedOrientations & rightUp); - ui_inspector->topDown->setEnabled(data.supportedOrientations & topDown); - } - - if (!mOrientationButtons->checkedButton()->isEnabled() && !data.menus.isEmpty() && !mOrientationLocked) { - Orientation fallback = data.menus.begin().key(); - if (data.supportedOrientations & fallback) - mOrientationButtons->button(fallback)->click(); - } -} - -void ConfigurationWidget::rotateScreenToggled() -{ - updateOrientationButtons(deviceList.at(currentDeviceIndex())); - - emit orientationChangeRequested(static_cast<Orientation>(mOrientationButtons->checkedId()), - ui_inspector->rotateScreen->isChecked()); -} - -void ConfigurationWidget::initializeSelection() -{ - if (deviceList.count() == 0) - return; - - ui_inspector->deviceListView->setCurrentIndex(0); - changeDeviceSelection(0); -} - -void ConfigurationWidget::changeScaleFactor(int sliderPosition) -{ - int index = currentDeviceIndex(); - if (index < 0 || index >= deviceList.size()) - return; - - const DeviceData &data = deviceList.at(index); - qreal pixelDiagonal = sqrt(pow((qreal)data.resolution.width(), 2) + pow((qreal)data.resolution.height(), 2)); - qreal displayWidthInInch = data.diagonalInInch / pixelDiagonal * data.resolution.width(); - - qreal minimalScale = mLogicalDpi.width() * displayWidthInInch / data.resolution.width() * mCorrectionFactor; - - emit scaleFactorChanged((minimalScale + qreal(sliderPosition) / 100. * (1. - minimalScale))); -} - -void ConfigurationWidget::changeCorrectionFactor(qreal newFactor) -{ - mCorrectionFactor = newFactor; - changeScaleFactor(ui_inspector->scaleSlider->value()); -} - void ConfigurationWidget::closeEvent(QCloseEvent *event) { event->ignore(); emit closeMainWindow(); } - -void ConfigurationWidget::writeSettings(const QString &vendor, const QString &name) const -{ - RemoteControlWidget::writeSettings(vendor, name); - - QSettings settings(vendor, name); - - settings.beginGroup("ConfigurationWidget"); - settings.setValue("scale", ui_inspector->scaleSlider->value()); - settings.setValue("corrfactor", mCorrectionFactor); - settings.setValue("viewPageVisible", mViewPage->isContentVisible()); - settings.setValue("appPageVisible", mAppPage->isContentVisible()); - settings.setValue("rotateScreen", ui_inspector->rotateScreen->isChecked()); - - int index = currentDeviceIndex(); - if (index >= 0 && index < deviceList.size()) - settings.setValue("device", deviceList.at(index).name); - - settings.endGroup(); -} - -void ConfigurationWidget::readSettings(const QString &vendor, const QString &name) -{ - RemoteControlWidget::readSettings(vendor, name); - - QSettings settings(vendor, name); - - settings.beginGroup("ConfigurationWidget"); - - bool deviceFound = false; - if (settings.contains("device")) { - QString deviceName = settings.value("device").toString(); - for (int i = 0; i < deviceList.size(); ++i) { - if (deviceList.at(i).name == deviceName) { - ui_inspector->deviceListView->setCurrentIndex(i); - changeDeviceSelection(i); - deviceFound = true; - break; - } - } - } - if (!deviceFound) - initializeSelection(); - - if (settings.contains("scale")) - ui_inspector->scaleSlider->setValue(settings.value("scale").toInt()); - if (settings.contains("corrfactor")) { - changeCorrectionFactor(settings.value("corrfactor").toDouble()); - } - if (settings.contains("viewPageVisible")) { - bool viewPageVisible = settings.value("viewPageVisible").toBool(); - if (viewPageVisible) - mViewPage->showContent(); - else - mViewPage->hideContent(); - } - if (settings.contains("appPageVisible")) { - bool appPageVisible = settings.value("appPageVisible").toBool(); - if (appPageVisible) - mAppPage->showContent(); - else - mAppPage->hideContent(); - } - if (settings.contains("rotateScreen")) - ui_inspector->rotateScreen->setChecked(settings.value("rotateScreen").toBool()); - - settings.endGroup(); -} - -void ConfigurationWidget::showViewConfiguration() -{ - if (!mViewConfiguration) { - mViewConfiguration = new ViewConfiguration(mCorrectionFactor, this); - connect(mViewConfiguration, SIGNAL(correctionFactorChanged(qreal)), SLOT(changeCorrectionFactor(qreal))); - } - - mViewConfiguration->exec(); - -} - -void ConfigurationWidget::changeOrientation(int orientation) -{ - emit orientationChangeRequested(static_cast<Orientation>(orientation), ui_inspector->rotateScreen->isChecked()); -} - -bool ConfigurationWidget::initializeDeviceList() -{ - QDir modelsDir("models"); - if (!modelsDir.exists()) { - QMessageBox errorMsg; - errorMsg.setWindowTitle(tr("Folder does not exist")); - errorMsg.setText(tr("The \"%1\" folder could not be located in the installation directory.").arg(modelsDir.dirName())); - errorMsg.setIcon(QMessageBox::Critical); - errorMsg.exec(); - return false; - } - - ConfigurationReader confReader; - deviceList.clear(); - bool noErrors = confReader.processDir(&modelsDir, deviceList); - if (!noErrors && !deviceList.isEmpty()) { - QMessageBox msgbox; - msgbox.setWindowTitle(tr("Errors occurred while reading device configurations")); - msgbox.setText(confReader.errorMessageLines()); - msgbox.setIcon(QMessageBox::Critical); - msgbox.exec(); - } - - if (deviceList.isEmpty()) { - QMessageBox errorMsg; - errorMsg.setWindowTitle(tr("Devices could not be found")); - QString msg; - if (!noErrors) { - msg = confReader.errorMessageLines(); - } - msg += tr("No valid device configuration files (.config) could be found in the \"%1\" folder.").arg(modelsDir.dirName()); - errorMsg.setText(msg); - errorMsg.setIcon(QMessageBox::Critical); - errorMsg.exec(); - return false; - } - - foreach (const DeviceData &data, deviceList) - ui_inspector->deviceListView->addItem(data.name); - return true; -} - -SimulatorScriptInterface *ConfigurationWidget::scriptInterface() -{ - return mScriptInterface; -} - -SimulatorScriptInterface::SimulatorScriptInterface(ConfigurationWidget *ui) - : QObject(ui), ui(ui) -{ - int enumIndex = metaObject()->indexOfEnumerator("Orientation"); - QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); - for (int i = 0; i < metaEnum.keyCount(); ++i) - setProperty(metaEnum.key(i), metaEnum.key(i)); -} - -SimulatorScriptInterface::~SimulatorScriptInterface() -{ -} - -/*! - \class SimulatorScriptInterface - \brief Exposed as simulator. -*/ - -/*! - \property SimulatorScriptInterface::zoom - - \brief the device scaling - - The value can be between between 0 for real-world size and 100 for pixel equivalence. - -*/ -int SimulatorScriptInterface::zoom() const -{ - return ui->ui_inspector->scaleSlider->value(); -} - -void SimulatorScriptInterface::setZoom(int z) -{ - if (z < 0) - z = 0; - else if (z > 100) - z = 100; - ui->ui_inspector->scaleSlider->setValue(z); -} - -/*! - Returns the index of the current device. - - \sa setDevice(), deviceCount() -*/ -int SimulatorScriptInterface::currentDeviceIndex() const -{ - return ui->currentDeviceIndex(); -} - -/*! - Returns the name of the current device. - - \sa setDevice() -*/ -QString SimulatorScriptInterface::currentDeviceName() const -{ - return ui->currentDeviceName(); -} - -/*! - Returns the number of available device models. - - \sa setDevice(), currentDeviceIndex() -*/ -int SimulatorScriptInterface::deviceCount() const -{ - return ui->deviceList.size(); -} - -/*! - Sets the current device to the one with \a index. - - \sa deviceCount(), currentDeviceIndex() -*/ -void SimulatorScriptInterface::setDevice(int index) -{ - ui->changeDeviceSelection(index); -} - -/*! - Sets the current device to be the one identified by \a dev. - - \sa currentDeviceName() -*/ -void SimulatorScriptInterface::setDevice(const QString &dev) -{ - const QList<DeviceData> &devices = ui->deviceList; - for (int i = 0; i < devices.size(); ++i) { - if (devices.at(i).name == dev) { - ui->changeDeviceSelection(i); - break; - } - } -} - -/*! - Rotates the current device, and - optionally - the screen. Returns true on success. -*/ -bool SimulatorScriptInterface::setDeviceOrientation(QString newOrientation, bool rotateScreen) -{ - const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); - const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); - - int orientation = metaEnum.keyToValue(newOrientation.toLatin1()); - - if (QAbstractButton *button = ui->mOrientationButtons->button(orientation)) { - ui->ui_inspector->rotateScreen->setChecked(rotateScreen); - if (!button->isEnabled()) - return false; - button->click(); - return true; - } - return false; -} - -/*! - Returns the current device orientation. -*/ -QString SimulatorScriptInterface::deviceOrientation() const -{ - const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); - const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); - - return metaEnum.valueToKey(ui->mDeviceItem->deviceOrientation()); -} - -/*! - Returns the current screen orientation. -*/ -QString SimulatorScriptInterface::screenOrientation() const -{ - const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); - const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); - - return metaEnum.valueToKey(ui->mDeviceItem->screenOrientation()); -} - -/*! - Returns the list of screen orientations. -*/ -QStringList SimulatorScriptInterface::supportedScreenOrientations() const -{ - const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); - const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); - - QStringList ret; - foreach (::Orientation o, ui->mDeviceItem->supportedScreenOrientations()) - ret.append(metaEnum.valueToKey(o)); - - return ret; -} - -void ConfigurationWidget::setOrientationLocked(bool locked) -{ - mOrientationLocked = locked; - ui_inspector->rotateScreen->setDisabled(locked); - updateOrientationButtons(deviceList.at(currentDeviceIndex())); - if (!locked) { - emit orientationChangeRequested(static_cast<Orientation>(mOrientationButtons->checkedId()), - ui_inspector->rotateScreen->isChecked()); - } -} diff --git a/src/ui/configurationwidget.h b/src/ui/configurationwidget.h index c65b9b0..6d7b1a5 100644 --- a/src/ui/configurationwidget.h +++ b/src/ui/configurationwidget.h @@ -34,139 +34,20 @@ #ifndef CONFIGURATIONWIDGET_H #define CONFIGURATIONWIDGET_H -#include "deviceitem.h" - #include <remotecontrolwidget/remotecontrolwidget.h> -#include <QtGui/QWidget> -#include <QtCore/QPointer> - -class Ui_Inspector; -class OptionsItem; -class FilterLineEdit; -class MobilityData; -class ToolBox; -class ToolBoxPage; -class StyledBar; -class QToolButton; -class QMenuBar; -class ViewConfiguration; -class QLineEdit; -class QPushButton; -class QButtonGroup; -class Widget; -class DeviceItem; -class SimulatorScriptInterface; - class ConfigurationWidget: public RemoteControlWidget { Q_OBJECT public: - explicit ConfigurationWidget(const DeviceItem *deviceItem, QWidget *parent = 0); + explicit ConfigurationWidget(QWidget *parent = 0); ~ConfigurationWidget(); - SimulatorScriptInterface *scriptInterface(); - - void initializeSelection(); - - int currentDeviceIndex() const; - QString currentDeviceName() const; - - bool initializeDeviceList(); - - virtual void writeSettings(const QString &vendor, const QString &name) const; - virtual void readSettings(const QString &vendor, const QString &name); - -public slots: - void changeDeviceSelection(int newIndex); - void updateMenuBarWidget(Widget *menuBarWidget); - void updateOrientationButtonsState(Orientation orientation); - void updateOrientationsButtonsIcons(bool standardOrientationPortrait); - void setOrientationLocked(bool locked); - signals: - void deviceSelectionChanged(const DeviceData &data); - void scaleFactorChanged(qreal newScaleFactor); - void orientationChangeRequested(Orientation newOrientation, bool rotateScreen); - void rotateRequested(); void closeMainWindow(); - void exitButtonClicked(); protected: virtual void closeEvent(QCloseEvent *event); - -private slots: - void changeScaleFactor(int sliderPosition); - void changeCorrectionFactor(qreal); - void changeOrientation(int orientation); - void showViewConfiguration(); - void updateOrientationButtons(const DeviceData &data); - void rotateScreenToggled(); - -private: - void initializeViewArea(); - void initializeApplicationArea(); - - QList<DeviceData> deviceList; - - Ui_Inspector *ui_inspector; - QButtonGroup *mOrientationButtons; - - qreal mCorrectionFactor; - QSize mLogicalDpi; - - QToolButton *viewButton; - - ViewConfiguration *mViewConfiguration; - QHBoxLayout *mMenuLayout; - QLineEdit *mWidgetTitle; - - PageWidget *mAppPage; - PageWidget *mViewPage; - - QPointer<QMenuBar> mMenuBar; - - const DeviceItem *mDeviceItem; - bool mOrientationLocked; - - SimulatorScriptInterface *mScriptInterface; - friend class SimulatorScriptInterface; -}; - -class SimulatorScriptInterface : public QObject -{ - Q_OBJECT -public: - SimulatorScriptInterface(ConfigurationWidget *ui); - virtual ~SimulatorScriptInterface(); - - // must mimic ::Orientation - enum Orientation { - topUp = 0x0000001, - topDown = 0x0000002, - leftUp = 0x0000004, - rightUp = 0x0000008, - }; - Q_ENUMS(Orientation); - - Q_PROPERTY(int zoom READ zoom WRITE setZoom) - - int zoom() const; - void setZoom(int z); - - Q_INVOKABLE int currentDeviceIndex() const; - Q_INVOKABLE QString currentDeviceName() const; - Q_INVOKABLE int deviceCount() const; - Q_INVOKABLE void setDevice(const QString &dev); - Q_INVOKABLE void setDevice(int index); - - Q_INVOKABLE QString deviceOrientation() const; - Q_INVOKABLE QString screenOrientation() const; - Q_INVOKABLE QStringList supportedScreenOrientations() const; - Q_INVOKABLE bool setDeviceOrientation(QString orientation, bool rotateScreen); - -private: - ConfigurationWidget *ui; }; #endif //CONFIGURATIONWIDGET_H diff --git a/src/ui/contactsui.h b/src/ui/contactsui.h index e9f41e9..3844a34 100644 --- a/src/ui/contactsui.h +++ b/src/ui/contactsui.h @@ -38,7 +38,6 @@ #include <QtCore/QObject> -class ConfigurationWidget; class Contacts; class QTableWidget; diff --git a/src/ui/docgalleryui.cpp b/src/ui/docgalleryui.cpp index f47311b..63e3c0c 100644 --- a/src/ui/docgalleryui.cpp +++ b/src/ui/docgalleryui.cpp @@ -32,6 +32,7 @@ **************************************************************************/ #include "docgalleryui.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtGui/QTreeWidget> #include <QtGui/QPushButton> diff --git a/src/ui/docgalleryui.h b/src/ui/docgalleryui.h index 901a108..54d1f45 100644 --- a/src/ui/docgalleryui.h +++ b/src/ui/docgalleryui.h @@ -34,7 +34,6 @@ #ifndef DOCGALLERYUI_H #define DOCGALLERYUI_H -#include <QObject> #include <remotecontrolwidget/toolbox.h> #include <gallery/simulator/docgallerysimulatordata.h> #include <QtCore/QFutureWatcher> diff --git a/src/ui/feedbackui.cpp b/src/ui/feedbackui.cpp index e2b38e6..05036d3 100644 --- a/src/ui/feedbackui.cpp +++ b/src/ui/feedbackui.cpp @@ -33,6 +33,7 @@ #include "feedbackui.h" #include "feedback.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtGui/QComboBox> #include <QtGui/QBoxLayout> diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 93d23c2..5c77811 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -41,6 +41,8 @@ #include "mobilitydata.h" #include "qtsingleapplication.h" +#include "viewui.h" +#include "applicationui.h" #include "contactsui.h" #include "systeminfogenericui.h" #include "systeminfonetworkui.h" @@ -156,6 +158,7 @@ MainWindow::MainWindow(QWidget *parent) connect(applicationManager, SIGNAL(softkeyTextSizeChanged(double)), mDeviceItem, SLOT(setSymbianSoftKeyTextSize(double))); connect(widgetManager, SIGNAL(symbianSoftKeyTextChanged(int,QString)), mDeviceItem, SLOT(setSymbianSoftKeyText(int,QString))); connect(widgetManager, SIGNAL(maemoNavigationChanged(MaemoNavigationMode)), mDeviceItem, SLOT(setMaemoNavigationMode(MaemoNavigationMode))); + connect(widgetManager, SIGNAL(topOrientationChanged(Qt::WidgetAttribute)), mDeviceItem, SLOT(updateOrientation(Qt::WidgetAttribute))); connect(mDeviceItem, SIGNAL(deviceChanged(QSize,DeviceData)), applicationManager, SLOT(updateDisplayInformation(QSize,DeviceData))); connect(mDeviceItem, SIGNAL(drag(QPoint)), this, SLOT(dragFromView(QPoint))); connect(mDeviceItem, SIGNAL(viewSizeRequired(QSize)), this, SLOT(setViewSize(QSize))); @@ -182,75 +185,74 @@ MainWindow::MainWindow(QWidget *parent) debugWindow->setLayout(layout); // Setup configuration window. - config = new ConfigurationWidget(mDeviceItem, this); + config = new ConfigurationWidget(this); config->setWindowFlags(Qt::Window); - if (!config->initializeDeviceList()) { - QTimer::singleShot(0, this, SLOT(close())); - startupError = true; - return; - } - connect(widgetManager, SIGNAL(topWidgetChanged(Widget *)), config, SLOT(updateMenuBarWidget(Widget *))); - connect(widgetManager, SIGNAL(topOrientationChanged(Qt::WidgetAttribute)), mDeviceItem, SLOT(updateOrientation(Qt::WidgetAttribute))); - connect(mDeviceItem, SIGNAL(orientationLocked(bool)), config, SLOT(setOrientationLocked(bool))); - connect(config, SIGNAL(deviceSelectionChanged(const DeviceData &)), mDeviceItem, SLOT(changeDevice(const DeviceData &))); connect(mDeviceItem, SIGNAL(sizeChanged(const QSize &)), this, SLOT(setSizeToDevice(const QSize &))); - connect(mDeviceItem, SIGNAL(orientationChanged(Orientation)), config, SLOT(updateOrientationButtonsState(Orientation))); - connect(mDeviceItem, SIGNAL(deviceChanged(bool)), config, SLOT(updateOrientationsButtonsIcons(bool))); connect(config, SIGNAL(closeMainWindow()), this, SLOT(close())); - connect(config, SIGNAL(orientationChangeRequested(Orientation, bool)), - mDeviceItem, SLOT(changeOrientation(Orientation, bool))); - connect(config, SIGNAL(scaleFactorChanged(qreal)), mDeviceItem, SLOT(changeScaleFactor(qreal))); - connect(config, SIGNAL(exitButtonClicked()), applicationManager, SLOT(killCurrentApplication())); scriptAdapter = new ScriptAdapter(this); // build ui pages + ViewUi *viewUi = new ViewUi(mDeviceItem, this); + if (!viewUi->initializeDeviceList()) { + QTimer::singleShot(0, this, SLOT(close())); + startupError = true; + return; + } + config->addPage(viewUi); + connect(mDeviceItem, SIGNAL(orientationLocked(bool)), viewUi, SLOT(setOrientationLocked(bool))); + + ApplicationUi *applicationUi = new ApplicationUi(this); + config->addPage(applicationUi); + connect(applicationUi, SIGNAL(exitButtonClicked()), applicationManager, SLOT(killCurrentApplication())); + connect(widgetManager, SIGNAL(topWidgetChanged(Widget *)), applicationUi, SLOT(updateMenuBarWidget(Widget *))); + GenericSystemInfoUi *genericSystemInfoUi = new GenericSystemInfoUi(this); mobility->mSystemInfoGenericUi = genericSystemInfoUi; - config->addSimulateSubPage(genericSystemInfoUi); + config->addPage(genericSystemInfoUi); StorageSystemInfoUi *storageSystemInfoUi = new StorageSystemInfoUi(this); mobility->mSystemInfoStorageUi = storageSystemInfoUi; - config->addSimulateSubPage(storageSystemInfoUi); + config->addPage(storageSystemInfoUi); NetworkSystemInfoUi *networkSystemInfoUi = new NetworkSystemInfoUi(this); mobility->mSystemInfoNetworkUi = networkSystemInfoUi; - config->addSimulateSubPage(networkSystemInfoUi); + config->addPage(networkSystemInfoUi); LocationUi *locationUi = new LocationUi(this); mobility->mLocationUi = locationUi; - config->addSimulateSubPage(locationUi); + config->addPage(locationUi); - config->addSimulateSubPage(new ContactsUi(mobility->mContacts, this)); - config->addSimulateSubPage(new MessagingUi(mobility, this)); + config->addPage(new ContactsUi(mobility->mContacts, this)); + config->addPage(new MessagingUi(mobility, this)); SensorsUi *sensorsUi = new SensorsUi(this); mobility->mSensorsUi = sensorsUi; - config->addSimulateSubPage(sensorsUi); + config->addPage(sensorsUi); connect(mDeviceItem, SIGNAL(deviceChanged(bool)), sensorsUi, SLOT(updateDeviceDefaultOrientation(bool))); OrganizerUi *organizerUi = new OrganizerUi(mobility->mOrganizer, this); - config->addSimulateSubPage(organizerUi); + config->addPage(organizerUi); FeedbackUi *feedbackUi = new FeedbackUi(mobility->mFeedback, this); - config->addSimulateSubPage(feedbackUi); + config->addPage(feedbackUi); DocGalleryUi *docgalleryUi = new DocGalleryUi(this); mobility->mDocGalleryUi = docgalleryUi; - config->addSimulateSubPage(docgalleryUi); + config->addPage(docgalleryUi); CameraUi *cameraUi = new CameraUi(this); mobility->mCameraUi = cameraUi; - config->addSimulateSubPage(cameraUi); + config->addPage(cameraUi); NfcUi *nfcUi = new NfcUi(this); mobility->mNfcUi = nfcUi; - config->addSimulateSubPage(nfcUi); + config->addPage(nfcUi); ScriptUi *scriptUi = new ScriptUi(scriptAdapter, this); FavoriteScriptButton *scriptButton = new FavoriteScriptButton(this); setupScriptDirectories(scriptUi, scriptButton); - config->addSimulateSubPage(scriptUi); + config->addPage(scriptUi); NetworkModeButton *networkModeButton = new NetworkModeButton(this); connect(networkModeButton, SIGNAL(networkModeChanged(NetworkModeButton::NetworkMode)), @@ -288,7 +290,7 @@ MainWindow::MainWindow(QWidget *parent) InputScriptInterface *inputScriptInterface = new InputScriptInterface(this, view->viewport()); // register script interfaces - scriptAdapter->addScriptInterface("simulator", config->scriptInterface()); + scriptAdapter->addScriptInterface("simulator", viewUi->scriptInterface()); scriptAdapter->addScriptInterface("sensors", sensorsUi->scriptInterface()); scriptAdapter->addScriptInterface("location", locationUi->scriptInterface()); scriptAdapter->addScriptInterface("sysinfo.generic", genericSystemInfoUi->scriptInterface()); @@ -297,20 +299,23 @@ MainWindow::MainWindow(QWidget *parent) scriptAdapter->addScriptInterface("camera", cameraUi->scriptInterface()); scriptAdapter->addScriptInterface("input", inputScriptInterface); - connect(config, SIGNAL(deviceSelectionChanged(const DeviceData &)), SLOT(callDeviceScript(const DeviceData &))); + connect(viewUi, SIGNAL(deviceSelectionChanged(const DeviceData &)), SLOT(callDeviceScript(const DeviceData &))); config->setWindowFlags(Qt::Tool); - config->readSettings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); + + // read settings + QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); mobility->setInitialData(); config->show(); + config->readSettings(settings); // Filter to show debug window on special key press. view->installEventFilter(this); view->setFocus(); - readSettings(); + readSettings(settings); scriptAdapter->runAutostartScripts(); } @@ -344,8 +349,9 @@ void MainWindow::closeEvent(QCloseEvent *event) } if (!startupError) { - writeSettings(); - config->writeSettings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); + QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); + writeSettings(settings); + config->writeSettings(settings); } } @@ -416,10 +422,8 @@ void MainWindow::setViewSize(const QSize &size) view->centerOn(size.width() / 2, size.height() / 2); } -void MainWindow::writeSettings() const +void MainWindow::writeSettings(QSettings &settings) const { - QSettings settings; - settings.beginGroup("MainWindow"); settings.setValue("pos", pos()); int deviceOrientation = static_cast<int>(mDeviceItem->deviceOrientation()); @@ -429,10 +433,8 @@ void MainWindow::writeSettings() const settings.endGroup(); } -void MainWindow::readSettings() +void MainWindow::readSettings(QSettings &settings) { - QSettings settings; - settings.beginGroup("MainWindow"); QPoint positionToSet; if (settings.contains("pos")) diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 03597d9..668cf47 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -47,6 +47,7 @@ class QGraphicsScene; class ScriptUi; class FavoriteScriptButton; class InputScriptInterface; +class QSettings; extern const VersionStruct simulatorVersion; @@ -77,8 +78,8 @@ private slots: void activateWindow(); private: - void writeSettings() const; - void readSettings(); + void writeSettings(QSettings &) const; + void readSettings(QSettings &); void setupScriptDirectories(ScriptUi *ui, FavoriteScriptButton *button); private: diff --git a/src/ui/messagingui.h b/src/ui/messagingui.h index 6cd607f..09ff27b 100644 --- a/src/ui/messagingui.h +++ b/src/ui/messagingui.h @@ -39,7 +39,6 @@ #include <QtCore/QObject> class MobilityData; -class ConfigurationWidget; class MessagingUi : public ToolBoxPage { diff --git a/src/ui/nfcui.cpp b/src/ui/nfcui.cpp index e556273..4943357 100644 --- a/src/ui/nfcui.cpp +++ b/src/ui/nfcui.cpp @@ -34,6 +34,7 @@ #include "nfcui.h" #include "targetemulator_p.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QModelIndex> #include <QtCore/QDirIterator> @@ -144,7 +145,7 @@ NfcUi::NfcUi(QWidget *parent) optionsList <<new OptionsItem(QString(), mReset, true); - setTitle(tr("Near Field Communication")); + setTitle(tr("NFC")); setOptions(optionsList); } diff --git a/src/ui/organizerui.cpp b/src/ui/organizerui.cpp index e169119..40d9fff 100644 --- a/src/ui/organizerui.cpp +++ b/src/ui/organizerui.cpp @@ -34,8 +34,7 @@ #include "organizerui.h" #include "organizer.h" #include "organizertreemodel.h" - -//#include <remotecontrolwidget/optionsitem.h> +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QList> #include <QtGui/QPushButton> diff --git a/src/ui/sensorsui.cpp b/src/ui/sensorsui.cpp index 7ea6228..bfffef7 100644 --- a/src/ui/sensorsui.cpp +++ b/src/ui/sensorsui.cpp @@ -34,6 +34,7 @@ #include "sensorsui.h" #include "configurationwidget.h" #include "accelerometercontrol.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QMetaEnum> #include <QtGui/QComboBox> diff --git a/src/ui/sensorsui.h b/src/ui/sensorsui.h index 9b8a391..f5b6547 100644 --- a/src/ui/sensorsui.h +++ b/src/ui/sensorsui.h @@ -40,7 +40,6 @@ #include <remotecontrolwidget/toolbox.h> -class ConfigurationWidget; class Sensors; class QComboBox; class QLineEdit; diff --git a/src/ui/systeminfogenericui.cpp b/src/ui/systeminfogenericui.cpp index aa3ebe8..14140ab 100644 --- a/src/ui/systeminfogenericui.cpp +++ b/src/ui/systeminfogenericui.cpp @@ -32,6 +32,7 @@ **************************************************************************/ #include "systeminfogenericui.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QMetaEnum> #include <QtGui/QPushButton> diff --git a/src/ui/systeminfonetworkui.cpp b/src/ui/systeminfonetworkui.cpp index e8f2cf7..a1e704f 100644 --- a/src/ui/systeminfonetworkui.cpp +++ b/src/ui/systeminfonetworkui.cpp @@ -32,6 +32,7 @@ **************************************************************************/ #include "systeminfonetworkui.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QMetaEnum> #include <QtGui/QPushButton> diff --git a/src/ui/systeminfonetworkui.h b/src/ui/systeminfonetworkui.h index a8d881d..1323e4e 100644 --- a/src/ui/systeminfonetworkui.h +++ b/src/ui/systeminfonetworkui.h @@ -40,7 +40,6 @@ #include <QtCore/QObject> -class ConfigurationWidget; class NetworkModeButton; class SignalStrengthButton; class QLineEdit; diff --git a/src/ui/systeminfostorageui.cpp b/src/ui/systeminfostorageui.cpp index 243ec85..6b3b8e2 100644 --- a/src/ui/systeminfostorageui.cpp +++ b/src/ui/systeminfostorageui.cpp @@ -32,6 +32,7 @@ **************************************************************************/ #include "systeminfostorageui.h" +#include <remotecontrolwidget/optionsitem.h> #include <QtCore/QMetaEnum> #include <QtGui/QPushButton> diff --git a/src/ui/ui.pri b/src/ui/ui.pri index bad855e..ca2f1e5 100644 --- a/src/ui/ui.pri +++ b/src/ui/ui.pri @@ -16,7 +16,10 @@ HEADERS += applicationtablewidget.h \ docgalleryui.h \ cameraui.h \ nfcui.h \ - inputscriptinterface.h + inputscriptinterface.h \ + applicationui.h \ + viewui.h \ + SOURCES += applicationtablewidget.cpp \ mainwindow.cpp \ configurationwidget.cpp \ @@ -33,7 +36,10 @@ SOURCES += applicationtablewidget.cpp \ docgalleryui.cpp \ cameraui.cpp \ nfcui.cpp \ - inputscriptinterface.cpp + inputscriptinterface.cpp \ + applicationui.cpp \ + viewui.cpp \ + FORMS += inspector.ui \ viewconfiguration.ui diff --git a/src/ui/viewui.cpp b/src/ui/viewui.cpp new file mode 100644 index 0000000..726d58c --- /dev/null +++ b/src/ui/viewui.cpp @@ -0,0 +1,489 @@ +/************************************************************************** +** +** This file is part of Qt Simulator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include <qmath.h> +#include "viewui.h" +#include "viewconfiguration.h" +#include "ui_inspector.h" +#include "configurationreader.h" +#include <remotecontrolwidget/optionsitem.h> + +#include <QtCore/QSettings> +#include <QtGui/QDesktopWidget> +#include <QtCore/QDir> +#include <QtGui/QMessageBox> +#include <QtCore/QMetaEnum> +#include <QtGui/QPushButton> + +Q_DECLARE_METATYPE(Orientation); + +ViewUi::ViewUi(const DeviceItem *deviceItem, QWidget *parent) : + ToolBoxPage(parent) + , mCorrectionFactor(1) + , mViewConfiguration(0) + , ui_inspector(new Ui_Inspector) + , mScriptInterface(0) + , mDeviceItem(deviceItem) + , mOrientationLocked(false) +{ + qRegisterMetaType<Orientation>(); + + QDesktopWidget *desktop = QApplication::desktop(); + mLogicalDpi.setWidth(desktop->logicalDpiX()); + mLogicalDpi.setHeight(desktop->logicalDpiY()); + + mScriptInterface = new ViewScriptInterface(this); + + QStringList tags; + QList<OptionsItem *> optionsList; + OptionsItem *item; + + QWidget *target = new QWidget(); + ui_inspector->setupUi(target); + item = new OptionsItem(QString(),target, true); + item->setTags(QStringList() << tr("models") << tr("rotation") << tr("size") << tr("scale")); + optionsList << item; + + mOrientationButtons = new QButtonGroup; + mOrientationButtons->setParent(ui_inspector->topUp->parent()); + mOrientationButtons->addButton(ui_inspector->topUp, static_cast<int>(topUp)); + mOrientationButtons->addButton(ui_inspector->rightUp, static_cast<int>(rightUp)); + mOrientationButtons->addButton(ui_inspector->topDown, static_cast<int>(topDown)); + mOrientationButtons->addButton(ui_inspector->leftUp, static_cast<int>(leftUp)); + connect(mOrientationButtons, SIGNAL(buttonClicked(int)), this, SLOT(changeOrientation(int))); + updateOrientationsButtonsIcons(false); + + QPushButton *dpiButton = new QPushButton(tr("Configure DPI correction")); + item = new OptionsItem(QString(), dpiButton, true); + item->setTags(QStringList() << tr("dpi")); + optionsList << item; + connect(dpiButton, SIGNAL(clicked()), SLOT(showViewConfiguration())); + + connect(ui_inspector->scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(changeScaleFactor(int))); + connect(ui_inspector->deviceListView, SIGNAL(currentIndexChanged(int)), this, SLOT(changeDeviceSelection(int))); + connect(ui_inspector->rotateScreen, SIGNAL(toggled(bool)), this, SLOT(rotateScreenToggled())); + connect(this, SIGNAL(deviceSelectionChanged(const DeviceData &)), mDeviceItem, SLOT(changeDevice(const DeviceData &))); + connect(this, SIGNAL(scaleFactorChanged(qreal)), mDeviceItem, SLOT(changeScaleFactor(qreal))); + connect(this, SIGNAL(orientationChangeRequested(Orientation, bool)), + mDeviceItem, SLOT(changeOrientation(Orientation, bool))); + connect(mDeviceItem, SIGNAL(orientationChanged(Orientation)), this, SLOT(updateOrientationButtonsState(Orientation))); + connect(mDeviceItem, SIGNAL(deviceChanged(bool)), this, SLOT(updateOrientationsButtonsIcons(bool))); + + setTitle(tr("Model")); + setOptions(optionsList); +} + +int ViewUi::currentDeviceIndex() const +{ + return ui_inspector->deviceListView->currentIndex(); +} + +QString ViewUi::currentDeviceName() const +{ + return ui_inspector->deviceListView->currentText(); +} + +void ViewUi::changeDeviceSelection(int newIndex) +{ + ui_inspector->deviceListView->setCurrentIndex(newIndex); + const DeviceData &newData = deviceList.at(newIndex); + emit deviceSelectionChanged(newData); + updateOrientationButtons(newData); + changeScaleFactor(ui_inspector->scaleSlider->value()); +} + +void ViewUi::updateOrientationButtonsState(Orientation orientation) +{ + mOrientationButtons->button(orientation)->setChecked(true); +} + +void ViewUi::updateOrientationsButtonsIcons(bool standardOrientationPortrait) +{ + if (standardOrientationPortrait) { + ui_inspector->topUp->setIcon(QIcon(":/ui/icons/topup.png")); + ui_inspector->topDown->setIcon(QIcon(":/ui/icons/topdown.png")); + ui_inspector->leftUp->setIcon(QIcon(":/ui/icons/leftup.png")); + ui_inspector->rightUp->setIcon(QIcon(":/ui/icons/rightup.png")); + } else { + ui_inspector->topUp->setIcon(QIcon(":/ui/icons/topup_landscape.png")); + ui_inspector->topDown->setIcon(QIcon(":/ui/icons/topdown_landscape.png")); + ui_inspector->leftUp->setIcon(QIcon(":/ui/icons/leftup_landscape.png")); + ui_inspector->rightUp->setIcon(QIcon(":/ui/icons/rightup_landscape.png")); + } +} + +void ViewUi::updateOrientationButtons(const DeviceData &data) +{ + const bool rotateScreen = ui_inspector->rotateScreen->isChecked(); + + if (!rotateScreen || mOrientationLocked) { + ui_inspector->topUp->setEnabled(true); + ui_inspector->leftUp->setEnabled(true); + ui_inspector->rightUp->setEnabled(true); + ui_inspector->topDown->setEnabled(true); + } else { + ui_inspector->topUp->setEnabled(data.supportedOrientations & topUp); + ui_inspector->leftUp->setEnabled(data.supportedOrientations & leftUp); + ui_inspector->rightUp->setEnabled(data.supportedOrientations & rightUp); + ui_inspector->topDown->setEnabled(data.supportedOrientations & topDown); + } + + if (!mOrientationButtons->checkedButton()->isEnabled() && !data.menus.isEmpty() && !mOrientationLocked) { + Orientation fallback = data.menus.begin().key(); + if (data.supportedOrientations & fallback) + mOrientationButtons->button(fallback)->click(); + } +} + +void ViewUi::rotateScreenToggled() +{ + updateOrientationButtons(deviceList.at(currentDeviceIndex())); + + emit orientationChangeRequested(static_cast<Orientation>(mOrientationButtons->checkedId()), + ui_inspector->rotateScreen->isChecked()); +} + +void ViewUi::initializeSelection() +{ + if (deviceList.count() == 0) + return; + + ui_inspector->deviceListView->setCurrentIndex(0); + changeDeviceSelection(0); +} + +void ViewUi::changeScaleFactor(int sliderPosition) +{ + int index = currentDeviceIndex(); + if (index < 0 || index >= deviceList.size()) + return; + + const DeviceData &data = deviceList.at(index); + qreal pixelDiagonal = sqrt(pow((qreal)data.resolution.width(), 2) + pow((qreal)data.resolution.height(), 2)); + qreal displayWidthInInch = data.diagonalInInch / pixelDiagonal * data.resolution.width(); + + qreal minimalScale = mLogicalDpi.width() * displayWidthInInch / data.resolution.width() * mCorrectionFactor; + + emit scaleFactorChanged((minimalScale + qreal(sliderPosition) / 100. * (1. - minimalScale))); +} + +void ViewUi::changeCorrectionFactor(qreal newFactor) +{ + mCorrectionFactor = newFactor; + changeScaleFactor(ui_inspector->scaleSlider->value()); +} + +void ViewUi::writeSettings(QSettings &settings) const +{ + ToolBoxPage::writeSettings(settings); + + settings.beginGroup("ViewUiWidget"); + settings.setValue("scale", ui_inspector->scaleSlider->value()); + settings.setValue("corrfactor", mCorrectionFactor); + settings.setValue("viewPageVisible", isContentVisible()); + settings.setValue("rotateScreen", ui_inspector->rotateScreen->isChecked()); + + int index = currentDeviceIndex(); + if (index >= 0 && index < deviceList.size()) + settings.setValue("device", deviceList.at(index).name); + + settings.endGroup(); +} + +void ViewUi::readSettings(QSettings &settings) +{ + ToolBoxPage::readSettings(settings); + + settings.beginGroup("ViewUiWidget"); + + bool deviceFound = false; + if (settings.contains("device")) { + QString deviceName = settings.value("device").toString(); + for (int i = 0; i < deviceList.size(); ++i) { + if (deviceList.at(i).name == deviceName) { + ui_inspector->deviceListView->setCurrentIndex(i); + changeDeviceSelection(i); + deviceFound = true; + break; + } + } + } + if (!deviceFound) + initializeSelection(); + + if (settings.contains("scale")) + ui_inspector->scaleSlider->setValue(settings.value("scale").toInt()); + if (settings.contains("corrfactor")) { + changeCorrectionFactor(settings.value("corrfactor").toDouble()); + } + if (settings.contains("viewPageVisible")) { + bool viewPageVisible = settings.value("viewPageVisible").toBool(); + if (viewPageVisible) + showContent(true); + else + showContent(false); + } + if (settings.contains("rotateScreen")) + ui_inspector->rotateScreen->setChecked(settings.value("rotateScreen").toBool()); + + settings.endGroup(); +} + +void ViewUi::changeOrientation(int orientation) +{ + emit orientationChangeRequested(static_cast<Orientation>(orientation), ui_inspector->rotateScreen->isChecked()); +} + +ViewScriptInterface *ViewUi::scriptInterface() const +{ + return mScriptInterface; +} + + +bool ViewUi::initializeDeviceList() +{ + QDir modelsDir("models"); + if (!modelsDir.exists()) { + QMessageBox errorMsg; + errorMsg.setWindowTitle(tr("Folder does not exist")); + errorMsg.setText(tr("The \"%1\" folder could not be located in the installation directory.").arg(modelsDir.dirName())); + errorMsg.setIcon(QMessageBox::Critical); + errorMsg.exec(); + return false; + } + + ConfigurationReader confReader; + deviceList.clear(); + bool noErrors = confReader.processDir(&modelsDir, deviceList); + if (!noErrors && !deviceList.isEmpty()) { + QMessageBox msgbox; + msgbox.setWindowTitle(tr("Errors occurred while reading device configurations")); + msgbox.setText(confReader.errorMessageLines()); + msgbox.setIcon(QMessageBox::Critical); + msgbox.exec(); + } + + if (deviceList.isEmpty()) { + QMessageBox errorMsg; + errorMsg.setWindowTitle(tr("Devices could not be found")); + QString msg; + if (!noErrors) { + msg = confReader.errorMessageLines(); + } + msg += tr("No valid device configuration files (.config) could be found in the \"%1\" folder.").arg(modelsDir.dirName()); + errorMsg.setText(msg); + errorMsg.setIcon(QMessageBox::Critical); + errorMsg.exec(); + return false; + } + + foreach (const DeviceData &data, deviceList) + ui_inspector->deviceListView->addItem(data.name); + return true; +} + +void ViewUi::showViewConfiguration() +{ + if (!mViewConfiguration) { + mViewConfiguration = new ViewConfiguration(mCorrectionFactor, this); + connect(mViewConfiguration, SIGNAL(correctionFactorChanged(qreal)), SLOT(changeCorrectionFactor(qreal))); + } + + mViewConfiguration->exec(); +} + +void ViewUi::setOrientationLocked(bool locked) +{ + mOrientationLocked = locked; + ui_inspector->rotateScreen->setDisabled(locked); + updateOrientationButtons(deviceList.at(currentDeviceIndex())); + if (!locked) { + emit orientationChangeRequested(static_cast<Orientation>(mOrientationButtons->checkedId()), + ui_inspector->rotateScreen->isChecked()); + } +} + + +/*! + \class ViewScriptInterface + \brief Exposed as simulator. +*/ + +/*! + \property ViewScriptInterface::zoom + + \brief the device scaling + + The value can be between between 0 for real-world size and 100 for pixel equivalence. + +*/ +ViewScriptInterface::ViewScriptInterface(ViewUi *ui) + : QObject(ui), ui(ui) +{ + int enumIndex = metaObject()->indexOfEnumerator("Orientation"); + QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); + for (int i = 0; i < metaEnum.keyCount(); ++i) + setProperty(metaEnum.key(i), metaEnum.key(i)); +} + +ViewScriptInterface::~ViewScriptInterface() +{ +} + +int ViewScriptInterface::zoom() const +{ + return ui->ui_inspector->scaleSlider->value(); +} + +void ViewScriptInterface::setZoom(int z) +{ + if (z < 0) + z = 0; + else if (z > 100) + z = 100; + ui->ui_inspector->scaleSlider->setValue(z); +} + +/*! + Returns the index of the current device. + + \sa setDevice(), deviceCount() +*/ +int ViewScriptInterface::currentDeviceIndex() const +{ + return ui->currentDeviceIndex(); +} + +/*! + Returns the name of the current device. + + \sa setDevice() +*/ +QString ViewScriptInterface::currentDeviceName() const +{ + return ui->currentDeviceName(); +} + +/*! + Returns the number of available device models. + + \sa setDevice(), currentDeviceIndex() +*/ +int ViewScriptInterface::deviceCount() const +{ + return ui->deviceList.size(); +} + +/*! + Sets the current device to the one with \a index. + + \sa deviceCount(), currentDeviceIndex() +*/ +void ViewScriptInterface::setDevice(int index) +{ + ui->changeDeviceSelection(index); +} + +/*! + Sets the current device to be the one identified by \a dev. + + \sa currentDeviceName() +*/ +void ViewScriptInterface::setDevice(const QString &dev) +{ + const QList<DeviceData> &devices = ui->deviceList; + for (int i = 0; i < devices.size(); ++i) { + if (devices.at(i).name == dev) { + ui->changeDeviceSelection(i); + break; + } + } +} + +/*! + Rotates the current device, and - optionally - the screen. Returns true on success. +*/ +bool ViewScriptInterface::setDeviceOrientation(QString newOrientation, bool rotateScreen) +{ + const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); + const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); + + int orientation = metaEnum.keyToValue(newOrientation.toLatin1()); + + if (QAbstractButton *button = ui->mOrientationButtons->button(orientation)) { + ui->ui_inspector->rotateScreen->setChecked(rotateScreen); + if (!button->isEnabled()) + return false; + button->click(); + return true; + } + return false; +} + +/*! + Returns the current device orientation. +*/ +QString ViewScriptInterface::deviceOrientation() const +{ + const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); + const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); + + return metaEnum.valueToKey(ui->mDeviceItem->deviceOrientation()); +} + +/*! + Returns the current screen orientation. +*/ +QString ViewScriptInterface::screenOrientation() const +{ + const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); + const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); + + return metaEnum.valueToKey(ui->mDeviceItem->screenOrientation()); +} + +/*! + Returns the list of screen orientations. +*/ +QStringList ViewScriptInterface::supportedScreenOrientations() const +{ + const int enumIndex = metaObject()->indexOfEnumerator("Orientation"); + const QMetaEnum metaEnum = metaObject()->enumerator(enumIndex); + + QStringList ret; + foreach (::Orientation o, ui->mDeviceItem->supportedScreenOrientations()) + ret.append(metaEnum.valueToKey(o)); + + return ret; +} + diff --git a/src/ui/viewui.h b/src/ui/viewui.h new file mode 100644 index 0000000..23a92c5 --- /dev/null +++ b/src/ui/viewui.h @@ -0,0 +1,130 @@ +/************************************************************************** +** +** This file is part of Qt Simulator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef VIEWUI_H +#define VIEWUI_H + +#include "deviceitem.h" +#include <remotecontrolwidget/toolbox.h> + +class Ui_Inspector; +class QButtonGroup; +class ViewConfiguration; +class ViewScriptInterface; + +class ViewUi : public ToolBoxPage +{ + Q_OBJECT +public: + explicit ViewUi(const DeviceItem *deviceItem, QWidget *parent = 0); + + QString currentDeviceName() const; + int currentDeviceIndex() const; + void initializeSelection(); + bool initializeDeviceList(); + ViewScriptInterface * scriptInterface() const; + void writeSettings(QSettings &) const; + void readSettings(QSettings &); + + +signals: + void deviceSelectionChanged(const DeviceData &data); + void orientationChangeRequested(Orientation newOrientation, bool rotateScreen); + void scaleFactorChanged(qreal newScaleFactor); + void rotateRequested(); + +public slots: + void changeDeviceSelection(int newIndex); + void updateOrientationButtonsState(Orientation orientation); + void updateOrientationsButtonsIcons(bool standardOrientationPortrait); + void setOrientationLocked(bool locked); + +private slots: + void updateOrientationButtons(const DeviceData &data); + void rotateScreenToggled(); + void changeScaleFactor(int sliderPosition); + void changeCorrectionFactor(qreal); + void changeOrientation(int orientation); + void showViewConfiguration(); + +private: + qreal mCorrectionFactor; + ViewConfiguration *mViewConfiguration; + QSize mLogicalDpi; + Ui_Inspector *ui_inspector; + QButtonGroup *mOrientationButtons; + ViewScriptInterface *mScriptInterface; + QList<DeviceData> deviceList; + const DeviceItem *mDeviceItem; + bool mOrientationLocked; + + friend class ViewScriptInterface; +}; + +class ViewScriptInterface : public QObject +{ + Q_OBJECT +public: + ViewScriptInterface(ViewUi *ui); + virtual ~ViewScriptInterface(); + + // must mimic ::Orientation + enum Orientation { + topUp = 0x0000001, + topDown = 0x0000002, + leftUp = 0x0000004, + rightUp = 0x0000008, + }; + Q_ENUMS(Orientation); + + Q_PROPERTY(int zoom READ zoom WRITE setZoom) + + int zoom() const; + void setZoom(int z); + + Q_INVOKABLE int currentDeviceIndex() const; + Q_INVOKABLE QString currentDeviceName() const; + Q_INVOKABLE int deviceCount() const; + Q_INVOKABLE void setDevice(const QString &dev); + Q_INVOKABLE void setDevice(int index); + + Q_INVOKABLE QString deviceOrientation() const; + Q_INVOKABLE QString screenOrientation() const; + Q_INVOKABLE QStringList supportedScreenOrientations() const; + Q_INVOKABLE bool setDeviceOrientation(QString orientation, bool rotateScreen); + +private: + ViewUi *ui; +}; + +#endif // VIEWUI_H |