#include <QDesktopServices>
#include <QtGui>
#include <QtWebKit>
+#include <QtMaemo5>
#include <QtGui/QX11Info>
#include <X11/Xlib.h>
}
}
+ signals:
+ void showNextEntry();
+ void showPrevEntry();
+ void showOriginal();
+ void toggleStarred();
+ void toggleShared();
+ void toggleRead();
+
protected:
bool sceneEventFilter(QGraphicsItem *i, QEvent *e) {
bool res = false;
resizeWebViewToFrame();
}
break;
+
+ case Qt::Key_J:
+ case Qt::Key_N:
+ emit showNextEntry();
+ break;
+
+ case Qt::Key_K:
+ case Qt::Key_P:
+ emit showPrevEntry();
+ break;
+
+ case Qt::Key_Space:
+ if(e->modifiers() & Qt::ShiftModifier) {
+ y = m_widget->y() + size().height();
+ m_widget->setY(y > 0 ? 0 : y);
+ }
+ else {
+ y = m_widget->y() - size().height();;
+ h = (m_widget->size() - size()).height();
+ m_widget->setY(y < -h ? -h : y);
+ }
+ break;
+
+ case Qt::Key_S:
+ if(e->modifiers() & Qt::ShiftModifier)
+ emit toggleShared();
+ else
+ emit toggleStarred();
+ break;
+
+ case Qt::Key_V:
+ emit showOriginal();
+ break;
+
+ case Qt::Key_M:
+ emit toggleRead();
+ break;
}
}
m_widget->setPos(-p + m_overShoot);
}
- void cancelLeftMouseButtonPress(const QPoint & /*globalPressPos*/) {
- }
-
void sendEvent(QGraphicsItem *i, QEvent *e) {
m_ignoreEvents = true;
scene()->sendEvent(i, e);
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
- entry = e;
-
starred = new QAction(tr("Starred"), this);
starred->setCheckable(true);
- starred->setChecked((entry->flags & ENTRY_FLAG_STARRED));
menuBar()->addAction(starred);
shared = new QAction(tr("Shared"), this);
shared->setCheckable(true);
- shared->setChecked((entry->flags & ENTRY_FLAG_SHARED));
menuBar()->addAction(shared);
keepUnread = new QAction(tr("Keep unread"), this);
keepUnread->setCheckable(true);
- keepUnread->setEnabled((entry->flags & ENTRY_FLAG_LOCKED) == 0);
menuBar()->addAction(keepUnread);
menuBar()->addAction(tr("See original"), this, SLOT(seeOriginal()));
- setWindowTitle(entry->title);
-
GraphicsView *gv = new GraphicsView();
webview = new QGraphicsWebView();
gv->viewportItem()->setWidget(webview);
- /* TODO: Configurable text size ?? */
webview->settings()->setFontSize(QWebSettings::MinimumFontSize, 22);
+ webview->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
connect(webview, SIGNAL(loadFinished(bool)), SLOT(loadFinished(bool)));
connect(webview, SIGNAL(loadStarted()), SLOT(loadStarted()));
-
- webview->setHtml(entry->content);
+ connect(webview->page(), SIGNAL(linkClicked(const QUrl &)), SLOT(showLink(const QUrl &)));
+ connect(gv->viewportItem(), SIGNAL(showNextEntry()), SIGNAL(showNextEntry()));
+ connect(gv->viewportItem(), SIGNAL(showPrevEntry()), SIGNAL(showPrevEntry()));
+ connect(gv->viewportItem(), SIGNAL(showOriginal()), SLOT(seeOriginal()));
+ connect(gv->viewportItem(), SIGNAL(toggleStarred()), SLOT(toggleStarred()));
+ connect(gv->viewportItem(), SIGNAL(toggleShared()), SLOT(toggleShared()));
+ connect(gv->viewportItem(), SIGNAL(toggleRead()), SLOT(toggleRead()));
setCentralWidget(gv);
gv->viewportItem()->setFocus();
gv->viewportItem()->grabKeyboard();
grabZoomKeys(true);
+
+ entry = NULL;
+
+ showEntry(e);
}
ContentWindow::~ContentWindow() {
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
}
-void ContentWindow::seeOriginal() {
+void ContentWindow::showLink(const QUrl &url) {
/* Attempt to launch external browser */
- if(!QDesktopServices::openUrl(entry->link))
- webview->setUrl(entry->link); /* Failed... Show inline */
+ if(!QDesktopServices::openUrl(url))
+ webview->setUrl(url); /* Failed... Show inline */
+}
+
+void ContentWindow::seeOriginal() {
+ showLink(entry->link);
+}
+
+void ContentWindow::toggleStarred() {
+ starred->toggle();
+ if(starred->isChecked()) {
+ QMaemo5InformationBox::information(this, "Starred",
+ QMaemo5InformationBox::DefaultTimeout);
+ }
+ else {
+ QMaemo5InformationBox::information(this, "Star removed",
+ QMaemo5InformationBox::DefaultTimeout);
+ }
+}
+
+void ContentWindow::toggleShared() {
+ shared->toggle();
+ if(shared->isChecked()) {
+ QMaemo5InformationBox::information(this, "Shared",
+ QMaemo5InformationBox::DefaultTimeout);
+ }
+ else {
+ QMaemo5InformationBox::information(this, "Unshared",
+ QMaemo5InformationBox::DefaultTimeout);
+ }
+}
+
+void ContentWindow::toggleRead() {
+ if(!keepUnread->isEnabled()) {
+ QMaemo5InformationBox::information(this, "Read state locked",
+ QMaemo5InformationBox::DefaultTimeout);
+ return;
+ }
+
+ keepUnread->toggle();
+ if(keepUnread->isChecked()) {
+ QMaemo5InformationBox::information(this, "Marked unread",
+ QMaemo5InformationBox::DefaultTimeout);
+ }
+ else {
+ QMaemo5InformationBox::information(this, "Marked read",
+ QMaemo5InformationBox::DefaultTimeout);
+ }
+}
+
+void ContentWindow::showEntry(Entry *e) {
+ if(entry) {
+ /* Store settings of previously shown entry */
+ entry->markRead(!keepUnread->isChecked());
+ entry->markStar(starred->isChecked());
+ entry->markShared(shared->isChecked());
+ }
+
+ entry = e;
+
+ starred->setChecked((entry->flags & ENTRY_FLAG_STARRED));
+ shared->setChecked((entry->flags & ENTRY_FLAG_SHARED));
+ keepUnread->setChecked(false);
+ keepUnread->setEnabled((entry->flags & ENTRY_FLAG_LOCKED) == 0);
+
+ setWindowTitle(entry->title);
+
+ webview->setHtml(entry->content);
}
void ContentWindow::closeEvent(QCloseEvent *event) {