Added mouse gestures.
This commit is contained in:
parent
d1c2b9aa84
commit
fcb257022b
|
@ -21,6 +21,7 @@
|
|||
#define APP_CFG_GEN "main"
|
||||
#define APP_CFG_PROXY "proxy"
|
||||
#define APP_CFG_CUTS "keyboard"
|
||||
#define APP_CFG_BROWSER "browser"
|
||||
|
||||
#define APP_DB_PATH "data/storage/database.db"
|
||||
#define APP_PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QWebFrame>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/basewebpage.h"
|
||||
#include "gui/basewebview.h"
|
||||
#include "gui/themefactory.h"
|
||||
|
@ -12,6 +14,7 @@
|
|||
BaseWebView::BaseWebView(QWidget *parent)
|
||||
: QWebView(parent), m_page(new BaseWebPage(this)) {
|
||||
setPage(m_page);
|
||||
setContextMenuPolicy(Qt::NoContextMenu);
|
||||
initializeActions();
|
||||
createConnections();
|
||||
}
|
||||
|
@ -28,7 +31,10 @@ void BaseWebView::onLoadFinished(bool ok) {
|
|||
}
|
||||
|
||||
void BaseWebView::createConnections() {
|
||||
connect(this, &BaseWebView::loadFinished, this, &BaseWebView::onLoadFinished);
|
||||
connect(this, &BaseWebView::loadFinished,
|
||||
this, &BaseWebView::onLoadFinished);
|
||||
connect(this, &BaseWebView::customContextMenuRequested,
|
||||
this, &BaseWebView::popupContextMenu);
|
||||
}
|
||||
|
||||
void BaseWebView::setupIcons() {
|
||||
|
@ -68,10 +74,10 @@ void BaseWebView::displayErrorPage() {
|
|||
setHtml("error", url());
|
||||
}
|
||||
|
||||
void BaseWebView::contextMenuEvent(QContextMenuEvent *event) {
|
||||
void BaseWebView::popupContextMenu(const QPoint &pos) {
|
||||
QMenu context_menu(tr("Web browser"), this);
|
||||
QMenu image_submenu(tr("Image"), &context_menu);
|
||||
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos());
|
||||
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(pos);
|
||||
|
||||
image_submenu.setIcon(ThemeFactory::fromTheme("image-x-generic"));
|
||||
|
||||
|
@ -94,11 +100,11 @@ void BaseWebView::contextMenuEvent(QContextMenuEvent *event) {
|
|||
}
|
||||
|
||||
// Display the menu.
|
||||
context_menu.exec(mapToGlobal(event->pos()));
|
||||
context_menu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void BaseWebView::mousePressEvent(QMouseEvent *event) {
|
||||
if (event->buttons() & Qt::MiddleButton) {
|
||||
if (event->button() & Qt::MiddleButton) {
|
||||
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos());
|
||||
|
||||
// Check if user clicked with middle mouse button on some
|
||||
|
@ -110,15 +116,51 @@ void BaseWebView::mousePressEvent(QMouseEvent *event) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if (event->button() & Qt::RightButton) {
|
||||
m_gestureOrigin = event->pos();
|
||||
}
|
||||
|
||||
// TODO: Add mouse gestures (from quite-rss).
|
||||
QWebView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void BaseWebView::mouseReleaseEvent(QMouseEvent *event) {
|
||||
QWebView::mousePressEvent(event);
|
||||
QWebView::mouseReleaseEvent(event);
|
||||
|
||||
if (event->button() & Qt::RightButton) {
|
||||
bool are_gestures_enabled = Settings::getInstance()->value(APP_CFG_BROWSER,
|
||||
"gestures_enabled",
|
||||
true).toBool();
|
||||
if (are_gestures_enabled) {
|
||||
QPoint release_point = event->pos();
|
||||
int left_move = m_gestureOrigin.x() - release_point.x();
|
||||
int right_move = release_point.x() - m_gestureOrigin.x();
|
||||
int top_move = m_gestureOrigin.y() - release_point.y();
|
||||
int bottom_move = release_point.y() - m_gestureOrigin.y();
|
||||
int total_max = qMax(qMax(qMax(left_move, right_move),
|
||||
qMax(top_move, bottom_move)),
|
||||
40);
|
||||
|
||||
if (total_max == left_move && are_gestures_enabled) {
|
||||
back();
|
||||
}
|
||||
else if (total_max == right_move && are_gestures_enabled) {
|
||||
forward();
|
||||
}
|
||||
else if (total_max == top_move && are_gestures_enabled) {
|
||||
reload();
|
||||
}
|
||||
else if (total_max == bottom_move && are_gestures_enabled) {
|
||||
emit newTabRequested();
|
||||
}
|
||||
else {
|
||||
emit customContextMenuRequested(event->pos());
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit customContextMenuRequested(event->pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BaseWebView::paintEvent(QPaintEvent *event) {
|
||||
|
|
|
@ -23,10 +23,16 @@ class BaseWebView : public QWebView {
|
|||
// web browser tab.
|
||||
void linkMiddleClicked(const QUrl &link_url);
|
||||
|
||||
// User wants to open new empty web browser tab.
|
||||
void newTabRequested();
|
||||
|
||||
protected slots:
|
||||
// Executes if loading of any page is done.
|
||||
void onLoadFinished(bool ok);
|
||||
|
||||
// Provides custom context menu.
|
||||
void popupContextMenu(const QPoint &pos);
|
||||
|
||||
protected:
|
||||
void initializeActions();
|
||||
|
||||
|
@ -39,9 +45,6 @@ class BaseWebView : public QWebView {
|
|||
// Does additional painting.
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
// Provides custom context menu.
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
// Provides custom mouse actions.
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
@ -53,6 +56,8 @@ class BaseWebView : public QWebView {
|
|||
QAction *m_actionCopyLink;
|
||||
QAction *m_actionCopyImage;
|
||||
QAction *m_actionCopyImageUrl;
|
||||
|
||||
QPoint m_gestureOrigin;
|
||||
};
|
||||
|
||||
#endif // BASEWEBVIEW_H
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
<locale language="English" country="UnitedStates"/>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_tabInfo">
|
||||
<attribute name="title">
|
||||
|
@ -135,8 +135,8 @@
|
|||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
|
@ -162,15 +162,15 @@ p, li { white-space: pre-wrap; }
|
|||
<item>
|
||||
<widget class="QToolBox" name="toolBox">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_GNU_GPL">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>687</width>
|
||||
<height>180</height>
|
||||
<width>685</width>
|
||||
<height>184</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
|
@ -227,12 +227,15 @@ p, li { white-space: pre-wrap; }
|
|||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'DejaVu Sans Mono'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'DejaVu Sans Mono'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -242,8 +245,8 @@ p, li { white-space: pre-wrap; }
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>687</width>
|
||||
<height>180</height>
|
||||
<width>685</width>
|
||||
<height>184</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
|
@ -294,12 +297,15 @@ p, li { white-space: pre-wrap; }
|
|||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'DejaVu Sans Mono'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'DejaVu Sans Mono'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -332,8 +338,8 @@ p, li { white-space: pre-wrap; }
|
|||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt;"><br /></span></p></body></html></string>
|
||||
</property>
|
||||
<property name="tabStopWidth">
|
||||
<number>30</number>
|
||||
|
@ -344,6 +350,9 @@ p, li { white-space: pre-wrap; }
|
|||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -365,8 +374,8 @@ p, li { white-space: pre-wrap; }
|
|||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
|
@ -374,6 +383,9 @@ p, li { white-space: pre-wrap; }
|
|||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -51,6 +51,7 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
|
|||
loadShortcuts();
|
||||
loadInterface();
|
||||
loadProxy();
|
||||
loadBrowser();
|
||||
loadLanguage();
|
||||
}
|
||||
|
||||
|
@ -82,6 +83,7 @@ void FormSettings::saveSettings() {
|
|||
saveShortcuts();
|
||||
saveInterface();
|
||||
saveProxy();
|
||||
saveBrowser();
|
||||
saveLanguage();
|
||||
|
||||
Settings::getInstance()->checkSettings();
|
||||
|
@ -103,6 +105,32 @@ void FormSettings::onProxyTypeChanged(int index) {
|
|||
m_ui->m_lblProxyUsername->setEnabled(is_proxy_selected);
|
||||
}
|
||||
|
||||
void FormSettings::loadBrowser() {
|
||||
// Load settings of web browser GUI.
|
||||
m_initialSettings.m_webBrowserProgress = Settings::getInstance()->value(APP_CFG_BROWSER,
|
||||
"browser_progress_color",
|
||||
QColor(0, 255, 0, 100)).value<QColor>();
|
||||
m_ui->m_checkBrowserProgressColor->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER,
|
||||
"browser_colored_progress_enabled",
|
||||
true).toBool());
|
||||
m_ui->m_checkMouseGestures->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER,
|
||||
"gestures_enabled",
|
||||
true).toBool());
|
||||
}
|
||||
|
||||
void FormSettings::saveBrowser() {
|
||||
// Save settings of GUI of web browser.
|
||||
Settings::getInstance()->setValue(APP_CFG_BROWSER,
|
||||
"browser_progress_color",
|
||||
m_initialSettings.m_webBrowserProgress);
|
||||
Settings::getInstance()->setValue(APP_CFG_BROWSER,
|
||||
"browser_colored_progress_enabled",
|
||||
m_ui->m_checkBrowserProgressColor->isChecked());
|
||||
Settings::getInstance()->setValue(APP_CFG_BROWSER,
|
||||
"gestures_enabled",
|
||||
m_ui->m_checkMouseGestures->isChecked());
|
||||
}
|
||||
|
||||
void FormSettings::loadProxy() {
|
||||
m_ui->m_cmbProxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy);
|
||||
m_ui->m_cmbProxyType->addItem(tr("Socks5"), QNetworkProxy::Socks5Proxy);
|
||||
|
@ -260,14 +288,6 @@ void FormSettings::loadInterface() {
|
|||
m_ui->m_grpTray->setDisabled(true);
|
||||
}
|
||||
|
||||
// Load settings of web browser GUI.
|
||||
m_initialSettings.m_webBrowserProgress = Settings::getInstance()->value(APP_CFG_GUI,
|
||||
"browser_progress_color",
|
||||
QColor(0, 255, 0, 100)).value<QColor>();
|
||||
m_ui->m_checkBrowserProgressColor->setChecked(Settings::getInstance()->value(APP_CFG_GUI,
|
||||
"browser_colored_progress_enabled",
|
||||
true).toBool());
|
||||
|
||||
// Load settings of icon theme.
|
||||
QString current_theme = ThemeFactory::getCurrentIconTheme();
|
||||
|
||||
|
@ -315,14 +335,6 @@ void FormSettings::saveInterface() {
|
|||
}
|
||||
}
|
||||
|
||||
// Save settings of GUI of web browser.
|
||||
Settings::getInstance()->setValue(APP_CFG_GUI,
|
||||
"browser_progress_color",
|
||||
m_initialSettings.m_webBrowserProgress);
|
||||
Settings::getInstance()->setValue(APP_CFG_GUI,
|
||||
"browser_colored_progress_enabled",
|
||||
m_ui->m_checkBrowserProgressColor->isChecked());
|
||||
|
||||
// Save selected icon theme.
|
||||
ThemeFactory::setCurrentIconTheme(m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString());
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ class FormSettings : public QDialog {
|
|||
void loadShortcuts();
|
||||
void saveShortcuts();
|
||||
|
||||
void loadBrowser();
|
||||
void saveBrowser();
|
||||
|
||||
void loadProxy();
|
||||
void saveProxy();
|
||||
void displayProxyPassword(int state);
|
||||
|
|
|
@ -69,8 +69,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>506</width>
|
||||
<height>367</height>
|
||||
<width>100</width>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
|
@ -314,7 +314,7 @@
|
|||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QLabel" name="m_lblMouseGestures">
|
||||
<property name="text">
|
||||
<string>Mouse gestures work with left mouse button. Possible gestures are:
|
||||
<string>Mouse gestures work with right mouse button. Possible gestures are:
|
||||
<ul>
|
||||
<li>previous web page (drag mouse left)</li>
|
||||
<li>next web page (drag mouse right)</li>
|
||||
|
@ -624,5 +624,37 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_checkBrowserProgressColor</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>m_lblBrowserProgressColor</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>300</x>
|
||||
<y>48</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>275</x>
|
||||
<y>73</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_checkBrowserProgressColor</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>m_btnBrowserProgressColor</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>300</x>
|
||||
<y>48</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>544</x>
|
||||
<y>74</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
|
@ -50,11 +50,11 @@ void LocationLineEdit::mousePressEvent(QMouseEvent *event) {
|
|||
|
||||
void LocationLineEdit::paintEvent(QPaintEvent *event) {
|
||||
// Draw "progress bar" if needed.
|
||||
if (m_progress > 0 && Settings::getInstance()->value(APP_CFG_GUI,
|
||||
if (m_progress > 0 && Settings::getInstance()->value(APP_CFG_BROWSER,
|
||||
"browser_colored_progress_enabled",
|
||||
true).toBool()) {
|
||||
QPalette current_palette = palette();
|
||||
QColor loadingColor = Settings::getInstance()->value(APP_CFG_GUI,
|
||||
QColor loadingColor = Settings::getInstance()->value(APP_CFG_BROWSER,
|
||||
"browser_progress_color",
|
||||
QColor(0, 255, 0, 100)).value<QColor>();
|
||||
QLinearGradient gradient(0, 0, width(), 0);
|
||||
|
|
Loading…
Reference in New Issue