Exemple #1
0
void TabBar::showCloseButton(int index)
{

    WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
    if (webTab && webTab->isPinned()) {
        return;
    }

    CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide);
    if (!button) {
        return;
    }

    button->show();
}
Exemple #2
0
void TabBar::showCloseButton(int index)
{
    if (!validIndex(index)) {
        return;
    }

    WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
    QAbstractButton* button = qobject_cast<QAbstractButton*>(tabButton(index, closeButtonPosition()));

    if (button || (webTab && webTab->isPinned())) {
        return;
    }

    insertCloseButton(index);
}
Exemple #3
0
void TabBar::closeTabFromButton()
{
    QWidget* button = qobject_cast<QWidget*>(sender());

    int tabToClose = -1;

    for (int i = 0; i < count(); ++i) {
        if (tabButton(i, closeButtonPosition()) == button) {
            tabToClose = i;
            break;
        }
    }

    if (tabToClose != -1) {
        m_tabWidget->requestCloseTab(tabToClose);
    }
}
Exemple #4
0
void TabBar::showCloseButton(int index)
{
    if (!validIndex(index)) {
        return;
    }

    WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
    QAbstractButton* button = qobject_cast<QAbstractButton*>(tabButton(index, QTabBar::RightSide));

    if (button || (webTab && webTab->isPinned())) {
        return;
    }

    QAbstractButton* closeButton = new CloseButton(this);
    connect(closeButton, SIGNAL(clicked()), this, SLOT(closeTabFromButton()));
    setTabButton(index, QTabBar::RightSide, closeButton);
}
Exemple #5
0
void TabBarWidget::addTab(int index, Window *window)
{
	insertTab(index, window->getTitle());
	setTabData(index, QVariant::fromValue(window));

	connect(window, SIGNAL(iconChanged(QIcon)), this, SLOT(updateTabs()));
	connect(window, SIGNAL(loadingStateChanged(WindowLoadingState)), this, SLOT(updateTabs()));
	connect(window, SIGNAL(isPinnedChanged(bool)), this, SLOT(updatePinnedTabsAmount()));
	connect(tabButton(index, QTabBar::LeftSide), SIGNAL(destroyed()), window, SLOT(deleteLater()));

	if (window->isPinned())
	{
		updatePinnedTabsAmount();
	}

	updateTabs(index);
}
Exemple #6
0
    setTabToolTip(index, text);
    ComboTabBar::setTabText(index, tabText);
}

void TabBar::tabInserted(int index)
{
    Q_UNUSED(index)

    // Initialize pinned tab metrics
    if (tabMetrics()->pinnedWidth() == -1) {
        QTimer::singleShot(0, this, [this]() {
            if (tabMetrics()->pinnedWidth() != -1) {
                return;
            }
            QWidget *w = tabButton(0, iconButtonPosition());
            if (w && w->parentWidget()) {
                const QRect wg = w->parentWidget()->geometry();
                const QRect wr = QStyle::visualRect(layoutDirection(), wg, w->geometry());
                tabMetrics()->setPinnedWidth(iconButtonSize().width() + wr.x() * 2);
                setUpLayout();
            }
        });
    }

    setVisible(!(count() <= 1 && m_hideTabBarWithOneTab));
}

void TabBar::tabRemoved(int index)
{
    Q_UNUSED(index)
Exemple #7
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())));
}