Открыть боковую панель
MOS
Исходные коды
mos-vkm
Коммиты
39e0b6b7
Коммит
39e0b6b7
создал
Дек 14, 2023
по автору
Коул Милена Ричардовна
Просмотр файлов
remove unnecessary in download
владелец
6a963b93
Изменения
7
Скрыть пробелы
Построчно
Рядом
mos-vkm.pro
Просмотр файла @
39e0b6b7
...
...
@@ -14,7 +14,6 @@ SOURCES += \
webEngineWidgets
/
browser
.
cpp
\
webEngineWidgets
/
browserwindow
.
cpp
\
webEngineWidgets
/
downloadmanagerwidget
.
cpp
\
webEngineWidgets
/
downloadwidget
.
cpp
\
webEngineWidgets
/
tabwidget
.
cpp
\
webEngineWidgets
/
webpage
.
cpp
\
webEngineWidgets
/
webpopupwindow
.
cpp
\
...
...
@@ -24,7 +23,6 @@ HEADERS += \
webEngineWidgets
/
browser
.
h
\
webEngineWidgets
/
browserwindow
.
h
\
webEngineWidgets
/
downloadmanagerwidget
.
h
\
webEngineWidgets
/
downloadwidget
.
h
\
webEngineWidgets
/
tabwidget
.
h
\
webEngineWidgets
/
webpage
.
h
\
webEngineWidgets
/
webpopupwindow
.
h
\
...
...
@@ -32,8 +30,6 @@ HEADERS += \
FORMS
+=
\
webEngineWidgets
/
certificateerrordialog
.
ui
\
webEngineWidgets
/
downloadmanagerwidget
.
ui
\
webEngineWidgets
/
downloadwidget
.
ui
\
webEngineWidgets
/
passworddialog
.
ui
TRANSLATIONS
+=
\
...
...
webEngineWidgets/downloadmanagerwidget.cpp
Просмотр файла @
39e0b6b7
...
...
@@ -52,7 +52,6 @@
#include
"browser.h"
#include
"browserwindow.h"
#include
"downloadwidget.h"
#include
<QFileDialog>
#include
<QDir>
...
...
@@ -60,9 +59,7 @@
DownloadManagerWidget
::
DownloadManagerWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
,
m_numDownloads
(
0
)
{
setupUi
(
this
);
}
void
DownloadManagerWidget
::
downloadRequested
(
QWebEngineDownloadItem
*
download
)
...
...
@@ -84,23 +81,4 @@ void DownloadManagerWidget::downloadRequested(QWebEngineDownloadItem *download)
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
Просмотр файла @
39e0b6b7
...
...
@@ -51,8 +51,6 @@
#ifndef DOWNLOADMANAGERWIDGET_H
#define DOWNLOADMANAGERWIDGET_H
#include
"ui_downloadmanagerwidget.h"
#include
<QWidget>
QT_BEGIN_NAMESPACE
...
...
@@ -62,7 +60,7 @@ QT_END_NAMESPACE
class
DownloadWidget
;
// Displays a list of downloads.
class
DownloadManagerWidget
final
:
public
QWidget
,
public
Ui
::
DownloadManagerWidget
class
DownloadManagerWidget
final
:
public
QWidget
{
Q_OBJECT
public:
...
...
@@ -72,12 +70,6 @@ public:
// 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
удалено
100644 → 0
Просмотр файла @
6a963b93
<?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
удалено
100644 → 0
Просмотр файла @
6a963b93
/****************************************************************************
**
** 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
удалено
100644 → 0
Просмотр файла @
6a963b93
/****************************************************************************
**
** 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
удалено
100644 → 0
Просмотр файла @
6a963b93
<?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>
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать