diff options
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/tabbar.cpp | 42 | ||||
| -rw-r--r-- | src/tabbar.h | 12 | ||||
| -rw-r--r-- | src/tabpreviewpopup.cpp | 108 | ||||
| -rw-r--r-- | src/tabpreviewpopup.h | 66 | 
5 files changed, 183 insertions, 46 deletions
| diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f623adfd..eae0f89c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ SET( rekonq_KDEINIT_SRCS      previewselectorbar.cpp      protocolhandler.cpp      sessionmanager.cpp +    tabpreviewpopup.cpp      tabbar.cpp      tabhighlighteffect.cpp      urlfilterproxymodel.cpp diff --git a/src/tabbar.cpp b/src/tabbar.cpp index dee49eaf..1b2dcb2b 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -42,11 +42,11 @@  #include "webtab.h"  #include "websnap.h"  #include "tabhighlighteffect.h" +#include "tabpreviewpopup.h"  // KDE Includes  #include <KActionMenu>  #include <KMenu> -#include <KPassivePopup>  #include <KToolBar>  #include <KColorScheme> @@ -183,46 +183,8 @@ void TabBar::showTabPreview()          return;      int w = (mv->sizeHint().width() / baseWidthDivisor); -    int h = w * 0.75; -    m_previewPopup = new KPassivePopup(this); -    m_previewPopup.data()->setFrameShape(QFrame::StyledPanel); -    m_previewPopup.data()->setFrameShadow(QFrame::Plain); - -    QWidget *widget = new QWidget(); -    QLabel *thumbnail = new QLabel(widget); -    QLabel *title = new QLabel(widget); -    QLabel *url = new QLabel(widget); -    thumbnail->setPixmap(WebSnap::renderTabPreview(*indexedTab->page(), w, h)); -    thumbnail->setAlignment(Qt::AlignHCenter); - -    QString text = indexedTab->view()->title(); -    if (text.length() > 20) -    { -        text = text.left(17) + "..."; -    } - -    title->setText(text); -    title->setAlignment(Qt::AlignHCenter); - -    text = indexedTab->url().prettyUrl(); -    if (text.length() > 20) -    { -        text = text.left(17) + "..."; -    } - -    url->setText(text); -    url->setAlignment(Qt::AlignHCenter); -    QVBoxLayout *vb = new QVBoxLayout(widget); -    vb->addWidget(title); -    vb->addWidget(thumbnail); -    vb->addWidget(url); -    widget->setLayout(vb); - -    m_previewPopup.data()->setFixedSize(w, h + url->heightForWidth(w) + title->heightForWidth(w)); -    m_previewPopup.data()->setView(widget); -    m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop); -    m_previewPopup.data()->layout()->setMargin(0); +    m_previewPopup = new TabPreviewPopup(indexedTab ,this);      int tabBarWidth = mv->size().width();      int leftIndex = tabRect(m_currentTabPreviewIndex).x() + (tabRect(m_currentTabPreviewIndex).width() - w)/2; diff --git a/src/tabbar.h b/src/tabbar.h index c1b0ba5c..1949673f 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -41,7 +41,7 @@  #include <QSignalMapper>  // Forward Declarations -class KPassivePopup; +class TabPreviewPopup;  class TabHighlightEffect;  class QPropertyAnimation; @@ -63,6 +63,10 @@ public:      QRect tabTextRect(int index);      void setAnimatedTabHighlighting(bool enabled); +    //constants +    static const int baseWidthDivisor = 4; +    static const int minWidthDivisor = 8; +  signals:      void cloneTab(int index);      void closeTab(int index); @@ -101,10 +105,6 @@ private slots:      void removeAnimation(int index);  private: -    //constants -    static const int baseWidthDivisor = 4; -    static const int minWidthDivisor = 8; -      void setupHistoryActions();      friend class MainView; @@ -113,7 +113,7 @@ private:       */      int m_actualIndex; -    QWeakPointer<KPassivePopup> m_previewPopup; +    QWeakPointer<TabPreviewPopup> m_previewPopup;      /**       * the index of the tab preview shown diff --git a/src/tabpreviewpopup.cpp b/src/tabpreviewpopup.cpp new file mode 100644 index 00000000..3d1bc5a6 --- /dev/null +++ b/src/tabpreviewpopup.cpp @@ -0,0 +1,108 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Vyacheslav Blinov <blinov dot vyacheslav at gmail dot com> +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program.  If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + +//Self Includes +#include "tabpreviewpopup.h" + +// Rekonq Includes +#include "webtab.h" +#include "tabbar.h" +#include "websnap.h" +#include "application.h" +#include "mainwindow.h" + +//Qt Includes +#include <QLabel> +#include <QVBoxLayout> +#include <QPalette> +#include <QBitmap> +#include <QPoint> + + +TabPreviewPopup::TabPreviewPopup(WebTab* tab,QWidget* parent) +  : KPassivePopup(parent), +    m_thumbnail(new QLabel(this)), +    m_url(new QLabel(this)) +{ +    m_thumbnail->setAlignment(Qt::AlignHCenter); +    m_url->setAlignment(Qt::AlignHCenter); + +    QVBoxLayout *vb = new QVBoxLayout(this); +    vb->addWidget(m_thumbnail); +    vb->addWidget(m_url); +    this->setLayout(vb); + +    layout()->setAlignment(Qt::AlignTop); +    layout()->setMargin(0); + +    setFrameShape(QFrame::StyledPanel); +    setFrameShadow(QFrame::Raised); +    setWindowOpacity(transparency); + +    setWebTab(tab); +} + +TabPreviewPopup::~TabPreviewPopup() +{ +    delete m_thumbnail; +    delete m_url; +} + + +void TabPreviewPopup::setWebTab(WebTab* tab) +{ +    int w = (tab->parentWidget()->sizeHint().width() / TabBar::baseWidthDivisor); +    int h = w * rApp->mainWindow()->size().height() / rApp->mainWindow()->size().width(); + +    setThumbnail(WebSnap::renderTabPreview(*tab->page(), w, h)); +    setUrl(tab->url().prettyUrl()); + +    setFixedSize(w, h + m_url->heightForWidth(w)); +} + + +void TabPreviewPopup::setThumbnail(const QPixmap& pixmap) +{ +    m_thumbnail->setPixmap(pixmap); +} + +void TabPreviewPopup::setUrl(const QString& text) +{ +    m_url->setText(text); +} + +void TabPreviewPopup::setFixedSize(int w, int h) +{ +    KPassivePopup::setFixedSize(w,h); +    m_url->setText(m_url->fontMetrics().elidedText(m_url->text(),Qt::ElideMiddle,this->width() - this->borderRadius)); + +    QPixmap pixmap(size()); +    QPainter painter(&pixmap); +    painter.setRenderHint(QPainter::Antialiasing); +    painter.fillRect(pixmap.rect(), Qt::red); +    painter.setBrush(QBrush(Qt::black)); +    painter.drawRoundRect(borderSpacing,borderSpacing,pixmap.width()-borderSpacing*2,pixmap.height()-borderSpacing*2, borderRadius, borderRadius); +    setMask(pixmap.createMaskFromColor(Qt::red)); +}
\ No newline at end of file diff --git a/src/tabpreviewpopup.h b/src/tabpreviewpopup.h new file mode 100644 index 00000000..fe2c50ac --- /dev/null +++ b/src/tabpreviewpopup.h @@ -0,0 +1,66 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Vyacheslav Blinov <blinov dot vyacheslav at gmail dot com> +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program.  If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + +#ifndef TABPREVIEWPOPUP_H +#define TABPREVIEWPOPUP_H + +// Rekonq Includes +#include "rekonq_defines.h" + +// KDE Includes +#include <KPassivePopup> + +// forward declatrations +class WebTab; +class QLabel; + +class REKONQ_TESTS_EXPORT TabPreviewPopup : public KPassivePopup +{ + +public: +    /** +    * @brief This constructs a new Tab Preview Popup witch will create a thumbnail and title with url from WebTab object +    * +    * @param tab a WebTab object witch will be used to create a preview +    * @param parent +    **/ +    explicit TabPreviewPopup(WebTab *tab, QWidget *parent = 0); +    virtual ~TabPreviewPopup(); +     + +private: +    QLabel *m_thumbnail; +    QLabel *m_url; + +    void setWebTab(WebTab *tab = 0); +    void setUrl(const QString& text); +    void setThumbnail(const QPixmap& pixmap); +    void setFixedSize(int w, int h); +    static const int borderRadius = 5; +    static const int borderSpacing = 2; +    static const double transparency = 0.90; +}; + +#endif // TABPREVIEWPOPUP_H | 
