diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/previewselectorbar.cpp | 3 | ||||
| -rw-r--r-- | src/tabbar.cpp | 2 | ||||
| -rw-r--r-- | src/websnap.cpp | 57 | ||||
| -rw-r--r-- | src/websnap.h | 22 | 
4 files changed, 55 insertions, 29 deletions
diff --git a/src/previewselectorbar.cpp b/src/previewselectorbar.cpp index cacf6968..037222d6 100644 --- a/src/previewselectorbar.cpp +++ b/src/previewselectorbar.cpp @@ -124,9 +124,6 @@ void PreviewSelectorBar::clicked()      if (page)      { -        // this is done just lo let the render process being faster.. -        WebSnap::renderPreview(*page); -          KUrl url = page->mainFrame()->url();          QStringList names = ReKonfig::previewNames();          QStringList urls = ReKonfig::previewUrls(); diff --git a/src/tabbar.cpp b/src/tabbar.cpp index f56bfda9..2d29032f 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -181,7 +181,7 @@ void TabBar::showTabPreview()      m_previewPopup.data()->setFixedSize(w, h);      QLabel *l = new QLabel(); -    l->setPixmap( WebSnap::renderPreview(*indexedTab->page(), w, h, false) ); +    l->setPixmap( WebSnap::renderTabPreview(*indexedTab->page(), w, h) );      m_previewPopup.data()->setView(l);      m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop); diff --git a/src/websnap.cpp b/src/websnap.cpp index 03bdb544..c4e50b3c 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -79,9 +79,33 @@ void WebSnap::load()  } + +QPixmap WebSnap::render(const QWebPage &page, int w, int h) +{ +    // create the page image +    QPixmap pageImage = QPixmap(w, h); +    pageImage.fill(Qt::transparent); + +    // render it +    QPainter p(&pageImage); +    page.mainFrame()->render(&p, QWebFrame::ContentsLayer); +    p.end(); +     +    return pageImage; +} + + +QPixmap WebSnap::renderTabPreview(const QWebPage &page, int w, int h) +{  +    QPixmap pageImage = WebSnap::render(page, page.viewportSize().width()+17, page.viewportSize().height()); +    return pageImage.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);   +} + + +  // NOTE please, be careful modifying this.  // You are playing with fire.. -QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h, bool save) +QPixmap WebSnap::renderPagePreview(const QWebPage &page, int w, int h)  {      // prepare page      QSize oldSize = page.viewportSize(); @@ -96,34 +120,25 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h, bool save)      size = QSize(width, width * ((0.0 + h) / w));      page.setViewportSize(size); -    // create the page image -    QImage pageImage = QImage(size, QImage::Format_ARGB32_Premultiplied); -    pageImage.fill(Qt::transparent); +    //render +    QPixmap pageImage = WebSnap::render(page, page.viewportSize().width(), page.viewportSize().height()); +     +    // detect scrollbar size +    int scrollbarWidth = (page.mainFrame()->scrollBarMaximum(Qt::Horizontal) ? 17  : 0); //TODO: detect QStyle size for scrollbars +    int scrollbarHeight = (page.mainFrame()->scrollBarMaximum(Qt::Vertical) ? 17 : 0); -    // render it -    QPainter p(&pageImage); -    page.mainFrame()->render(&p, QWebFrame::ContentsLayer); -    p.end(); +    // resize image +    pageImage = pageImage.copy(0, 0, width - scrollbarWidth, size.height() - scrollbarHeight);      pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);      // restore page settings      page.setViewportSize(oldSize); - -    QPixmap pm = QPixmap::fromImage(pageImage); -    if(save) -    { -        KUrl url(page.mainFrame()->url()); -        kDebug() << "saving preview"; -        QString path = imagePathFromUrl(url); -        QFile::remove(path); -        pm.save(path); -    } -     -    return pm; +    return pageImage;  } +  QString WebSnap::imagePathFromUrl(const KUrl &url)  {      QUrl temp = QUrl(url.url()); @@ -148,7 +163,7 @@ void WebSnap::saveResult(bool ok)  {      if (ok)      { -        QPixmap image = renderPreview(m_page, WIDTH, HEIGHT); +        QPixmap image = renderPagePreview(m_page, WIDTH, HEIGHT);          QString path = imagePathFromUrl(m_url);          QFile::remove(path);          image.save(path); diff --git a/src/websnap.h b/src/websnap.h index cfc2c83e..d1006c18 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -80,17 +80,28 @@ public:      ~WebSnap();      /** -     * Snaps a pixmap of size w * h from a page and save it to cache +     * Snaps a pixmap of size w * h from a page       *       * @param page the page to snap       * @param w the image width       * @param h the image height -     * @param save decide to save or not the preview on cache       *       * @return the pixmap snapped from the page       */ -    static QPixmap renderPreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT, bool save = true); - +    static QPixmap renderPagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT); +     +     +    /** +     * Snaps a pixmap of size w * h from a page for tab preview +     * +     * @param page the page to snap +     * @param w the image width +     * @param h the image height +     * +     * @return the pixmap snapped from the page +     */ +    static QPixmap renderTabPreview(const QWebPage &page, int w, int h);    +          /**       * Guess the local path where the image for the url provided       * should be @@ -118,6 +129,9 @@ signals:  private:      QWebPage m_page;      KUrl m_url; +     +    //render a preview: common part of renderPagePreview() and renderTabPreview() +    static QPixmap render(const QWebPage &page, int w, int h);  };  #endif // WEB_SNAP_H  | 
