Ticket #4337: mythbrowser2.patch

File mythbrowser2.patch, 11.3 KB (added by Jonatan <mythtv@…>, 16 years ago)

Page up/down handling and removal of trailing spaces in mythbrowser

  • mythbrowser/tabview.cpp

     
    4242
    4343using namespace std;
    4444
    45 TabView::TabView(MythMainWindow *parent, const char *name, QStringList urls, 
     45TabView::TabView(MythMainWindow *parent, const char *name, QStringList urls,
    4646                 int zoom, int width, int height, WFlags flags)
    4747    :MythDialog(parent, name)
    4848{
     
    6969    scrollSpeed = gContext->GetNumSetting("WebBrowserScrollSpeed", 4);
    7070    scrollPage = gContext->GetNumSetting("WebBrowserScrollMode", 1);
    7171    hideScrollbars = gContext->GetNumSetting("WebBrowserHideScrollbars", 0);
    72     if (scrollPage == 1) 
     72    if (scrollPage == 1)
    7373       scrollSpeed *= -1;  // scroll page vs background
    7474
    7575    urlHistory.setAutoDelete(true);
     
    109109void TabView::pageCompleted(WebPage *page)
    110110{
    111111    // Strip leading and trailing whitespace from page title
    112     QString title = 
     112    QString title =
    113113            page->browser->htmlDocument().title().string().stripWhiteSpace();
    114114
    115115    if (title.isEmpty())
     
    190190    int step = 5;
    191191
    192192    // speed up mouse movement if the same key is held down
    193     if (action == lastMouseAction && 
     193    if (action == lastMouseAction &&
    194194           lastMouseActionTime.msecsTo(QTime::currentTime()) < 500)
    195195    {
    196196        lastMouseActionTime = QTime::currentTime();
     
    205205        mouseKeyCount = 1;
    206206    }
    207207
    208     if (action == "MOUSEUP") 
     208    if (action == "MOUSEUP")
    209209    {
    210210        QPoint curPos = QCursor::pos();
    211211        QCursor::setPos(curPos.x(), curPos.y() - step);
    212212    }
    213     else if (action == "MOUSELEFT") 
     213    else if (action == "MOUSELEFT")
    214214    {
    215215        QPoint curPos = QCursor::pos();
    216216        QCursor::setPos(curPos.x() - step, curPos.y());
    217217    }
    218     else if (action == "MOUSERIGHT") 
     218    else if (action == "MOUSERIGHT")
    219219    {
    220220        QPoint curPos = QCursor::pos();
    221221        QCursor::setPos(curPos.x() + step, curPos.y());
    222222    }
    223     else if (action == "MOUSEDOWN") 
     223    else if (action == "MOUSEDOWN")
    224224    {
    225225        QPoint curPos = QCursor::pos();
    226226        QCursor::setPos(curPos.x(), curPos.y() + step);
    227227    }
    228     else if (action == "MOUSELEFTBUTTON") 
     228    else if (action == "MOUSELEFTBUTTON")
    229229    {
    230230        QPoint curPos = mouse->pos();
    231231        QWidget *widget = QApplication::widgetAt(curPos, TRUE);
    232232
    233         if (widget) 
     233        if (widget)
    234234        {
    235235            curPos = widget->mapFromGlobal(curPos);
    236236
     
    240240
    241241            me = new QMouseEvent(QEvent::MouseButtonRelease, curPos,
    242242                                Qt::LeftButton, Qt::NoButton);
    243             QApplication::postEvent(widget, me); 
     243            QApplication::postEvent(widget, me);
    244244        }
    245245    }
    246246}
     
    275275
    276276    int index = mytab->currentPageIndex();
    277277
    278     // delete web pages stored in history 
     278    // delete web pages stored in history
    279279    urlHistory.remove(index);
    280280
    281281    // delete current web page
     
    315315    caption->setAlignment(Qt::AlignCenter);
    316316
    317317    popup->addLabel(tr("Group:"), MythPopupBox::Small);
    318     MythRemoteLineEdit *group = new MythRemoteLineEdit(popup); 
     318    MythRemoteLineEdit *group = new MythRemoteLineEdit(popup);
    319319    popup->addWidget(group);
    320320
    321321    popup->addLabel(tr("Description:"), MythPopupBox::Small);
    322     MythRemoteLineEdit *desc = new MythRemoteLineEdit(popup); 
     322    MythRemoteLineEdit *desc = new MythRemoteLineEdit(popup);
    323323    popup->addWidget(desc);
    324324
    325325    popup->addLabel(tr("URL:"), MythPopupBox::Small);
    326     MythRemoteLineEdit *url = new MythRemoteLineEdit(popup); 
     326    MythRemoteLineEdit *url = new MythRemoteLineEdit(popup);
    327327    url->setText(((WebPage*)mytab->currentPage())->browser->baseURL().htmlURL());
    328328    popup->addWidget(url);
    329329
     
    354354    QString descStr = QString(desc);
    355355    QString urlStr = QString(url);
    356356    urlStr.stripWhiteSpace();
    357     if( !urlStr.startsWith("http://") && !urlStr.startsWith("https://") && 
     357    if( !urlStr.startsWith("http://") && !urlStr.startsWith("https://") &&
    358358            !urlStr.startsWith("file:/") )
    359359        urlStr.prepend("http://");
    360360
     
    394394
    395395    MythRemoteLineEdit *editor = new MythRemoteLineEdit(popup);
    396396    popup->addWidget(editor);
    397     editor->setFocus(); 
     397    editor->setFocus();
    398398
    399399    popup->addButton(tr("OK"),     popup, SLOT(accept()));
    400400    popup->addButton(tr("Cancel"), popup, SLOT(reject()));
     
    427427    connect(page,SIGNAL( newUrlRequested(const KURL &,const KParts::URLArgs&)),
    428428            this, SLOT( newUrlRequested(const KURL &,const KParts::URLArgs &)));
    429429
    430     connect(page, SIGNAL( newWindowRequested( const KURL &, const KParts::URLArgs &, 
    431                   const KParts::WindowArgs &, KParts::ReadOnlyPart *&) ), 
    432             this, SLOT( newWindowRequested( const KURL &, const KParts::URLArgs &, 
     430    connect(page, SIGNAL( newWindowRequested( const KURL &, const KParts::URLArgs &,
     431                  const KParts::WindowArgs &, KParts::ReadOnlyPart *&) ),
     432            this, SLOT( newWindowRequested( const KURL &, const KParts::URLArgs &,
    433433                                  const KParts::WindowArgs &, KParts::ReadOnlyPart *&) ) );
    434434    connect(page, SIGNAL( pageCompleted(WebPage *) ),
    435435            this, SLOT( pageCompleted(WebPage *) ) );
     
    451451
    452452    if (mytab->tabLabel(mytab->currentPage()) == "")
    453453    {
    454         // if the tab title is blank then a new blank web page has already been 
    455         // created for a popup window just need to open the URL 
     454        // if the tab title is blank then a new blank web page has already been
     455        // created for a popup window just need to open the URL
    456456        ((WebPage*)mytab->currentPage())->openURL(url.url());
    457457
    458458        mytab->setTabLabel(mytab->currentPage(), tr("Loading..."));
     
    485485{
    486486    object = object;
    487487
    488     if (event->type() == QEvent::MouseButtonPress) 
     488    if (event->type() == QEvent::MouseButtonPress)
    489489    {
    490490        QMouseEvent* me = (QMouseEvent*)event;
    491491
     
    500500        }
    501501    }
    502502
    503     if (event->type() == QEvent::MouseButtonRelease) 
     503    if (event->type() == QEvent::MouseButtonRelease)
    504504    {
    505505        QMouseEvent* me = (QMouseEvent*)event;
    506506        lastButtonState = me->stateAfter();
    507507    }
    508508
    509509    QScrollView *view=((WebPage*)mytab->currentPage())->browser->view();
    510     if (event->type() == QEvent::Show) 
     510    if (event->type() == QEvent::Show)
    511511    {
    512         // hide scrollbars - kind of a hack to do it on a show event but 
    513         // for some reason I can't get it to work upon creation of the page 
     512        // hide scrollbars - kind of a hack to do it on a show event but
     513        // for some reason I can't get it to work upon creation of the page
    514514        //   - TSH
    515         if (hideScrollbars) 
     515        if (hideScrollbars)
    516516        {
    517517            QScrollView *view=((WebPage*)mytab->currentPage())->browser->view();
    518518            view->setVScrollBarMode(QScrollView::AlwaysOff);
     
    522522
    523523    // MouseMove while middlebutton pressed pans page
    524524    int deltax = 0, deltay = 0;
    525     if (event->type() == QEvent::MouseMove) 
     525    if (event->type() == QEvent::MouseMove)
    526526    {
    527527        QMouseEvent* me = (QMouseEvent*)event;
    528528        lastButtonState = me->stateAfter();
     
    530530        deltay = me->globalY() - lastPosY;
    531531        deltax *= scrollSpeed;
    532532        deltay *= scrollSpeed;
    533         if (lastPosX != -1 
    534 //            && (lastButtonState & (LeftButton|AltButton)) 
    535             && (lastButtonState & (MidButton|AltButton)) 
     533        if (lastPosX != -1
     534//            && (lastButtonState & (LeftButton|AltButton))
     535            && (lastButtonState & (MidButton|AltButton))
    536536            && !view->isHorizontalSliderPressed()
    537             && !view->isVerticalSliderPressed() ) 
     537            && !view->isVerticalSliderPressed() )
    538538        {
    539539            view->scrollBy(deltax, deltay);
    540540        }
     
    543543    }
    544544
    545545    // MouseWheel scrolling while middlebutton/ctrlkey pressed to zoom in/out
    546     if (event->type() == QEvent::Wheel) 
     546    if (event->type() == QEvent::Wheel)
    547547    {
    548548        QWheelEvent* we = (QWheelEvent*)event;
    549         if (lastButtonState & MidButton || we->state() & AltButton) 
     549        if (lastButtonState & MidButton || we->state() & AltButton)
    550550        {
    551             if (we->delta() > 0) 
     551            if (we->delta() > 0)
    552552            {
    553553                we->accept();
    554554                ((WebPage*)mytab->currentPage())->zoomIn();
    555555                return true;
    556556            }
    557             else if (we->delta() < 0) 
     557            else if (we->delta() < 0)
    558558            {
    559559                we->accept();
    560560                ((WebPage*)mytab->currentPage())->zoomOut();
     
    598598            QString action = actions[i];
    599599            handled = true;
    600600
    601             if (action == "TOGGLEINPUT") 
     601            if (action == "TOGGLEINPUT")
    602602            {
    603603                if (gContext->GetNumSetting("UseVirtualKeyboard", 1) == 1)
    604604                {
     
    607607
    608608                    inputToggled = true;
    609609                    VirtualKeyboard *keyboard = new VirtualKeyboard(
    610                         gContext->GetMainWindow(), 
     610                        gContext->GetMainWindow(),
    611611                        ((WebPage*)mytab->currentPage())->browser->view());
    612612                    gContext->GetMainWindow()->detach(keyboard);
    613613                    keyboard->exec();
     
    627627            if (inputToggled)
    628628                return false;
    629629
    630             if (action == "NEXTTAB") 
     630            if (action == "NEXTTAB")
    631631            {
    632632                actionNextTab();
    633633                return true;
     
    661661                actionZoomOut();
    662662                return true;
    663663            }
    664             else if (action == "MOUSEUP" || action == "MOUSEDOWN" || 
     664            else if (action == "MOUSEUP" || action == "MOUSEDOWN" ||
    665665                     action == "MOUSELEFT" || action == "MOUSERIGHT" ||
    666666                     action == "MOUSELEFTBUTTON") {
    667667                handleMouseAction(action);
     
    678678                showEnterURLDialog();
    679679                return true;
    680680            }
    681             else if (action == "MENU") 
     681            else if (action == "MENU")
    682682            {
    683683                emit menuPressed();
    684684                return true;
    685685            }
    686             else if (action == "UP") 
     686            else if (action == "UP")
    687687            {
    688688                KHTMLView *view = ((WebPage*)mytab->currentPage())->browser->view();
    689689                view->scrollBy(0, -view->visibleHeight() / 10);
    690690                return true;
    691 
    692691            }
    693             else if (action == "DOWN") 
     692            else if (action == "DOWN")
    694693            {
    695694                KHTMLView *view = ((WebPage*)mytab->currentPage())->browser->view();
    696695                view->scrollBy(0, view->visibleHeight() / 10);
    697696                return true;
    698697            }
     698            else if (action == "PAGEUP")
     699            {
     700                KHTMLView *view = ((WebPage*)mytab->currentPage())->browser->view();
     701                view->scrollBy(0, -view->visibleHeight());
     702                return true;
     703            }
     704            else if (action == "PAGEDOWN")
     705            {
     706                KHTMLView *view = ((WebPage*)mytab->currentPage())->browser->view();
     707                view->scrollBy(0, view->visibleHeight());
     708                return true;
     709            }
    699710        }
    700711    }
    701712