summaryrefslogtreecommitdiffstats
path: root/tools/qml
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@nokia.com>2010-06-21 15:59:23 (GMT)
committerKai Koehne <kai.koehne@nokia.com>2010-06-25 06:41:15 (GMT)
commit156cabe79a64ffca8d6e1a2df99f35b413a48a39 (patch)
tree2c4868d95038c9d6a91ac6d3db269a993ef1feb1 /tools/qml
parent543bbe2e122d1d3394ec589c32f9640d1fd88f3b (diff)
downloadQt-156cabe79a64ffca8d6e1a2df99f35b413a48a39.zip
Qt-156cabe79a64ffca8d6e1a2df99f35b413a48a39.tar.gz
Qt-156cabe79a64ffca8d6e1a2df99f35b413a48a39.tar.bz2
Make the QML viewer usable on the N900
Diffstat (limited to 'tools/qml')
-rw-r--r--tools/qml/deviceorientation_maemo5.cpp (renamed from tools/qml/deviceorientation_maemo.cpp)0
-rw-r--r--tools/qml/loggerwidget.cpp25
-rw-r--r--tools/qml/loggerwidget.h16
-rw-r--r--tools/qml/main.cpp2
-rw-r--r--tools/qml/proxysettings.cpp5
-rw-r--r--tools/qml/proxysettings.h4
-rw-r--r--tools/qml/proxysettings_maemo5.ui177
-rw-r--r--tools/qml/qml.pri10
-rw-r--r--tools/qml/qml.pro3
-rw-r--r--tools/qml/qmlruntime.cpp471
-rw-r--r--tools/qml/qmlruntime.h19
-rw-r--r--tools/qml/recopts_maemo5.ui254
-rw-r--r--tools/qml/texteditautoresizer_maemo5.h122
13 files changed, 909 insertions, 199 deletions
diff --git a/tools/qml/deviceorientation_maemo.cpp b/tools/qml/deviceorientation_maemo5.cpp
index 443edc8..443edc8 100644
--- a/tools/qml/deviceorientation_maemo.cpp
+++ b/tools/qml/deviceorientation_maemo5.cpp
diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp
index 3ae2b5e..71d20e8 100644
--- a/tools/qml/loggerwidget.cpp
+++ b/tools/qml/loggerwidget.cpp
@@ -39,29 +39,48 @@
**
****************************************************************************/
-#include "loggerwidget.h"
#include <qglobal.h>
#include <QDebug>
#include <QSettings>
#include <QActionGroup>
#include <QMenu>
+#include <QPlainTextEdit>
+#ifdef Q_WS_MAEMO_5
+# include <QScrollArea>
+# include <QVBoxLayout>
+# include "texteditautoresizer_maemo5.h"
+#endif
+
+#include "loggerwidget.h"
QT_BEGIN_NAMESPACE
LoggerWidget::LoggerWidget(QWidget *parent) :
- QPlainTextEdit(parent),
+ QMainWindow(parent),
m_visibilityOrigin(SettingsOrigin)
{
setAttribute(Qt::WA_QuitOnClose, false);
setWindowTitle(tr("Warnings"));
+ m_plainTextEdit = new QPlainTextEdit();
+
+#ifdef Q_WS_MAEMO_5
+ new TextEditAutoResizer(m_plainTextEdit);
+ setAttribute(Qt::WA_Maemo5StackedWindow);
+ QScrollArea *area = new QScrollArea();
+ area->setWidget(m_plainTextEdit);
+ area->setWidgetResizable(true);
+ setCentralWidget(area);
+#else
+ setCentralWidget(m_plainTextEdit);
+#endif
readSettings();
setupPreferencesMenu();
}
void LoggerWidget::append(const QString &msg)
{
- appendPlainText(msg);
+ m_plainTextEdit->appendPlainText(msg);
if (!isVisible() && (defaultVisibility() == AutoShowWarnings))
setVisible(true);
diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h
index fd20c41..0623432 100644
--- a/tools/qml/loggerwidget.h
+++ b/tools/qml/loggerwidget.h
@@ -42,12 +42,17 @@
#ifndef LOGGERWIDGET_H
#define LOGGERWIDGET_H
-#include <QPlainTextEdit>
+#include <QMainWindow>
+#include <QMetaType>
-QT_BEGIN_NAMESPACE
+QT_USE_NAMESPACE
-class LoggerWidget : public QPlainTextEdit {
-Q_OBJECT
+class QPlainTextEdit;
+class QMenu;
+class QAction;
+
+class LoggerWidget : public QMainWindow {
+ Q_OBJECT
public:
LoggerWidget(QWidget *parent=0);
@@ -80,14 +85,13 @@ private:
QMenu *m_preferencesMenu;
QAction *m_showWidgetAction;
+ QPlainTextEdit *m_plainTextEdit;
enum ConfigOrigin { CommandLineOrigin, SettingsOrigin };
ConfigOrigin m_visibilityOrigin;
Visibility m_visibility;
};
-QT_END_NAMESPACE
-
Q_DECLARE_METATYPE(LoggerWidget::Visibility)
#endif // LOGGERWIDGET_H
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index a75023b..de5bca2 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -346,7 +346,7 @@ int main(int argc, char ** argv)
if (stayOnTop)
wflags |= Qt::WindowStaysOnTopHint;
- QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
+ QDeclarativeViewer *viewer = QDeclarativeViewer::instance(0, wflags);
viewer->setAttribute(Qt::WA_DeleteOnClose, true);
if (!scriptopts.isEmpty()) {
QStringList options =
diff --git a/tools/qml/proxysettings.cpp b/tools/qml/proxysettings.cpp
index 3255e42..ffaa4c0 100644
--- a/tools/qml/proxysettings.cpp
+++ b/tools/qml/proxysettings.cpp
@@ -48,11 +48,14 @@
QT_BEGIN_NAMESPACE
ProxySettings::ProxySettings (QWidget * parent)
- : QDialog (parent), Ui::ProxySettings()
+ : QDialog (parent), Ui::ProxySettings()
{
setupUi (this);
+#if !defined Q_WS_MAEMO_5
+ // the onscreen keyboard can't cope with masks
proxyServerEdit->setInputMask ("000.000.000.000;_");
+#endif
QIntValidator *validator = new QIntValidator (0, 9999, this);
proxyPortEdit->setValidator (validator);
diff --git a/tools/qml/proxysettings.h b/tools/qml/proxysettings.h
index 325929a..5d4d137 100644
--- a/tools/qml/proxysettings.h
+++ b/tools/qml/proxysettings.h
@@ -44,7 +44,11 @@
#include <QDialog>
#include <QNetworkProxy>
+#ifdef Q_WS_MAEMO_5
+#include "ui_proxysettings_maemo5.h"
+#else
#include "ui_proxysettings.h"
+#endif
QT_BEGIN_NAMESPACE
/**
diff --git a/tools/qml/proxysettings_maemo5.ui b/tools/qml/proxysettings_maemo5.ui
new file mode 100644
index 0000000..83f0c2a
--- /dev/null
+++ b/tools/qml/proxysettings_maemo5.ui
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ProxySettings</class>
+ <widget class="QDialog" name="ProxySettings">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>449</width>
+ <height>164</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>HTTP Proxy</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <property name="leftMargin">
+ <number>16</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>16</number>
+ </property>
+ <property name="bottomMargin">
+ <number>8</number>
+ </property>
+ <property name="horizontalSpacing">
+ <number>16</number>
+ </property>
+ <property name="verticalSpacing">
+ <number>0</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="proxyCheckBox">
+ <property name="text">
+ <string>Use HTTP Proxy</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" rowspan="2">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0" rowspan="2">
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QGridLayout" name="gridLayout">
+ <property name="horizontalSpacing">
+ <number>16</number>
+ </property>
+ <property name="verticalSpacing">
+ <number>0</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="serverAddressLabel">
+ <property name="text">
+ <string>Server</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="proxyServerEdit">
+ <property name="placeholderText">
+ <string>Name or IP</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Port</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="proxyPortEdit">
+ <property name="text">
+ <string>8080</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="usernameLabel">
+ <property name="text">
+ <string>Username</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="usernameEdit"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="passwordLabel">
+ <property name="text">
+ <string>Password</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="passwordEdit">
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>proxyCheckBox</tabstop>
+ <tabstop>proxyServerEdit</tabstop>
+ <tabstop>proxyPortEdit</tabstop>
+ <tabstop>usernameEdit</tabstop>
+ <tabstop>passwordEdit</tabstop>
+ <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ProxySettings</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>318</x>
+ <y>100</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>116</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ProxySettings</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>318</x>
+ <y>100</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>116</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri
index 58d8cc1..3e5a88b 100644
--- a/tools/qml/qml.pri
+++ b/tools/qml/qml.pri
@@ -19,10 +19,12 @@ SOURCES += $$PWD/qmlruntime.cpp \
RESOURCES = $$PWD/qmlruntime.qrc
maemo5 {
QT += dbus
- SOURCES += $$PWD/deviceorientation_maemo.cpp
+ HEADERS += $$PWD/texteditautoresizer_maemo5.h
+ SOURCES += $$PWD/deviceorientation_maemo5.cpp
+ FORMS = $$PWD/recopts_maemo5.ui \
+ $$PWD/proxysettings_maemo5.ui
} else {
SOURCES += $$PWD/deviceorientation.cpp
+ FORMS = $$PWD/recopts.ui \
+ $$PWD/proxysettings.ui
}
-
-FORMS = $$PWD/recopts.ui \
- $$PWD/proxysettings.ui
diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro
index 9cdec77..63efff1 100644
--- a/tools/qml/qml.pro
+++ b/tools/qml/qml.pro
@@ -29,6 +29,9 @@ wince* {
QT += webkit
}
}
+maemo5 {
+ QT += maemo5
+}
symbian {
TARGET.UID3 = 0x20021317
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp
index 676881d..090ca2a 100644
--- a/tools/qml/qmlruntime.cpp
+++ b/tools/qml/qmlruntime.cpp
@@ -44,7 +44,15 @@
#ifdef hz
#undef hz
#endif
-#include "ui_recopts.h"
+#ifdef Q_WS_MAEMO_5
+# include <QMaemo5ValueButton>
+# include <QMaemo5ListPickSelector>
+# include <QWidgetAction>
+# include <QStringListModel>
+# include "ui_recopts_maemo5.h"
+#else
+# include "ui_recopts.h"
+#endif
#include "qmlruntime.h"
#include <qdeclarativecontext.h>
@@ -136,24 +144,59 @@ private:
};
-class SizedMenuBar : public QMenuBar
-{
+
+#if defined(Q_WS_MAEMO_5)
+
+class Maemo5PickerAction : public QWidgetAction {
Q_OBJECT
public:
- SizedMenuBar(QWidget *parent, QWidget *referenceWidget)
- : QMenuBar(parent), refWidget(referenceWidget)
+ Maemo5PickerAction(const QString &text, QActionGroup *actions, QObject *parent)
+ : QWidgetAction(parent), m_text(text), m_actions(actions)
+ { }
+
+ QWidget *createWidget(QWidget *parent)
{
+ QMaemo5ValueButton *button = new QMaemo5ValueButton(m_text, parent);
+ button->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered);
+ QMaemo5ListPickSelector *pick = new QMaemo5ListPickSelector(button);
+ button->setPickSelector(pick);
+ if (m_actions) {
+ QStringList sl;
+ int curIdx = -1, idx = 0;
+ foreach (QAction *a, m_actions->actions()) {
+ sl << a->text();
+ if (a->isChecked())
+ curIdx = idx;
+ idx++;
+ }
+ pick->setModel(new QStringListModel(sl));
+ pick->setCurrentIndex(curIdx);
+ } else {
+ button->setEnabled(false);
+ }
+ connect(pick, SIGNAL(selected(QString)), this, SLOT(emitTriggered()));
+ return button;
}
- virtual QSize sizeHint() const
+private slots:
+ void emitTriggered()
{
- return QSize(refWidget->sizeHint().width(), QMenuBar::sizeHint().height());
+ QMaemo5ListPickSelector *pick = qobject_cast<QMaemo5ListPickSelector *>(sender());
+ if (!pick)
+ return;
+ int idx = pick->currentIndex();
+
+ if (m_actions && idx >= 0 && idx < m_actions->actions().count())
+ m_actions->actions().at(idx)->trigger();
}
private:
- QWidget *refWidget;
+ QString m_text;
+ QPointer<QActionGroup> m_actions;
};
+#endif // Q_WS_MAEMO_5
+
static struct { const char *name, *args; } ffmpegprofiles[] = {
{"Maximum Quality", "-sameq"},
{"High Quality", "-qmax 2"},
@@ -170,7 +213,9 @@ public:
RecordingDialog(QWidget *parent) : QDialog(parent)
{
setupUi(this);
+#ifndef Q_WS_MAEMO_5
hz->setValidator(new QDoubleValidator(hz));
+#endif
for (int i=0; ffmpegprofiles[i].name; ++i) {
profile->addItem(ffmpegprofiles[i].name);
}
@@ -197,6 +242,132 @@ public:
return ffmpegprofiles[i].args[0] ? QLatin1String(ffmpegprofiles[i].args) : customargs;
}
+ void setOriginalSize(const QSize &s)
+ {
+ QString str = tr("Original (%1x%2)").arg(s.width()).arg(s.height());
+
+#ifdef Q_WS_MAEMO_5
+ sizeCombo->setItemText(0, str);
+#else
+ sizeOriginal->setText(str);
+ if (sizeWidth->value()<=1) {
+ sizeWidth->setValue(s.width());
+ sizeHeight->setValue(s.height());
+ }
+#endif
+ }
+
+ void showffmpegOptions(bool b)
+ {
+#ifdef Q_WS_MAEMO_5
+ profileLabel->setVisible(b);
+ profile->setVisible(b);
+ ffmpegHelp->setVisible(b);
+ args->setVisible(b);
+#else
+ ffmpegOptions->setVisible(b);
+#endif
+ }
+
+ void showRateOptions(bool b)
+ {
+#ifdef Q_WS_MAEMO_5
+ rateLabel->setVisible(b);
+ rateCombo->setVisible(b);
+#else
+ rateOptions->setVisible(b);
+#endif
+ }
+
+ void setVideoRate(int rate)
+ {
+#ifdef Q_WS_MAEMO_5
+ int idx;
+ if (rate >= 60)
+ idx = 0;
+ else if (rate >= 50)
+ idx = 2;
+ else if (rate >= 25)
+ idx = 3;
+ else if (rate >= 24)
+ idx = 4;
+ else if (rate >= 20)
+ idx = 5;
+ else if (rate >= 15)
+ idx = 6;
+ else
+ idx = 7;
+ rateCombo->setCurrentIndex(idx);
+#else
+ if (rate == 24)
+ hz24->setChecked(true);
+ else if (rate == 25)
+ hz25->setChecked(true);
+ else if (rate == 50)
+ hz50->setChecked(true);
+ else if (rate == 60)
+ hz60->setChecked(true);
+ else {
+ hzCustom->setChecked(true);
+ hz->setText(QString::number(rate));
+ }
+#endif
+ }
+
+ int videoRate() const
+ {
+#ifdef Q_WS_MAEMO_5
+ switch (rateCombo->currentIndex()) {
+ case 0: return 60;
+ case 1: return 50;
+ case 2: return 25;
+ case 3: return 24;
+ case 4: return 20;
+ case 5: return 15;
+ case 7: return 10;
+ default: return 60;
+ }
+#else
+ if (hz24->isChecked())
+ return 24;
+ else if (hz25->isChecked())
+ return 25;
+ else if (hz50->isChecked())
+ return 50;
+ else if (hz60->isChecked())
+ return 60;
+ else {
+ return hz->text().toInt();
+ }
+#endif
+ }
+
+ QSize videoSize() const
+ {
+#ifdef Q_WS_MAEMO_5
+ switch (sizeCombo->currentIndex()) {
+ case 0: return QSize();
+ case 1: return QSize(640,480);
+ case 2: return QSize(320,240);
+ case 3: return QSize(1280,720);
+ default: return QSize();
+ }
+#else
+ if (sizeOriginal->isChecked())
+ return QSize();
+ else if (size720p->isChecked())
+ return QSize(1280,720);
+ else if (sizeVGA->isChecked())
+ return QSize(640,480);
+ else if (sizeQVGA->isChecked())
+ return QSize(320,240);
+ else
+ return QSize(sizeWidth->value(), sizeHeight->value());
+#endif
+ }
+
+
+
private slots:
void pickProfile(int i)
{
@@ -363,15 +534,21 @@ QString QDeclarativeViewer::getVideoFileName()
return QFileDialog::getSaveFileName(this, title, "", types.join(";; "));
}
+QDeclarativeViewer *QDeclarativeViewer::inst = 0;
+
+QDeclarativeViewer *QDeclarativeViewer::instance(QWidget *parent, Qt::WindowFlags flags)
+{
+ if (!inst) {
+ inst = new QDeclarativeViewer(parent, flags);
+ inst->setAttribute(Qt::WA_DeleteOnClose);
+ }
+ return inst;
+}
QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
-#if defined(Q_OS_SYMBIAN)
: QMainWindow(parent, flags)
-#else
- : QWidget(parent, flags)
-#endif
- , loggerWindow(new LoggerWidget())
- , frame_stream(0), mb(0)
+ , loggerWindow(new LoggerWidget(this))
+ , frame_stream(0)
, orientation(0)
, showWarningsWindow(0)
, m_scriptOptions(0)
@@ -381,6 +558,10 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
{
QDeclarativeViewer::registerTypes();
setWindowTitle(tr("Qt QML Viewer"));
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow);
+// setPalette(QApplication::palette("QLabel"));
+#endif
devicemode = false;
canvas = 0;
@@ -393,9 +574,9 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
senseFfmpeg();
senseImageMagick();
if (!ffmpegAvailable)
- recdlg->ffmpegOptions->hide();
+ recdlg->showffmpegOptions(false);
if (!ffmpegAvailable && !convertAvailable)
- recdlg->rateOptions->hide();
+ recdlg->showRateOptions(false);
QString warn;
if (!ffmpegAvailable) {
if (!convertAvailable)
@@ -422,21 +603,14 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed()));
if (!(flags & Qt::FramelessWindowHint)) {
- createMenu(menuBar(),0);
+ createMenu();
changeOrientation(orientation->actions().value(0));
+ } else {
+ setMenuBar(0);
}
-#if !defined(Q_OS_SYMBIAN)
- QVBoxLayout *layout = new QVBoxLayout;
- layout->setMargin(0);
- layout->setSpacing(0);
- setLayout(layout);
- if (mb)
- layout->addWidget(mb);
- layout->addWidget(canvas);
-#else
setCentralWidget(canvas);
-#endif
+
namFactory = new NetworkAccessManagerFactory;
canvas->engine()->setNetworkAccessManagerFactory(namFactory);
@@ -468,26 +642,6 @@ void QDeclarativeViewer::enableExperimentalGestures()
canvas->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
}
-int QDeclarativeViewer::menuBarHeight() const
-{
- if (!(windowFlags() & Qt::FramelessWindowHint))
- return menuBar()->height();
- else
- return 0; // don't create menu
-}
-
-QMenuBar *QDeclarativeViewer::menuBar() const
-{
-#if !defined(Q_OS_SYMBIAN)
- if (!mb)
- mb = new SizedMenuBar((QWidget*)this, canvas);
-#else
- mb = QMainWindow::menuBar();
-#endif
-
- return mb;
-}
-
QDeclarativeView *QDeclarativeViewer::view() const
{
return canvas;
@@ -498,120 +652,128 @@ LoggerWidget *QDeclarativeViewer::warningsWidget() const
return loggerWindow;
}
-void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
+void QDeclarativeViewer::createMenu()
{
- QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu;
-
- QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File"));
-
- QAction *openAction = new QAction(tr("&Open..."), parent);
+ QAction *openAction = new QAction(tr("&Open..."), this);
openAction->setShortcut(QKeySequence("Ctrl+O"));
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
- fileMenu->addAction(openAction);
- QAction *reloadAction = new QAction(tr("&Reload"), parent);
+ QAction *reloadAction = new QAction(tr("&Reload"), this);
reloadAction->setShortcut(QKeySequence("Ctrl+R"));
connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
- fileMenu->addAction(reloadAction);
-#if !defined(Q_OS_SYMBIAN)
- if (flatmenu) flatmenu->addSeparator();
-
- QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording"));
-
- QAction *snapshotAction = new QAction(tr("&Take Snapshot\tF3"), parent);
+ QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this);
+ snapshotAction->setShortcut(QKeySequence("F3"));
connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
- recordMenu->addAction(snapshotAction);
- recordAction = new QAction(tr("Start Recording &Video\tF9"), parent);
+ recordAction = new QAction(tr("Start Recording &Video"), this);
+ recordAction->setShortcut(QKeySequence("F9"));
connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection()));
- recordMenu->addAction(recordAction);
- QAction *recordOptions = new QAction(tr("Video &Options..."), parent);
+ QAction *recordOptions = new QAction(tr("Video &Options..."), this);
connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions()));
- if (flatmenu)
- flatmenu->addAction(recordOptions);
-
- if (flatmenu) flatmenu->addSeparator();
-
- QMenu *debugMenu = flatmenu ? flatmenu->addMenu(tr("&Debugging")) : menu->addMenu(tr("&Debugging"));
-
- QAction *slowAction = new QAction(tr("&Slow Down Animations"), parent);
+ QAction *slowAction = new QAction(tr("&Slow Down Animations"), this);
slowAction->setShortcut(QKeySequence("Ctrl+."));
slowAction->setCheckable(true);
connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool)));
- debugMenu->addAction(slowAction);
- showWarningsWindow = new QAction(tr("Show Warnings"), parent);
+ showWarningsWindow = new QAction(tr("Show Warnings"), this);
showWarningsWindow->setCheckable((true));
showWarningsWindow->setChecked(loggerWindow->isVisible());
connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool)));
-#if !defined(Q_OS_SYMBIAN)
- debugMenu->addAction(showWarningsWindow);
-#endif
-
- if (flatmenu) flatmenu->addSeparator();
-
-#endif // Q_OS_SYMBIAN
-
- QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings"));
- QAction *proxyAction = new QAction(tr("Http &proxy..."), parent);
+ QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this);
connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings()));
- settingsMenu->addAction(proxyAction);
-#if !defined(Q_OS_SYMBIAN)
- if (!flatmenu)
- settingsMenu->addAction(recordOptions);
- settingsMenu->addMenu(loggerWindow->preferencesMenu());
-#else
- QAction *fullscreenAction = new QAction(tr("Full Screen"), parent);
+ QAction *fullscreenAction = new QAction(tr("Full Screen"), this);
fullscreenAction->setCheckable(true);
connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
- settingsMenu->addAction(fullscreenAction);
-#endif
- if (flatmenu) flatmenu->addSeparator();
-
- QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties"));
-
- orientation = new QActionGroup(parent);
-
- QAction *rotateOrientation = new QAction(tr("Rotate orientation"), parent);
+ QAction *rotateOrientation = new QAction(tr("Rotate orientation"), this);
rotateOrientation->setShortcut(QKeySequence("Ctrl+T"));
- settingsMenu->addAction(rotateOrientation);
connect(rotateOrientation, SIGNAL(triggered()), this, SLOT(rotateOrientation()));
+ orientation = new QActionGroup(this);
orientation->setExclusive(true);
connect(orientation, SIGNAL(triggered(QAction*)), this, SLOT(changeOrientation(QAction*)));
- orientation->addAction(tr("orientation: Portrait"));
- orientation->addAction(tr("orientation: Landscape"));
- orientation->addAction(tr("orientation: Portrait (Inverted)"));
- orientation->addAction(tr("orientation: Landscape (Inverted)"));
- QList<QAction *> actions = orientation->actions();
- for (int i=0; i<actions.count(); i++) {
- propertiesMenu->addAction(actions[i]);
- actions[i]->setCheckable(true);
- }
+ QAction *portraitAction = new QAction(tr("Portrait"), this);
+ portraitAction->setCheckable(true);
+ QAction *landscapeAction = new QAction(tr("Landscape"), this);
+ landscapeAction->setCheckable(true);
+ QAction *portraitInvAction = new QAction(tr("Portrait (inverted)"), this);
+ portraitInvAction->setCheckable(true);
+ QAction *landscapeInvAction = new QAction(tr("Landscape (inverted)"), this);
+ landscapeInvAction->setCheckable(true);
- if (flatmenu) flatmenu->addSeparator();
-
- QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help"));
- QAction *aboutAction = new QAction(tr("&About Qt..."), parent);
+ QAction *aboutAction = new QAction(tr("&About Qt..."), this);
connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
- helpMenu->addAction(aboutAction);
- QAction *quitAction = new QAction(tr("&Quit"), parent);
+ QAction *quitAction = new QAction(tr("&Quit"), this);
quitAction->setShortcut(QKeySequence("Ctrl+Q"));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ QMenuBar *menu = menuBar();
+ if (!menu)
+ return;
+
+#if defined(Q_WS_MAEMO_5)
+ menu->addAction(openAction);
+ menu->addAction(reloadAction);
+
+ menu->addAction(snapshotAction);
+ menu->addAction(recordAction);
+
+ menu->addAction(recordOptions);
+ menu->addAction(proxyAction);
+
+ menu->addAction(slowAction);
+ menu->addAction(showWarningsWindow);
+
+ orientation->addAction(landscapeAction);
+ orientation->addAction(portraitAction);
+ menu->addAction(new Maemo5PickerAction(tr("Set orientation"), orientation, this));
+ menu->addAction(fullscreenAction);
+ return;
+#endif // Q_WS_MAEMO_5
+
+ QMenu *fileMenu = menu->addMenu(tr("&File"));
+ fileMenu->addAction(openAction);
+ fileMenu->addAction(reloadAction);
fileMenu->addSeparator();
fileMenu->addAction(quitAction);
- if (menu) {
- menu->setFixedHeight(menu->sizeHint().height());
- menu->setMinimumWidth(10);
- }
+
+#if !defined(Q_OS_SYMBIAN)
+ QMenu *recordMenu = menu->addMenu(tr("&Recording"));
+ recordMenu->addAction(snapshotAction);
+ recordMenu->addAction(recordAction);
+
+ QMenu *debugMenu = menu->addMenu(tr("&Debugging"));
+ debugMenu->addAction(slowAction);
+ debugMenu->addAction(showWarningsWindow);
+#endif // ! Q_OS_SYMBIAN
+
+ QMenu *settingsMenu = menu->addMenu(tr("S&ettings"));
+ settingsMenu->addAction(proxyAction);
+#if !defined(Q_OS_SYMBIAN)
+ settingsMenu->addAction(recordOptions);
+ settingsMenu->addMenu(loggerWindow->preferencesMenu());
+#else // ! Q_OS_SYMBIAN
+ settingsMenu->addAction(fullscreenAction);
+#endif // Q_OS_SYMBIAN
+ settingsMenu->addAction(rotateOrientation);
+
+ QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties"));
+
+ orientation->addAction(portraitAction);
+ orientation->addAction(landscapeAction);
+ orientation->addAction(portraitInvAction);
+ orientation->addAction(landscapeInvAction);
+ propertiesMenu->addActions(orientation->actions());
+
+ QMenu *helpMenu = menu->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAction);
}
void QDeclarativeViewer::showProxySettings()
@@ -685,25 +847,11 @@ void QDeclarativeViewer::chooseRecordingOptions()
recdlg->file->setText(record_file);
// Size
- recdlg->sizeOriginal->setText(tr("Original (%1x%2)").arg(canvas->width()).arg(canvas->height()));
- if (recdlg->sizeWidth->value()<=1) {
- recdlg->sizeWidth->setValue(canvas->width());
- recdlg->sizeHeight->setValue(canvas->height());
- }
+ recdlg->setOriginalSize(canvas->size());
// Rate
- if (record_rate == 24)
- recdlg->hz24->setChecked(true);
- else if (record_rate == 25)
- recdlg->hz25->setChecked(true);
- else if (record_rate == 50)
- recdlg->hz50->setChecked(true);
- else if (record_rate == 60)
- recdlg->hz60->setChecked(true);
- else {
- recdlg->hzCustom->setChecked(true);
- recdlg->hz->setText(QString::number(record_rate));
- }
+ recdlg->setVideoRate(record_rate);
+
// Profile
recdlg->setArguments(record_args.join(" "));
@@ -711,28 +859,9 @@ void QDeclarativeViewer::chooseRecordingOptions()
// File
record_file = recdlg->file->text();
// Size
- if (recdlg->sizeOriginal->isChecked())
- record_outsize = QSize();
- else if (recdlg->size720p->isChecked())
- record_outsize = QSize(1280,720);
- else if (recdlg->sizeVGA->isChecked())
- record_outsize = QSize(640,480);
- else if (recdlg->sizeQVGA->isChecked())
- record_outsize = QSize(320,240);
- else
- record_outsize = QSize(recdlg->sizeWidth->value(),recdlg->sizeHeight->value());
+ record_outsize = recdlg->videoSize();
// Rate
- if (recdlg->hz24->isChecked())
- record_rate = 24;
- else if (recdlg->hz25->isChecked())
- record_rate = 25;
- else if (recdlg->hz50->isChecked())
- record_rate = 50;
- else if (recdlg->hz60->isChecked())
- record_rate = 60;
- else {
- record_rate = recdlg->hz->text().toDouble();
- }
+ record_rate = recdlg->videoRate();
// Profile
record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts);
}
@@ -807,7 +936,8 @@ void QDeclarativeViewer::statusChanged()
initialSize = canvas->initialSize();
if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) {
if (!isFullScreen() && !isMaximized()) {
- resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight()));
+ canvas->setFixedSize(initialSize);
+ resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks
updateSizeHints();
}
}
@@ -1181,14 +1311,14 @@ void QDeclarativeViewer::changeOrientation(QAction *action)
return;
action->setChecked(true);
- QString o = action->text().split(QLatin1Char(':')).value(1).trimmed();
+ QString o = action->text();
if (o == QLatin1String("Portrait"))
DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait);
else if (o == QLatin1String("Landscape"))
DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape);
- else if (o == QLatin1String("Portrait (Inverted)"))
+ else if (o == QLatin1String("Portrait (inverted)"))
DeviceOrientation::instance()->setOrientation(DeviceOrientation::PortraitInverted);
- else if (o == QLatin1String("Landscape (Inverted)"))
+ else if (o == QLatin1String("Landscape (inverted)"))
DeviceOrientation::instance()->setOrientation(DeviceOrientation::LandscapeInverted);
}
@@ -1197,9 +1327,9 @@ void QDeclarativeViewer::orientationChanged()
if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) {
if (canvas->rootObject()) {
QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size();
- QSize newSize(rootObjectSize.width(), rootObjectSize.height()+menuBarHeight());
- if (size() != newSize) {
- resize(newSize);
+ if (size() != rootObjectSize.toSize()) {
+ canvas->setFixedSize(rootObjectSize.toSize());
+ resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks
}
}
}
@@ -1253,16 +1383,13 @@ void QDeclarativeViewer::updateSizeHints()
{
if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) {
QSize newWindowSize = canvas->sizeHint();
- newWindowSize.setHeight(newWindowSize.height()+menuBarHeight());
if (!isFullScreen() && !isMaximized()) {
- resize(newWindowSize);
- setFixedSize(newWindowSize);
+ canvas->setFixedSize(newWindowSize);
+ resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks
}
} else { // QDeclarativeView::SizeRootObjectToView
canvas->setMinimumSize(QSize(0,0));
canvas->setMaximumSize(QSize(16777215,16777215));
- setMinimumSize(QSize(0,0));
- setMaximumSize(QSize(16777215,16777215));
}
}
diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h
index 27bd217..cb1b438 100644
--- a/tools/qml/qmlruntime.h
+++ b/tools/qml/qmlruntime.h
@@ -43,7 +43,6 @@
#define QDECLARATIVEVIEWER_H
#include <QMainWindow>
-#include <QMenuBar>
#include <private/qdeclarativetimer_p.h>
#include <QTime>
#include <QList>
@@ -62,17 +61,17 @@ class QNetworkReply;
class QNetworkCookieJar;
class NetworkAccessManagerFactory;
class QTranslator;
+class QActionGroup;
class QDeclarativeViewer
-#if defined(Q_OS_SYMBIAN)
: public QMainWindow
-#else
- : public QWidget
-#endif
{
-Q_OBJECT
+ Q_OBJECT
+ QDeclarativeViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ static QDeclarativeViewer *inst;
+
public:
- QDeclarativeViewer(QWidget *parent=0, Qt::WindowFlags flags=0);
+ static QDeclarativeViewer *instance(QWidget *parent = 0, Qt::WindowFlags flags = 0);
~QDeclarativeViewer();
static void registerTypes();
@@ -106,8 +105,6 @@ public:
void updateSizeHints();
void setSizeToView(bool sizeToView);
- QMenuBar *menuBar() const;
-
QDeclarativeView *view() const;
LoggerWidget *warningsWidget() const;
@@ -132,7 +129,7 @@ public slots:
protected:
virtual void keyPressEvent(QKeyEvent *);
virtual bool event(QEvent *);
- void createMenu(QMenuBar *menu, QMenu *flatmenu);
+ void createMenu();
private slots:
void autoStartRecording();
@@ -150,7 +147,6 @@ private slots:
private:
QString getVideoFileName();
- int menuBarHeight() const;
LoggerWidget *loggerWindow;
QDeclarativeView *canvas;
@@ -173,7 +169,6 @@ private:
QAction *recordAction;
QString currentSkin;
bool scaleSkin;
- mutable QMenuBar *mb;
RecordingDialog *recdlg;
void senseImageMagick();
diff --git a/tools/qml/recopts_maemo5.ui b/tools/qml/recopts_maemo5.ui
new file mode 100644
index 0000000..3bb5eca
--- /dev/null
+++ b/tools/qml/recopts_maemo5.ui
@@ -0,0 +1,254 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>RecordingOptions</class>
+ <widget class="QDialog" name="RecordingOptions">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>469</width>
+ <height>142</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Video options</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" columnstretch="0,2,0">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinAndMaxSize</enum>
+ </property>
+ <property name="leftMargin">
+ <number>16</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>16</number>
+ </property>
+ <property name="bottomMargin">
+ <number>8</number>
+ </property>
+ <property name="horizontalSpacing">
+ <number>16</number>
+ </property>
+ <property name="verticalSpacing">
+ <number>0</number>
+ </property>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="file"/>
+ </item>
+ <item row="0" column="2" rowspan="3">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>72</width>
+ <height>56</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Size</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="sizeCombo">
+ <item>
+ <property name="text">
+ <string/>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>VGA</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>QVGA</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>720p</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0" rowspan="2">
+ <widget class="QLabel" name="rateLabel">
+ <property name="text">
+ <string>Rate</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" rowspan="2">
+ <widget class="QComboBox" name="rateCombo">
+ <item>
+ <property name="text">
+ <string>60 Hz</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>50 Hz</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>25 Hz</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>24 Hz</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>20 Hz</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>15 Hz</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>10 Hz</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLineEdit" name="args"/>
+ </item>
+ <item row="4" column="1">
+ <widget class="QComboBox" name="profile"/>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="profileLabel">
+ <property name="text">
+ <string>Profile</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" colspan="2">
+ <widget class="QLabel" name="warning">
+ <property name="text">
+ <string notr="true">warning</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="2" rowspan="3">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QPushButton" name="pickfile">
+ <property name="text">
+ <string>File</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QPushButton" name="ffmpegHelp">
+ <property name="text">
+ <string>Options</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>RecordingOptions</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>258</x>
+ <y>424</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>60</x>
+ <y>219</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>RecordingOptions</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>258</x>
+ <y>424</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>92</x>
+ <y>219</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>profile</sender>
+ <signal>activated(int)</signal>
+ <receiver>RecordingOptions</receiver>
+ <slot>pickProfile(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>92</x>
+ <y>329</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>48</x>
+ <y>194</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>args</sender>
+ <signal>textEdited(QString)</signal>
+ <receiver>RecordingOptions</receiver>
+ <slot>storeCustomArgs(QString)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>128</x>
+ <y>357</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>102</x>
+ <y>189</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+ <slots>
+ <signal>filePicked(QString)</signal>
+ <signal>argumentsPicked(QString)</signal>
+ <slot>pickFile()</slot>
+ <slot>pickProfile(int)</slot>
+ <slot>storeCustomArgs(QString)</slot>
+ </slots>
+</ui>
diff --git a/tools/qml/texteditautoresizer_maemo5.h b/tools/qml/texteditautoresizer_maemo5.h
new file mode 100644
index 0000000..2b9a5f9
--- /dev/null
+++ b/tools/qml/texteditautoresizer_maemo5.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples 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 <QtGui/qplaintextedit.h>
+#include <QtGui/qtextedit.h>
+#include <QtGui/qabstractkineticscroller.h>
+#include <QtGui/qscrollarea.h>
+#include <QtDebug>
+
+#ifndef TEXTEDITAUTORESIZER_H
+#define TEXTEDITAUTORESIZER_H
+
+class TextEditAutoResizer : public QObject
+{
+ Q_OBJECT
+public:
+ TextEditAutoResizer(QWidget *parent)
+ : QObject(parent), plainTextEdit(qobject_cast<QPlainTextEdit *>(parent)),
+ textEdit(qobject_cast<QTextEdit *>(parent)), edit(qobject_cast<QFrame *>(parent))
+ {
+ // parent must either inherit QPlainTextEdit or QTextEdit!
+ Q_ASSERT(plainTextEdit || textEdit);
+
+ connect(parent, SIGNAL(textChanged()), this, SLOT(textEditChanged()));
+ connect(parent, SIGNAL(cursorPositionChanged()), this, SLOT(textEditChanged()));
+
+ textEditChanged();
+ }
+
+private Q_SLOTS:
+ inline void textEditChanged();
+
+private:
+ QPlainTextEdit *plainTextEdit;
+ QTextEdit *textEdit;
+ QFrame *edit;
+};
+
+void TextEditAutoResizer::textEditChanged()
+{
+ QTextDocument *doc = textEdit ? textEdit->document() : plainTextEdit->document();
+ QRect cursor = textEdit ? textEdit->cursorRect() : plainTextEdit->cursorRect();
+
+ QSize s = doc->size().toSize();
+ if (plainTextEdit)
+ s.setHeight((s.height() + 2) * edit->fontMetrics().lineSpacing());
+
+ const QRect fr = edit->frameRect();
+ const QRect cr = edit->contentsRect();
+
+ edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height() - 1)));
+
+// QString s1;
+// QDebug ts(&s1);
+// ts << "DOC: " << s << " CURSOR: " << cursor << " MINH: " << edit->minimumHeight();
+// fprintf(stderr, "%s\n", qPrintable(s1));
+
+ // make sure the cursor is visible in case we have a QAbstractScrollArea parent
+ QPoint pos = edit->pos();
+ QWidget *pw = edit->parentWidget();
+ while (pw) {
+ if (qobject_cast<QScrollArea *>(pw))
+ break;
+ pw = pw->parentWidget();
+ }
+
+ if (pw) {
+ QScrollArea *area = static_cast<QScrollArea *>(pw);
+ QPoint scrollto = area->widget()->mapFrom(edit, cursor.center());
+ QPoint margin(10 + cursor.width(), 2 * cursor.height());
+
+ if (QAbstractKineticScroller *scroller = area->property("kineticScroller").value<QAbstractKineticScroller *>()) {
+ scroller->ensureVisible(scrollto, margin.x(), margin.y());
+ } else {
+ area->ensureVisible(scrollto.x(), scrollto.y(), margin.x(), margin.y());
+ }
+ }
+// QDebug ts(&s2);
+// ts << "ENSURE VIS: " << pos << " + " << cursor.center() << "(pos + cursor.center())" << scroller->isEnabled() << area;
+// ts << "PW: " << pw << " PPW: " << (pw ? pw->parentWidget() : 0); //ENSURE VIS: " << pos << " + " << cursor.center() << "(pos + cursor.center())" << scroller->isEnabled() << area;
+// fprintf(stderr, "%s\n", qPrintable(s2));
+}
+
+#endif