From 91ba9959e4339dc547cea98a15d2aac011ac060e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 1 Dec 2009 13:01:16 +1000 Subject: Make focusOnPress the default behaviour for TextEdit (like TextInput). --- src/declarative/graphicsitems/qmlgraphicstextedit.cpp | 2 +- src/declarative/graphicsitems/qmlgraphicstextedit_p_p.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp index 5f5269f..3521638 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp @@ -562,7 +562,7 @@ QString QmlGraphicsTextEdit::selectedText() const \qmlproperty bool TextEdit::focusOnPress Whether the TextEdit should gain focus on a mouse press. By default this is - set to false. + set to true. */ bool QmlGraphicsTextEdit::focusOnPress() const { diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit_p_p.h b/src/declarative/graphicsitems/qmlgraphicstextedit_p_p.h index 4cbc56d..6541921 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicstextedit_p_p.h @@ -69,7 +69,7 @@ class QmlGraphicsTextEditPrivate : public QmlGraphicsPaintedItemPrivate public: QmlGraphicsTextEditPrivate() : color("black"), imgDirty(true), hAlign(QmlGraphicsTextEdit::AlignLeft), vAlign(QmlGraphicsTextEdit::AlignTop), - dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), + dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(true), persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), cursorComponent(0), cursor(0), format(QmlGraphicsTextEdit::AutoText), document(0) { -- cgit v0.12 From 5f9172a3db108a0cc4719fd75f7ffe3f256f1fcc Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 1 Dec 2009 13:30:13 +1000 Subject: Add Screen element in QmlViewr Module including orientation property. Add support for automatic Maemo rotation update. --- tools/qmlviewer/deviceorientation.cpp | 73 +++++++++++++++ tools/qmlviewer/deviceorientation.h | 69 ++++++++++++++ tools/qmlviewer/deviceorientation_maemo.cpp | 139 ++++++++++++++++++++++++++++ tools/qmlviewer/qmlviewer.cpp | 42 ++++++++- tools/qmlviewer/qmlviewer.pro | 8 +- 5 files changed, 328 insertions(+), 3 deletions(-) create mode 100644 tools/qmlviewer/deviceorientation.cpp create mode 100644 tools/qmlviewer/deviceorientation.h create mode 100644 tools/qmlviewer/deviceorientation_maemo.cpp diff --git a/tools/qmlviewer/deviceorientation.cpp b/tools/qmlviewer/deviceorientation.cpp new file mode 100644 index 0000000..c507479 --- /dev/null +++ b/tools/qmlviewer/deviceorientation.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "deviceorientation.h" + +class DefaultDeviceOrientation : public DeviceOrientation +{ + Q_OBJECT +public: + DefaultDeviceOrientation() : DeviceOrientation(), m_orientation(DeviceOrientation::Portrait) {} + + Orientation orientation() const { + return m_orientation; + } + + void setOrientation(Orientation o) { + if (o != m_orientation) { + m_orientation = o; + emit orientationChanged(); + } + } + + Orientation m_orientation; +}; + +DeviceOrientation* DeviceOrientation::instance() +{ + static DefaultDeviceOrientation *o = 0; + if (!o) + o = new DefaultDeviceOrientation; + return o; +} + +#include "deviceorientation.moc" + diff --git a/tools/qmlviewer/deviceorientation.h b/tools/qmlviewer/deviceorientation.h new file mode 100644 index 0000000..fa7758f --- /dev/null +++ b/tools/qmlviewer/deviceorientation.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ORIENTATION_H +#define ORIENTATION_H + +#include + +class DeviceOrientationPrivate; +class DeviceOrientation : public QObject +{ + Q_OBJECT +public: + enum Orientation { UnknownOrientation, Portrait, Landscape }; + virtual Orientation orientation() const = 0; + virtual void setOrientation(Orientation) = 0; + + static DeviceOrientation *instance(); + +signals: + void orientationChanged(); + +protected: + DeviceOrientation() {} + +private: + DeviceOrientationPrivate *d_ptr; + friend class DeviceOrientationPrivate; +}; + +#endif diff --git a/tools/qmlviewer/deviceorientation_maemo.cpp b/tools/qmlviewer/deviceorientation_maemo.cpp new file mode 100644 index 0000000..9df9af4 --- /dev/null +++ b/tools/qmlviewer/deviceorientation_maemo.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "deviceorientation.h" +#include +#include + +class MaemoOrientation : public DeviceOrientation +{ + Q_OBJECT +public: + MaemoOrientation() + : DeviceOrientation(),m_current(Portrait), m_lastSeen(Portrait), m_lastSeenCount(0) + { + startTimer(100); + } + + Orientation orientation() const { + return m_current; + } + + void setOrientation(Orientation orient) { + //XXX maybe better to just ignore + if (orient != m_current) { + m_current = orient; + emit orientationChanged(); + } + } + + +protected: + virtual void timerEvent(QTimerEvent *) + { + Orientation c = get(); + + if (c == m_lastSeen) { + m_lastSeenCount++; + } else { + m_lastSeenCount = 0; + m_lastSeen = c; + } + + if (m_lastSeen != UnknownOrientation && m_lastSeen != m_current && m_lastSeenCount > 4) { + m_current = m_lastSeen; + emit orientationChanged(); + printf("%d\n", m_current); + } + } + +signals: + void changed(); + +private: + Orientation m_current; + Orientation m_lastSeen; + int m_lastSeenCount; + + Orientation get() + { + Orientation o = UnknownOrientation; + + int ax, ay, az; + + read(&ax, &ay, &az); + + if (abs(az) > 850) { + o = UnknownOrientation; + } else if (ax < -750) { + o = Portrait; + } else if (ay < -750) { + o = Landscape; + } + + return o; + } + + int read(int *ax,int *ay,int *az) + { + static const char *accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord"; + + FILE *fd; + int rs; + fd = fopen(accel_filename, "r"); + if(fd==NULL){ printf("liqaccel, cannot open for reading\n"); return -1;} + rs=fscanf((FILE*) fd,"%i %i %i",ax,ay,az); + fclose(fd); + if(rs != 3){ printf("liqaccel, cannot read information\n"); return -2;} + return 0; + } +}; + + +DeviceOrientation* DeviceOrientation::instance() +{ + static MaemoOrientation *o = 0; + if (!o) + o = new MaemoOrientation; + return o; +} + +#include "deviceorientation_maemo.moc" diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index a354653..8c50b09 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -74,6 +74,7 @@ #include #include #include "proxysettings.h" +#include "deviceorientation.h" #ifdef GL_SUPPORTED #include @@ -84,6 +85,43 @@ QT_BEGIN_NAMESPACE +class Screen : public QObject +{ + Q_OBJECT + + Q_PROPERTY(Orientation orientation READ orientation NOTIFY orientationChanged) + Q_ENUMS(Orientation) + +public: + Screen(QObject *parent=0) : QObject(parent) { + m_screens.append(this); + connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), + this, SIGNAL(orientationChanged())); + } + ~Screen() { m_screens.removeAll(this); } + + enum Orientation { UnknownOrientation = DeviceOrientation::UnknownOrientation, + Portrait = DeviceOrientation::Portrait, + Landscape = DeviceOrientation::Landscape }; + Orientation orientation() const { return Orientation(DeviceOrientation::instance()->orientation()); } + static void setOrientation(Orientation orient) { + if (orient != Orientation(DeviceOrientation::instance()->orientation())) { + DeviceOrientation::instance()->setOrientation(DeviceOrientation::Orientation(orient)); + } + } + +signals: + void orientationChanged(); + +private: + static QList m_screens; +}; + +QList Screen::m_screens; + +QML_DECLARE_TYPE(Screen) +QML_DEFINE_TYPE(QmlViewer, 1, 0, Screen, Screen) + class SizedMenuBar : public QMenuBar { Q_OBJECT @@ -532,13 +570,13 @@ void QmlViewer::proxySettingsChanged() void QmlViewer::setPortrait() { - canvas->rootContext()->setContextProperty("orientation", "Portrait"); + Screen::setOrientation(Screen::Portrait); portraitOrientation->setChecked(true); } void QmlViewer::setLandscape() { - canvas->rootContext()->setContextProperty("orientation", "Landscape"); + Screen::setOrientation(Screen::Landscape); landscapeOrientation->setChecked(true); } diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index ed26d00..4d5effd 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -15,11 +15,17 @@ contains(QT_CONFIG, opengl) { # Input HEADERS += qmlviewer.h \ proxysettings.h \ - qfxtester.h + qfxtester.h \ + deviceorientation.h SOURCES += main.cpp \ qmlviewer.cpp \ proxysettings.cpp \ qfxtester.cpp +maemo: { + SOURCES += deviceorientation_maemo.cpp +} else { + SOURCES += deviceorientation.cpp +} FORMS = recopts.ui \ proxysettings.ui INCLUDEPATH += ../../include/QtDeclarative -- cgit v0.12 From 3c115a2f574ffc54a1f629e365def931133d286a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 1 Dec 2009 13:38:38 +1000 Subject: Cleanup orientation stuff. --- tools/qmlviewer/qmlviewer.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 8c50b09..98a9702 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -94,31 +94,19 @@ class Screen : public QObject public: Screen(QObject *parent=0) : QObject(parent) { - m_screens.append(this); connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), this, SIGNAL(orientationChanged())); } - ~Screen() { m_screens.removeAll(this); } enum Orientation { UnknownOrientation = DeviceOrientation::UnknownOrientation, Portrait = DeviceOrientation::Portrait, Landscape = DeviceOrientation::Landscape }; Orientation orientation() const { return Orientation(DeviceOrientation::instance()->orientation()); } - static void setOrientation(Orientation orient) { - if (orient != Orientation(DeviceOrientation::instance()->orientation())) { - DeviceOrientation::instance()->setOrientation(DeviceOrientation::Orientation(orient)); - } - } signals: void orientationChanged(); - -private: - static QList m_screens; }; -QList Screen::m_screens; - QML_DECLARE_TYPE(Screen) QML_DEFINE_TYPE(QmlViewer, 1, 0, Screen, Screen) @@ -570,13 +558,13 @@ void QmlViewer::proxySettingsChanged() void QmlViewer::setPortrait() { - Screen::setOrientation(Screen::Portrait); + DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait); portraitOrientation->setChecked(true); } void QmlViewer::setLandscape() { - Screen::setOrientation(Screen::Landscape); + DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape); landscapeOrientation->setChecked(true); } -- cgit v0.12 From f36455bc3b559261c73b4f6269591a2eda8d0baa Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 1 Dec 2009 13:45:20 +1000 Subject: Build correct QmlViewer Screen orientation implementation for Maemo. --- tools/qmlviewer/qmlviewer.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index 4d5effd..91c9534 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -21,7 +21,7 @@ SOURCES += main.cpp \ qmlviewer.cpp \ proxysettings.cpp \ qfxtester.cpp -maemo: { +maemo5 { SOURCES += deviceorientation_maemo.cpp } else { SOURCES += deviceorientation.cpp -- cgit v0.12