[mythtv] [PATCH] Mythbrowser GUIOffset fix and misc additions

Tim Harvey tharvey at alumni.calpoly.edu
Wed Jan 21 05:43:27 EST 2004


Woops... how about I actually attach the patch this time!

> -----Original Message-----
> From: mythtv-dev-bounces at mythtv.org
[mailto:mythtv-dev-bounces at mythtv.org]
> On Behalf Of Tim Harvey
> Sent: Wednesday, January 21, 2004 2:36 AM
> To: mythtv-dev at mythtv.org
> Subject: [mythtv] [PATCH] Mythbrowser GUIOffset fix and misc additions
> 
> I noticed back in the mail list that someone had mentioned MythBrowser
> doesn't honor the GuiOffsetX/Y settings so I decided to patch it up.
> While I was playing with it, I added a few things.
> 
> This patch effects the following changes to the MythBrowser plugin:
> 
>    - places browser window according to GuiOffsetX/Y
>    - implements mouse-scrolling options:
>         When holding either the middle mouse button or the ALT key and
>         dragging the mouse, the page will scroll in a direction based
on
> 
>         the 'Scroll Page' option, at a speed related to the 'Scroll
> Speed'
>         setting.
>    - implements ability to hide the scrollbars based on a setting
> checkbox
>    - implements options in settings dlg for 'Scroll Page' and 'Scroll
> Speed'
>      and 'Hide Scrollbars'
>    - implements mouse-wheel zooming:
>         When holding either the middle mouse button or the ALT key and
>         scrolling the mouse-wheel, the zoom factor will adjusted
>         according to the direction of the wheel movement
> 
> 
> I'm much grateful for Philippe Cattin's contribution of MythBrowser,
> I've found it to be a pretty cool addition.
> 
> I hope others find this patch of use.
> 
> Tim

-------------- next part --------------
Index: mythbrowser/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythbrowser/mythbrowser/main.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 main.cpp
--- mythbrowser/main.cpp	29 Oct 2003 16:04:51 -0000	1.1.1.1
+++ mythbrowser/main.cpp	21 Jan 2004 10:31:33 -0000
@@ -39,6 +39,8 @@
 
 int main(int argc, char **argv)
 {
+    int x = 0, y = 0;
+    float xm = 0, ym = 0;
     int zoom,width=-1,height=-1;    // defaults
     char usage[] = "Usage: mythbrowser [-z n] [-w n] [-h n] -u URL [URL]";
     QStringList urls;
@@ -80,10 +82,15 @@
 //    gContext->SetMainWindow(mainWindow);
 //    a.setMainWidget(mainWindow);
 
+    // Obtain width/height and x/y offset from context
+    gContext->GetScreenSettings(x, width, xm, y, height, ym);
+
     TabView *mainWindow = 
         new TabView(db, urls, zoom, width, height, Qt::WStyle_Customize | Qt::WStyle_NoBorder);
     gContext->SetMainWindow(mainWindow);
     a.setMainWidget(mainWindow);
+    mainWindow->setGeometry(x, y, width, height);
+    mainWindow->setFixedSize(QSize(width, height));
     mainWindow->Show();
 
     return a.exec();
Index: mythbrowser/tabview.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythbrowser/mythbrowser/tabview.cpp,v
retrieving revision 1.4
diff -u -r1.4 tabview.cpp
--- mythbrowser/tabview.cpp	31 Dec 2003 21:47:44 -0000	1.4
+++ mythbrowser/tabview.cpp	21 Jan 2004 10:31:33 -0000
@@ -32,6 +32,7 @@
 #include <kaction.h>
 #include <kstdaction.h>
 #include <khtml_part.h>
+#include <khtmlview.h>
 
 #include "mythtv/mythcontext.h"
 
@@ -52,6 +53,19 @@
     h=height-rect.height();
     f=flags;
 
+    // Qt doesn't give you mousebutton states from QWheelEvent->state()
+    // so we have to remember the last mousebutton press/release state
+    lastButtonState = (ButtonState)0;
+
+    lastPosX = -1;
+    lastPosY = -1;
+    scrollSpeed = gContext->GetNumSetting("WebBrowserScrollSpeed", 4);
+    scrollPage = gContext->GetNumSetting("WebBrowserScrollMode", 1);
+    hideScrollbars = gContext->GetNumSetting("WebBrowserHideScrollbars", 0);
+    if (scrollPage == 1) {
+       scrollSpeed *= -1;  // scroll page vs background
+    }
+
     for(QStringList::Iterator it = urls.begin(); it != urls.end(); ++it) {
         // is rect.height() really the height of the tab in pixels???
         WebPage *page = new WebPage(*it,z,w,h,f);
@@ -59,6 +73,15 @@
            this, SLOT( newUrlRequested(const KURL &,const KParts::URLArgs &)));
         mytab->addTab(page,*it);
 
+/* moved this into show event processing
+        // Hide Scrollbars - Why doesn't this work??? TSH 1/20/04
+        if (hideScrollbars) {
+            KHTMLView* view = page->browser->view();
+            view->setVScrollBarMode(QScrollView::AlwaysOff);
+            view->setHScrollBarMode(QScrollView::AlwaysOff);
+        }
+*/
+
 	QPtrStack<QWidget> *currWidgetHistory = new QPtrStack<QWidget>;
 	widgetHistory.append(currWidgetHistory);
 	QValueStack<QString> *currUrlHistory = new QValueStack<QString>;
@@ -256,6 +279,7 @@
     if (event->type() == QEvent::MouseButtonPress) {
         QMouseEvent* me = (QMouseEvent*)event;
 
+        lastButtonState = me->stateAfter(); 
         if(me->button() == Qt::RightButton) {
             if(menuIsOpen)
                 emit closeMenu();
@@ -265,6 +289,61 @@
         }
     }
 
+    if (event->type() == QEvent::MouseButtonRelease) {
+        QMouseEvent* me = (QMouseEvent*)event;
+        lastButtonState = me->stateAfter(); 
+    }
+
+    QScrollView *view=((WebPage*)mytab->currentPage())->browser->view();
+    if (event->type() == QEvent::Show) {
+        // hide scrollbars - kind of a hack to do it on a show event but 
+        // for some reason I can't get it to work upon creation of the page 
+        //   - TSH
+        if (hideScrollbars) {
+            QScrollView *view=((WebPage*)mytab->currentPage())->browser->view();
+            view->setVScrollBarMode(QScrollView::AlwaysOff);
+            view->setHScrollBarMode(QScrollView::AlwaysOff);
+        }
+    }
+
+    // MouseMove while middlebutton pressed pans page
+    int deltax = 0, deltay = 0;
+    if (event->type() == QEvent::MouseMove) {
+        QMouseEvent* me = (QMouseEvent*)event;
+        lastButtonState = me->stateAfter(); 
+        deltax = me->globalX() - lastPosX;
+        deltay = me->globalY() - lastPosY;
+        deltax *= scrollSpeed;
+        deltay *= scrollSpeed;
+        if (lastPosX != -1 
+//            && (lastButtonState & (LeftButton|AltButton)) 
+            && (lastButtonState & (MidButton|AltButton)) 
+            && !view->isHorizontalSliderPressed()
+            && !view->isVerticalSliderPressed() ) 
+        {
+            view->scrollBy(deltax, deltay);
+        }
+        lastPosX = me->globalX();
+        lastPosY = me->globalY();
+    }
+
+    // MouseWheel scrolling while middlebutton/ctrlkey pressed to zoom in/out
+    if (event->type() == QEvent::Wheel) {
+        QWheelEvent* we = (QWheelEvent*)event;
+        if (lastButtonState & MidButton || we->state() & AltButton) {
+            if (we->delta() > 0) {
+                we->accept();
+                ((WebPage*)mytab->currentPage())->zoomIn();
+                return true;
+            } else if (we->delta() < 0)  {
+                we->accept();
+                ((WebPage*)mytab->currentPage())->zoomOut();
+                return true;
+            }
+        }
+
+    }
+
     if(menuIsOpen)
         return false;
 
Index: mythbrowser/tabview.h
===================================================================
RCS file: /var/lib/mythcvs/mythbrowser/mythbrowser/tabview.h,v
retrieving revision 1.2
diff -u -r1.2 tabview.h
--- mythbrowser/tabview.h	30 Dec 2003 21:20:20 -0000	1.2
+++ mythbrowser/tabview.h	21 Jan 2004 10:31:33 -0000
@@ -78,6 +78,13 @@
 
     QPtrList<WIDGET_HISTORY> widgetHistory;
     QPtrList<URL_HISTORY> urlHistory;
+
+    ButtonState lastButtonState;
+    int lastPosX; 
+    int lastPosY; 
+    int scrollSpeed;
+    int scrollPage;
+    int hideScrollbars;
 };
 
 class PopupBox : public QDialog


More information about the mythtv-dev mailing list