Открыть боковую панель
MOS
Исходные коды
mos-vkm
Коммиты
b0102fe2
Коммит
b0102fe2
создал
Дек 14, 2023
по автору
Коул Милена Ричардовна
Просмотр файлов
hide tabBar and remove work with tabs
владелец
d4d2e1eb
Изменения
2
Скрыть пробелы
Построчно
Рядом
webEngineWidgets/tabwidget.cpp
Просмотр файла @
b0102fe2
...
...
@@ -60,89 +60,7 @@ TabWidget::TabWidget(QWebEngineProfile *profile, QWidget *parent)
:
QTabWidget
(
parent
)
,
m_profile
(
profile
)
{
QTabBar
*
tabBar
=
this
->
tabBar
();
tabBar
->
setTabsClosable
(
true
);
tabBar
->
setSelectionBehaviorOnRemove
(
QTabBar
::
SelectPreviousTab
);
tabBar
->
setMovable
(
true
);
tabBar
->
setContextMenuPolicy
(
Qt
::
CustomContextMenu
);
connect
(
tabBar
,
&
QTabBar
::
customContextMenuRequested
,
this
,
&
TabWidget
::
handleContextMenuRequested
);
connect
(
tabBar
,
&
QTabBar
::
tabCloseRequested
,
this
,
&
TabWidget
::
closeTab
);
connect
(
tabBar
,
&
QTabBar
::
tabBarDoubleClicked
,
[
this
](
int
index
)
{
if
(
index
==
-
1
)
createTab
();
});
setDocumentMode
(
true
);
setElideMode
(
Qt
::
ElideRight
);
connect
(
this
,
&
QTabWidget
::
currentChanged
,
this
,
&
TabWidget
::
handleCurrentChanged
);
if
(
profile
->
isOffTheRecord
())
{
QLabel
*
icon
=
new
QLabel
(
this
);
QPixmap
pixmap
(
QStringLiteral
(
":ninja.png"
));
icon
->
setPixmap
(
pixmap
.
scaledToHeight
(
tabBar
->
height
()));
setStyleSheet
(
QStringLiteral
(
"QTabWidget::tab-bar { left: %1px; }"
).
arg
(
icon
->
pixmap
()
->
width
()));
}
}
void
TabWidget
::
handleCurrentChanged
(
int
index
)
{
if
(
index
!=
-
1
)
{
WebView
*
view
=
webView
(
index
);
if
(
!
view
->
url
().
isEmpty
())
view
->
setFocus
();
emit
titleChanged
(
view
->
title
());
emit
loadProgress
(
view
->
loadProgress
());
emit
urlChanged
(
view
->
url
());
emit
favIconChanged
(
view
->
favIcon
());
emit
webActionEnabledChanged
(
QWebEnginePage
::
Back
,
view
->
isWebActionEnabled
(
QWebEnginePage
::
Back
));
emit
webActionEnabledChanged
(
QWebEnginePage
::
Forward
,
view
->
isWebActionEnabled
(
QWebEnginePage
::
Forward
));
emit
webActionEnabledChanged
(
QWebEnginePage
::
Stop
,
view
->
isWebActionEnabled
(
QWebEnginePage
::
Stop
));
emit
webActionEnabledChanged
(
QWebEnginePage
::
Reload
,
view
->
isWebActionEnabled
(
QWebEnginePage
::
Reload
));
}
else
{
emit
titleChanged
(
QString
());
emit
loadProgress
(
0
);
emit
urlChanged
(
QUrl
());
emit
favIconChanged
(
QIcon
());
emit
webActionEnabledChanged
(
QWebEnginePage
::
Back
,
false
);
emit
webActionEnabledChanged
(
QWebEnginePage
::
Forward
,
false
);
emit
webActionEnabledChanged
(
QWebEnginePage
::
Stop
,
false
);
emit
webActionEnabledChanged
(
QWebEnginePage
::
Reload
,
true
);
}
}
void
TabWidget
::
handleContextMenuRequested
(
const
QPoint
&
pos
)
{
QMenu
menu
;
menu
.
addAction
(
tr
(
"New &Tab"
),
this
,
&
TabWidget
::
createTab
,
QKeySequence
::
AddTab
);
int
index
=
tabBar
()
->
tabAt
(
pos
);
if
(
index
!=
-
1
)
{
QAction
*
action
=
menu
.
addAction
(
tr
(
"Clone Tab"
));
connect
(
action
,
&
QAction
::
triggered
,
this
,
[
this
,
index
]()
{
cloneTab
(
index
);
});
menu
.
addSeparator
();
action
=
menu
.
addAction
(
tr
(
"&Close Tab"
));
action
->
setShortcut
(
QKeySequence
::
Close
);
connect
(
action
,
&
QAction
::
triggered
,
this
,
[
this
,
index
]()
{
closeTab
(
index
);
});
action
=
menu
.
addAction
(
tr
(
"Close &Other Tabs"
));
connect
(
action
,
&
QAction
::
triggered
,
this
,
[
this
,
index
]()
{
closeOtherTabs
(
index
);
});
menu
.
addSeparator
();
action
=
menu
.
addAction
(
tr
(
"Reload Tab"
));
action
->
setShortcut
(
QKeySequence
::
Refresh
);
connect
(
action
,
&
QAction
::
triggered
,
this
,
[
this
,
index
]()
{
reloadTab
(
index
);
});
}
else
{
menu
.
addSeparator
();
}
menu
.
addAction
(
tr
(
"Reload All Tabs"
),
this
,
&
TabWidget
::
reloadAllTabs
);
menu
.
exec
(
QCursor
::
pos
());
this
->
tabBar
()
->
hide
();
}
WebView
*
TabWidget
::
currentWebView
()
const
...
...
@@ -194,13 +112,6 @@ void TabWidget::setupView(WebView *webView)
if
(
currentIndex
()
==
indexOf
(
webView
))
emit
webActionEnabledChanged
(
action
,
enabled
);
});
connect
(
webPage
,
&
QWebEnginePage
::
windowCloseRequested
,
[
this
,
webView
]()
{
int
index
=
indexOf
(
webView
);
if
(
webView
->
page
()
->
inspectedPage
())
window
()
->
close
();
else
if
(
index
>=
0
)
closeTab
(
index
);
});
connect
(
webView
,
&
WebView
::
devToolsRequested
,
this
,
&
TabWidget
::
devToolsRequested
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
connect
(
webPage
,
&
QWebEnginePage
::
findTextFinished
,
[
this
,
webView
](
const
QWebEngineFindTextResult
&
result
)
{
...
...
@@ -231,41 +142,6 @@ WebView *TabWidget::createBackgroundTab()
return
webView
;
}
void
TabWidget
::
reloadAllTabs
()
{
for
(
int
i
=
0
;
i
<
count
();
++
i
)
webView
(
i
)
->
reload
();
}
void
TabWidget
::
closeOtherTabs
(
int
index
)
{
for
(
int
i
=
count
()
-
1
;
i
>
index
;
--
i
)
closeTab
(
i
);
for
(
int
i
=
index
-
1
;
i
>=
0
;
--
i
)
closeTab
(
i
);
}
void
TabWidget
::
closeTab
(
int
index
)
{
if
(
WebView
*
view
=
webView
(
index
))
{
bool
hasFocus
=
view
->
hasFocus
();
removeTab
(
index
);
if
(
hasFocus
&&
count
()
>
0
)
currentWebView
()
->
setFocus
();
if
(
count
()
==
0
)
createTab
();
view
->
deleteLater
();
}
}
void
TabWidget
::
cloneTab
(
int
index
)
{
if
(
WebView
*
view
=
webView
(
index
))
{
WebView
*
tab
=
createTab
();
tab
->
setUrl
(
view
->
url
());
}
}
void
TabWidget
::
setUrl
(
const
QUrl
&
url
)
{
if
(
WebView
*
view
=
currentWebView
())
{
...
...
@@ -281,25 +157,3 @@ void TabWidget::triggerWebPageAction(QWebEnginePage::WebAction action)
webView
->
setFocus
();
}
}
void
TabWidget
::
nextTab
()
{
int
next
=
currentIndex
()
+
1
;
if
(
next
==
count
())
next
=
0
;
setCurrentIndex
(
next
);
}
void
TabWidget
::
previousTab
()
{
int
next
=
currentIndex
()
-
1
;
if
(
next
<
0
)
next
=
count
()
-
1
;
setCurrentIndex
(
next
);
}
void
TabWidget
::
reloadTab
(
int
index
)
{
if
(
WebView
*
view
=
webView
(
index
))
view
->
reload
();
}
webEngineWidgets/tabwidget.h
Просмотр файла @
b0102fe2
...
...
@@ -89,17 +89,6 @@ public slots:
WebView
*
createTab
();
WebView
*
createBackgroundTab
();
void
closeTab
(
int
index
);
void
nextTab
();
void
previousTab
();
private
slots
:
void
handleCurrentChanged
(
int
index
);
void
handleContextMenuRequested
(
const
QPoint
&
pos
);
void
cloneTab
(
int
index
);
void
closeOtherTabs
(
int
index
);
void
reloadAllTabs
();
void
reloadTab
(
int
index
);
private:
WebView
*
webView
(
int
index
)
const
;
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать