From 9ee78b359a52b91f772c6fe1df35a84a7aca6394 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Wed, 28 Jul 2010 23:51:13 +0200 Subject: [PATCH] Make full screen truly full screen. --- dorian.pro | 6 ++++-- fullscreenwindow.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ fullscreenwindow.h | 32 ++++++++++++++++++++++++++++++++ mainwindow.cpp | 48 +++++++++--------------------------------------- mainwindow.h | 15 ++------------- pkg/changelog | 6 ++++++ pkg/version.txt | 2 +- translucentbutton.cpp | 22 ++++++++-------------- translucentbutton.h | 5 ----- 9 files changed, 107 insertions(+), 74 deletions(-) create mode 100644 fullscreenwindow.cpp create mode 100644 fullscreenwindow.h diff --git a/dorian.pro b/dorian.pro index 9bce40e..5fe929b 100644 --- a/dorian.pro +++ b/dorian.pro @@ -19,7 +19,8 @@ SOURCES += \ sortedlibrary.cpp \ bookmarkinfodialog.cpp \ dialog.cpp \ - chaptersdialog.cpp + chaptersdialog.cpp \ + fullscreenwindow.cpp HEADERS += \ mainwindow.h \ @@ -44,7 +45,8 @@ HEADERS += \ ncxhandler.h \ bookmarkinfodialog.h \ dialog.h \ - chaptersdialog.h + chaptersdialog.h \ + fullscreenwindow.h RESOURCES += \ dorian.qrc diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp new file mode 100644 index 0000000..e5dc3c0 --- /dev/null +++ b/fullscreenwindow.cpp @@ -0,0 +1,45 @@ +#include + +#include "fullscreenwindow.h" +#include "translucentbutton.h" + +FullScreenWindow::FullScreenWindow(QWidget *child, QWidget *parent): + QMainWindow(parent) +{ + Q_ASSERT(parent); +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow, true); + setAttribute(Qt::WA_Maemo5PortraitOrientation, + parent->testAttribute(Qt::WA_Maemo5PortraitOrientation)); + setAttribute(Qt::WA_Maemo5LandscapeOrientation, + parent->testAttribute(Qt::WA_Maemo5LandscapeOrientation)); +#endif // Q_WS_MAEMO_5 + child->setParent(this); + setCentralWidget(child); + restoreButton = new TranslucentButton("view-fullscreen", this); +} + +void FullScreenWindow::showFullScreen() +{ + QWidget::showFullScreen(); + restoreButton->flash(); +} + +void FullScreenWindow::MOUSE_ACTIVATE_EVENT(QMouseEvent *event) +{ + if (fullScreenZone().contains(event->x(), event->y())) { + emit restore(); + } + QMainWindow::MOUSE_ACTIVATE_EVENT(event); +} + +QRect FullScreenWindow::fullScreenZone() const +{ + return QRect(width() / 2 - 45, height() - 104, 95, 95); +} + +void FullScreenWindow::resizeEvent(QResizeEvent *e) +{ + restoreButton->setGeometry(fullScreenZone()); + QMainWindow::resizeEvent(e); +} diff --git a/fullscreenwindow.h b/fullscreenwindow.h new file mode 100644 index 0000000..f7844a4 --- /dev/null +++ b/fullscreenwindow.h @@ -0,0 +1,32 @@ +#ifndef FULLSCREENWINDOW_H +#define FULLSCREENWINDOW_H + +#include + +class TranslucentButton; + +class FullScreenWindow: public QMainWindow +{ + Q_OBJECT +public: + explicit FullScreenWindow(QWidget *child, QWidget *parent); + void showFullScreen(); + +signals: + void restore(); + +public slots: + +protected: +#ifdef Q_WS_MAEMO_5 +# define MOUSE_ACTIVATE_EVENT mouseReleaseEvent +#else +# define MOUSE_ACTIVATE_EVENT mousePressEvent +#endif + virtual void MOUSE_ACTIVATE_EVENT(QMouseEvent *event); + virtual void resizeEvent(QResizeEvent *event); + QRect fullScreenZone() const; + TranslucentButton *restoreButton; +}; + +#endif // FULLSCREENWINDOW_H diff --git a/mainwindow.cpp b/mainwindow.cpp index aa956dd..6392631 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,11 +14,11 @@ #include "librarydialog.h" #include "devtools.h" #include "mainwindow.h" -#include "translucentbutton.h" #include "settingswindow.h" #include "bookmarksdialog.h" #include "settings.h" #include "chaptersdialog.h" +#include "fullscreenwindow.h" #ifdef DORIAN_TEST_MODEL #include "modeltest.h" @@ -35,7 +35,7 @@ const Qt::WindowFlags WIN_BIG_FLAGS = const int WIN_BIG_TIMER = 3000; MainWindow::MainWindow(QWidget *parent): - QMainWindow(parent), view(0), isFullscreen(false) + QMainWindow(parent), view(0), fullScreenWindow(0) { #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5StackedWindow, true); @@ -91,9 +91,6 @@ MainWindow::MainWindow(QWidget *parent): connect(Library::instance(), SIGNAL(nowReadingChanged()), this, SLOT(onCurrentBookChanged())); - normalFlags = windowFlags(); - restoreButton = new TranslucentButton("view-fullscreen", this); - // Load book on command line, or load last read book, or load default book Library *library = Library::instance(); if (QCoreApplication::arguments().size() == 2) { @@ -142,24 +139,19 @@ void MainWindow::onCurrentBookChanged() void MainWindow::showNormal() { qDebug() << "MainWindow::showNormal"; - isFullscreen = false; - setWindowFlags(normalFlags); - hide(); - setGeometry(normalGeometry); - toolBar->show(); - restoreButton->hide(); + view->setParent(this); + setCentralWidget(view); show(); + delete fullScreenWindow; + fullScreenWindow = 0; } void MainWindow::showFullScreen() { qDebug() << "MainWindow::showFullscreen"; - normalGeometry = geometry(); - isFullscreen = true; - toolBar->hide(); - setWindowFlags(normalFlags | WIN_BIG_FLAGS); - showMaximized(); - restoreButton->flash(); + fullScreenWindow = new FullScreenWindow(view, this); + fullScreenWindow->showFullScreen(); + connect(fullScreenWindow, SIGNAL(restore()), this, SLOT(showNormal())); } void MainWindow::setCurrentBook(const QModelIndex ¤t) @@ -218,28 +210,6 @@ void MainWindow::showBookmarks() } } -void MainWindow::MOUSE_ACTIVATE_EVENT(QMouseEvent *event) -{ - qDebug() << "MainWindow::mousePress/ReleaseEvent at" << event->pos() - << "against" << fullScreenZone(); - if (isFullscreen && fullScreenZone().contains(event->x(), event->y())) { - qDebug() << " In fullScreenZone"; - showNormal(); - } - QMainWindow::MOUSE_ACTIVATE_EVENT(event); -} - -QRect MainWindow::fullScreenZone() const -{ - return QRect(width() / 2 - 45, height() - 104, 95, 95); -} - -void MainWindow::resizeEvent(QResizeEvent *event) -{ - (void)event; - restoreButton->setGeometry(fullScreenZone()); -} - void MainWindow::closeEvent(QCloseEvent *event) { qDebug() << "MainWindow::closeEvent"; diff --git a/mainwindow.h b/mainwindow.h index 8de1543..f2a5f6f 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,7 +8,7 @@ class QModelIndex; class DevTools; class BookView; class Book; -class TranslucentButton; +class FullScreenWindow; class MainWindow: public QMainWindow { @@ -36,20 +36,12 @@ public slots: void onGoToChapter(int index); protected: -#ifdef Q_WS_MAEMO5 -# define MOUSE_ACTIVATE_EVENT mouseReleaseEvent -#else -# define MOUSE_ACTIVATE_EVENT mousePressEvent -#endif - virtual void MOUSE_ACTIVATE_EVENT(QMouseEvent *event); - virtual void resizeEvent(QResizeEvent *event); virtual void closeEvent(QCloseEvent *event); private: void setCurrentBook(const QModelIndex ¤t); QAction *addToolBarAction(const QObject *receiver, const char *member, const QString &name); - QRect fullScreenZone() const; BookView *view; QAction *settingsAction; QAction *libraryAction; @@ -66,10 +58,7 @@ private: QDialog *settings; DevTools *devTools; QModelIndex mCurrent; - Qt::WindowFlags normalFlags; - TranslucentButton *restoreButton; - bool isFullscreen; - QRect normalGeometry; + FullScreenWindow *fullScreenWindow; }; #endif // MAINWINDOW_H diff --git a/pkg/changelog b/pkg/changelog index 3a7e927..0351bfa 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -1,3 +1,9 @@ +dorian (0.0.12-1) unstable; urgency=low + + * Make full screen truly full screen + + -- Akos Polster Tue, 28 Jul 2010 20:00:00 +0200 + dorian (0.0.11-1) unstable; urgency=low * Facelift bookmark manager diff --git a/pkg/version.txt b/pkg/version.txt index 2cfabea..8cbf02c 100644 --- a/pkg/version.txt +++ b/pkg/version.txt @@ -1 +1 @@ -0.0.11 +0.0.12 diff --git a/translucentbutton.cpp b/translucentbutton.cpp index cc70aa5..8be09aa 100644 --- a/translucentbutton.cpp +++ b/translucentbutton.cpp @@ -10,16 +10,17 @@ TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent): QWidget(parent), name(name_), mOpacity(1.) { setGeometry(0, 0, 50, 50); - hide(); + show(); } -void TranslucentButton::paintEvent(QPaintEvent *e) +void TranslucentButton::paintEvent(QPaintEvent *) { - (void)e; - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.drawPixmap(0, 0, QPixmap(ICON_PREFIX + name + ".png"). - scaled(QSize(95, 95), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + if (mOpacity < 1) { + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.drawPixmap(0, 0, QPixmap(ICON_PREFIX + name + ".png").scaled( + QSize(95, 95), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } } void TranslucentButton::flash() @@ -29,9 +30,7 @@ void TranslucentButton::flash() ani->setStartValue(0.); ani->setEndValue(1.); ani->setEasingCurve(QEasingCurve::OutQuart); - show(); ani->start(QPropertyAnimation::DeleteWhenStopped); - connect(ani, SIGNAL(destroyed()), this, SLOT(onAnimationEnd())); } void TranslucentButton::setOpacity(qreal opacity) @@ -39,8 +38,3 @@ void TranslucentButton::setOpacity(qreal opacity) mOpacity = opacity; update(); } - -void TranslucentButton::onAnimationEnd() -{ - hide(); -} diff --git a/translucentbutton.h b/translucentbutton.h index 93fa219..bdb3c29 100644 --- a/translucentbutton.h +++ b/translucentbutton.h @@ -15,11 +15,6 @@ public: qreal opacity() const {return mOpacity;} void setOpacity(qreal opacity); -signals: - -public slots: - void onAnimationEnd(); - protected: virtual void paintEvent(QPaintEvent *); -- 1.7.9.5