Открыть боковую панель
MOS
Исходные коды
mos-vkm
Коммиты
6a963b93
Коммит
6a963b93
создал
Дек 14, 2023
по автору
Коул Милена Ричардовна
Просмотр файлов
clean webView
владелец
df150697
Изменения
4
Скрыть пробелы
Построчно
Рядом
webEngineWidgets/tabwidget.cpp
Просмотр файла @
6a963b93
...
...
@@ -86,7 +86,6 @@ WebView *TabWidget::createBackgroundTab()
WebPage
*
webPage
=
new
WebPage
(
m_profile
,
webView
);
webView
->
setPage
(
webPage
);
int
index
=
addTab
(
webView
,
tr
(
"(Untitled)"
));
setTabIcon
(
index
,
webView
->
favIcon
());
// Workaround for QTBUG-61770
webView
->
resize
(
currentWidget
()
->
size
());
webView
->
show
();
...
...
webEngineWidgets/webpopupwindow.cpp
Просмотр файла @
6a963b93
...
...
@@ -81,7 +81,6 @@ WebPopupWindow::WebPopupWindow(QWebEngineProfile *profile)
connect
(
m_view
,
&
WebView
::
urlChanged
,
[
this
](
const
QUrl
&
url
)
{
m_urlLineEdit
->
setText
(
url
.
toDisplayString
());
});
connect
(
m_view
,
&
WebView
::
favIconChanged
,
m_favAction
,
&
QAction
::
setIcon
);
connect
(
m_view
->
page
(),
&
WebPage
::
geometryChangeRequested
,
this
,
&
WebPopupWindow
::
handleGeometryChangeRequested
);
connect
(
m_view
->
page
(),
&
WebPage
::
windowCloseRequested
,
this
,
&
QWidget
::
close
);
}
...
...
webEngineWidgets/webview.cpp
Просмотр файла @
6a963b93
...
...
@@ -62,23 +62,7 @@
WebView
::
WebView
(
QWidget
*
parent
)
:
QWebEngineView
(
parent
)
,
m_loadProgress
(
100
)
{
connect
(
this
,
&
QWebEngineView
::
loadStarted
,
[
this
]()
{
m_loadProgress
=
0
;
emit
favIconChanged
(
favIcon
());
});
connect
(
this
,
&
QWebEngineView
::
loadProgress
,
[
this
](
int
progress
)
{
m_loadProgress
=
progress
;
});
connect
(
this
,
&
QWebEngineView
::
loadFinished
,
[
this
](
bool
success
)
{
m_loadProgress
=
success
?
100
:
-
1
;
emit
favIconChanged
(
favIcon
());
});
connect
(
this
,
&
QWebEngineView
::
iconChanged
,
[
this
](
const
QIcon
&
)
{
emit
favIconChanged
(
favIcon
());
});
connect
(
this
,
&
QWebEngineView
::
renderProcessTerminated
,
[
this
](
QWebEnginePage
::
RenderProcessTerminationStatus
termStatus
,
int
statusCode
)
{
QString
status
;
...
...
@@ -104,51 +88,6 @@ WebView::WebView(QWidget *parent)
});
}
void
WebView
::
setPage
(
WebPage
*
page
)
{
createWebActionTrigger
(
page
,
QWebEnginePage
::
Forward
);
createWebActionTrigger
(
page
,
QWebEnginePage
::
Back
);
createWebActionTrigger
(
page
,
QWebEnginePage
::
Reload
);
createWebActionTrigger
(
page
,
QWebEnginePage
::
Stop
);
QWebEngineView
::
setPage
(
page
);
}
int
WebView
::
loadProgress
()
const
{
return
m_loadProgress
;
}
void
WebView
::
createWebActionTrigger
(
QWebEnginePage
*
page
,
QWebEnginePage
::
WebAction
webAction
)
{
QAction
*
action
=
page
->
action
(
webAction
);
connect
(
action
,
&
QAction
::
changed
,
[
this
,
action
,
webAction
]{
emit
webActionEnabledChanged
(
webAction
,
action
->
isEnabled
());
});
}
bool
WebView
::
isWebActionEnabled
(
QWebEnginePage
::
WebAction
webAction
)
const
{
return
page
()
->
action
(
webAction
)
->
isEnabled
();
}
QIcon
WebView
::
favIcon
()
const
{
QIcon
favIcon
=
icon
();
if
(
!
favIcon
.
isNull
())
return
favIcon
;
if
(
m_loadProgress
<
0
)
{
static
QIcon
errorIcon
(
QStringLiteral
(
":dialog-error.png"
));
return
errorIcon
;
}
else
if
(
m_loadProgress
<
100
)
{
static
QIcon
loadingIcon
(
QStringLiteral
(
":view-refresh.png"
));
return
loadingIcon
;
}
else
{
static
QIcon
defaultIcon
(
QStringLiteral
(
":text-html.png"
));
return
defaultIcon
;
}
}
QWebEngineView
*
WebView
::
createWindow
(
QWebEnginePage
::
WebWindowType
type
)
{
BrowserWindow
*
mainWindow
=
qobject_cast
<
BrowserWindow
*>
(
window
());
...
...
@@ -167,32 +106,8 @@ QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type)
}
case
QWebEnginePage
::
WebDialog
:
{
WebPopupWindow
*
popup
=
new
WebPopupWindow
(
page
()
->
profile
());
connect
(
popup
->
view
(),
&
WebView
::
devToolsRequested
,
this
,
&
WebView
::
devToolsRequested
);
return
popup
->
view
();
}
}
return
nullptr
;
}
void
WebView
::
contextMenuEvent
(
QContextMenuEvent
*
event
)
{
QMenu
*
menu
=
page
()
->
createStandardContextMenu
();
const
QList
<
QAction
*>
actions
=
menu
->
actions
();
auto
inspectElement
=
std
::
find
(
actions
.
cbegin
(),
actions
.
cend
(),
page
()
->
action
(
QWebEnginePage
::
InspectElement
));
if
(
inspectElement
==
actions
.
cend
())
{
auto
viewSource
=
std
::
find
(
actions
.
cbegin
(),
actions
.
cend
(),
page
()
->
action
(
QWebEnginePage
::
ViewSource
));
if
(
viewSource
==
actions
.
cend
())
menu
->
addSeparator
();
QAction
*
action
=
new
QAction
(
menu
);
action
->
setText
(
"Open inspector in new window"
);
connect
(
action
,
&
QAction
::
triggered
,
[
this
]()
{
emit
devToolsRequested
(
page
());
});
QAction
*
before
(
inspectElement
==
actions
.
cend
()
?
nullptr
:
*
inspectElement
);
menu
->
insertAction
(
before
,
action
);
}
else
{
(
*
inspectElement
)
->
setText
(
tr
(
"Inspect element"
));
}
menu
->
popup
(
event
->
globalPos
());
}
webEngineWidgets/webview.h
Просмотр файла @
6a963b93
...
...
@@ -62,26 +62,10 @@ class WebView : public QWebEngineView
public:
WebView
(
QWidget
*
parent
=
nullptr
);
void
setPage
(
WebPage
*
page
);
int
loadProgress
()
const
;
bool
isWebActionEnabled
(
QWebEnginePage
::
WebAction
webAction
)
const
;
QIcon
favIcon
()
const
;
protected:
void
contextMenuEvent
(
QContextMenuEvent
*
event
)
override
;
QWebEngineView
*
createWindow
(
QWebEnginePage
::
WebWindowType
type
)
override
;
signals:
void
webActionEnabledChanged
(
QWebEnginePage
::
WebAction
webAction
,
bool
enabled
);
void
favIconChanged
(
const
QIcon
&
icon
);
void
devToolsRequested
(
QWebEnginePage
*
source
);
private:
void
createWebActionTrigger
(
QWebEnginePage
*
page
,
QWebEnginePage
::
WebAction
);
private:
int
m_loadProgress
;
};
#endif
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать