Коммит 287a895b создал по автору Коул Милена Ричардовна's avatar Коул Милена Ричардовна
Просмотр файлов

Слияние ветки 'interface_fix' с 'master'

Interface fix

Посмотреть запрос на слияние !4
владельцы 97d450bb 94798094
#include "mainwindow.h"
#include "webEngineWidgets/browser.h"
#include "webEngineWidgets/browserwindow.h"
#include "webEngineWidgets/tabwidget.h"
#include "webEngineWidgets/webview.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
const QString vkm_link = "https://web.vk.me/";
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setWindowIcon(QIcon(QStringLiteral(":/icon.png")));
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
......@@ -17,7 +27,17 @@ 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(vkm_link);
QUrl vkm_url = QUrl(vkm_link);
window->tabWidget()->currentWebView()->setUrl(vkm_url);
return a.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QUrl>
#include <QWebEngineView>
#include <QMenu>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
app_tray_icon = new QSystemTrayIcon( this );
app_tray_icon->setToolTip(tr("Open VKM"));
app_tray_icon->setIcon(QIcon(":/icon.png"));
// Set Tray Icon Context Menu
QMenu* tray_menu = new QMenu(this);
QAction* closeAppAction = new QAction(tr("Quit VK Messenger"), this);
connect(closeAppAction, SIGNAL(triggered()), this, SLOT(close()));
tray_menu->addAction(closeAppAction);
connect(app_tray_icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivation()));
app_tray_icon->setContextMenu(tray_menu);
app_tray_icon->show();
// Open VK Messenger
QUrl vkm_url = QUrl(vkm_link);
ui->webEngineView->load(vkm_url);
}
MainWindow::~MainWindow()
{
delete app_tray_icon;
delete ui;
}
void MainWindow::close()
{
exit(0);
}
void MainWindow::trayIconActivation()
{
if (this->isVisible())
{
this->hide();
} else
{
this->show();
}
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSystemTrayIcon>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
const QString vkm_link = "https://web.vk.me/";
QSystemTrayIcon* app_tray_icon;
protected slots:
void close();
void trayIconActivation();
};
#endif // MAINWINDOW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MOS VK Messenger</string>
</property>
<property name="windowIcon">
<iconset resource="resources/mos-vkm.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWebEngineView" name="webEngineView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>QWebEngineView</class>
<extends>QWidget</extends>
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
</customwidget>
</customwidgets>
<resources>
<include location="resources/mos-vkm.qrc"/>
</resources>
<connections/>
</ui>
......@@ -11,13 +11,26 @@ CONFIG += c++17
SOURCES += \
main.cpp \
mainwindow.cpp
webEngineWidgets/browser.cpp \
webEngineWidgets/browserwindow.cpp \
webEngineWidgets/downloadmanagerwidget.cpp \
webEngineWidgets/linkwindow.cpp \
webEngineWidgets/tabwidget.cpp \
webEngineWidgets/webpage.cpp \
webEngineWidgets/webview.cpp
HEADERS += \
mainwindow.h
webEngineWidgets/browser.h \
webEngineWidgets/browserwindow.h \
webEngineWidgets/downloadmanagerwidget.h \
webEngineWidgets/linkwindow.h \
webEngineWidgets/tabwidget.h \
webEngineWidgets/webpage.h \
webEngineWidgets/webview.h
FORMS += \
mainwindow.ui
webEngineWidgets/certificateerrordialog.ui \
webEngineWidgets/passworddialog.ui
TRANSLATIONS += \
mos-vkm_ru_RU.ts
......
Это отличие свёрнуто
Это отличие свёрнуто
Это отличие свёрнуто
<RCC>
<qresource prefix="/">
<file>icon.png</file>
<file>libs/jQuery/jquery.js</file>
<file>libs/jQuery/jquery.min.js</file>
<file>libs/jQuery/jquery.min.map</file>
</qresource>
</RCC>
/****************************************************************************
**
** 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(QString vkm_link, 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, vkm_link, false);
m_windows.append(mainWindow);
QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
m_windows.removeOne(mainWindow);
});
mainWindow->show();
return mainWindow;
}
LinkWindow *Browser::createLinkWindow(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 LinkWindow(this, profile, false);
mainWindow->show();
return mainWindow;
}
/****************************************************************************
**
** 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 "linkwindow.h"
#include <QVector>
#include <QWebEngineProfile>
class BrowserWindow;
class Browser
{
public:
Browser();
QVector<BrowserWindow*> windows() { return m_windows; }
BrowserWindow *createWindow(QString vkm_link = "https://web.vk.me/", bool offTheRecord = false);
LinkWindow *createLinkWindow(bool offTheRecord = false);
private:
QVector<BrowserWindow*> m_windows;
DownloadManagerWidget m_downloadManagerWidget;
QScopedPointer<QWebEngineProfile> m_otrProfile;
};
#endif // BROWSER_H
/****************************************************************************
**
** 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"
#include "downloadmanagerwidget.h"
#include "tabwidget.h"
#include "webview.h"
#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QMenuBar>
#include <QMessageBox>
#include <QProgressBar>
#include <QScreen>
#include <QStatusBar>
#include <QToolBar>
#include <QVBoxLayout>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QWebEngineFindTextResult>
#endif
#include <QWebEngineProfile>
#include <QTimer>
BrowserWindow::BrowserWindow(Browser *browser, QWebEngineProfile *profile, QString vkm_link, bool forDevTools)
: m_browser(browser)
, m_profile(profile)
, m_homeLink(vkm_link)
, m_tabWidget(new TabWidget(profile, this))
{
setFocusPolicy(Qt::ClickFocus);
/////////////SetTrayMenu/////////////
m_appTrayIcon = new QSystemTrayIcon( this );
m_appTrayIcon->setToolTip(tr("Open VKM"));
m_appTrayIcon->setIcon(QIcon(":/icon.png"));
// Set Tray Icon Context Menu
QMenu* tray_menu = new QMenu(this);
QAction* closeAppAction = new QAction(tr("Quit VK Messenger"), this);
connect(closeAppAction, SIGNAL(triggered()), this, SLOT(close()));
tray_menu->addAction(closeAppAction);
connect(m_appTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivation()));
m_appTrayIcon->setContextMenu(tray_menu);
m_appTrayIcon->show();
/////////////////////////////////////
//////////////SetMenuBar/////////////
QMenu *appMenu = new QMenu(tr("App"));
QAction *reloadAction = appMenu->addAction(tr("Reload"));
connect(reloadAction, &QAction::triggered, this, &BrowserWindow::reload);
QAction *homeAction = appMenu->addAction(tr("Return home page"));
connect(homeAction, &QAction::triggered, this, &BrowserWindow::home);
QAction *closeAction = appMenu->addAction(tr("Close application"));
connect(closeAction, &QAction::triggered, this, &BrowserWindow::close);
menuBar()->addMenu(appMenu);
/////////////////////////////////////
QWidget *centralWidget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_tabWidget);
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
m_tabWidget->createTab();
//////////////SetjQuery//////////////
QFile file;
file.setFileName(":/libs/jQuery/jquery.min.js");
file.open(QIODevice::ReadOnly);
jQuery = file.readAll();
jQuery.append("\nvar qt = { 'jQuery': jQuery.noConflict(true) };");
file.close();
connect(m_tabWidget->currentWebView(), &QWebEngineView::loadFinished, this, &BrowserWindow::finishLoading);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(setButtons()));
timer->start(100);
/////////////////////////////////////
}
QSize BrowserWindow::sizeHint() const
{
QRect desktopRect = QApplication::primaryScreen()->geometry();
QSize size = desktopRect.size() * qreal(0.9);
return size;
}
TabWidget *BrowserWindow::tabWidget() const
{
return m_tabWidget;
}
WebView *BrowserWindow::currentTab() const
{
return m_tabWidget->currentWebView();
}
void BrowserWindow::close()
{
exit(0);
}
void BrowserWindow::reload()
{
m_tabWidget->currentWebView()->reload();
}
void BrowserWindow::home()
{
QUrl vkm_url = QUrl(m_homeLink);
m_tabWidget->currentWebView()->setUrl(vkm_url);
}
void BrowserWindow::trayIconActivation()
{
if (this->isVisible())
{
this->hide();
} else
{
this->show();
}
}
void BrowserWindow::finishLoading(bool)
{
m_tabWidget->currentWebView()->page()->runJavaScript(jQuery);
}
void BrowserWindow::setButtons()
{
QString code;
code = QStringLiteral("var selectColor = 'rgb(245, 246, 247)'; qt.jQuery('.MEApp__route').each(function() {"
"if(qt.jQuery('.MEApp__route').css('background-color') == 'rgb(25, 25, 26)'){selectColor = 'rgb(34, 34, 35)'}"
"});");
code += QStringLiteral("qt.jQuery('.ActionsMenu').each(function() {"
"if(qt.jQuery(this).css('background-color') != 'var(--vkui--color_background_content)'){"
"qt.jQuery(this).css('background-color', 'var(--vkui--color_background_content)'); qt.jQuery(this).css('width', '260'); "
"qt.jQuery(this).css('border-style', 'solid'); qt.jQuery(this).css('border-radius', '10px'); qt.jQuery(this).css('border-width', '0.5'); qt.jQuery(this).css('border-color', 'var(--vkui--color_transparent--active)');"
"}});");
code += QStringLiteral("qt.jQuery('.ActionsMenuAction').each( function () { "
"qt.jQuery(this).css('display', 'inline-flex');"
"}); ");
code += QStringLiteral("qt.jQuery('.ActionsMenuAction').each(function() {"
"if(qt.jQuery(this).css('background-color') == 'rgb(239, 239, 239)'){"
"qt.jQuery(this).css('background-color', 'var(--vkui--color_background_content)'); qt.jQuery(this).css('color', 'var(--vkui--color_text_primary)'); "
"qt.jQuery(this).css('width', '260'); qt.jQuery(this).css('height', '32'); qt.jQuery(this).css('border', 'none'); qt.jQuery(this).css('display', 'list-item'); qt.jQuery(this).css('text-align', 'left'); qt.jQuery(this).css('vertical-align', 'middle');"
"qt.jQuery('.ActionsMenuAction__icon').each( function (){"
"qt.jQuery(this).css('align-items', 'center');"
"}); "
"qt.jQuery('.ActionsMenuAction__title').each( function (){"
"qt.jQuery(this).css('margin-left', '10px'); qt.jQuery(this).css('font', '400 var(--messageActionsMenuTitleFontSize) /var(--messageActionsMenuTitleLineHeight) var(--font)');"
"}); "
"}"
"});");
code += QStringLiteral("qt.jQuery('.ActionsMenuAction').closest('button').hover( function () { "
"qt.jQuery(this).css('background-color', selectColor)}, function () { qt.jQuery(this).css('background-color', 'var(--vkui--color_background_content)')"
"}); ");
code += QStringLiteral("qt.jQuery('.RightPanel__container').each( function () { "
"qt.jQuery(this).css('background-color', 'var(--vkui--color_background_content)');"
"}); ");
code += QStringLiteral("qt.jQuery('.RightPanelContainer__mainContent').each( function () { "
"qt.jQuery(this).css('width', 'calc(100% - var(--compress_width))');"
"}); ");
code += QStringLiteral("qt.jQuery('.RE_ModalHeader').each( function () { "
"qt.jQuery(this).css('background-color', 'var(--vkui--color_background_tertiary)'); qt.jQuery(this).css('border-bottom', '1px solid var(--vkui--color_separator_secondary)'); qt.jQuery(this).css('height', '54px'); qt.jQuery(this).css('font', '14px/16px var(--font)');"
"}); ");
code += QStringLiteral("qt.jQuery('.RE_ModalPanel').each( function () { "
"qt.jQuery(this).css('background', 'var(--vkui--color_background_modal)'); qt.jQuery(this).css('border-radius', '8px'); qt.jQuery(this).css('display', 'grid');"
"qt.jQuery(this).css('grid-auto-rows', 'auto 1fr auto');"
"}); ");
code += QStringLiteral("qt.jQuery('.RE_ModalHeader__title').each( function () { "
"qt.jQuery(this).css('padding-left', '15px');"
"}); ");
code += QStringLiteral("qt.jQuery('.ImportantMessagesList').each( function () { "
"qt.jQuery(this).css('width', '610px');"
"}); ");
code += QStringLiteral("qt.jQuery('button').each( function () { "
"qt.jQuery(this).css('outline', '0');"
"}); ");
m_tabWidget->currentWebView()->page()->runJavaScript(code);
}
BrowserWindow::~BrowserWindow()
{
deleteLater();
delete m_appTrayIcon;
}
/****************************************************************************
**
** 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>
#include <QSystemTrayIcon>
class Browser;
class TabWidget;
class WebView;
class BrowserWindow : public QMainWindow
{
Q_OBJECT
public:
BrowserWindow(Browser *browser, QWebEngineProfile *profile, QString vkm_link = "https://web.vk.me/", bool forDevTools = false);
~BrowserWindow();
QSize sizeHint() const override;
TabWidget *tabWidget() const;
WebView *currentTab() const;
Browser *browser() { return m_browser; }
private slots:
void close();
void trayIconActivation();
void reload();
void home();
void finishLoading(bool);
void setButtons();
private:
Browser *m_browser;
QWebEngineProfile *m_profile;
TabWidget *m_tabWidget;
QSystemTrayIcon* m_appTrayIcon;
QString m_homeLink;
QString jQuery;
};
#endif // BROWSERWINDOW_H
<?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>
/****************************************************************************
**
** 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 <QFileDialog>
#include <QDir>
#include <QWebEngineDownloadItem>
DownloadManagerWidget::DownloadManagerWidget(QWidget *parent)
: QWidget(parent)
{
}
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();
}
/****************************************************************************
**
** 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 <QWidget>
QT_BEGIN_NAMESPACE
class QWebEngineDownloadItem;
QT_END_NAMESPACE
class DownloadWidget;
// Displays a list of downloads.
class DownloadManagerWidget final : public QWidget
{
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);
};
#endif // DOWNLOADMANAGERWIDGET_H
#include "linkwindow.h"
#include "browser.h"
#include "downloadmanagerwidget.h"
#include "tabwidget.h"
#include "webview.h"
#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QMenuBar>
#include <QMessageBox>
#include <QProgressBar>
#include <QScreen>
#include <QStatusBar>
#include <QToolBar>
#include <QVBoxLayout>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QWebEngineFindTextResult>
#endif
#include <QWebEngineProfile>
LinkWindow::LinkWindow(Browser *browser, QWebEngineProfile *profile, bool forDevTools)
: m_browser(browser)
, m_profile(profile)
, m_tabWidget(new TabWidget(profile, this))
{
setFocusPolicy(Qt::ClickFocus);
QWidget *centralWidget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_tabWidget);
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
m_tabWidget->createTab();
}
QSize LinkWindow::sizeHint() const
{
QRect desktopRect = QApplication::primaryScreen()->geometry();
QSize size = desktopRect.size() * qreal(0.9);
return size;
}
TabWidget *LinkWindow::tabWidget() const
{
return m_tabWidget;
}
WebView *LinkWindow::currentTab() const
{
return m_tabWidget->currentWebView();
}
LinkWindow::~LinkWindow()
{
deleteLater();
}
#ifndef LINKWINDOW_H
#define LINKWINDOW_H
#include <QMainWindow>
#include <QTime>
#include <QWebEnginePage>
#include <QSystemTrayIcon>
class Browser;
class TabWidget;
class WebView;
class LinkWindow : public QMainWindow
{
Q_OBJECT
public:
explicit LinkWindow(Browser *browser, QWebEngineProfile *profile, bool forDevTools = false);
~LinkWindow();
QSize sizeHint() const override;
TabWidget *tabWidget() const;
WebView *currentTab() const;
Browser *browser() { return m_browser; }
private:
Browser *m_browser;
QWebEngineProfile *m_profile;
TabWidget *m_tabWidget;
};
#endif // LINKWINDOW_H
<?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>
/****************************************************************************
**
** 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)
{
this->tabBar()->hide();
}
WebView *TabWidget::currentWebView() const
{
return webView(currentIndex());
}
WebView *TabWidget::webView(int index) const
{
return qobject_cast<WebView*>(widget(index));
}
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);
int index = addTab(webView, tr("(Untitled)"));
// Workaround for QTBUG-61770
webView->resize(currentWidget()->size());
webView->show();
return webView;
}
WebView *TabWidget::createLinkTab()
{
WebView *webView = new WebView;
WebPage *webPage = new WebPage(m_profile, webView);
webView->setPage(webPage);
return webView;
}
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать