玉兔远程控制 0.1.0-bate4
载入中...
搜索中...
未找到
FrmPopup.cpp
1
2#include <QIcon>
3#include <QVBoxLayout>
4#include <QWebEnginePage>
5#include <QWindow>
6#include <QLoggingCategory>
7#include "FrmPopup.h"
8#include "FrmWebView.h"
9#include "FrmWebBrowser.h"
10
11static Q_LOGGING_CATEGORY(log, "WebBrowser.Widget.Popup")
12CFrmPopup::CFrmPopup(QWebEngineProfile *profile, CFrmWebBrowser* pWebBrowser, QWidget *parent)
13 : QWidget{parent}
14 , m_pleUrl(nullptr)
15 , m_pFavAction(nullptr)
16 , m_pView(nullptr)
17{
18 qDebug(log) << Q_FUNC_INFO;
19 bool check = false;
20 setAttribute(Qt::WA_DeleteOnClose);
21 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
22
23 this->resize(pWebBrowser->size());
24
25 QVBoxLayout *layout = new QVBoxLayout;
26 layout->setContentsMargins(0, 0, 0, 0);
27 setLayout(layout);
28 m_pleUrl = new QLineEdit(this);
29 m_pFavAction = new QAction(this);
30 layout->addWidget(m_pleUrl);
31 m_pView = new CFrmWebView(pWebBrowser, this);
32 layout->addWidget(m_pView);
33 m_pView->setPage(new QWebEnginePage(profile, m_pView));
34 m_pView->setFocus();
35 m_pleUrl->setReadOnly(true);
36 m_pleUrl->addAction(m_pFavAction, QLineEdit::LeadingPosition);
37 check = connect(m_pView, &CFrmWebView::titleChanged, this, &QWidget::setWindowTitle);
38 Q_ASSERT(check);
39 check = connect(m_pView, &CFrmWebView::urlChanged, [this](const QUrl& url){
40 m_pleUrl->setText(url.toDisplayString());
41 });
42 Q_ASSERT(check);
43 check = connect(m_pView, &CFrmWebView::favIconChanged, m_pFavAction, &QAction::setIcon);
44 Q_ASSERT(check);
45 check = connect(m_pView->page(), &QWebEnginePage::geometryChangeRequested, this, &CFrmPopup::slotHandleGeometryChangeRequested);
46 Q_ASSERT(check);
47 check = connect(m_pView->page(), &QWebEnginePage::windowCloseRequested, this, &QWidget::close);
48 Q_ASSERT(check);
49}
50
51CFrmPopup::~CFrmPopup()
52{
53 qDebug(log) << Q_FUNC_INFO;
54}
55
56CFrmWebView* CFrmPopup::GetView()
57{
58 return m_pView;
59}
60
61void CFrmPopup::slotHandleGeometryChangeRequested(const QRect &newGeometry)
62{
63 if(QWindow* window = windowHandle())
64 setGeometry(newGeometry.marginsRemoved(window->frameMargins()));
65 show();
66 m_pView->setFocus();
67}