From: Jan Dumon Date: Fri, 26 Mar 2010 22:26:01 +0000 (+0100) Subject: Added a bunch of key shortcuts. X-Git-Url: http://git.maemo.org/git/?p=grr;a=commitdiff_plain;h=2450c81c33839397fcae653c76a876b7a6b86452 Added a bunch of key shortcuts. --- diff --git a/src/contentwindow.cpp b/src/contentwindow.cpp index bb0f88a..b18e78c 100644 --- a/src/contentwindow.cpp +++ b/src/contentwindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,14 @@ class ViewportItem : public QGraphicsWidget, public QAbstractKineticScroller { } } + signals: + void showNextEntry(); + void showPrevEntry(); + void showOriginal(); + void toggleStarred(); + void toggleShared(); + void toggleRead(); + protected: bool sceneEventFilter(QGraphicsItem *i, QEvent *e) { bool res = false; @@ -104,6 +113,43 @@ class ViewportItem : public QGraphicsWidget, public QAbstractKineticScroller { 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; } } @@ -200,46 +246,46 @@ ContentWindow::ContentWindow(QWidget *parent, Entry *e) : QMainWindow(parent) { 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())); connect(webview->page(), SIGNAL(linkClicked(const QUrl &)), SLOT(showLink(const QUrl &))); - - webview->setHtml(entry->content); + 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() { @@ -264,6 +310,68 @@ 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) { grabZoomKeys(false); entry->markRead(!keepUnread->isChecked()); diff --git a/src/contentwindow.h b/src/contentwindow.h index a366a50..63453bb 100644 --- a/src/contentwindow.h +++ b/src/contentwindow.h @@ -14,12 +14,20 @@ class ContentWindow : public QMainWindow { ContentWindow(QWidget *parent = 0, Entry *e = 0); virtual ~ContentWindow(); void closeEvent(QCloseEvent *event); + void showEntry(Entry *e); public slots: void loadFinished(bool); void loadStarted(); void seeOriginal(); void showLink(const QUrl &); + void toggleRead(); + void toggleShared(); + void toggleStarred(); + + signals: + void showNextEntry(); + void showPrevEntry(); private: Entry *entry; diff --git a/src/entrieswindow.cpp b/src/entrieswindow.cpp index 02192bc..40e10cf 100644 --- a/src/entrieswindow.cpp +++ b/src/entrieswindow.cpp @@ -63,8 +63,30 @@ void EntriesWindow::entriesUpdated() { void EntriesWindow::entrySelected(const QModelIndex &index) { Entry *e = qVariantValue(index.data()); - ContentWindow *w = new ContentWindow(this, e); - w->show(); + current_row = index.row(); + + content = new ContentWindow(this, e); + + connect(content, SIGNAL(showNextEntry()), SLOT(showNextEntry())); + connect(content, SIGNAL(showPrevEntry()), SLOT(showPrevEntry())); + + content->show(); +} + +void EntriesWindow::showNextEntry() { + QAbstractListModel *model = static_cast(list->model()); + if(current_row + 1 < model->rowCount()) { + current_row++; + content->showEntry(qVariantValue(model->index(current_row).data())); + } +} + +void EntriesWindow::showPrevEntry() { + QAbstractListModel *model = static_cast(list->model()); + if(current_row > 0) { + current_row--; + content->showEntry(qVariantValue(model->index(current_row).data())); + } } int EntryListModel::rowCount(const QModelIndex &) const { diff --git a/src/entrieswindow.h b/src/entrieswindow.h index 873c054..054df17 100644 --- a/src/entrieswindow.h +++ b/src/entrieswindow.h @@ -5,6 +5,7 @@ #include #include #include "googlereader.h" +#include "contentwindow.h" class EntriesWindow : public QMainWindow { Q_OBJECT @@ -18,12 +19,16 @@ class EntriesWindow : public QMainWindow { void markRead(); void entriesUpdated(); void entrySelected(const QModelIndex &); + void showNextEntry(); + void showPrevEntry(); private: QListView *list; QAction *show_all; QAction *show_updated; Feed *feed; + int current_row; + ContentWindow *content; }; class EntryListModel : public QAbstractListModel {