New relase with auto-rotaion and fixed setting dialog in portrait mode.
authorMalte Marquarding <malte@marquarding.com>
Tue, 26 Apr 2011 10:56:15 +0000 (20:56 +1000)
committerMalte Marquarding <malte@marquarding.com>
Tue, 26 Apr 2011 10:56:15 +0000 (20:56 +1000)
debian/changelog
debian/control
quickwidget.cpp
quickwidget.hpp
quickwidgetsettings.cpp
quickwidgetsettings.ui

index 3cc4f7e..2336139 100644 (file)
@@ -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 <malte@marquarding.com>  Tue, 26 Apr 2011 20:53:20 +1000
+
 quick-widgets (0.2.5) unstable; urgency=low
 
   * added symlink to /usr/bin
 quick-widgets (0.2.5) unstable; urgency=low
 
   * added symlink to /usr/bin
index 9286bfc..4924c67 100644 (file)
@@ -8,7 +8,7 @@ Homepage: http://quick-widgets.garage.maemo.org/
 
 Package: quick-widgets
 Architecture: any
 
 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)
 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)
index 9c9dffd..4f3f307 100644 (file)
@@ -1,33 +1,36 @@
 #include <QtDeclarative>
 #include <QtMaemo5>
 #include <QtDeclarative>
 #include <QtMaemo5>
-#include <QtGui/QX11Info>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/Xutil.h>
+
+#include <mce/dbus-names.h>
+#include <mce/mode-names.h>
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusMessage>
+
 #include "quickwidget.hpp"
 
 #define SETTING_QUICK_FILE "QuickWidgetFile"
 #define SETTING_QUICK_SIZE "QuickWidgetSize"
 #include "quickwidget.hpp"
 
 #define SETTING_QUICK_FILE "QuickWidgetFile"
 #define SETTING_QUICK_SIZE "QuickWidgetSize"
+#define SETTING_QUICK_ROTATE "QuickWidgetRotate"
 #define SETTING_SAVE_WAITINTERVAL 3000
 
 #define SETTING_SAVE_WAITINTERVAL 3000
 
-static Atom onCurrentHomescreenAtom;
-static bool _atomsInitialized = false;
 
 QuickWidget *QuickWidget::createAndShowNew(const QString& fileName, 
 
 QuickWidget *QuickWidget::createAndShowNew(const QString& fileName, 
-                                          const QSize& size)
+                                          const QSize& size,
+                                          bool rotate)
 {
     QuickWidget *widget = new QuickWidget;
 {
     QuickWidget *widget = new QuickWidget;
-    widget->initView(fileName, size);
+    widget->initView(fileName, size, rotate);
     widget->show();
     QeMaemo5DynamicWidgetHelper::globalInstance()->registerWidget(widget);
     return widget;
 }
 
     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_);
 {
     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();
     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
     {
     }
     else
     {
-        size_ = view_->sceneRect().size().toSize();
+      size_ = view_->sceneRect().size().toSize();
     }    
     connect(view_, SIGNAL(sceneResized(QSize)), this, SLOT(resizer(QSize)));
     }    
     connect(view_, SIGNAL(sceneResized(QSize)), this, SLOT(resizer(QSize)));
-
+    qDebug() << size_;
     view_->resize(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),
 }
 
 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);
     //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_);
     view_->rootContext()->setContextProperty("runtime", wrapper_);
+    landscape_ = true;
 }
 
 QuickWidget::~QuickWidget()
 {
 }
 
 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<QSize>();
 
 bool QuickWidget::restoreWidgetState()
 {
     QString fileName = loadSetting(SETTING_QUICK_FILE).toString();
     QSize size = loadSetting(SETTING_QUICK_SIZE, QSize()).value<QSize>();
-    initView(fileName, size);
+    bool rotate = loadSetting(SETTING_QUICK_ROTATE).toBool();
+    initView(fileName, size, rotate);
     return true;
 }
 
     return true;
 }
 
@@ -120,13 +144,8 @@ endl;
     view_->scene()->addItem(errwdgt);
     size_ = QSize(errwdgt->width(), errwdgt->height());
 }
     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())
   {
 {
   if (size_.isValid())
   {
index a81fb47..1250535 100644 (file)
@@ -14,26 +14,28 @@ class QuickWidget : public QeMaemo5DynamicHomescreenWidget
     Q_OBJECT
 
 private:
     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_;
     QSize size_;
     QDeclarativeView* view_;
     QuickWidgetWrapper* wrapper_;
+    bool landscape_;
 
 protected:
 //    void showSettingsDialog();
     bool restoreWidgetState();
     void errorWidget();
 
 protected:
 //    void showSettingsDialog();
     bool restoreWidgetState();
     void errorWidget();
-    bool x11Event(XEvent *event);
-    void paintEvent(QPaintEvent *event);
 
 public slots:
   void resizer(QSize size);
 
 public slots:
   void resizer(QSize size);
+  void rotateScreen(const QString& orientation);
 
 public:
 
 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);
 
     explicit QuickWidget(QWidget *parent = 0);
-    Q_INVOKABLE bool onHomescreen() { return isVisibleOnCurrentHomescreen(); }
     ~QuickWidget();
 
 };
     ~QuickWidget();
 
 };
@@ -49,22 +51,20 @@ public:
     QuickWidgetWrapper(QuickWidget *owner) : m_owner(owner) {;}
     Q_PROPERTY(bool isActiveWindow READ onHomeScreen NOTIFY onHomeScreenChanged);
 
     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)
     {
     void setOnHomeScreen(bool active)
     {
-        if (active == homeScreen)
+        if (active == m_homeScreen)
             return;
             return;
-        homeScreen = active;
+        m_homeScreen = active;
         emit onHomeScreenChanged();
     }
 
         emit onHomeScreenChanged();
     }
 
-
 private:
     QuickWidget *m_owner;
 private:
     QuickWidget *m_owner;
-    bool homeScreen;
-
-
+    bool m_homeScreen;
 };
 
 #endif // QuickWidget_HPP
 };
 
 #endif // QuickWidget_HPP
index 22f2650..ad6378f 100644 (file)
@@ -19,6 +19,7 @@ QuickWidgetSettings::~QuickWidgetSettings()
 void QuickWidgetSettings::accept() {
     QFile f(ui->fileEdit->text());
     QSize size;
 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);
     if (ui->sizingCheckBox->isChecked()) {
         bool wok, hok;
         int width = ui->widthEdit->text().toInt(&wok);
@@ -30,7 +31,7 @@ void QuickWidgetSettings::accept() {
     }
     if (f.exists())
     {
     }
     if (f.exists())
     {
-        QuickWidget::createAndShowNew(ui->fileEdit->text(), size);
+      QuickWidget::createAndShowNew(ui->fileEdit->text(), size, rotate);
     }
 
     QDialog::accept();
     }
 
     QDialog::accept();
index 74b15be..5ef63cb 100644 (file)
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>800</width>
-    <height>400</height>
+    <width>173</width>
+    <height>149</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>QtQuick Widget Selection</string>
   </property>
    </rect>
   </property>
   <property name="windowTitle">
    <string>QtQuick Widget Selection</string>
   </property>
-  <widget class="QDialogButtonBox" name="buttonBox">
-   <property name="geometry">
-    <rect>
-     <x>20</x>
-     <y>310</y>
-     <width>751</width>
-     <height>61</height>
-    </rect>
-   </property>
-   <property name="standardButtons">
-    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-   </property>
-  </widget>
-  <widget class="QWidget" name="">
-   <property name="geometry">
-    <rect>
-     <x>10</x>
-     <y>10</y>
-     <width>771</width>
-     <height>261</height>
-    </rect>
-   </property>
-   <layout class="QGridLayout" name="gridLayout">
-    <item row="0" column="0">
-     <layout class="QHBoxLayout" name="horizontalLayout">
-      <item>
-       <widget class="QPushButton" name="fileButton">
-        <property name="text">
-         <string>qml</string>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QLineEdit" name="fileEdit"/>
-      </item>
-     </layout>
-    </item>
-    <item row="1" column="0">
-     <widget class="QCheckBox" name="sizingCheckBox">
-      <property name="text">
-       <string>Fixed Size</string>
-      </property>
-     </widget>
-    </item>
-    <item row="2" column="0">
-     <layout class="QHBoxLayout" name="horizontalLayout_2">
-      <item>
-       <spacer name="horizontalSpacer">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType">
-         <enum>QSizePolicy::Expanding</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>13</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QLineEdit" name="widthEdit">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QLabel" name="label">
-        <property name="text">
-         <string>x</string>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignCenter</set>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QLineEdit" name="heightEdit">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <spacer name="horizontalSpacer_2">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>40</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-     </layout>
-    </item>
-   </layout>
-  </widget>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QGridLayout" name="gridLayout">
+     <property name="sizeConstraint">
+      <enum>QLayout::SetNoConstraint</enum>
+     </property>
+     <item row="0" column="0">
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <property name="sizeConstraint">
+        <enum>QLayout::SetNoConstraint</enum>
+       </property>
+       <item>
+        <widget class="QPushButton" name="fileButton">
+         <property name="text">
+          <string>qml</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="fileEdit"/>
+       </item>
+      </layout>
+     </item>
+     <item row="2" column="0">
+      <widget class="QCheckBox" name="sizingCheckBox">
+       <property name="text">
+        <string>Fixed Size</string>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="0">
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <spacer name="horizontalSpacer">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeType">
+          <enum>QSizePolicy::Expanding</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>13</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="widthEdit">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="label">
+         <property name="text">
+          <string>x</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="heightEdit">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </item>
+     <item row="1" column="0">
+      <widget class="QCheckBox" name="autoRotateCheckBox">
+       <property name="text">
+        <string>Auto-rotate</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
  </widget>
  <resources/>
  <connections>
  </widget>
  <resources/>
  <connections>