From: Akos Polster Date: Sun, 1 Aug 2010 17:43:41 +0000 (+0200) Subject: Much ado about nothing. X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=826aea4a3e3f4b4361b7592ad824963a529ffefd;p=dorian Much ado about nothing. --- diff --git a/bookmarksdialog.cpp b/bookmarksdialog.cpp index f7d2400..033c8c4 100644 --- a/bookmarksdialog.cpp +++ b/bookmarksdialog.cpp @@ -14,7 +14,7 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent): QFrame *frame = new QFrame(this); setCentralWidget(frame); - QHBoxLayout *horizontalLayout = new QHBoxLayout(this); + QHBoxLayout *horizontalLayout = new QHBoxLayout(frame); frame->setLayout(horizontalLayout); list = new QListWidget(this); diff --git a/bookview.cpp b/bookview.cpp index 08a5d64..32c2b4c 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -18,7 +18,7 @@ #endif BookView::BookView(QWidget *parent): - QWebView(parent), contentIndex(-1), mBook(0), restore(true), + QWebView(parent), contentIndex(-1), mBook(0), restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false), contentsHeight(0), decorated(false) { Trace t("BookView::BookView"); @@ -106,13 +106,17 @@ void BookView::loadContent(int index) void BookView::setBook(Book *book) { Trace t("BookView::setBook"); + + // Save position in current book setLastBookmark(); + + // Open new book, restore last position if (book != mBook) { mBook = book; if (book) { contentIndex = -1; book->open(); - goToBookmark(book->lastBookmark()); + restoreLastBookmark(); } else { contentIndex = 0; @@ -140,9 +144,9 @@ void BookView::goNext() void BookView::setLastBookmark() { - Trace t("BookView::saveLastBookmark"); + Trace t("BookView::setLastBookmark"); if (mBook) { - int height = contentsHeight; // page()->mainFrame()->contentsSize().height(); + int height = contentsHeight; int pos = page()->mainFrame()->scrollPosition().y(); t.trace(QString("At %1 (%2%, height %3)"). arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height)); @@ -150,16 +154,25 @@ void BookView::setLastBookmark() } } +void BookView::restoreLastBookmark() +{ + Trace t("BookView::restoreLastBookmark"); + if (mBook) { + goToBookmark(mBook->lastBookmark()); + } +} + void BookView::goToBookmark(const Book::Bookmark &bookmark) { Trace t("BookView::goToBookmark"); if (mBook) { - restore = true; - positionAfterLoad = bookmark.pos; if (bookmark.chapter != contentIndex) { + t.trace(QString("Loading new chapter %1").arg(bookmark.chapter)); + restorePositionAfterLoad = true; + positionAfterLoad = bookmark.pos; loadContent(bookmark.chapter); } else { - onLoadFinished(true); + goToPosition(bookmark.pos); } } } @@ -217,7 +230,7 @@ void BookView::paintEvent(QPaintEvent *e) if (b.chapter != contentIndex) { continue; } - int height = contentsHeight; // page()->mainFrame()->contentsSize().height(); + int height = contentsHeight; int bookmarkPos = (qreal)height * (qreal)b.pos; painter.drawPixmap(2, bookmarkPos - scrollPos.y(), bookmarkPixmap); } @@ -307,12 +320,20 @@ void BookView::removeIcons() QDir().rmpath(tmpPath()); } -bool BookView::eventFilter(QObject *, QEvent *e) +bool BookView::eventFilter(QObject *o, QEvent *e) { +#if 0 if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) { - Trace::debug(QString("BookView::eventFilter %1"). - arg(Trace::event(e->type()))); + if (e->type() == QEvent::Resize) { + Trace::debug(QString("BookView::eventFilter QEvent::Resize to %1"). + arg(page()->mainFrame()->contentsSize().height())); + } else { + Trace::debug(QString("BookView::eventFilter %1"). + arg(Trace::event(e->type()))); + } } +#endif + switch (e->type()) { case QEvent::MouseButtonPress: emit suppressedMouseButtonPress(); @@ -331,7 +352,8 @@ bool BookView::eventFilter(QObject *, QEvent *e) default: break; } - return false; + + return QObject::eventFilter(o, e); } void BookView::addJavaScriptObjects() @@ -345,22 +367,32 @@ void BookView::onContentsSizeChanged(const QSize &size) t.trace(QString("To %1").arg(size.height())); contentsHeight = size.height(); if (decorated) { - decorated = false; - if (restore) { - restore = false; - if (mBook) { - QWebPage *webPage = page(); - QWebFrame *mainFrame = webPage->mainFrame(); - int height = contentsHeight; - int scrollPos = (qreal)height * positionAfterLoad; - mainFrame->setScrollPosition(QPoint(0, scrollPos)); - t.trace(QString("Restoring positon to %1 (%2%, height %3)"). - arg(scrollPos).arg(positionAfterLoad * 100).arg(height)); - foreach (QString key, mainFrame->metaData().keys()) { - QString value = mainFrame->metaData().value(key); - t.trace(key + ": " + value); - } - } + if (restorePositionAfterLoad) { + restorePositionAfterLoad = false; + goToPosition(positionAfterLoad); } } } + +void BookView::leaveEvent(QEvent *e) +{ + Trace t("BookView::leaveEvent"); + setLastBookmark(); + QWebView::leaveEvent(e); +} + +void BookView::enterEvent(QEvent *e) +{ + Trace t("BookView::enterEvent"); + restoreLastBookmark(); + QWebView::enterEvent(e); +} + +void BookView::goToPosition(qreal position) +{ + int scrollPos = (qreal)contentsHeight * position; + page()->mainFrame()->setScrollPosition(QPoint(0, scrollPos)); + // FIXME: update(); + Trace::debug(QString("BookView::goToPosition: To %1 (%2%, height %3)"). + arg(scrollPos).arg(position * 100).arg(contentsHeight)); +} diff --git a/bookview.h b/bookview.h index 82b7a3c..66422d7 100644 --- a/bookview.h +++ b/bookview.h @@ -24,6 +24,7 @@ public: void goToBookmark(const Book::Bookmark &bookmark); void addBookmark(); void setLastBookmark(); + void restoreLastBookmark(); signals: void chapterLoadStart(int index); @@ -48,6 +49,8 @@ protected: virtual void paintEvent(QPaintEvent *e); virtual void mousePressEvent(QMouseEvent *e); bool eventFilter(QObject *o, QEvent *e); + virtual void leaveEvent(QEvent *); + virtual void enterEvent(QEvent *); private: /** Save navigation icons from resource to the file system. */ @@ -65,9 +68,13 @@ private: /** Get temporary directory for extracting book contents. */ QString tmpPath(); + /** Go to a given (relative) position in current chapter. */ + void goToPosition(qreal position); + int contentIndex; /**< Current chapter in book. */ Book *mBook; /**< Book to show. */ - bool restore; /**< Restoring position after load is needed. */ + bool restorePositionAfterLoad; + /**< If true, restoring position after load is needed. */ qreal positionAfterLoad; /**< Position to be restored after load. */ QImage bookmarkImage; diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp index fa3446b..a81fae3 100644 --- a/fullscreenwindow.cpp +++ b/fullscreenwindow.cpp @@ -37,7 +37,7 @@ void FullScreenWindow::MOUSE_ACTIVATE_EVENT(QMouseEvent *event) if (fullScreenZone().contains(event->x(), event->y())) { emit restore(); } else { - restoreButton->flash(); + restoreButton->flash(700); } QMainWindow::MOUSE_ACTIVATE_EVENT(event); } diff --git a/mainwindow.cpp b/mainwindow.cpp index dadcbca..e9d28ce 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #ifdef Q_WS_MAEMO_5 # include @@ -228,15 +228,30 @@ void MainWindow::onSettingsChanged(const QString &key) Trace t("MainWindow::onSettingsChanged"); #ifdef Q_WS_MAEMO_5 if (key == "orientation") { + // view->setLastBookmark(); QString value = Settings::instance()->value(key).toString(); if (value == "portrait") { setAttribute(Qt::WA_Maemo5PortraitOrientation, true); - setAttribute(Qt::WA_Maemo5LandscapeOrientation, false); } else { - setAttribute(Qt::WA_Maemo5PortraitOrientation, false); setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); } + + // view->restoreLastBookmark(); + // view->setFocus(); + // raise(); + + // QApplication::setActiveWindow(this); + // activateWindow(); + // QEvent *enter = new QEvent(QEvent::Enter); + // QApplication::postEvent(view, enter); + + // view->grabKeyboard(); + // showNormal(); + + // QTestEventList events; + // events.addMouseClick(Qt::LeftButton); + // events.simulate(view); } #else Q_UNUSED(key); diff --git a/pkg/changelog b/pkg/changelog index 60e5fcc..c3e5fb0 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -3,6 +3,7 @@ dorian (0.0.14-1) unstable; urgency=low * Make returning from full screen even more obvious * Add more restrictions to JavaScript handling * Restore bookmarks to the correct position + * Save and restore positon when application changes orientation temporarily -- Akos Polster Sat, 31 Jul 2010 20:00:00 +0200 diff --git a/settingswindow.cpp b/settingswindow.cpp index dfd60b6..3407a92 100644 --- a/settingswindow.cpp +++ b/settingswindow.cpp @@ -119,7 +119,7 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) QHBoxLayout *orientationLayout = new QHBoxLayout(orientationBox); orientationLayout->setMargin(0); orientationBox->setLayout(orientationLayout); - QButtonGroup *orientationGroup = new QButtonGroup(this); + orientationGroup = new QButtonGroup(this); QToolButton *portraitButton = new QToolButton(box); portraitButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); @@ -202,20 +202,32 @@ void SettingsWindow::onSchemeButtonClicked(int id) void SettingsWindow::onOrientationButtonClicked(int id) { +#ifdef Q_WS_MAEMO_5 + Q_UNUSED(id); +#else QString orientation; switch (id) { - case OrientationLandscape: orientation = "landscape"; break; - default: orientation = "portrait"; break; + case OrientationLandscape: + orientation = "landscape"; + break; + default: + orientation = "portrait"; + break; } Settings::instance()->setValue("orientation", orientation); +#endif // Q_WS_MAEMO_5 } #ifdef Q_WS_MAEMO_5 void SettingsWindow::closeEvent(QCloseEvent *e) { - Settings::instance()->setValue("zoom", zoomSlider->value()); - Settings::instance()->setValue("font", fontButton->currentFont().family()); + Settings *settings = Settings::instance(); + settings->setValue("zoom", zoomSlider->value()); + settings->setValue("font", fontButton->currentFont().family()); + settings->setValue("orientation", + (orientationGroup->checkedId() == OrientationLandscape)? + "landscape": "portrait"); e->accept(); } diff --git a/settingswindow.h b/settingswindow.h index 613e3ad..f120701 100644 --- a/settingswindow.h +++ b/settingswindow.h @@ -8,6 +8,7 @@ class QFontComboBox; class QFont; class QSlider; class QFontComboBox; +class QButtonGroup; class SettingsWindow: public QMainWindow { @@ -34,6 +35,7 @@ protected: private: QSlider *zoomSlider; QFontComboBox *fontButton; + QButtonGroup *orientationGroup; }; #endif // SETTINGSWINDOW_H diff --git a/translucentbutton.cpp b/translucentbutton.cpp index 4a680e8..bdb103b 100644 --- a/translucentbutton.cpp +++ b/translucentbutton.cpp @@ -23,10 +23,10 @@ void TranslucentButton::paintEvent(QPaintEvent *) } } -void TranslucentButton::flash() +void TranslucentButton::flash(int duration) { QPropertyAnimation *ani = new QPropertyAnimation(this, "opacity", 0); - ani->setDuration(3000); + ani->setDuration(duration); ani->setStartValue(0.); ani->setEndValue(1.); ani->setEasingCurve(QEasingCurve::OutQuart); diff --git a/translucentbutton.h b/translucentbutton.h index 6ee333b..7160d12 100644 --- a/translucentbutton.h +++ b/translucentbutton.h @@ -15,7 +15,7 @@ public: void setOpacity(qreal opacity); public slots: - void flash(); + void flash(int duration = 3000); protected: virtual void paintEvent(QPaintEvent *);