Открыть боковую панель
MOS
Исходные коды
mos-vkm
Коммиты
956087ea
Коммит
956087ea
создал
Дек 14, 2023
по автору
Коул Милена Ричардовна
Просмотр файлов
take example of simplebrowser
владелец
97d450bb
Изменения
22
Развернуть все
Скрыть пробелы
Построчно
Рядом
main.cpp
Просмотр файла @
956087ea
#include
"mainwindow.h"
#include
"webEngineWidgets/browser.h"
#include
"webEngineWidgets/browserwindow.h"
#include
"webEngineWidgets/tabwidget.h"
#include
<QApplication>
#include
<QLocale>
#include
<QTranslator>
#include
<QWebEngineProfile>
#include
<QWebEngineSettings>
int
main
(
int
argc
,
char
*
argv
[])
{
QApplication
a
(
argc
,
argv
);
QCoreApplication
::
setAttribute
(
Qt
::
AA_EnableHighDpiScaling
);
QCoreApplication
::
setAttribute
(
Qt
::
AA_UseHighDpiPixmaps
);
QTranslator
translator
;
const
QStringList
uiLanguages
=
QLocale
::
system
().
uiLanguages
();
...
...
@@ -17,7 +24,18 @@ int main(int argc, char *argv[])
break
;
}
}
MainWindow
w
;
w
.
show
();
QWebEngineSettings
::
defaultSettings
()
->
setAttribute
(
QWebEngineSettings
::
PluginsEnabled
,
true
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
QWebEngineSettings
::
defaultSettings
()
->
setAttribute
(
QWebEngineSettings
::
DnsPrefetchEnabled
,
true
);
QWebEngineProfile
::
defaultProfile
()
->
setUseForGlobalCertificateVerification
();
#endif
Browser
browser
;
BrowserWindow
*
window
=
browser
.
createWindow
();
QString
vkm_link
=
"https://web.vk.me/"
;
QUrl
vkm_url
=
QUrl
(
vkm_link
);
window
->
tabWidget
()
->
setUrl
(
vkm_url
);
return
a
.
exec
();
}
mos-vkm.pro
Просмотр файла @
956087ea
...
...
@@ -11,13 +11,33 @@ CONFIG += c++17
SOURCES
+=
\
main
.
cpp
\
mainwindow
.
cpp
mainwindow
.
cpp
\
webEngineWidgets
/
browser
.
cpp
\
webEngineWidgets
/
browserwindow
.
cpp
\
webEngineWidgets
/
downloadmanagerwidget
.
cpp
\
webEngineWidgets
/
downloadwidget
.
cpp
\
webEngineWidgets
/
tabwidget
.
cpp
\
webEngineWidgets
/
webpage
.
cpp
\
webEngineWidgets
/
webpopupwindow
.
cpp
\
webEngineWidgets
/
webview
.
cpp
HEADERS
+=
\
mainwindow
.
h
mainwindow
.
h
\
webEngineWidgets
/
browser
.
h
\
webEngineWidgets
/
browserwindow
.
h
\
webEngineWidgets
/
downloadmanagerwidget
.
h
\
webEngineWidgets
/
downloadwidget
.
h
\
webEngineWidgets
/
tabwidget
.
h
\
webEngineWidgets
/
webpage
.
h
\
webEngineWidgets
/
webpopupwindow
.
h
\
webEngineWidgets
/
webview
.
h
FORMS
+=
\
mainwindow
.
ui
mainwindow
.
ui
\
webEngineWidgets
/
certificateerrordialog
.
ui
\
webEngineWidgets
/
downloadmanagerwidget
.
ui
\
webEngineWidgets
/
downloadwidget
.
ui
\
webEngineWidgets
/
passworddialog
.
ui
TRANSLATIONS
+=
\
mos
-
vkm_ru_RU
.
ts
...
...
webEngineWidgets/browser.cpp
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
"browser.h"
#include
"browserwindow.h"
Browser
::
Browser
()
{
// Quit application if the download manager window is the only remaining window
m_downloadManagerWidget
.
setAttribute
(
Qt
::
WA_QuitOnClose
,
false
);
QObject
::
connect
(
QWebEngineProfile
::
defaultProfile
(),
&
QWebEngineProfile
::
downloadRequested
,
&
m_downloadManagerWidget
,
&
DownloadManagerWidget
::
downloadRequested
);
}
BrowserWindow
*
Browser
::
createWindow
(
bool
offTheRecord
)
{
if
(
offTheRecord
&&
!
m_otrProfile
)
{
m_otrProfile
.
reset
(
new
QWebEngineProfile
);
QObject
::
connect
(
m_otrProfile
.
get
(),
&
QWebEngineProfile
::
downloadRequested
,
&
m_downloadManagerWidget
,
&
DownloadManagerWidget
::
downloadRequested
);
}
auto
profile
=
offTheRecord
?
m_otrProfile
.
get
()
:
QWebEngineProfile
::
defaultProfile
();
auto
mainWindow
=
new
BrowserWindow
(
this
,
profile
,
false
);
m_windows
.
append
(
mainWindow
);
QObject
::
connect
(
mainWindow
,
&
QObject
::
destroyed
,
[
this
,
mainWindow
]()
{
m_windows
.
removeOne
(
mainWindow
);
});
mainWindow
->
show
();
return
mainWindow
;
}
BrowserWindow
*
Browser
::
createDevToolsWindow
()
{
auto
profile
=
QWebEngineProfile
::
defaultProfile
();
auto
mainWindow
=
new
BrowserWindow
(
this
,
profile
,
true
);
m_windows
.
append
(
mainWindow
);
QObject
::
connect
(
mainWindow
,
&
QObject
::
destroyed
,
[
this
,
mainWindow
]()
{
m_windows
.
removeOne
(
mainWindow
);
});
mainWindow
->
show
();
return
mainWindow
;
}
webEngineWidgets/browser.h
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef BROWSER_H
#define BROWSER_H
#include
"downloadmanagerwidget.h"
#include
<QVector>
#include
<QWebEngineProfile>
class
BrowserWindow
;
class
Browser
{
public:
Browser
();
QVector
<
BrowserWindow
*>
windows
()
{
return
m_windows
;
}
BrowserWindow
*
createWindow
(
bool
offTheRecord
=
false
);
BrowserWindow
*
createDevToolsWindow
();
DownloadManagerWidget
&
downloadManagerWidget
()
{
return
m_downloadManagerWidget
;
}
private:
QVector
<
BrowserWindow
*>
m_windows
;
DownloadManagerWidget
m_downloadManagerWidget
;
QScopedPointer
<
QWebEngineProfile
>
m_otrProfile
;
};
#endif // BROWSER_H
webEngineWidgets/browserwindow.cpp
0 → 100644
Просмотр файла @
956087ea
Это отличие свёрнуто
Нажмите, чтобы развернуть
webEngineWidgets/browserwindow.h
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef BROWSERWINDOW_H
#define BROWSERWINDOW_H
#include
<QMainWindow>
#include
<QTime>
#include
<QWebEnginePage>
QT_BEGIN_NAMESPACE
class
QLineEdit
;
class
QProgressBar
;
QT_END_NAMESPACE
class
Browser
;
class
TabWidget
;
class
WebView
;
class
BrowserWindow
:
public
QMainWindow
{
Q_OBJECT
public:
BrowserWindow
(
Browser
*
browser
,
QWebEngineProfile
*
profile
,
bool
forDevTools
=
false
);
QSize
sizeHint
()
const
override
;
TabWidget
*
tabWidget
()
const
;
WebView
*
currentTab
()
const
;
Browser
*
browser
()
{
return
m_browser
;
}
protected:
void
closeEvent
(
QCloseEvent
*
event
)
override
;
private
slots
:
void
handleNewWindowTriggered
();
void
handleNewIncognitoWindowTriggered
();
void
handleFileOpenTriggered
();
void
handleFindActionTriggered
();
void
handleShowWindowTriggered
();
void
handleWebViewLoadProgress
(
int
);
void
handleWebViewTitleChanged
(
const
QString
&
title
);
void
handleWebActionEnabledChanged
(
QWebEnginePage
::
WebAction
action
,
bool
enabled
);
void
handleDevToolsRequested
(
QWebEnginePage
*
source
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
void
handleFindTextFinished
(
const
QWebEngineFindTextResult
&
result
);
#endif
private:
QMenu
*
createFileMenu
(
TabWidget
*
tabWidget
);
QMenu
*
createEditMenu
();
QMenu
*
createViewMenu
(
QToolBar
*
toolBar
);
QMenu
*
createWindowMenu
(
TabWidget
*
tabWidget
);
QMenu
*
createHelpMenu
();
QToolBar
*
createToolBar
();
private:
Browser
*
m_browser
;
QWebEngineProfile
*
m_profile
;
TabWidget
*
m_tabWidget
;
QProgressBar
*
m_progressBar
;
QAction
*
m_historyBackAction
;
QAction
*
m_historyForwardAction
;
QAction
*
m_stopAction
;
QAction
*
m_reloadAction
;
QAction
*
m_stopReloadAction
;
QLineEdit
*
m_urlLineEdit
;
QAction
*
m_favAction
;
QString
m_lastSearch
;
};
#endif // BROWSERWINDOW_H
webEngineWidgets/certificateerrordialog.ui
0 → 100644
Просмотр файла @
956087ea
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
CertificateErrorDialog
</class>
<widget
class=
"QDialog"
name=
"CertificateErrorDialog"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
370
</width>
<height>
141
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Dialog
</string>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
<property
name=
"leftMargin"
>
<number>
20
</number>
</property>
<property
name=
"rightMargin"
>
<number>
20
</number>
</property>
<item>
<widget
class=
"QLabel"
name=
"m_iconLabel"
>
<property
name=
"text"
>
<string>
Icon
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignCenter
</set>
</property>
</widget>
</item>
<item>
<widget
class=
"QLabel"
name=
"m_errorLabel"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Preferred"
vsizetype=
"Preferred"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Error
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignCenter
</set>
</property>
<property
name=
"wordWrap"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<widget
class=
"QLabel"
name=
"m_infoLabel"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"MinimumExpanding"
vsizetype=
"MinimumExpanding"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
If you wish so, you may continue with an unverified certificate. Accepting an unverified certificate mean you may not be connected with the host you tried to connect to.
Do you wish to override the security check and continue ?
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
</set>
</property>
<property
name=
"wordWrap"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
<height>
16
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QDialogButtonBox"
name=
"buttonBox"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"standardButtons"
>
<set>
QDialogButtonBox::No|QDialogButtonBox::Yes
</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>
buttonBox
</sender>
<signal>
accepted()
</signal>
<receiver>
CertificateErrorDialog
</receiver>
<slot>
accept()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
248
</x>
<y>
254
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
157
</x>
<y>
274
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
buttonBox
</sender>
<signal>
rejected()
</signal>
<receiver>
CertificateErrorDialog
</receiver>
<slot>
reject()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
316
</x>
<y>
260
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
286
</x>
<y>
274
</y>
</hint>
</hints>
</connection>
</connections>
</ui>
webEngineWidgets/downloadmanagerwidget.cpp
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
"downloadmanagerwidget.h"
#include
"browser.h"
#include
"browserwindow.h"
#include
"downloadwidget.h"
#include
<QFileDialog>
#include
<QDir>
#include
<QWebEngineDownloadItem>
DownloadManagerWidget
::
DownloadManagerWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
,
m_numDownloads
(
0
)
{
setupUi
(
this
);
}
void
DownloadManagerWidget
::
downloadRequested
(
QWebEngineDownloadItem
*
download
)
{
Q_ASSERT
(
download
&&
download
->
state
()
==
QWebEngineDownloadItem
::
DownloadRequested
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QString
path
=
QFileDialog
::
getSaveFileName
(
this
,
tr
(
"Save as"
),
QDir
(
download
->
downloadDirectory
()).
filePath
(
download
->
downloadFileName
()));
#else
QString
path
=
QFileDialog
::
getSaveFileName
(
this
,
tr
(
"Save as"
),
download
->
path
());
#endif
if
(
path
.
isEmpty
())
return
;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
download
->
setDownloadDirectory
(
QFileInfo
(
path
).
path
());
download
->
setDownloadFileName
(
QFileInfo
(
path
).
fileName
());
#else
download
->
setPath
(
path
);
#endif
download
->
accept
();
//add(new DownloadWidget(download));
//show();
}
void
DownloadManagerWidget
::
add
(
DownloadWidget
*
downloadWidget
)
{
connect
(
downloadWidget
,
&
DownloadWidget
::
removeClicked
,
this
,
&
DownloadManagerWidget
::
remove
);
m_itemsLayout
->
insertWidget
(
0
,
downloadWidget
,
0
,
Qt
::
AlignTop
);
if
(
m_numDownloads
++
==
0
)
m_zeroItemsLabel
->
hide
();
}
void
DownloadManagerWidget
::
remove
(
DownloadWidget
*
downloadWidget
)
{
m_itemsLayout
->
removeWidget
(
downloadWidget
);
downloadWidget
->
deleteLater
();
if
(
--
m_numDownloads
==
0
)
m_zeroItemsLabel
->
show
();
}
webEngineWidgets/downloadmanagerwidget.h
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef DOWNLOADMANAGERWIDGET_H
#define DOWNLOADMANAGERWIDGET_H
#include
"ui_downloadmanagerwidget.h"
#include
<QWidget>
QT_BEGIN_NAMESPACE
class
QWebEngineDownloadItem
;
QT_END_NAMESPACE
class
DownloadWidget
;
// Displays a list of downloads.
class
DownloadManagerWidget
final
:
public
QWidget
,
public
Ui
::
DownloadManagerWidget
{
Q_OBJECT
public:
explicit
DownloadManagerWidget
(
QWidget
*
parent
=
nullptr
);
// Prompts user with a "Save As" dialog. If the user doesn't cancel it, then
// the QWebEngineDownloadItem will be accepted and the DownloadManagerWidget
// will be shown on the screen.
void
downloadRequested
(
QWebEngineDownloadItem
*
webItem
);
private:
void
add
(
DownloadWidget
*
downloadWidget
);
void
remove
(
DownloadWidget
*
downloadWidget
);
int
m_numDownloads
;
};
#endif // DOWNLOADMANAGERWIDGET_H
webEngineWidgets/downloadmanagerwidget.ui
0 → 100644
Просмотр файла @
956087ea
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
DownloadManagerWidget
</class>
<widget
class=
"QWidget"
name=
"DownloadManagerWidget"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
400
</width>
<height>
212
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Downloads
</string>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#DownloadManagerWidget {
background: palette(button)
}
</string>
</property>
<layout
class=
"QVBoxLayout"
name=
"m_topLevelLayout"
>
<property
name=
"sizeConstraint"
>
<enum>
QLayout::SetNoConstraint
</enum>
</property>
<property
name=
"leftMargin"
>
<number>
0
</number>
</property>
<property
name=
"topMargin"
>
<number>
0
</number>
</property>
<property
name=
"rightMargin"
>
<number>
0
</number>
</property>
<property
name=
"bottomMargin"
>
<number>
0
</number>
</property>
<item>
<widget
class=
"QScrollArea"
name=
"m_scrollArea"
>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#m_scrollArea {
margin: 2px;
border: none;
}
</string>
</property>
<property
name=
"verticalScrollBarPolicy"
>
<enum>
Qt::ScrollBarAlwaysOn
</enum>
</property>
<property
name=
"horizontalScrollBarPolicy"
>
<enum>
Qt::ScrollBarAlwaysOff
</enum>
</property>
<property
name=
"widgetResizable"
>
<bool>
true
</bool>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
</set>
</property>
<widget
class=
"QWidget"
name=
"m_items"
>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#m_items {background: palette(mid)}
</string>
</property>
<layout
class=
"QVBoxLayout"
name=
"m_itemsLayout"
>
<property
name=
"spacing"
>
<number>
2
</number>
</property>
<property
name=
"leftMargin"
>
<number>
3
</number>
</property>
<property
name=
"topMargin"
>
<number>
3
</number>
</property>
<property
name=
"rightMargin"
>
<number>
3
</number>
</property>
<property
name=
"bottomMargin"
>
<number>
3
</number>
</property>
<item>
<widget
class=
"QLabel"
name=
"m_zeroItemsLabel"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Expanding"
vsizetype=
"Expanding"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
color: palette(shadow)
</string>
</property>
<property
name=
"text"
>
<string>
No downloads
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignCenter
</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
webEngineWidgets/downloadwidget.cpp
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
"downloadwidget.h"
#include
<QFileInfo>
#include
<QUrl>
#include
<QWebEngineDownloadItem>
DownloadWidget
::
DownloadWidget
(
QWebEngineDownloadItem
*
download
,
QWidget
*
parent
)
:
QFrame
(
parent
)
,
m_download
(
download
)
,
m_timeAdded
()
{
m_timeAdded
.
start
();
setupUi
(
this
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_dstName
->
setText
(
m_download
->
downloadFileName
());
#else
m_dstName
->
setText
(
QFileInfo
(
m_download
->
path
()).
fileName
());
#endif
m_srcUrl
->
setText
(
m_download
->
url
().
toDisplayString
());
connect
(
m_cancelButton
,
&
QPushButton
::
clicked
,
[
this
](
bool
)
{
if
(
m_download
->
state
()
==
QWebEngineDownloadItem
::
DownloadInProgress
)
m_download
->
cancel
();
else
emit
removeClicked
(
this
);
});
connect
(
m_download
,
&
QWebEngineDownloadItem
::
downloadProgress
,
this
,
&
DownloadWidget
::
updateWidget
);
connect
(
m_download
,
&
QWebEngineDownloadItem
::
stateChanged
,
this
,
&
DownloadWidget
::
updateWidget
);
updateWidget
();
}
inline
QString
DownloadWidget
::
withUnit
(
qreal
bytes
)
{
if
(
bytes
<
(
1
<<
10
))
return
tr
(
"%L1 B"
).
arg
(
bytes
);
else
if
(
bytes
<
(
1
<<
20
))
return
tr
(
"%L1 KiB"
).
arg
(
bytes
/
(
1
<<
10
),
0
,
'f'
,
2
);
else
if
(
bytes
<
(
1
<<
30
))
return
tr
(
"%L1 MiB"
).
arg
(
bytes
/
(
1
<<
20
),
0
,
'f'
,
2
);
else
return
tr
(
"%L1 GiB"
).
arg
(
bytes
/
(
1
<<
30
),
0
,
'f'
,
2
);
}
void
DownloadWidget
::
updateWidget
()
{
qreal
totalBytes
=
m_download
->
totalBytes
();
qreal
receivedBytes
=
m_download
->
receivedBytes
();
qreal
bytesPerSecond
=
receivedBytes
/
m_timeAdded
.
elapsed
()
*
1000
;
auto
state
=
m_download
->
state
();
switch
(
state
)
{
case
QWebEngineDownloadItem
::
DownloadRequested
:
Q_UNREACHABLE
();
break
;
case
QWebEngineDownloadItem
::
DownloadInProgress
:
if
(
totalBytes
>=
0
)
{
m_progressBar
->
setValue
(
qRound
(
100
*
receivedBytes
/
totalBytes
));
m_progressBar
->
setDisabled
(
false
);
m_progressBar
->
setFormat
(
tr
(
"%p% - %1 of %2 downloaded - %3/s"
)
.
arg
(
withUnit
(
receivedBytes
))
.
arg
(
withUnit
(
totalBytes
))
.
arg
(
withUnit
(
bytesPerSecond
)));
}
else
{
m_progressBar
->
setValue
(
0
);
m_progressBar
->
setDisabled
(
false
);
m_progressBar
->
setFormat
(
tr
(
"unknown size - %1 downloaded - %2/s"
)
.
arg
(
withUnit
(
receivedBytes
))
.
arg
(
withUnit
(
bytesPerSecond
)));
}
break
;
case
QWebEngineDownloadItem
::
DownloadCompleted
:
m_progressBar
->
setValue
(
100
);
m_progressBar
->
setDisabled
(
true
);
m_progressBar
->
setFormat
(
tr
(
"completed - %1 downloaded - %2/s"
)
.
arg
(
withUnit
(
receivedBytes
))
.
arg
(
withUnit
(
bytesPerSecond
)));
break
;
case
QWebEngineDownloadItem
::
DownloadCancelled
:
m_progressBar
->
setValue
(
0
);
m_progressBar
->
setDisabled
(
true
);
m_progressBar
->
setFormat
(
tr
(
"cancelled - %1 downloaded - %2/s"
)
.
arg
(
withUnit
(
receivedBytes
))
.
arg
(
withUnit
(
bytesPerSecond
)));
break
;
case
QWebEngineDownloadItem
::
DownloadInterrupted
:
m_progressBar
->
setValue
(
0
);
m_progressBar
->
setDisabled
(
true
);
m_progressBar
->
setFormat
(
tr
(
"interrupted: %1"
)
.
arg
(
m_download
->
interruptReasonString
()));
break
;
}
if
(
state
==
QWebEngineDownloadItem
::
DownloadInProgress
)
{
static
QIcon
cancelIcon
(
QStringLiteral
(
":process-stop.png"
));
m_cancelButton
->
setIcon
(
cancelIcon
);
m_cancelButton
->
setToolTip
(
tr
(
"Stop downloading"
));
}
else
{
static
QIcon
removeIcon
(
QStringLiteral
(
":edit-clear.png"
));
m_cancelButton
->
setIcon
(
removeIcon
);
m_cancelButton
->
setToolTip
(
tr
(
"Remove from list"
));
}
}
webEngineWidgets/downloadwidget.h
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef DOWNLOADWIDGET_H
#define DOWNLOADWIDGET_H
#include
"ui_downloadwidget.h"
#include
<QFrame>
#include
<QElapsedTimer>
QT_BEGIN_NAMESPACE
class
QWebEngineDownloadItem
;
QT_END_NAMESPACE
// Displays one ongoing or finished download (QWebEngineDownloadItem).
class
DownloadWidget
final
:
public
QFrame
,
public
Ui
::
DownloadWidget
{
Q_OBJECT
public:
// Precondition: The QWebEngineDownloadItem has been accepted.
explicit
DownloadWidget
(
QWebEngineDownloadItem
*
download
,
QWidget
*
parent
=
nullptr
);
signals:
// This signal is emitted when the user indicates that they want to remove
// this download from the downloads list.
void
removeClicked
(
DownloadWidget
*
self
);
private
slots
:
void
updateWidget
();
private:
QString
withUnit
(
qreal
bytes
);
QWebEngineDownloadItem
*
m_download
;
QElapsedTimer
m_timeAdded
;
};
#endif // DOWNLOADWIDGET_H
webEngineWidgets/downloadwidget.ui
0 → 100644
Просмотр файла @
956087ea
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
DownloadWidget
</class>
<widget
class=
"QFrame"
name=
"DownloadWidget"
>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#DownloadWidget {
background: palette(button);
border: 1px solid palette(dark);
margin: 0px;
}
</string>
</property>
<layout
class=
"QGridLayout"
name=
"m_topLevelLayout"
>
<property
name=
"sizeConstraint"
>
<enum>
QLayout::SetMinAndMaxSize
</enum>
</property>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"m_dstName"
>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
font-weight: bold
</string>
</property>
<property
name=
"text"
>
<string>
TextLabel
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QPushButton"
name=
"m_cancelButton"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Fixed"
vsizetype=
"Fixed"
/>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
QPushButton {
margin: 1px;
border: none;
}
QPushButton:pressed {
margin: none;
border: 1px solid palette(shadow);
background: palette(midlight);
}
</string>
</property>
<property
name=
"flat"
>
<bool>
false
</bool>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
colspan=
"2"
>
<widget
class=
"QLabel"
name=
"m_srcUrl"
>
<property
name=
"maximumSize"
>
<size>
<width>
350
</width>
<height>
16777215
</height>
</size>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
/>
</property>
<property
name=
"text"
>
<string>
TextLabel
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"0"
colspan=
"2"
>
<widget
class=
"QProgressBar"
name=
"m_progressBar"
>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
font-size: 12px
</string>
</property>
<property
name=
"value"
>
<number>
24
</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include
location=
"data/simplebrowser.qrc"
/>
</resources>
<connections/>
</ui>
webEngineWidgets/passworddialog.ui
0 → 100644
Просмотр файла @
956087ea
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
PasswordDialog
</class>
<widget
class=
"QDialog"
name=
"PasswordDialog"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
399
</width>
<height>
148
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Authentication Required
</string>
</property>
<layout
class=
"QGridLayout"
name=
"gridLayout"
columnstretch=
"0,0"
columnminimumwidth=
"0,0"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"m_iconLabel"
>
<property
name=
"text"
>
<string>
Icon
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignCenter
</set>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QLabel"
name=
"m_infoLabel"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Preferred"
vsizetype=
"Preferred"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Info
</string>
</property>
<property
name=
"wordWrap"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"userLabel"
>
<property
name=
"text"
>
<string>
Username:
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QLineEdit"
name=
"m_userNameLineEdit"
/>
</item>
<item
row=
"2"
column=
"0"
>
<widget
class=
"QLabel"
name=
"passwordLabel"
>
<property
name=
"text"
>
<string>
Password:
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QLineEdit"
name=
"m_passwordLineEdit"
>
<property
name=
"echoMode"
>
<enum>
QLineEdit::Password
</enum>
</property>
</widget>
</item>
<item
row=
"3"
column=
"0"
colspan=
"2"
>
<widget
class=
"QDialogButtonBox"
name=
"buttonBox"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"standardButtons"
>
<set>
QDialogButtonBox::Cancel|QDialogButtonBox::Ok
</set>
</property>
</widget>
</item>
</layout>
<zorder>
userLabel
</zorder>
<zorder>
m_userNameLineEdit
</zorder>
<zorder>
passwordLabel
</zorder>
<zorder>
m_passwordLineEdit
</zorder>
<zorder>
buttonBox
</zorder>
<zorder>
m_iconLabel
</zorder>
<zorder>
m_infoLabel
</zorder>
</widget>
<resources/>
<connections>
<connection>
<sender>
buttonBox
</sender>
<signal>
accepted()
</signal>
<receiver>
PasswordDialog
</receiver>
<slot>
accept()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
248
</x>
<y>
254
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
157
</x>
<y>
274
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
buttonBox
</sender>
<signal>
rejected()
</signal>
<receiver>
PasswordDialog
</receiver>
<slot>
reject()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
316
</x>
<y>
260
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
286
</x>
<y>
274
</y>
</hint>
</hints>
</connection>
</connections>
</ui>
webEngineWidgets/tabwidget.cpp
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
"tabwidget.h"
#include
"webpage.h"
#include
"webview.h"
#include
<QLabel>
#include
<QMenu>
#include
<QTabBar>
#include
<QWebEngineProfile>
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
());
}
WebView
*
TabWidget
::
currentWebView
()
const
{
return
webView
(
currentIndex
());
}
WebView
*
TabWidget
::
webView
(
int
index
)
const
{
return
qobject_cast
<
WebView
*>
(
widget
(
index
));
}
void
TabWidget
::
setupView
(
WebView
*
webView
)
{
QWebEnginePage
*
webPage
=
webView
->
page
();
connect
(
webView
,
&
QWebEngineView
::
titleChanged
,
[
this
,
webView
](
const
QString
&
title
)
{
int
index
=
indexOf
(
webView
);
if
(
index
!=
-
1
)
{
setTabText
(
index
,
title
);
setTabToolTip
(
index
,
title
);
}
if
(
currentIndex
()
==
index
)
emit
titleChanged
(
title
);
});
connect
(
webView
,
&
QWebEngineView
::
urlChanged
,
[
this
,
webView
](
const
QUrl
&
url
)
{
int
index
=
indexOf
(
webView
);
if
(
index
!=
-
1
)
tabBar
()
->
setTabData
(
index
,
url
);
if
(
currentIndex
()
==
index
)
emit
urlChanged
(
url
);
});
connect
(
webView
,
&
QWebEngineView
::
loadProgress
,
[
this
,
webView
](
int
progress
)
{
if
(
currentIndex
()
==
indexOf
(
webView
))
emit
loadProgress
(
progress
);
});
connect
(
webPage
,
&
QWebEnginePage
::
linkHovered
,
[
this
,
webView
](
const
QString
&
url
)
{
if
(
currentIndex
()
==
indexOf
(
webView
))
emit
linkHovered
(
url
);
});
connect
(
webView
,
&
WebView
::
favIconChanged
,
[
this
,
webView
](
const
QIcon
&
icon
)
{
int
index
=
indexOf
(
webView
);
if
(
index
!=
-
1
)
setTabIcon
(
index
,
icon
);
if
(
currentIndex
()
==
index
)
emit
favIconChanged
(
icon
);
});
connect
(
webView
,
&
WebView
::
webActionEnabledChanged
,
[
this
,
webView
](
QWebEnginePage
::
WebAction
action
,
bool
enabled
)
{
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
)
{
if
(
currentIndex
()
==
indexOf
(
webView
))
emit
findTextFinished
(
result
);
});
#endif
}
WebView
*
TabWidget
::
createTab
()
{
WebView
*
webView
=
createBackgroundTab
();
setCurrentWidget
(
webView
);
return
webView
;
}
WebView
*
TabWidget
::
createBackgroundTab
()
{
WebView
*
webView
=
new
WebView
;
WebPage
*
webPage
=
new
WebPage
(
m_profile
,
webView
);
webView
->
setPage
(
webPage
);
setupView
(
webView
);
int
index
=
addTab
(
webView
,
tr
(
"(Untitled)"
));
setTabIcon
(
index
,
webView
->
favIcon
());
// Workaround for QTBUG-61770
webView
->
resize
(
currentWidget
()
->
size
());
webView
->
show
();
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
())
{
view
->
setUrl
(
url
);
view
->
setFocus
();
}
}
void
TabWidget
::
triggerWebPageAction
(
QWebEnginePage
::
WebAction
action
)
{
if
(
WebView
*
webView
=
currentWebView
())
{
webView
->
triggerPageAction
(
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
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef TABWIDGET_H
#define TABWIDGET_H
#include
<QTabWidget>
#include
<QWebEnginePage>
QT_BEGIN_NAMESPACE
class
QUrl
;
QT_END_NAMESPACE
class
WebView
;
class
TabWidget
:
public
QTabWidget
{
Q_OBJECT
public:
TabWidget
(
QWebEngineProfile
*
profile
,
QWidget
*
parent
=
nullptr
);
WebView
*
currentWebView
()
const
;
signals:
// current tab/page signals
void
linkHovered
(
const
QString
&
link
);
void
loadProgress
(
int
progress
);
void
titleChanged
(
const
QString
&
title
);
void
urlChanged
(
const
QUrl
&
url
);
void
favIconChanged
(
const
QIcon
&
icon
);
void
webActionEnabledChanged
(
QWebEnginePage
::
WebAction
action
,
bool
enabled
);
void
devToolsRequested
(
QWebEnginePage
*
source
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
void
findTextFinished
(
const
QWebEngineFindTextResult
&
result
);
#endif
public
slots
:
// current tab/page slots
void
setUrl
(
const
QUrl
&
url
);
void
triggerWebPageAction
(
QWebEnginePage
::
WebAction
action
);
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
;
void
setupView
(
WebView
*
webView
);
QWebEngineProfile
*
m_profile
;
};
#endif // TABWIDGET_H
webEngineWidgets/webpage.cpp
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
"browserwindow.h"
#include
"tabwidget.h"
#include
"ui_certificateerrordialog.h"
#include
"ui_passworddialog.h"
#include
"webpage.h"
#include
"webview.h"
#include
<QAuthenticator>
#include
<QMessageBox>
#include
<QStyle>
#include
<QTimer>
#include
<QWebEngineCertificateError>
WebPage
::
WebPage
(
QWebEngineProfile
*
profile
,
QObject
*
parent
)
:
QWebEnginePage
(
profile
,
parent
)
{
connect
(
this
,
&
QWebEnginePage
::
authenticationRequired
,
this
,
&
WebPage
::
handleAuthenticationRequired
);
connect
(
this
,
&
QWebEnginePage
::
featurePermissionRequested
,
this
,
&
WebPage
::
handleFeaturePermissionRequested
);
connect
(
this
,
&
QWebEnginePage
::
proxyAuthenticationRequired
,
this
,
&
WebPage
::
handleProxyAuthenticationRequired
);
connect
(
this
,
&
QWebEnginePage
::
registerProtocolHandlerRequested
,
this
,
&
WebPage
::
handleRegisterProtocolHandlerRequested
);
#if !defined(QT_NO_SSL) || QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
connect
(
this
,
&
QWebEnginePage
::
selectClientCertificate
,
this
,
&
WebPage
::
handleSelectClientCertificate
);
#endif
}
bool
WebPage
::
certificateError
(
const
QWebEngineCertificateError
&
error
)
{
QWidget
*
mainWindow
=
view
()
->
window
();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QWebEngineCertificateError
deferredError
=
error
;
deferredError
.
defer
();
QTimer
::
singleShot
(
0
,
mainWindow
,
[
mainWindow
,
error
=
std
::
move
(
deferredError
)]
()
mutable
{
if
(
!
error
.
deferred
())
{
QMessageBox
::
critical
(
mainWindow
,
tr
(
"Certificate Error"
),
error
.
errorDescription
());
}
else
{
#else
if
(
error
.
isOverridable
())
{
#endif
QDialog
dialog
(
mainWindow
);
dialog
.
setModal
(
true
);
dialog
.
setWindowFlags
(
dialog
.
windowFlags
()
&
~
Qt
::
WindowContextHelpButtonHint
);
Ui
::
CertificateErrorDialog
certificateDialog
;
certificateDialog
.
setupUi
(
&
dialog
);
certificateDialog
.
m_iconLabel
->
setText
(
QString
());
QIcon
icon
(
mainWindow
->
style
()
->
standardIcon
(
QStyle
::
SP_MessageBoxWarning
,
0
,
mainWindow
));
certificateDialog
.
m_iconLabel
->
setPixmap
(
icon
.
pixmap
(
32
,
32
));
certificateDialog
.
m_errorLabel
->
setText
(
error
.
errorDescription
());
dialog
.
setWindowTitle
(
tr
(
"Certificate Error"
));
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if
(
dialog
.
exec
()
==
QDialog
::
Accepted
)
error
.
ignoreCertificateError
();
else
error
.
rejectCertificate
();
}
});
return
true
;
#else
return
dialog
.
exec
()
==
QDialog
::
Accepted
;
}
QMessageBox
::
critical
(
mainWindow
,
tr
(
"Certificate Error"
),
error
.
errorDescription
());
return
false
;
#endif
}
void
WebPage
::
handleAuthenticationRequired
(
const
QUrl
&
requestUrl
,
QAuthenticator
*
auth
)
{
QWidget
*
mainWindow
=
view
()
->
window
();
QDialog
dialog
(
mainWindow
);
dialog
.
setModal
(
true
);
dialog
.
setWindowFlags
(
dialog
.
windowFlags
()
&
~
Qt
::
WindowContextHelpButtonHint
);
Ui
::
PasswordDialog
passwordDialog
;
passwordDialog
.
setupUi
(
&
dialog
);
passwordDialog
.
m_iconLabel
->
setText
(
QString
());
QIcon
icon
(
mainWindow
->
style
()
->
standardIcon
(
QStyle
::
SP_MessageBoxQuestion
,
0
,
mainWindow
));
passwordDialog
.
m_iconLabel
->
setPixmap
(
icon
.
pixmap
(
32
,
32
));
QString
introMessage
(
tr
(
"Enter username and password for
\"
%1
\"
at %2"
)
.
arg
(
auth
->
realm
()).
arg
(
requestUrl
.
toString
().
toHtmlEscaped
()));
passwordDialog
.
m_infoLabel
->
setText
(
introMessage
);
passwordDialog
.
m_infoLabel
->
setWordWrap
(
true
);
if
(
dialog
.
exec
()
==
QDialog
::
Accepted
)
{
auth
->
setUser
(
passwordDialog
.
m_userNameLineEdit
->
text
());
auth
->
setPassword
(
passwordDialog
.
m_passwordLineEdit
->
text
());
}
else
{
// Set authenticator null if dialog is cancelled
*
auth
=
QAuthenticator
();
}
}
inline
QString
questionForFeature
(
QWebEnginePage
::
Feature
feature
)
{
switch
(
feature
)
{
case
QWebEnginePage
::
Geolocation
:
return
WebPage
::
tr
(
"Allow %1 to access your location information?"
);
case
QWebEnginePage
::
MediaAudioCapture
:
return
WebPage
::
tr
(
"Allow %1 to access your microphone?"
);
case
QWebEnginePage
::
MediaVideoCapture
:
return
WebPage
::
tr
(
"Allow %1 to access your webcam?"
);
case
QWebEnginePage
::
MediaAudioVideoCapture
:
return
WebPage
::
tr
(
"Allow %1 to access your microphone and webcam?"
);
case
QWebEnginePage
::
MouseLock
:
return
WebPage
::
tr
(
"Allow %1 to lock your mouse cursor?"
);
case
QWebEnginePage
::
DesktopVideoCapture
:
return
WebPage
::
tr
(
"Allow %1 to capture video of your desktop?"
);
case
QWebEnginePage
::
DesktopAudioVideoCapture
:
return
WebPage
::
tr
(
"Allow %1 to capture audio and video of your desktop?"
);
case
QWebEnginePage
::
Notifications
:
return
WebPage
::
tr
(
"Allow %1 to show notification on your desktop?"
);
}
return
QString
();
}
void
WebPage
::
handleFeaturePermissionRequested
(
const
QUrl
&
securityOrigin
,
Feature
feature
)
{
QString
title
=
tr
(
"Permission Request"
);
QString
question
=
questionForFeature
(
feature
).
arg
(
securityOrigin
.
host
());
if
(
!
question
.
isEmpty
()
&&
QMessageBox
::
question
(
view
()
->
window
(),
title
,
question
)
==
QMessageBox
::
Yes
)
setFeaturePermission
(
securityOrigin
,
feature
,
PermissionGrantedByUser
);
else
setFeaturePermission
(
securityOrigin
,
feature
,
PermissionDeniedByUser
);
}
void
WebPage
::
handleProxyAuthenticationRequired
(
const
QUrl
&
,
QAuthenticator
*
auth
,
const
QString
&
proxyHost
)
{
QWidget
*
mainWindow
=
view
()
->
window
();
QDialog
dialog
(
mainWindow
);
dialog
.
setModal
(
true
);
dialog
.
setWindowFlags
(
dialog
.
windowFlags
()
&
~
Qt
::
WindowContextHelpButtonHint
);
Ui
::
PasswordDialog
passwordDialog
;
passwordDialog
.
setupUi
(
&
dialog
);
passwordDialog
.
m_iconLabel
->
setText
(
QString
());
QIcon
icon
(
mainWindow
->
style
()
->
standardIcon
(
QStyle
::
SP_MessageBoxQuestion
,
0
,
mainWindow
));
passwordDialog
.
m_iconLabel
->
setPixmap
(
icon
.
pixmap
(
32
,
32
));
QString
introMessage
=
tr
(
"Connect to proxy
\"
%1
\"
using:"
);
introMessage
=
introMessage
.
arg
(
proxyHost
.
toHtmlEscaped
());
passwordDialog
.
m_infoLabel
->
setText
(
introMessage
);
passwordDialog
.
m_infoLabel
->
setWordWrap
(
true
);
if
(
dialog
.
exec
()
==
QDialog
::
Accepted
)
{
auth
->
setUser
(
passwordDialog
.
m_userNameLineEdit
->
text
());
auth
->
setPassword
(
passwordDialog
.
m_passwordLineEdit
->
text
());
}
else
{
// Set authenticator null if dialog is cancelled
*
auth
=
QAuthenticator
();
}
}
//! [registerProtocolHandlerRequested]
void
WebPage
::
handleRegisterProtocolHandlerRequested
(
QWebEngineRegisterProtocolHandlerRequest
request
)
{
auto
answer
=
QMessageBox
::
question
(
view
()
->
window
(),
tr
(
"Permission Request"
),
tr
(
"Allow %1 to open all %2 links?"
)
.
arg
(
request
.
origin
().
host
())
.
arg
(
request
.
scheme
()));
if
(
answer
==
QMessageBox
::
Yes
)
request
.
accept
();
else
request
.
reject
();
}
//! [registerProtocolHandlerRequested]
#if !defined(QT_NO_SSL) || QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
void
WebPage
::
handleSelectClientCertificate
(
QWebEngineClientCertificateSelection
selection
)
{
// Just select one.
selection
.
select
(
selection
.
certificates
().
at
(
0
));
}
#endif
webEngineWidgets/webpage.h
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef WEBPAGE_H
#define WEBPAGE_H
#include
<QWebEnginePage>
#include
<QWebEngineRegisterProtocolHandlerRequest>
class
WebPage
:
public
QWebEnginePage
{
Q_OBJECT
public:
WebPage
(
QWebEngineProfile
*
profile
,
QObject
*
parent
=
nullptr
);
protected:
bool
certificateError
(
const
QWebEngineCertificateError
&
error
)
override
;
private
slots
:
void
handleAuthenticationRequired
(
const
QUrl
&
requestUrl
,
QAuthenticator
*
auth
);
void
handleFeaturePermissionRequested
(
const
QUrl
&
securityOrigin
,
Feature
feature
);
void
handleProxyAuthenticationRequired
(
const
QUrl
&
requestUrl
,
QAuthenticator
*
auth
,
const
QString
&
proxyHost
);
void
handleRegisterProtocolHandlerRequested
(
QWebEngineRegisterProtocolHandlerRequest
request
);
#if !defined(QT_NO_SSL) || QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
void
handleSelectClientCertificate
(
QWebEngineClientCertificateSelection
clientCertSelection
);
#endif
};
#endif // WEBPAGE_H
webEngineWidgets/webpopupwindow.cpp
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
"webpage.h"
#include
"webpopupwindow.h"
#include
"webview.h"
#include
<QAction>
#include
<QIcon>
#include
<QLineEdit>
#include
<QVBoxLayout>
#include
<QWindow>
WebPopupWindow
::
WebPopupWindow
(
QWebEngineProfile
*
profile
)
:
m_urlLineEdit
(
new
QLineEdit
(
this
))
,
m_favAction
(
new
QAction
(
this
))
,
m_view
(
new
WebView
(
this
))
{
setAttribute
(
Qt
::
WA_DeleteOnClose
);
setSizePolicy
(
QSizePolicy
::
Minimum
,
QSizePolicy
::
Minimum
);
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
layout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
setLayout
(
layout
);
layout
->
addWidget
(
m_urlLineEdit
);
layout
->
addWidget
(
m_view
);
m_view
->
setPage
(
new
WebPage
(
profile
,
m_view
));
m_view
->
setFocus
();
m_urlLineEdit
->
setReadOnly
(
true
);
m_urlLineEdit
->
addAction
(
m_favAction
,
QLineEdit
::
LeadingPosition
);
connect
(
m_view
,
&
WebView
::
titleChanged
,
this
,
&
QWidget
::
setWindowTitle
);
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
);
}
WebView
*
WebPopupWindow
::
view
()
const
{
return
m_view
;
}
void
WebPopupWindow
::
handleGeometryChangeRequested
(
const
QRect
&
newGeometry
)
{
if
(
QWindow
*
window
=
windowHandle
())
setGeometry
(
newGeometry
.
marginsRemoved
(
window
->
frameMargins
()));
show
();
m_view
->
setFocus
();
}
webEngineWidgets/webpopupwindow.h
0 → 100644
Просмотр файла @
956087ea
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef WEBPOPUPWINDOW_H
#define WEBPOPUPWINDOW_H
#include
<QWidget>
QT_BEGIN_NAMESPACE
class
QLineEdit
;
class
QWebEngineProfile
;
class
QWebEngineView
;
QT_END_NAMESPACE
class
WebView
;
class
WebPopupWindow
:
public
QWidget
{
Q_OBJECT
public:
WebPopupWindow
(
QWebEngineProfile
*
profile
);
WebView
*
view
()
const
;
private
slots
:
void
handleGeometryChangeRequested
(
const
QRect
&
newGeometry
);
private:
QLineEdit
*
m_urlLineEdit
;
QAction
*
m_favAction
;
WebView
*
m_view
;
};
#endif // WEBPOPUPWINDOW_H
Пред
1
2
След
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать