From 986c5df2ad57bad44e8dd02286a2326406ace831 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Sat, 6 Nov 2010 20:17:14 +0100 Subject: [PATCH] Clean up volume key handling code. --- adopterwindow.cpp | 213 ++++++++++++++++++++++++++++++++++++++++++ adopterwindow.h | 62 ++++++++++++ bookview.cpp | 92 ++++++++++-------- bookview.h | 43 +++++---- dorian.pro | 8 +- fullscreenwindow.cpp | 49 ++++++++++ fullscreenwindow.h | 34 +++++++ mainwindow.cpp | 38 ++------ mainwindow.h | 2 +- platform.cpp | 10 ++ platform.h | 1 + widgets/adopterwindow.cpp | 182 ------------------------------------ widgets/adopterwindow.h | 64 ------------- widgets/fullscreenwindow.cpp | 49 ---------- widgets/fullscreenwindow.h | 34 ------- 15 files changed, 463 insertions(+), 418 deletions(-) create mode 100644 adopterwindow.cpp create mode 100644 adopterwindow.h create mode 100644 fullscreenwindow.cpp create mode 100644 fullscreenwindow.h delete mode 100644 widgets/adopterwindow.cpp delete mode 100644 widgets/adopterwindow.h delete mode 100644 widgets/fullscreenwindow.cpp delete mode 100644 widgets/fullscreenwindow.h diff --git a/adopterwindow.cpp b/adopterwindow.cpp new file mode 100644 index 0000000..d553a5c --- /dev/null +++ b/adopterwindow.cpp @@ -0,0 +1,213 @@ +#include + +#if defined(Q_WS_MAEMO_5) +# include +# include +# include +# include +#endif + +#include "adopterwindow.h" +#include "trace.h" +#include "bookview.h" +#include "platform.h" +#include "settings.h" + +AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0) +{ + TRACE; + +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow, true); +#endif // Q_WS_MAEMO_5 + + QFrame *frame = new QFrame(this); + QVBoxLayout *layout = new QVBoxLayout(frame); + layout->setMargin(0); + frame->setLayout(layout); + setCentralWidget(frame); + +#ifdef Q_OS_SYMBIAN + QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this); + closeAction->setSoftKeyRole(QAction::NegativeSoftKey); + connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); + QMainWindow::addAction(closeAction); +#else + // Tool bar + setUnifiedTitleAndToolBarOnMac(true); + toolBar = addToolBar("controls"); + toolBar->setMovable(false); + toolBar->setFloatable(false); + toolBar->toggleViewAction()->setVisible(false); +#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5) + toolBar->setIconSize(QSize(42, 42)); +#endif +#endif // Q_OS_SYMBIAN + + // Monitor settings + Settings *settings = Settings::instance(); + connect(settings, SIGNAL(valueChanged(const QString &)), + this, SLOT(onSettingsChanged(const QString &))); + settings->setValue("usevolumekeys", settings->value("usevolumekeys")); +} + +void AdopterWindow::takeChildren(BookView *view, const QList &others) +{ + TRACE; + leaveChildren(); + if (view) { + bookView = view; + bookView->setParent(centralWidget()); + centralWidget()->layout()->addWidget(bookView); + bookView->show(); + } + foreach (QWidget *child, others) { + if (child) { + child->setParent(this); + } + } +} + +void AdopterWindow::leaveChildren() +{ + TRACE; + if (bookView) { + centralWidget()->layout()->removeWidget(bookView); + bookView = 0; + } +} + +void AdopterWindow::show() +{ +#ifdef Q_OS_SYMBIAN + foreach (QWidget *w, QApplication::allWidgets()) { + w->setContextMenuPolicy(Qt::NoContextMenu); + } + showMaximized(); + raise(); +#else + QMainWindow::show(); +#endif +} + +QAction *AdopterWindow::addToolBarAction(QObject *receiver, + const char *member, + const QString &iconName, + const QString &text) +{ + TRACE; + qDebug() << "icon" << iconName << "text" << text; +#ifndef Q_OS_SYMBIAN + return toolBar->addAction(QIcon(Platform::icon(iconName)), + text, receiver, member); +#else + Q_UNUSED(iconName); + QAction *action = new QAction(text, this); + menuBar()->addAction(action); + connect(action, SIGNAL(triggered()), receiver, member); + return action; +#endif +} + +void AdopterWindow::addToolBarSpace() +{ +#ifndef Q_OS_SYMBIAN + QFrame *frame = new QFrame(toolBar); + frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + toolBar->addWidget(frame); +#endif +} + +void AdopterWindow::grabVolumeKeys(bool grab) +{ + TRACE; + grabbingVolumeKeys = grab; +#ifdef Q_WS_MAEMO_5 + doGrabVolumeKeys(grab); +#endif +} + +#ifdef Q_WS_MAEMO_5 + +void AdopterWindow::doGrabVolumeKeys(bool grab) +{ + TRACE; + if (!isVisible()) { + qDebug() << "Not visible - skipping"; + return; + } + if (!winId()) { + qDebug() << "Could not get window ID - skipping"; + return; + } + unsigned long val = grab? 1: 0; + Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); + if (!atom) { + qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM"; + return; + } + XChangeProperty(QX11Info::display(), + winId(), + atom, + XA_INTEGER, + 32, + PropModeReplace, + reinterpret_cast(&val), + 1); + qDebug() << "Grabbed volume keys"; +} + +#endif // Q_WS_MAEMO_5 + +#ifdef Q_WS_MAEMO_5 + +void AdopterWindow::showEvent(QShowEvent *e) +{ + TRACE; + doGrabVolumeKeys(grabbingVolumeKeys); + QMainWindow::showEvent(e); +} + +#endif // Q_WS_MAEMO_5 + +void AdopterWindow::keyPressEvent(QKeyEvent *event) +{ + TRACE; + if (bookView && grabbingVolumeKeys) { + switch (event->key()) { +#ifdef Q_WS_MAEMO_5 + case Qt::Key_F7: + qDebug() << "F7"; + bookView->goNextPage(); + event->accept(); + break; + case Qt::Key_F8: + qDebug() << "F8"; + bookView->goPreviousPage(); + event->accept(); + break; +#endif // Q_WS_MAEMO_5 + case Qt::Key_PageUp: + bookView->goPreviousPage(); + event->accept(); + break; + case Qt::Key_PageDown: + bookView->goNextPage(); + event->accept(); + break; + default: + ; + } + } + QMainWindow::keyPressEvent(event); +} + +void AdopterWindow::onSettingsChanged(const QString &key) +{ + TRACE; + if (key == "usevolumekeys") { + qDebug() << key; + grabVolumeKeys(Settings::instance()->value(key).toBool()); + } +} + diff --git a/adopterwindow.h b/adopterwindow.h new file mode 100644 index 0000000..d2e3fe9 --- /dev/null +++ b/adopterwindow.h @@ -0,0 +1,62 @@ +#ifndef ADOPTERWINDOW_H +#define ADOPTERWINDOW_H + +#include +#include + +class QWidget; +class QToolBar; +class QAction; +class BookView; + +/** + * A toplevel window that can adopt a BookView and other children. + * On Maemo, it can also grab the volume keys. + */ +class AdopterWindow: public QMainWindow +{ + Q_OBJECT + +public: + explicit AdopterWindow(QWidget *parent = 0); + + /** Adopt children "bookView" and "others". */ + void takeChildren(BookView *bookView, const QList &others); + + /** Release current children (adopted in @see takeChildren). */ + void leaveChildren(); + + /** + * Add action that is visible on the tool bar (except on Symbian, where + * it is visible on the Options menu). + */ + QAction *addToolBarAction(QObject *receiver, const char *slot, + const QString &iconName, const QString &text); + + /** Add spacing to tool bar. */ + void addToolBarSpace(); + + /** Show window. */ + void show(); + + /** If grab is true, volume keys will generate pageUp/Down keys. */ + void grabVolumeKeys(bool grab); + +public slots: + /** Handle settings changes. */ + void onSettingsChanged(const QString &key); + +protected: + void keyPressEvent(QKeyEvent *event); +#ifdef Q_WS_MAEMO_5 + void showEvent(QShowEvent *event); + void doGrabVolumeKeys(bool grab); +#endif + BookView *bookView; + bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */ +#ifndef Q_OS_SYMBIAN + QToolBar *toolBar; +#endif +}; + +#endif // ADOPTERWINDOW_H diff --git a/bookview.cpp b/bookview.cpp index 4f78291..d588c28 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -2,9 +2,8 @@ #include #include -#if defined(Q_WS_MAEMO_5) -# include -#elif defined(Q_OS_SYMBIAN) +#if defined(Q_OS_SYMBIAN) +# include "mediakeysobserver.h" # include "flickcharm.h" #endif @@ -17,12 +16,13 @@ #include "progressdialog.h" #include "platform.h" -BookView::BookView(QWidget *parent): - QWebView(parent), contentIndex(-1), mBook(0), +BookView::BookView(QWidget *parent): QWebView(parent), contentIndex(-1), mBook(0), restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false), - contentsHeight(0) + contentsHeight(0), grabbingVolumeKeys(false) { TRACE; + + // Set up web view defaults settings()->setAttribute(QWebSettings::AutoLoadImages, true); settings()->setAttribute(QWebSettings::JavascriptEnabled, true); settings()->setAttribute(QWebSettings::JavaEnabled, false); @@ -40,32 +40,36 @@ BookView::BookView(QWidget *parent): false); settings()->setDefaultTextEncoding("utf-8"); page()->setContentEditable(false); - -#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) - // Suppress unwanted text selections on Maemo and Symbian - installEventFilter(this); -#endif QWebFrame *frame = page()->mainFrame(); #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); #endif frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); - - bookmarkImage = QImage(":/icons/bookmark.png"); - connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); connect(frame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJavaScriptObjects())); connect(frame, SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); - connect(Settings::instance(), SIGNAL(valueChanged(const QString &)), - this, SLOT(onSettingsChanged(const QString &))); + + // Suppress unwanted text selections on Maemo and Symbian +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) + installEventFilter(this); +#endif + + // Pre-load bookmark icon + bookmarkImage = QImage(":/icons/bookmark.png"); + + // Handle settings changes, force handling initial settings Settings *s = Settings::instance(); + connect(s, SIGNAL(valueChanged(const QString &)), + this, SLOT(onSettingsChanged(const QString &))); s->setValue("zoom", s->value("zoom", 160)); s->setValue("font", s->value("font", Platform::defaultFont())); s->setValue("scheme", s->value("scheme", "default")); + s->setValue("usevolumekeys", s->value("usevolumekeys", false)); setBook(0); + // Enable kinetic scrolling #if defined(Q_WS_MAEMO_5) scrollerMonitor = 0; scroller = property("kineticScroller").value(); @@ -74,16 +78,19 @@ BookView::BookView(QWidget *parent): charm = new FlickCharm(this); charm->activateOn(this); #endif -} -BookView::~BookView() -{ - TRACE; + // Observe media keys on Symbian +#ifdef Q_OS_SYMBIAN + MediaKeysObserver *observer = MediaKeysObserver::instance(); + connect(observer, SIGNAL(mediaKeyPressed(MediaKeysObserver::MediaKeys)), + this, SLOT(onMediaKeysPressed(MediaKeysObserver::MediaKeys))); +#endif } void BookView::loadContent(int index) { TRACE; + if (!mBook) { return; } @@ -258,6 +265,9 @@ void BookView::onSettingsChanged(const QString &key) script.close(); QVariant ret = frame->evaluateJavaScript(scriptText); } + else if (key == "usevolumekeys") { + grabVolumeKeys(Settings::instance()->value(key).toBool()); + } } void BookView::paintEvent(QPaintEvent *e) @@ -444,23 +454,6 @@ void BookView::timerEvent(QTimerEvent *e) QWebView::timerEvent(e); } -void BookView::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_F7: - goNextPage(); - event->accept(); - break; - case Qt::Key_F8: - goPreviousPage(); - event->accept(); - break; - default: - ; - } - QWebView::keyPressEvent(event); -} - void BookView::goPreviousPage() { QWebFrame *frame = page()->mainFrame(); @@ -490,3 +483,28 @@ void BookView::goNextPage() showProgress(); } } + +void BookView::grabVolumeKeys(bool grab) +{ + TRACE; + grabbingVolumeKeys = grab; +} + +#ifdef Q_OS_SYMBIAN + +void BookView::onMediaKeysPressed(MediaKeysObserver::MediaKeys key) +{ + TRACE; + qDebug() << "Key" << (int)key; + if (grabbingVolumeKeys) { + if (key == MediaKeysObserver::EVolIncKey) { + qDebug() << "Volume up"; + goNextPage(); + } else if (key == MediaKeysObserver::EVolDecKey){ + qDebug() << "Volume down"; + goPreviousPage(); + } + } +} + +#endif // Q_OS_SYMBIAN diff --git a/bookview.h b/bookview.h index b79e8bf..bc2cf3f 100644 --- a/bookview.h +++ b/bookview.h @@ -10,6 +10,10 @@ #include "book.h" +#ifdef Q_OS_SYMBIAN +# include "mediakeysobserver.h" +#endif + class QModelIndex; class Progress; class QAbstractKineticScroller; @@ -23,7 +27,6 @@ class BookView: public QWebView public: explicit BookView(QWidget *parent = 0); - virtual ~BookView(); void setBook(Book *book); Book *book(); void goToBookmark(const Book::Bookmark &bookmark); @@ -33,6 +36,9 @@ public: void goToPart(int part, const QString &fragment); void goToFragment(const QString &fragment); + /** If grab is true, volume keys will generate act as page up/down. */ + void grabVolumeKeys(bool grab); + signals: void partLoadStart(int index); void partLoadEnd(int index); @@ -65,19 +71,23 @@ public slots: /** Go to next page. */ void goNextPage(); +protected slots: +#ifdef Q_OS_SYMBIAN + /** Observe media keys. */ + void onMediaKeysPressed(MediaKeysObserver::MediaKeys key); +#endif + protected: void paintEvent(QPaintEvent *e); void mousePressEvent(QMouseEvent *e); void wheelEvent(QWheelEvent *); bool eventFilter(QObject *o, QEvent *e); + void timerEvent(QTimerEvent *e); #ifdef Q_WS_MAEMO_5 void leaveEvent(QEvent *e); void enterEvent(QEvent *e); #endif // Q_WS_MAEMO_5 - void timerEvent(QTimerEvent *e); - void keyPressEvent(QKeyEvent *e); -private: /** Load given part. */ void loadContent(int index); @@ -90,24 +100,23 @@ private: /** Show reading progress. */ void showProgress(); - int contentIndex; /**< Current part in book. */ - Book *mBook; /**< Book to show. */ + int contentIndex; /**< Current part in book. */ + Book *mBook; /**< Book to show. */ bool restorePositionAfterLoad; - /**< If true, restore current position after load. */ - qreal positionAfterLoad; - /**< Position to be restored after load. */ + /**< If true, restore current position after load. */ + qreal positionAfterLoad;/**< Position to be restored after load. */ bool restoreFragmentAfterLoad; - /**< If true, restore fragment location after load. */ + /**< If true, restore fragment location after load. */ QString fragmentAfterLoad; - /**< Fragment location to be restored after load. */ - QImage bookmarkImage; - /**< Bookmark icon pre-loaded. */ - bool loaded; /**< True if content has been loaded. */ - bool mousePressed; - int contentsHeight; /**< Last know height of the frame. */ + /**< Fragment location to be restored after load. */ + QImage bookmarkImage; /**< Bookmark icon pre-loaded. */ + bool loaded; /**< True, if content has been loaded. */ + bool mousePressed; /**< Event filter's mouse button state. */ + int contentsHeight; /**< Last know height of the frame. */ + bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */ #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) - int scrollerMonitor; + int scrollerMonitor; /**< ID of timer monitoring kinetic scroll. */ #endif #if defined(Q_WS_MAEMO_5) QAbstractKineticScroller *scroller; diff --git a/dorian.pro b/dorian.pro index 53529b7..5eca6d9 100644 --- a/dorian.pro +++ b/dorian.pro @@ -24,13 +24,13 @@ SOURCES += \ bookmarkinfodialog.cpp \ widgets/dyalog.cpp \ chaptersdialog.cpp \ - widgets/fullscreenwindow.cpp \ + fullscreenwindow.cpp \ trace.cpp \ widgets/toolbuttonbox.cpp \ model/bookfinder.cpp \ widgets/listwindow.cpp \ widgets/progress.cpp \ - widgets/adopterwindow.cpp \ + adopterwindow.cpp \ platform.cpp \ model/bookdb.cpp \ searchdialog.cpp \ @@ -64,13 +64,13 @@ HEADERS += \ bookmarkinfodialog.h \ widgets/dyalog.h \ chaptersdialog.h \ - widgets/fullscreenwindow.h \ + fullscreenwindow.h \ trace.h \ widgets/toolbuttonbox.h \ model/bookfinder.h \ widgets/listwindow.h \ widgets/progress.h \ - widgets/adopterwindow.h \ + adopterwindow.h \ widgets/listview.h \ model/xmlhandler.h \ platform.h \ diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp new file mode 100644 index 0000000..f708f53 --- /dev/null +++ b/fullscreenwindow.cpp @@ -0,0 +1,49 @@ +#include + +#include "fullscreenwindow.h" +#include "translucentbutton.h" +#include "trace.h" + +FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent) +{ + Q_ASSERT(parent); +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow, true); + setAttribute(Qt::WA_Maemo5NonComposited, true); +#endif // Q_WS_MAEMO_5 +#ifndef Q_OS_SYMBIAN + toolBar->hide(); +#endif + QFrame *frame = new QFrame(this); + QVBoxLayout *layout = new QVBoxLayout(frame); + layout->setMargin(0); + frame->setLayout(layout); + setCentralWidget(frame); + restoreButton = new TranslucentButton("view-normal", this); + QRect screen = QApplication::desktop()->screenGeometry(); + restoreButton->setGeometry((screen.width() - TranslucentButton::pixels) / 2, + screen.height() - TranslucentButton::pixels - 9, + TranslucentButton::pixels, TranslucentButton::pixels); + connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore())); +} + +void FullScreenWindow::showFullScreen() +{ +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5PortraitOrientation, parentWidget()-> + testAttribute(Qt::WA_Maemo5PortraitOrientation)); + setAttribute(Qt::WA_Maemo5LandscapeOrientation, parentWidget()-> + testAttribute(Qt::WA_Maemo5LandscapeOrientation)); +#endif // Q_WS_MAEMO_5 + QWidget::showFullScreen(); + restoreButton->flash(3000); +} + +void FullScreenWindow::resizeEvent(QResizeEvent *e) +{ + Q_UNUSED(e); + QRect screen = QApplication::desktop()->screenGeometry(); + restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9, + screen.height() - TranslucentButton::pixels - 9, + TranslucentButton::pixels, TranslucentButton::pixels); +} diff --git a/fullscreenwindow.h b/fullscreenwindow.h new file mode 100644 index 0000000..601269b --- /dev/null +++ b/fullscreenwindow.h @@ -0,0 +1,34 @@ +#ifndef FULLSCREENWINDOW_H +#define FULLSCREENWINDOW_H + +#include +#include + +#include "adopterwindow.h" + +class QWidget; +class QMouseEvent; +class QResizeEvent; +class TranslucentButton; + +/** A full screen window with a restore button. */ +class FullScreenWindow: public AdopterWindow +{ + Q_OBJECT + +public: + explicit FullScreenWindow(QWidget *parent); + void showFullScreen(); + +signals: + /** Emitted when the restore button is pressed. */ + void restore(); + +protected: + void resizeEvent(QResizeEvent *e); + +private: + TranslucentButton *restoreButton; +}; + +#endif // FULLSCREENWINDOW_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 37b66eb..33a730a 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,4 +1,5 @@ #include +#include #ifdef Q_WS_MAEMO_5 # include @@ -161,21 +162,19 @@ MainWindow::MainWindow(QWidget *parent): this, SLOT(onSettingsChanged(const QString &))); settings->setValue("orientation", settings->value("orientation")); settings->setValue("lightson", settings->value("lightson")); - settings->setValue("usevolumekeys", settings->value("usevolumekeys")); // Handle book view buttons connect(nextButton, SIGNAL(triggered()), this, SLOT(goToNextPage())); connect(previousButton, SIGNAL(triggered()), this, SLOT(goToPreviousPage())); + // Adopt view, show window + showRegular(); + #ifdef DORIAN_TEST_MODEL (void)new ModelTest(Library::instance(), this); #endif } -MainWindow::~MainWindow() -{ -} - void MainWindow::onCurrentBookChanged() { setCurrentBook(Library::instance()->nowReading()); @@ -316,10 +315,11 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::onSettingsChanged(const QString &key) { + TRACE; + qDebug() << key; #if defined(Q_WS_MAEMO_5) if (key == "orientation") { QString value = Settings::instance()->value(key).toString(); - qDebug() << "MainWindow::onSettingsChanged: orientation" << value; if (value == "portrait") { setAttribute(Qt::WA_Maemo5LandscapeOrientation, false); setAttribute(Qt::WA_Maemo5PortraitOrientation, true); @@ -329,35 +329,18 @@ void MainWindow::onSettingsChanged(const QString &key) } } else if (key == "lightson") { bool enable = Settings::instance()->value(key, false).toBool(); - qDebug() << "MainWindow::onSettingsChanged: lightson:" << enable; killTimer(preventBlankingTimer); if (enable) { preventBlankingTimer = startTimer(29 * 1000); } - } else if (key == "usevolumekeys") { - bool value = Settings::instance()->value(key).toBool(); - qDebug() << "MainWindow::onSettingsChanged: usevolumekeys" << value; - grabZoomKeys(value); - fullScreenWindow->grabZoomKeys(value); - } -#elif defined Q_OS_SYMBIAN - if (key == "usevolumekeys") { - bool value = Settings::instance()->value(key).toBool(); - qDebug() << "MainWindow::onSettingsChanged: usevolumekeys" << value; - grabZoomKeys(value); - fullScreenWindow->grabZoomKeys(value); } -#else - Q_UNUSED(key); #endif // Q_WS_MAEMO_5 } void MainWindow::onPartLoadStart() { TRACE; -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); -#endif + Platform::showBusy(this, true); } void MainWindow::onPartLoadEnd(int index) @@ -374,9 +357,7 @@ void MainWindow::onPartLoadEnd(int index) enableNext = true; } } -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); -#endif // Q_WS_MAEMO_5 + Platform::showBusy(this, false); } void MainWindow::onAddBookmark(const QString ¬e) @@ -477,7 +458,6 @@ void MainWindow::about() aboutDialog->show(); } - void MainWindow::goToNextPage() { nextButton->flash(); @@ -512,7 +492,6 @@ void MainWindow::onEndUpgrade() libraryProgress->reset(); } - void MainWindow::onBeginLoad(int total) { libraryProgress->setVisible(total > 0); @@ -532,4 +511,3 @@ void MainWindow::onEndLoad() libraryProgress->hide(); libraryProgress->reset(); } - diff --git a/mainwindow.h b/mainwindow.h index b284919..e3d61d9 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include #include "adopterwindow.h" @@ -21,7 +22,6 @@ class MainWindow: public AdopterWindow public: MainWindow(QWidget *parent = 0); - ~MainWindow(); public slots: void showLibrary(); diff --git a/platform.cpp b/platform.cpp index dff134c..f72a073 100644 --- a/platform.cpp +++ b/platform.cpp @@ -90,3 +90,13 @@ void Platform::information(const QString &label, QWidget *parent) QMessageBox::Ok); #endif } + +void Platform::showBusy(QWidget *w, bool isBusy) +{ +#ifdef Q_WS_MAEMO_5 + w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy); +#else + Q_UNUSED(w); + Q_UNUSED(isBusy); +#endif +} diff --git a/platform.h b/platform.h index daec6f3..6c8ddef 100644 --- a/platform.h +++ b/platform.h @@ -16,6 +16,7 @@ public: static QString downloadDir(); static QString defaultFont(); static void information(const QString &label, QWidget *parent = 0); + static void showBusy(QWidget *w, bool isBusy); }; #endif // PLATFORM_H diff --git a/widgets/adopterwindow.cpp b/widgets/adopterwindow.cpp deleted file mode 100644 index fa8c640..0000000 --- a/widgets/adopterwindow.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include - -#if defined(Q_WS_MAEMO_5) -# include -# include -# include -#elif defined(Q_OS_SYMBIAN) -# include "mediakeysobserver.h" -#endif - -#include "trace.h" -#include "adopterwindow.h" -#include "platform.h" - -AdopterWindow::AdopterWindow(QWidget *parent): - QMainWindow(parent), grabbingZoomKeys(false), mainChild(0) -{ - TRACE; - -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5StackedWindow, true); -#endif // Q_WS_MAEMO_5 - - QFrame *frame = new QFrame(this); - QVBoxLayout *layout = new QVBoxLayout(frame); - layout->setMargin(0); - frame->setLayout(layout); - setCentralWidget(frame); - -#ifdef Q_OS_SYMBIAN - QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this); - closeAction->setSoftKeyRole(QAction::NegativeSoftKey); - connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); - QMainWindow::addAction(closeAction); - MediaKeysObserver *observer = MediaKeysObserver::instance(); - connect(observer, SIGNAL(mediaKeyPressed(MediaKeysObserver::MediaKeys)), - this, SLOT(onMediaKeysPressed(MediaKeysObserver::MediaKeys))); -#else - // Tool bar - setUnifiedTitleAndToolBarOnMac(true); - toolBar = addToolBar("controls"); - toolBar->setMovable(false); - toolBar->setFloatable(false); - toolBar->toggleViewAction()->setVisible(false); -#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5) - toolBar->setIconSize(QSize(42, 42)); -#endif -#endif // Q_OS_SYMBIAN -} - -void AdopterWindow::takeChildren(QWidget *main, const QList &others) -{ - TRACE; - leaveChildren(); - if (main) { - mainChild = main; - mainChild->setParent(centralWidget()); - centralWidget()->layout()->addWidget(mainChild); - mainChild->show(); - } - foreach (QWidget *child, others) { - if (child) { - child->setParent(this); - } - } -} - -void AdopterWindow::leaveChildren() -{ - TRACE; - if (mainChild) { - centralWidget()->layout()->removeWidget(mainChild); - mainChild = 0; - } -} - -void AdopterWindow::grabZoomKeys(bool grab) -{ - TRACE; - grabbingZoomKeys = grab; - doGrabZoomKeys(grab); -} - -void AdopterWindow::showEvent(QShowEvent *e) -{ - TRACE; - doGrabZoomKeys(grabbingZoomKeys); - QMainWindow::showEvent(e); -} - -void AdopterWindow::doGrabZoomKeys(bool grab) -{ - TRACE; -#ifdef Q_WS_MAEMO_5 - if (!isVisible()) { - qDebug() << "Not visible - skipping"; - } - if (!winId()) { - qDebug() << "Could not get window ID - skipping"; - return; - } - unsigned long val = grab? 1: 0; - Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); - if (!atom) { - qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM"; - return; - } - XChangeProperty(QX11Info::display(), - winId(), - atom, - XA_INTEGER, - 32, - PropModeReplace, - reinterpret_cast(&val), - 1); -#else - Q_UNUSED(grab); -#endif // Q_WS_MAEMO_5 -} - -void AdopterWindow::show() -{ -#ifdef Q_OS_SYMBIAN - foreach (QWidget *w, QApplication::allWidgets()) { - w->setContextMenuPolicy(Qt::NoContextMenu); - } - showMaximized(); - raise(); -#else - QMainWindow::show(); -#endif -} - -QAction *AdopterWindow::addToolBarAction(QObject *receiver, - const char *member, - const QString &iconName, - const QString &text) -{ - TRACE; - qDebug() << "icon" << iconName << "text" << text; -#ifndef Q_OS_SYMBIAN - return toolBar->addAction(QIcon(Platform::icon(iconName)), - text, receiver, member); -#else - Q_UNUSED(iconName); - QAction *action = new QAction(text, this); - menuBar()->addAction(action); - connect(action, SIGNAL(triggered()), receiver, member); - return action; -#endif -} - -void AdopterWindow::addToolBarSpace() -{ -#ifndef Q_OS_SYMBIAN - QFrame *frame = new QFrame(toolBar); - frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - toolBar->addWidget(frame); -#endif -} - -#ifdef Q_OS_SYMBIAN - -void AdopterWindow::onMediaKeysPressed(MediaKeysObserver::MediaKeys key) -{ - qDebug() << "AdopterWindow::onMediaKeysPressed:" << (int)key; - - if ((key != MediaKeysObserver::EVolIncKey) && - (key != MediaKeysObserver::EVolDecKey)) { - return; - } - - if (grabbingZoomKeys) { - qDebug() << "Posting" - << ((key == MediaKeysObserver::EVolIncKey)? "Key_F7": "Key_F8"); - QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, - (key == MediaKeysObserver::EVolIncKey)? Qt::Key_F7: Qt::Key_F8, 0); - QCoreApplication::sendEvent(this, event); - } -} - -#endif // Q_OS_SYMBIAN diff --git a/widgets/adopterwindow.h b/widgets/adopterwindow.h deleted file mode 100644 index f09a05b..0000000 --- a/widgets/adopterwindow.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef ADOPTERWINDOW_H -#define ADOPTERWINDOW_H - -#include -#include - -#ifdef Q_OS_SYMBIAN -# include "mediakeysobserver.h" -#endif - -class QWidget; -class QToolBar; -class QAction; - -/** - * A main window that can adopt other windows' children, and grabs the - * zoom (volume) keys on Maemo. - */ -class AdopterWindow: public QMainWindow -{ - Q_OBJECT -public: - explicit AdopterWindow(QWidget *parent = 0); - - /* If true, zoom (volume) keys will generate Key_F7 and Key_F8 events. */ - void grabZoomKeys(bool grab); - - /** Adopt children "main" and "others". */ - void takeChildren(QWidget *main, const QList &others); - - /** Release current children (adopted in @see takeChildren). */ - void leaveChildren(); - - /** - * Add action that is visible on the tool bar (except on Symbian, where - * it is visible on the Options menu). - */ - QAction *addToolBarAction(QObject *receiver, const char *slot, - const QString &iconName, const QString &text); - - /** Add space. */ - void addToolBarSpace(); - - /** Show window. */ - void show(); - -signals: - -protected slots: -#ifdef Q_OS_SYMBIAN - void onMediaKeysPressed(MediaKeysObserver::MediaKeys key); -#endif - -protected: - void showEvent(QShowEvent *e); - void doGrabZoomKeys(bool grab); - bool grabbingZoomKeys; - QWidget *mainChild; -#ifndef Q_OS_SYMBIAN - QToolBar *toolBar; -#endif -}; - -#endif // ADOPTERWINDOW_H diff --git a/widgets/fullscreenwindow.cpp b/widgets/fullscreenwindow.cpp deleted file mode 100644 index f708f53..0000000 --- a/widgets/fullscreenwindow.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include - -#include "fullscreenwindow.h" -#include "translucentbutton.h" -#include "trace.h" - -FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent) -{ - Q_ASSERT(parent); -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5StackedWindow, true); - setAttribute(Qt::WA_Maemo5NonComposited, true); -#endif // Q_WS_MAEMO_5 -#ifndef Q_OS_SYMBIAN - toolBar->hide(); -#endif - QFrame *frame = new QFrame(this); - QVBoxLayout *layout = new QVBoxLayout(frame); - layout->setMargin(0); - frame->setLayout(layout); - setCentralWidget(frame); - restoreButton = new TranslucentButton("view-normal", this); - QRect screen = QApplication::desktop()->screenGeometry(); - restoreButton->setGeometry((screen.width() - TranslucentButton::pixels) / 2, - screen.height() - TranslucentButton::pixels - 9, - TranslucentButton::pixels, TranslucentButton::pixels); - connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore())); -} - -void FullScreenWindow::showFullScreen() -{ -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5PortraitOrientation, parentWidget()-> - testAttribute(Qt::WA_Maemo5PortraitOrientation)); - setAttribute(Qt::WA_Maemo5LandscapeOrientation, parentWidget()-> - testAttribute(Qt::WA_Maemo5LandscapeOrientation)); -#endif // Q_WS_MAEMO_5 - QWidget::showFullScreen(); - restoreButton->flash(3000); -} - -void FullScreenWindow::resizeEvent(QResizeEvent *e) -{ - Q_UNUSED(e); - QRect screen = QApplication::desktop()->screenGeometry(); - restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9, - screen.height() - TranslucentButton::pixels - 9, - TranslucentButton::pixels, TranslucentButton::pixels); -} diff --git a/widgets/fullscreenwindow.h b/widgets/fullscreenwindow.h deleted file mode 100644 index 601269b..0000000 --- a/widgets/fullscreenwindow.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef FULLSCREENWINDOW_H -#define FULLSCREENWINDOW_H - -#include -#include - -#include "adopterwindow.h" - -class QWidget; -class QMouseEvent; -class QResizeEvent; -class TranslucentButton; - -/** A full screen window with a restore button. */ -class FullScreenWindow: public AdopterWindow -{ - Q_OBJECT - -public: - explicit FullScreenWindow(QWidget *parent); - void showFullScreen(); - -signals: - /** Emitted when the restore button is pressed. */ - void restore(); - -protected: - void resizeEvent(QResizeEvent *e); - -private: - TranslucentButton *restoreButton; -}; - -#endif // FULLSCREENWINDOW_H -- 1.7.9.5