QupZilla / qupzilla

Cross-platform Qt web browser
http://www.qupzilla.com
GNU General Public License v3.0
1.12k stars 348 forks source link

Opera like 'fit to width' feature #1222

Open pejakm opened 10 years ago

pejakm commented 10 years ago

Perhaps there is a way to emulate Opera's "Fit to width" feature (picture attached). From the QtTestBrowser's source code:

void WebViewGraphicsBased::setResizesToContents(bool b)
{
    if (b == m_resizesToContents)
        return;

    m_resizesToContents = b;
    graphicsWebView()->setResizesToContents(m_resizesToContents);

    // When setting resizesToContents ON, our web view widget will always size as big as the
    // web content being displayed, and so will the QWebPage's viewport. It implies that internally
    // WebCore will work as if there was no content rendered offscreen, and then no scrollbars need
    // drawing. In order to keep scrolling working, we:
    //
    // 1) Set QGraphicsView's scrollbars policy back to 'auto'.
    // 2) Set scene's boundaries rect to an invalid size, which automatically makes it to be as big
    //    as it needs to enclose all items onto it. We do that because QGraphicsView also calculates
    //    the size of its scrollable area according to the amount of content in scene that is rendered
    //    offscreen.
    // 3) Set QWebPage's preferredContentsSize according to the size of QGraphicsView's viewport,
    //    so WebCore properly lays pages out.
    //
    // On the other hand, when toggling resizesToContents OFF, we set back the default values, as
    // opposite as described above.
    if (m_resizesToContents) {
        setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        graphicsWebView()->page()->setPreferredContentsSize(size());
        QRectF itemRect(graphicsWebView()->geometry().topLeft(), graphicsWebView()->page()->mainFrame()->contentsSize());
        graphicsWebView()->setGeometry(itemRect);
        scene()->setSceneRect(itemRect);
    } else {
        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        graphicsWebView()->page()->setPreferredContentsSize(QSize());
        QRect viewportRect(QPoint(0, 0), size());
        graphicsWebView()->setGeometry(viewportRect);
        scene()->setSceneRect(viewportRect);
    }
}

Now, if it's possible, the real question is whether it is actually needed in a web browser, now when wide screens are more common then before.

opera

ghost commented 10 years ago

Yes, it's a nice feature and needed (at least here) despite having a 27" monitor, especially as it (by text wrapping) eliminates the need to annoyingly scroll left and right in some web pages.

Frenzie commented 7 years ago

Now, if it's possible, the real question is whether it is actually needed in a web browser, now when wide screens are more common then before.

My monitor size and window size are related only on tiny monitors. The main reason it's less useful is because sites tend to take smaller screensizes (i.e. cellphones) into account already.