From 673a98afc23b311b04823ac683e36d1ba4ac7758 Mon Sep 17 00:00:00 2001 From: Malte Marquarding Date: Tue, 26 Apr 2011 20:56:15 +1000 Subject: [PATCH] New relase with auto-rotaion and fixed setting dialog in portrait mode. --- debian/changelog | 8 ++ debian/control | 2 +- quickwidget.cpp | 101 ++++++++++++++--------- quickwidget.hpp | 24 +++--- quickwidgetsettings.cpp | 3 +- quickwidgetsettings.ui | 211 ++++++++++++++++++++++++----------------------- 6 files changed, 189 insertions(+), 160 deletions(-) diff --git a/debian/changelog b/debian/changelog index 3cc4f7e..2336139 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +quick-widgets (0.3.0) unstable; urgency=low + + * added auto-rotation of widgets (configurable) + * use q-extras-1.0.6 + * fixed layout of settings dialog in portrait mode + + -- Malte Marquarding Tue, 26 Apr 2011 20:53:20 +1000 + quick-widgets (0.2.5) unstable; urgency=low * added symlink to /usr/bin diff --git a/debian/control b/debian/control index 9286bfc..4924c67 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Homepage: http://quick-widgets.garage.maemo.org/ Package: quick-widgets Architecture: any -Depends: ${shlibs:Depends}, libhildon-extras1, q-extras (>=1.0.5), libqtm-12-declarative (>=1.2.0) +Depends: ${shlibs:Depends}, libhildon-extras1, q-extras (>=1.0.6), libqtm-12-declarative (>=1.2.0) XB-Maemo-Display-Name: Quick Widgets Description: This application simplifies running Qt Quick applications as home desktop widgets. It only needs the file. Thanks to Timur Kristóf (Venemo) diff --git a/quickwidget.cpp b/quickwidget.cpp index 9c9dffd..4f3f307 100644 --- a/quickwidget.cpp +++ b/quickwidget.cpp @@ -1,33 +1,36 @@ #include #include -#include -#include -#include -#include + +#include +#include +#include +#include + #include "quickwidget.hpp" #define SETTING_QUICK_FILE "QuickWidgetFile" #define SETTING_QUICK_SIZE "QuickWidgetSize" +#define SETTING_QUICK_ROTATE "QuickWidgetRotate" #define SETTING_SAVE_WAITINTERVAL 3000 -static Atom onCurrentHomescreenAtom; -static bool _atomsInitialized = false; QuickWidget *QuickWidget::createAndShowNew(const QString& fileName, - const QSize& size) + const QSize& size, + bool rotate) { QuickWidget *widget = new QuickWidget; - widget->initView(fileName, size); + widget->initView(fileName, size, rotate); widget->show(); QeMaemo5DynamicWidgetHelper::globalInstance()->registerWidget(widget); return widget; } -void QuickWidget::initView(const QString& fileName, const QSize& size) +void QuickWidget::initView(const QString& fileName, const QSize& size, bool rotate) { size_ = size; saveSetting(SETTING_QUICK_FILE, fileName); saveSetting(SETTING_QUICK_SIZE, size_); + saveSetting(SETTING_QUICK_ROTATE, rotate); view_->setSource(QUrl::fromLocalFile(fileName)); if ( view_->status() == QDeclarativeView::Error) { errorWidget(); @@ -40,59 +43,80 @@ void QuickWidget::initView(const QString& fileName, const QSize& size) } else { - size_ = view_->sceneRect().size().toSize(); + size_ = view_->sceneRect().size().toSize(); } connect(view_, SIGNAL(sceneResized(QSize)), this, SLOT(resizer(QSize))); - + qDebug() << size_; view_->resize(size_); - view_->show(); + if (rotate) { + QDBusConnection::systemBus() \ + .call(QDBusMessage::createMethodCall(MCE_SERVICE, + MCE_REQUEST_PATH, + MCE_REQUEST_IF, + MCE_ACCELEROMETER_ENABLE_REQ)); + QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, + MCE_DEVICE_ORIENTATION_SIG, + this, SLOT(rotateScreen(QString))); + } +} + +void QuickWidget::rotateScreen(const QString& orientation) { + + qreal angle = 90; + if (orientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || + orientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED)) { + if (!landscape_) { + return; + } + angle = -90; + landscape_ = false; + } else { + if (landscape_) { + return; + } + landscape_ = true; + } + size_.transpose(); + view_->resize(size_); + view_->rotate(angle); } QuickWidget::QuickWidget(QWidget *parent) : QeMaemo5DynamicHomescreenWidget(true, parent), - size_(QSize()), - view_(0) + size_(QSize()), + view_(0), + wrapper_(0) { - if (!_atomsInitialized) { - onCurrentHomescreenAtom = XInternAtom(QX11Info::display(), - "_HILDON_APPLET_ON_CURRENT_DESKTOP", - false); - _atomsInitialized = true; - } //layout()->setSizeConstraint(QLayout::SetNoConstraint); view_ = new QDeclarativeView(this); view_->engine()->addImportPath(QString("/opt/qtm12/imports")); view_->setStyleSheet("background:transparent"); view_->setAttribute(Qt::WA_TranslucentBackground); wrapper_ = new QuickWidgetWrapper(this); + connect(this, SIGNAL(isVisibleOnCurrentHomescreenChanged(bool)), + wrapper_, SLOT(setOnHomeScreen(bool))); view_->rootContext()->setContextProperty("runtime", wrapper_); + landscape_ = true; } QuickWidget::~QuickWidget() { - delete wrapper_; + + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, + MCE_REQUEST_PATH, + MCE_REQUEST_IF, + MCE_ACCELEROMETER_DISABLE_REQ)); + delete wrapper_; } -bool QuickWidget::x11Event(XEvent *event) -{ - bool passon = QeMaemo5DynamicHomescreenWidget::x11Event(event); - if (event->xclient.message_type == onCurrentHomescreenAtom) - { - bool visible = isVisibleOnCurrentHomescreen() ; - if (visible != wrapper_->onHomeScreen()) - { - wrapper_->setOnHomeScreen(visible); - } - } - return passon; -} bool QuickWidget::restoreWidgetState() { QString fileName = loadSetting(SETTING_QUICK_FILE).toString(); QSize size = loadSetting(SETTING_QUICK_SIZE, QSize()).value(); - initView(fileName, size); + bool rotate = loadSetting(SETTING_QUICK_ROTATE).toBool(); + initView(fileName, size, rotate); return true; } @@ -120,13 +144,8 @@ endl; view_->scene()->addItem(errwdgt); size_ = QSize(errwdgt->width(), errwdgt->height()); } - -void QuickWidget::paintEvent(QPaintEvent *event) -{ - QWidget::paintEvent(event); -} -void QuickWidget::resizer( QSize size) +void QuickWidget::resizer(const QSize& size) { if (size_.isValid()) { diff --git a/quickwidget.hpp b/quickwidget.hpp index a81fb47..1250535 100644 --- a/quickwidget.hpp +++ b/quickwidget.hpp @@ -14,26 +14,28 @@ class QuickWidget : public QeMaemo5DynamicHomescreenWidget Q_OBJECT private: - void initView(const QString& fileName, const QSize& size=QSize()); + void initView(const QString& fileName, const QSize& size=QSize(), + bool rotate=false); QSize size_; QDeclarativeView* view_; QuickWidgetWrapper* wrapper_; + bool landscape_; protected: // void showSettingsDialog(); bool restoreWidgetState(); void errorWidget(); - bool x11Event(XEvent *event); - void paintEvent(QPaintEvent *event); public slots: void resizer(QSize size); + void rotateScreen(const QString& orientation); public: - static QuickWidget *createAndShowNew(const QString& fileName, const QSize& size=QSize()); + static QuickWidget *createAndShowNew(const QString& fileName, + const QSize& size=QSize(), + bool rotate=false); explicit QuickWidget(QWidget *parent = 0); - Q_INVOKABLE bool onHomescreen() { return isVisibleOnCurrentHomescreen(); } ~QuickWidget(); }; @@ -49,22 +51,20 @@ public: QuickWidgetWrapper(QuickWidget *owner) : m_owner(owner) {;} Q_PROPERTY(bool isActiveWindow READ onHomeScreen NOTIFY onHomeScreenChanged); - bool onHomeScreen() const { return homeScreen; } + bool onHomeScreen() const { return m_homeScreen; } +public slots: void setOnHomeScreen(bool active) { - if (active == homeScreen) + if (active == m_homeScreen) return; - homeScreen = active; + m_homeScreen = active; emit onHomeScreenChanged(); } - private: QuickWidget *m_owner; - bool homeScreen; - - + bool m_homeScreen; }; #endif // QuickWidget_HPP diff --git a/quickwidgetsettings.cpp b/quickwidgetsettings.cpp index 22f2650..ad6378f 100644 --- a/quickwidgetsettings.cpp +++ b/quickwidgetsettings.cpp @@ -19,6 +19,7 @@ QuickWidgetSettings::~QuickWidgetSettings() void QuickWidgetSettings::accept() { QFile f(ui->fileEdit->text()); QSize size; + bool rotate = ui->autoRotateCheckBox->isChecked(); if (ui->sizingCheckBox->isChecked()) { bool wok, hok; int width = ui->widthEdit->text().toInt(&wok); @@ -30,7 +31,7 @@ void QuickWidgetSettings::accept() { } if (f.exists()) { - QuickWidget::createAndShowNew(ui->fileEdit->text(), size); + QuickWidget::createAndShowNew(ui->fileEdit->text(), size, rotate); } QDialog::accept(); diff --git a/quickwidgetsettings.ui b/quickwidgetsettings.ui index 74b15be..5ef63cb 100644 --- a/quickwidgetsettings.ui +++ b/quickwidgetsettings.ui @@ -6,116 +6,117 @@ 0 0 - 800 - 400 + 173 + 149 QtQuick Widget Selection - - - - 20 - 310 - 751 - 61 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 10 - 10 - 771 - 261 - - - - - - - - - qml - - - - - - - - - - - - Fixed Size - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 13 - 20 - - - - - - - - false - - - - - - - x - - - Qt::AlignCenter - - - - - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + + + + + QLayout::SetNoConstraint + + + + + QLayout::SetNoConstraint + + + + + qml + + + + + + + + + + + + Fixed Size + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 13 + 20 + + + + + + + + false + + + + + + + x + + + Qt::AlignCenter + + + + + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Auto-rotate + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + -- 1.7.9.5