Ejemplo n.º 1
0
void TabBar::showTabPreview()
{
    if (m_isFirstTimeOnTab)
        m_isFirstTimeOnTab = false;

    //delete previous tab preview
    delete m_previewPopup.data();
    m_previewPopup.clear();

    MainView *mv = qobject_cast<MainView *>(parent());

    WebTab *indexedTab = mv->webTab(m_currentTabPreviewIndex);
    WebTab *currentTab = mv->webTab(currentIndex());

    // check if view && currentView exist before using them :)
    if (!currentTab || !indexedTab)
        return;

    // no previews during load
    if (indexedTab->isPageLoading())
        return;

    // Make sure the hovered webtab match the current size
    // Only the active one is updated by window resize events
    indexedTab->resize(currentTab->size());

    m_previewPopup = new TabPreviewPopup(indexedTab , this);

    int tabWidth = tabSizeHint(m_currentTabPreviewIndex).width();
    int tabBarWidth = mv->size().width();
    int leftIndex = tabRect(m_currentTabPreviewIndex).x() + (tabRect(m_currentTabPreviewIndex).width() - tabWidth) / 2;
    int popupWidth = m_previewPopup.data()->thumbnailSize().width();

    // Center the popup if the tab width is bigger or smaller
    leftIndex += (tabWidth - popupWidth) / 2;

    if (leftIndex < 0)
    {
        leftIndex = 0;
    }
    else if (leftIndex + tabWidth > tabBarWidth)
    {
        leftIndex = tabBarWidth - tabWidth;
    }

    QPoint pos(leftIndex, tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height());
    m_previewPopup.data()->show(mapToGlobal(pos));
}
Ejemplo n.º 2
0
void SessionManager::saveSession()
{
    if (!m_safe || QWebSettings::globalSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
        return;
    m_safe = false;


    QFile sessionFile(m_sessionFilePath);
    if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate))
    {
        kDebug() << "Unable to open session file" << sessionFile.fileName();
        return;
    }
    QTextStream out(&sessionFile);
    MainWindowList wl = rApp->mainWindowList();
    Q_FOREACH(const QWeakPointer<MainWindow> &w, wl)
    {
        out << "window\n";
        MainView *mv = w.data()->mainView();
        for (int i = 0 ; i < mv->count() ; i++)
        {
            out << mv->webTab(i)->url().toEncoded() << "\n";
        }

        // Current Tab for window
        out << "currenttab\n";
        out << mv->tabBar()->currentIndex() << "\n";
    }
Ejemplo n.º 3
0
void TabBar::showTabPreview()
{
    //delete previous tab preview
    delete m_previewPopup.data();
    m_previewPopup.clear();

    MainView *mv = qobject_cast<MainView *>(parent());

    WebTab *indexedTab = mv->webTab(m_currentTabPreviewIndex);
    WebTab *currentTab = mv->webTab(currentIndex());

    // check if view && currentView exist before using them :)
    if (!currentTab || !indexedTab)
        return;

    // no previews during load
    if (indexedTab->isPageLoading())
        return;

    int w = tabSizeHint(m_currentTabPreviewIndex).width();
    int h = w * ((0.0 + currentTab->height()) / currentTab->width());

    m_previewPopup = new KPassivePopup(this);
    m_previewPopup.data()->setFrameShape(QFrame::StyledPanel);
    m_previewPopup.data()->setFrameShadow(QFrame::Plain);
    m_previewPopup.data()->setFixedSize(w, h);

    QLabel *l = new QLabel();
    l->setPixmap( WebSnap::renderTabPreview(*indexedTab->page(), w, h) );

    m_previewPopup.data()->setView(l);
    m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop);
    m_previewPopup.data()->layout()->setMargin(0);

    QPoint pos(tabRect(m_currentTabPreviewIndex).x() , tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height());
    m_previewPopup.data()->show(mapToGlobal(pos));
}