Hide 'Exit fullscreen' button during scrolling (improves performance)
[presencevnc] / src / scrollarea.h
index fa59830..912a4c0 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef SCROLLAREA_H
 #define SCROLLAREA_H
 
+#include "fullscreenexitbutton.h"
+
 #include <QScrollArea>
 #include <QLabel>
 #include <QTimer>
@@ -30,7 +32,8 @@ class ScrollArea : public QScrollArea
 public:
     explicit ScrollArea(QWidget *parent):
         QScrollArea(parent),
-        message(this)
+        message(this),
+        fullscreen_exit_button(parent) //owned by parent!
     {
         message.setVisible(false);
         message.setAlignment(Qt::AlignCenter);
@@ -44,10 +47,18 @@ public:
         message.setAutoFillBackground(true);
 
         message_timer.setSingleShot(true);
-        message_timer.setInterval(2500);
+        message_timer.setInterval(4000);
         connect(&message_timer, SIGNAL(timeout()),
                 &message, SLOT(hide()));
 
+        connect(&fullscreen_exit_button, SIGNAL(clicked()),
+            this, SIGNAL(fullscreenButtonClicked()));
+
+        button_reenable_timer.setSingleShot(true);
+        button_reenable_timer.setInterval(500);
+        connect(&button_reenable_timer, SIGNAL(timeout()),
+                &fullscreen_exit_button, SLOT(reenable()));
+
 #ifdef Q_WS_MAEMO_5
         // disable overshooting because it somehow causes repaint events for the whole widget (slow)
         QAbstractKineticScroller *scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
@@ -65,6 +76,9 @@ public slots:
 
     //provided for convenience
     void showMessage(QString /*title*/, QString msg) { showMessage(msg); }
+
+signals:
+    void fullscreenButtonClicked();
 protected:
     virtual void resizeEvent(QResizeEvent* ev) {
         QScrollArea::resizeEvent(ev);
@@ -72,11 +86,18 @@ protected:
     }
     virtual void scrollContentsBy(int dx, int dy) {
         QScrollArea::scrollContentsBy(dx, dy);
-        if(widget())
-            message.hide(); //overlay-widget slows down scrolling
+        if(widget()) {
+            //overlay-widgets slow down scrolling
+            message.hide();
+            fullscreen_exit_button.hide();
+            fullscreen_exit_button.setEnabled(false);
+            button_reenable_timer.start();
+        }
     }
 private:
     QLabel message;
     QTimer message_timer;
+    FullScreenExitButton fullscreen_exit_button;
+    QTimer button_reenable_timer;
 };
 #endif