| 57 | #include <QWebEngineProfile> |
| 58 | |
| 59 | TabWidget::TabWidget(QWebEngineProfile *profile, QWidget *parent) |
| 60 | : QTabWidget(parent) |
| 61 | , m_profile(profile) |
| 62 | { |
| 63 | QTabBar *tabBar = this->tabBar(); |
| 64 | tabBar->setTabsClosable(true); |
| 65 | tabBar->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); |
| 66 | tabBar->setMovable(true); |
| 67 | tabBar->setContextMenuPolicy(Qt::CustomContextMenu); |
| 68 | connect(tabBar, &QTabBar::customContextMenuRequested, this, &TabWidget::handleContextMenuRequested); |
| 69 | connect(tabBar, &QTabBar::tabCloseRequested, this, &TabWidget::closeTab); |
| 70 | connect(tabBar, &QTabBar::tabBarDoubleClicked, this, [this](int index) { |
| 71 | if (index == -1) |
| 72 | createTab(); |
| 73 | }); |
| 74 | |
| 75 | setDocumentMode(true); |
| 76 | setElideMode(Qt::ElideRight); |
| 77 | |
| 78 | connect(this, &QTabWidget::currentChanged, this, &TabWidget::handleCurrentChanged); |
| 79 | |
| 80 | if (profile->isOffTheRecord()) { |
| 81 | QLabel *icon = new QLabel(this); |
| 82 | QPixmap pixmap(QStringLiteral(":ninja.png")); |
| 83 | icon->setPixmap(pixmap.scaledToHeight(tabBar->height())); |
| 84 | #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) |
| 85 | setStyleSheet(QStringLiteral("QTabWidget::tab-bar { left: %1px; }"). |
| 86 | arg(icon->pixmap().width())); |
| 87 | #else |
| 88 | setStyleSheet(QStringLiteral("QTabWidget::tab-bar { left: %1px; }"). |
| 89 | arg(icon->pixmap(Qt::ReturnByValue).width())); |
| 90 | #endif |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void TabWidget::handleCurrentChanged(int index) |
| 95 | { |