Make full screen truly full screen.
authorAkos Polster <polster@marzipan.pipacs.com>
Wed, 28 Jul 2010 21:51:13 +0000 (23:51 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Wed, 28 Jul 2010 21:51:13 +0000 (23:51 +0200)
dorian.pro
fullscreenwindow.cpp [new file with mode: 0644]
fullscreenwindow.h [new file with mode: 0644]
mainwindow.cpp
mainwindow.h
pkg/changelog
pkg/version.txt
translucentbutton.cpp
translucentbutton.h

index 9bce40e..5fe929b 100644 (file)
@@ -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 (file)
index 0000000..e5dc3c0
--- /dev/null
@@ -0,0 +1,45 @@
+#include <QtGui>
+
+#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 (file)
index 0000000..f7844a4
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef FULLSCREENWINDOW_H
+#define FULLSCREENWINDOW_H
+
+#include <QMainWindow>
+
+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
index aa956dd..6392631 100755 (executable)
 #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 &current)
@@ -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";
index 8de1543..f2a5f6f 100755 (executable)
@@ -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 &current);
     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
index 3a7e927..0351bfa 100644 (file)
@@ -1,3 +1,9 @@
+dorian (0.0.12-1) unstable; urgency=low
+
+  * Make full screen truly full screen
+
+ -- Akos Polster <akos@pipacs.com>  Tue, 28 Jul 2010 20:00:00 +0200
+
 dorian (0.0.11-1) unstable; urgency=low
 
   * Facelift bookmark manager
index 2cfabea..8cbf02c 100644 (file)
@@ -1 +1 @@
-0.0.11
+0.0.12
index cc70aa5..8be09aa 100644 (file)
@@ -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();
-}
index 93fa219..bdb3c29 100644 (file)
@@ -15,11 +15,6 @@ public:
     qreal opacity() const {return mOpacity;}
     void setOpacity(qreal opacity);
 
-signals:
-
-public slots:
-    void onAnimationEnd();
-
 protected:
     virtual void paintEvent(QPaintEvent *);