Beispiel #1
0
FancyTabBar::FancyTabBar(QWidget *parent, bool text, int iSize, Pos pos)
    : QWidget(parent)
    , withText(text)
    , pos(pos)
    , icnSize(iSize)
{
    setFont(Utils::smallFont(font()));
    setAttribute(Qt::WA_Hover, true);
    setFocusPolicy(Qt::NoFocus);
    setMouseTracking(true); // Needed for hover events
    triggerTimer.setSingleShot(true);

    QBoxLayout* layout=0;

    if (Side!=pos) {
        setMinimumHeight(tabSizeHint().height());
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
        layout=new QHBoxLayout;
    } else {
        setMinimumWidth(tabSizeHint().width());
        setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
        layout=new QVBoxLayout;
        layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
    }

    layout->setSpacing(0);
    layout->setContentsMargins(0, 0, 0, 0);
    setLayout(layout);

    // We use a zerotimer to keep the sidebar responsive
    connect(&triggerTimer, SIGNAL(timeout()), this, SLOT(emitCurrentIndex()));
}
Beispiel #2
0
void TabBarWidget::removeTab(int index)
{
	if (underMouse())
	{
		const QSize size = tabSizeHint(count() - 1);

		m_tabSize = size.width();
	}

	Window *window = getWindow(index);

	if (window)
	{
		window->deleteLater();
	}

	QTabBar::removeTab(index);

	if (underMouse() && tabAt(mapFromGlobal(QCursor::pos())) < 0)
	{
		m_tabSize = 0;

		updateGeometry();
		adjustSize();
	}
}
bool PlaylistTabBar::event(QEvent* e) {
  switch (e->type()) {
    case QEvent::ToolTip: {
      QHelpEvent* he = static_cast<QHelpEvent*>(e);

      QRect displayed_tab;
      QSize real_tab;
      bool is_elided = false;

      real_tab = tabSizeHint(tabAt(he->pos()));
      displayed_tab = tabRect(tabAt(he->pos()));
      // Check whether the tab is elided or not
      is_elided = displayed_tab.width() < real_tab.width();
      if (!is_elided) {
        // If it's not elided, don't show the tooltip
        QToolTip::hideText();
      } else {
        QToolTip::showText(he->globalPos(), tabToolTip(tabAt(he->pos())));
      }
      return true;
    }
    default:
      return QTabBar::event(e);
  }
}
Beispiel #4
0
QRect FancyTabBar::tabRect(int index) const
{
    QSize sh = tabSizeHint();

    if (sh.height() * m_tabs.count() > height())
        sh.setHeight(height() / m_tabs.count());

    return QRect(0, index * sh.height(), sh.width(), sh.height());

}
Beispiel #5
0
	QRect ModeTabBar::tabRect(const int &index) const
	{
		QSize size = tabSizeHint();

		//shrink tabs if necessary
		if(size.height() * count() > height()) {
			size.setHeight(height() / count());
		}

		return QRect(0, index * size.height() + tabPadding, size.width(), size.height());
	}
Beispiel #6
0
void TabBarWidget::tabLayoutChange()
{
	QTabBar::tabLayoutChange();

	int offset = 0;
	const bool isHorizontal = (shape() == QTabBar::RoundedNorth || shape() == QTabBar::RoundedSouth);

	for (int i = 0; i < count(); ++i)
	{
		if (isHorizontal)
		{
			offset += tabSizeHint(i).width();
		}
		else
		{
			offset += tabSizeHint(i).height();
		}
	}

	emit moveNewTabButton(offset);
}
Beispiel #7
0
void TabBarWidget::updateButtons()
{
	const QSize size = tabSizeHint(count() - 1);
	const bool isNarrow = (((shape() == QTabBar::RoundedNorth || shape() == QTabBar::RoundedSouth) ? size.width() : size.height()) < 60);

	for (int i = 0; i < count(); ++i)
	{
		QWidget *button = tabButton(i, QTabBar::RightSide);

		if (button)
		{
			button->setVisible((!isNarrow || (i == currentIndex())) && !getTabProperty(i, QLatin1String("isPinned"), false).toBool());
		}
	}
}
Beispiel #8
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));
}
Beispiel #9
0
void MainTabBar::paintEvent(QPaintEvent *) {
    QPainter p(this);

    QLinearGradient g(QPointF(0,0), QPointF(BASE_WIDTH,0));
    g.setSpread(QLinearGradient::PadSpread);
    g.setColorAt(0.0, QColor(170,170,170));
    g.setColorAt(1.0 - 1.0 / BASE_WIDTH, QColor(235,235,235));
    g.setColorAt(1.0, QColor(49,49,49));
    p.fillRect(QRect(QPoint(0,0),this->size()), g);

    QFont font;

    unsigned accumulator(TOP_MARGIN);
    for (int i(0); i != this->count(); ++i) {
        QSize size(tabSizeHint(i));
        if (this->currentIndex() == i) {
            QLinearGradient g(QPointF(0,0), QPointF(BASE_WIDTH,0));
            g.setSpread(QLinearGradient::PadSpread);
            g.setColorAt(0.0, QColor(64,64,64));
            g.setColorAt(1.0 - 1.0 / BASE_WIDTH, QColor(130,130,130));
            g.setColorAt(1.0, QColor(49,49,49));
            QPolygon polygon;
            polygon.reserve(6);
            if (i) {
                polygon.push_back(QPoint(0,accumulator - ARROW_HEIGHT / 2));
                polygon.push_back(QPoint(size.width() / 2,accumulator + ARROW_HEIGHT / 2));
                polygon.push_back(QPoint(size.width(),accumulator - ARROW_HEIGHT / 2));
            } else {
                polygon.push_back(QPoint(0,accumulator));
                polygon.push_back(QPoint(size.width(),accumulator));
            }
            polygon.push_back(QPoint(size.width(),accumulator + size.height() - ARROW_HEIGHT / 2));
            polygon.push_back(QPoint(size.width() / 2,accumulator + size.height() + ARROW_HEIGHT / 2));
            polygon.push_back(QPoint(0,accumulator + size.height() - ARROW_HEIGHT / 2));
            QPainterPath path;
            path.addPolygon(polygon);
            p.fillPath(path, g);
        }
        this->tabIcon(i).paint(&p,QRect(BASE_WIDTH / 2 - iconSize / 2, accumulator + ARROW_HEIGHT / 2,iconSize,iconSize));
        QTextOption options(Qt::AlignCenter);
        options.setWrapMode(QTextOption::WordWrap);
        p.drawText(QRect(0, iconSize + ARROW_HEIGHT / 2 + accumulator, BASE_WIDTH, ROW_HEIGHT),this->tabText(i),options);

        accumulator += size.height();
    }
}
Beispiel #10
0
void TabBar::pinTab()
{
    WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
    if (!webTab) {
        return;
    }

    webTab->pinTab(m_clickedTab);

    if (webTab->isPinned()) {
        m_pinnedTabsCount++;
    }
    else {
        m_pinnedTabsCount--;
    }

    // Adjust add tab button in proper position
    tabSizeHint(count() - 1);
}
Beispiel #11
0
void TabBarWidget::removeTab(int index)
{
	if (underMouse())
	{
		const bool isHorizontal = (shape() == QTabBar::RoundedNorth || shape() == QTabBar::RoundedSouth);
		const QSize size = tabSizeHint(count() - 1);

		m_tabSize = (isHorizontal ? size.width() : size.height());
	}

	QTabBar::removeTab(index);

	if (underMouse() && tabAt(mapFromGlobal(QCursor::pos())) < 0)
	{
		m_tabSize = 0;

		updateGeometry();
		adjustSize();
	}
}
Beispiel #12
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));
}
Beispiel #13
0
	QSize ModeTabBar::sizeHint() const
	{
		QSize size = tabSizeHint();

		return QSize(size.width(), size.height() * count());
	}
Beispiel #14
0
void TabBarWidget::updateTabs(int index)
{
	if (index < 0 && sender() && sender()->inherits(QStringLiteral("Otter::Window").toLatin1()))
	{
		for (int i = 0; i < count(); ++i)
		{
			if (sender() == qvariant_cast<QObject*>(tabData(i)))
			{
				index = i;

				break;
			}
		}
	}

	const QSize size = tabSizeHint(count() - 1);
	const int limit = ((index >= 0) ? (index + 1) : count());
	const bool canResize = (m_tabSize > 0);
	const bool isHorizontal = (shape() == QTabBar::RoundedNorth || shape() == QTabBar::RoundedSouth);
	const bool isNarrow = ((isHorizontal ? size.width() : size.height()) < 60);

	for (int i = ((index >= 0) ? index : 0); i < limit; ++i)
	{
		const bool isLoading = getTabProperty(i, QLatin1String("isLoading"), false).toBool();
		QLabel *label = qobject_cast<QLabel*>(tabButton(i, QTabBar::LeftSide));

		if (label)
		{
			if (isLoading)
			{
				if (!label->movie())
				{
					QMovie *movie = new QMovie(QLatin1String(":/icons/loading.gif"), QByteArray(), label);
					movie->start();

					label->setMovie(movie);
				}
			}
			else
			{
				if (label->movie())
				{
					label->movie()->deleteLater();
					label->setMovie(NULL);
				}

				label->setPixmap(getTabProperty(i, QLatin1String("icon"), QIcon(getTabProperty(i, QLatin1String("isPrivate"), false).toBool() ? ":/icons/tab-private.png" : ":/icons/tab.png")).value<QIcon>().pixmap(16, 16));
			}
		}

		if (canResize)
		{
			QWidget *button = tabButton(i, QTabBar::RightSide);

			if (button)
			{
				button->setVisible((!isNarrow || (i == currentIndex())) && !getTabProperty(i, QLatin1String("isPinned"), false).toBool());
			}
		}
	}

	showPreview(tabAt(mapFromGlobal(QCursor::pos())));
}
Beispiel #15
0
	QSize ModeTabBar::minimumSizeHint() const
	{
		QSize size = tabSizeHint();

		return QSize(size.width(), (size.height() - iconSize) * count());
	}
Beispiel #16
0
QSize FancyTabBar::minimumSizeHint() const
{
    QSize sh = tabSizeHint(true);
    return QSize(sh.width(), sh.height() * m_tabs.count());
}
Beispiel #17
0
// Set minimumTabSizeHint to tabSizeHint
// to keep tabs from shrinking with eliding.
QSize TabBar::minimumTabSizeHint(int index) const
{
    return tabSizeHint (index);
}