#include <QDesktopServices>
#include <QtGui>
#include <QtWebKit>
+
+#include <QtGui/QX11Info>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
#include "contentwindow.h"
/* Got ViewportItem and GraphicsView from maemobrowser in the qt examples. The
case QEvent::GraphicsSceneMousePress:
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
- /*case QEvent::GraphicsSceneMouseDoubleClick:*/ {
res = handleMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e));
break;
- }
default:
break;
}
return res ? true : QGraphicsWidget::sceneEventFilter(i, e);
}
+ void keyPressEvent(QKeyEvent *e) {
+ int x, y, w, h;
+
+ switch(e->key()) {
+ case Qt::Key_Down:
+ y = m_widget->y() - 50;
+ h = (m_widget->size() - size()).height();
+ m_widget->setY(y < -h ? -h : y);
+ break;
+
+ case Qt::Key_Up:
+ y = m_widget->y() + 50;
+ m_widget->setY(y > 0 ? 0 : y);
+ break;
+
+ case Qt::Key_Right:
+ x = m_widget->x() - 50;
+ w = (m_widget->size() - size()).width();
+ m_widget->setX(x < -w ? -w : x);
+ break;
+
+ case Qt::Key_Left:
+ x = m_widget->x() + 50;
+ m_widget->setX(x > 0 ? 0 : x);
+ break;
+
+ case Qt::Key_F7:
+ if(qgraphicsitem_cast<QGraphicsWebView *>(m_widget)) {
+ QGraphicsWebView *wv = (QGraphicsWebView *)m_widget;
+ wv->setZoomFactor(wv->zoomFactor() * 1.25);
+ resizeWebViewToFrame();
+ }
+ break;
+
+ case Qt::Key_F8:
+ if(qgraphicsitem_cast<QGraphicsWebView *>(m_widget)) {
+ QGraphicsWebView *wv = (QGraphicsWebView *)m_widget;
+ wv->setZoomFactor(wv->zoomFactor() / 1.25);
+ resizeWebViewToFrame();
+ }
+ break;
+ }
+ }
+
QSize viewportSize() const {
return size().toSize();
}
webview->setHtml(entry->content);
setCentralWidget(gv);
+ gv->viewportItem()->setFocus();
+ gv->viewportItem()->grabKeyboard();
+
+ grabZoomKeys(true);
}
ContentWindow::~ContentWindow() {
}
void ContentWindow::closeEvent(QCloseEvent *event) {
+ grabZoomKeys(false);
entry->markRead(!keepUnread->isChecked());
entry->markStar(starred->isChecked());
QMainWindow::closeEvent(event);
}
+void ContentWindow::grabZoomKeys(bool grab) {
+ if (!winId()) {
+ qWarning("Can't grab keys unless we have a window id");
+ return;
+ }
+
+ unsigned long val = (grab) ? 1 : 0;
+ Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+ if (!atom) {
+ qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM. This example will only work "
+ "on a Maemo 5 device!");
+ return;
+ }
+
+ XChangeProperty (QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace,
+ reinterpret_cast<unsigned char *>(&val), 1);
+}
+
#include "contentwindow.moc"