34#include <QWebEngineHistory>
39static const int savedTabVersion = 6;
58 const auto children = webTab->
childTabs();
60 for (
WebTab *child : children) {
87 stream << savedTabVersion;
90 stream << tab.
icon.pixmap(16);
130 tab.
icon = QIcon(pixmap);
138 setObjectName(
QSL(
"webtab"));
142 m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
143 setFocusProxy(m_webView);
151 m_layout =
new QVBoxLayout(
this);
152 m_layout->setContentsMargins(0, 0, 0, 0);
153 m_layout->setSpacing(0);
154 m_layout->addWidget(m_webView);
156 auto *viewWidget =
new QWidget(
this);
157 viewWidget->setLayout(m_layout);
159 m_splitter =
new QSplitter(Qt::Vertical,
this);
160 m_splitter->setChildrenCollapsible(
false);
161 m_splitter->addWidget(viewWidget);
163 auto *layout =
new QVBoxLayout(
this);
164 layout->setContentsMargins(0, 0, 0, 0);
165 layout->setSpacing(0);
166 layout->addWidget(m_splitter);
169 m_notificationWidget =
new QWidget(
this);
170 m_notificationWidget->setAutoFillBackground(
true);
171 QPalette pal = m_notificationWidget->palette();
172 pal.setColor(QPalette::Window, pal.window().color().darker(110));
173 m_notificationWidget->setPalette(pal);
175 auto *nlayout =
new QVBoxLayout(m_notificationWidget);
176 nlayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
177 nlayout->setContentsMargins(0, 0, 0, 0);
178 nlayout->setSpacing(1);
181 connect(m_webView, &QWebEngineView::loadFinished,
this, &WebTab::loadFinished);
182 connect(m_webView, &TabbedWebView::titleChanged,
this, &WebTab::titleWasChanged);
189 auto pageChanged = [
this](
WebPage *page) {
193 pageChanged(m_webView->
page());
216 return m_splitter->count() > 1 && m_splitter->widget(1)->inherits(
"WebInspector");
225 inspector->setView(m_webView);
227 inspector->inspectElement();
229 const int height = inspector->sizeHint().height();
230 m_splitter->addWidget(inspector);
231 m_splitter->setSizes({m_splitter->height() - height, height});
239 delete m_splitter->widget(1);
248 if (m_layout->count() == 1) {
250 m_layout->insertWidget(index, toolBar);
251 }
else if (m_layout->count() == 2) {
252 Q_ASSERT(qobject_cast<SearchToolBar*>(m_layout->itemAt(index)->widget()));
253 toolBar =
static_cast<SearchToolBar*
>(m_layout->itemAt(index)->widget());
257 if (!searchText.isEmpty()) {
266 if (m_webView->url().isEmpty() && m_webView->
isLoading()) {
267 return m_webView->
page()->requestedUrl();
269 return m_webView->url();
272 return m_savedTab.
url;
279 return m_webView->
title(allowEmpty);
282 return m_savedTab.
title;
289 return m_webView->
icon(allowNull);
292 if (allowNull || !m_savedTab.
icon.isNull()) {
293 return m_savedTab.
icon;
301 return m_webView->history();
324 m_tabIcon->setParent(
this);
330 m_locationBar->setParent(
this);
334 if (m_isCurrentTab) {
335 m_isCurrentTab =
false;
338 m_tabBar->disconnect(
this);
356 auto currentChanged = [
this](
int index) {
357 const bool wasCurrent = m_isCurrentTab;
358 m_isCurrentTab = index ==
tabIndex();
359 if (wasCurrent != m_isCurrentTab) {
371 QByteArray historyArray;
372 QDataStream historyStream(&historyArray, QIODevice::WriteOnly);
373 historyStream << *m_webView->history();
395 QTimer::singleShot(0,
this, std::bind(&
WebTab::load,
this, request));
397 m_webView->
load(request);
406 m_webView->setFocus();
421 if (m_isPinned ==
state) {
435 return m_webView->
page()->isAudioMuted();
440 return m_webView->
page()->recentlyAudible();
445 m_webView->
page()->setAudioMuted(muted);
461 return m_locationBar;
476 if (m_isPinned || m_parentTab == tab) {
485 const int index = m_parentTab->m_childTabs.indexOf(
this);
487 m_parentTab->m_childTabs.removeAt(index);
495 m_parentTab =
nullptr;
504 if (m_isPinned || !tab || tab->
isPinned()) {
508 WebTab *oldParent = tab->m_parentTab;
509 tab->m_parentTab =
this;
511 const int index = oldParent->m_childTabs.indexOf(tab);
513 oldParent->m_childTabs.removeAt(index);
518 if (index < 0 || index > m_childTabs.size()) {
521 index = m_childTabs.size();
527 m_childTabs.insert(index, tab);
540 return m_sessionData;
545 m_sessionData[key] =
value;
572 QTimer::singleShot(1000,
this, [=]() {
583 static const QStringList blacklistedSchemes = {
588 if (!blacklistedSchemes.contains(
url.scheme())) {
590 stream >> *m_webView->history();
594 m_webView->setFocus();
602void WebTab::showNotification(QWidget* notif)
604 m_notificationWidget->setParent(
this);
605 m_notificationWidget->raise();
606 m_notificationWidget->setFixedWidth(width());
607 m_notificationWidget->layout()->addWidget(notif);
608 m_notificationWidget->show();
612void WebTab::loadFinished()
614 titleWasChanged(m_webView->
title());
617void WebTab::titleWasChanged(
const QString &title)
619 if (!m_tabBar || !m_window ||
title.isEmpty()) {
623 if (m_isCurrentTab) {
636 QTimer::singleShot(0,
this, [
this]() {
651 return s_addChildBehavior;
657 s_addChildBehavior = behavior;
660void WebTab::resizeEvent(QResizeEvent *event)
662 QWidget::resizeEvent(event);
664 m_notificationWidget->setFixedWidth(width());
667void WebTab::removeFromTabTree()
675 while (!m_childTabs.isEmpty()) {
676 WebTab *child = m_childTabs.at(0);
686 return m_isCurrentTab;
TabWidget * tabWidget() const
void setWindowTitle(const QString &t)
QTabBar::ButtonPosition iconButtonPosition() const
void setTabButton(int index, QTabBar::ButtonPosition position, QWidget *widget)
void currentChanged(int index)
static QIcon emptyWebIcon()
void setBrowserWindow(BrowserWindow *window)
void setWebView(TabbedWebView *view)
void showUrl(const QUrl &url)
void setTabText(int index, const QString &text)
TabWidget * tabWidget() const
void setWebTab(WebTab *tab)
void setPage(WebPage *page)
void setBrowserWindow(BrowserWindow *window)
TabIcon * tabIcon() const
void setPinned(bool state)
void showWebInspector(bool inspectElement=false)
void setZoomLevel(int level)
void mutedChanged(bool muted)
void titleChanged(const QString &title)
bool isCurrentTab() const
LocationBar * locationBar() const
void currentTabChanged(bool current)
void restoredChanged(bool restored)
void setParentTab(WebTab *tab)
void toggleWebInspector()
void iconChanged(const QIcon &icon)
void p_restoreTab(const SavedTab &tab)
void parentTabChanged(WebTab *tab)
void pinnedChanged(bool pinned)
bool haveInspector() const
static void setAddChildBehavior(AddChildBehavior behavior)
QString title(bool allowEmpty=false) const
void load(const LoadRequest &request)
QVector< WebTab * > childTabs() const
void setMuted(bool muted)
void childTabRemoved(WebTab *tab, int index)
QWebEngineHistory * history() const
BrowserWindow * browserWindow() const
void addChildTab(WebTab *tab, int index=-1)
TabbedWebView * webView() const
bool backgroundActivity() const
void childTabAdded(WebTab *tab, int index)
void attach(BrowserWindow *window)
WebTab * parentTab() const
void backgroundActivityChanged(bool activity)
WebTab(QWidget *parent=nullptr)
void loadingChanged(bool loading)
QHash< QString, QVariant > sessionData() const
void playingChanged(bool playing)
QIcon icon(bool allowNull=false) const
static AddChildBehavior addChildBehavior()
void restoreTab(const SavedTab &tab)
void showSearchToolBar(const QString &searchText=QString())
QByteArray historyData() const
void setSessionData(const QString &key, const QVariant &value)
bool backgroundActivity() const
void showNotification(QWidget *)
void backgroundActivityChanged(bool)
QIcon icon(bool allowNull=false) const
void pageChanged(WebPage *page)
void load(const QUrl &url)
QString title(bool allowEmpty=false) const
void setZoomLevel(int level)
int value(const QColor &c)
QHash< QString, QVariant > sessionData
QDataStream & operator<<(QDataStream &stream, const WebTab::SavedTab &tab)
QDataStream & operator>>(QDataStream &stream, WebTab::SavedTab &tab)