-
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathFrmPopup.cpp
More file actions
68 lines (61 loc) · 2.12 KB
/
FrmPopup.cpp
File metadata and controls
68 lines (61 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Author: Kang Lin <kl222@126.com>
#include <QIcon>
#include <QVBoxLayout>
#include <QWebEnginePage>
#include <QWindow>
#include <QLoggingCategory>
#include "FrmPopup.h"
#include "FrmWebView.h"
#include "FrmWebBrowser.h"
static Q_LOGGING_CATEGORY(log, "WebBrowser.Widget.Popup")
CFrmPopup::CFrmPopup(QWebEngineProfile *profile, CFrmWebBrowser* pWebBrowser, QWidget *parent)
: QWidget{parent}
, m_pleUrl(nullptr)
, m_pFavAction(nullptr)
, m_pView(nullptr)
{
qDebug(log) << Q_FUNC_INFO;
bool check = false;
setAttribute(Qt::WA_DeleteOnClose);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
this->resize(pWebBrowser->size());
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
m_pleUrl = new QLineEdit(this);
m_pFavAction = new QAction(this);
layout->addWidget(m_pleUrl);
m_pView = new CFrmWebView(pWebBrowser, this);
layout->addWidget(m_pView);
m_pView->setPage(new QWebEnginePage(profile, m_pView));
m_pView->setFocus();
m_pleUrl->setReadOnly(true);
m_pleUrl->addAction(m_pFavAction, QLineEdit::LeadingPosition);
check = connect(m_pView, &CFrmWebView::titleChanged, this, &QWidget::setWindowTitle);
Q_ASSERT(check);
check = connect(m_pView, &CFrmWebView::urlChanged, [this](const QUrl& url){
m_pleUrl->setText(url.toDisplayString());
});
Q_ASSERT(check);
check = connect(m_pView, &CFrmWebView::favIconChanged, m_pFavAction, &QAction::setIcon);
Q_ASSERT(check);
check = connect(m_pView->page(), &QWebEnginePage::geometryChangeRequested, this, &CFrmPopup::slotHandleGeometryChangeRequested);
Q_ASSERT(check);
check = connect(m_pView->page(), &QWebEnginePage::windowCloseRequested, this, &QWidget::close);
Q_ASSERT(check);
}
CFrmPopup::~CFrmPopup()
{
qDebug(log) << Q_FUNC_INFO;
}
CFrmWebView* CFrmPopup::GetView()
{
return m_pView;
}
void CFrmPopup::slotHandleGeometryChangeRequested(const QRect &newGeometry)
{
if(QWindow* window = windowHandle())
setGeometry(newGeometry.marginsRemoved(window->frameMargins()));
show();
m_pView->setFocus();
}