mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Fixed bad behaviour of QWebPage on leaveEvent.
- when leaving web widget, QWebPagePrivate generates fake mouse move event, but unfortunately with bad coordinates. So sometimes it just hovered a link and the link's url got stuck in status bar message.
This commit is contained in:
parent
dbfc09538c
commit
cf973c46fb
2
src/lib/3rdparty/lineedit.cpp
vendored
2
src/lib/3rdparty/lineedit.cpp
vendored
@ -162,7 +162,7 @@ void LineEdit::updateTextMargins()
|
|||||||
else {
|
else {
|
||||||
left = m_leftMargin;
|
left = m_leftMargin;
|
||||||
}
|
}
|
||||||
int right = textMargin(LineEdit::RightSide);
|
int right = textMargin(LineEdit::RightSide) + 3;
|
||||||
int top = 0;
|
int top = 0;
|
||||||
int bottom = 0;
|
int bottom = 0;
|
||||||
setTextMargins(left, top, right, bottom);
|
setTextMargins(left, top, right, bottom);
|
||||||
|
6
src/lib/3rdparty/lineedit.h
vendored
6
src/lib/3rdparty/lineedit.h
vendored
@ -71,13 +71,13 @@ public:
|
|||||||
|
|
||||||
void setLeftMargin(int margin);
|
void setLeftMargin(int margin);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateTextMargins();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent* event);
|
void resizeEvent(QResizeEvent* event);
|
||||||
bool event(QEvent* event);
|
bool event(QEvent* event);
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void updateTextMargins();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void updateSideWidgetLocations();
|
void updateSideWidgetLocations();
|
||||||
|
@ -150,6 +150,8 @@ void LocationBar::showGoButton()
|
|||||||
m_bookmarkIcon->hide();
|
m_bookmarkIcon->hide();
|
||||||
m_rssIcon->hide();
|
m_rssIcon->hide();
|
||||||
m_goIcon->show();
|
m_goIcon->show();
|
||||||
|
|
||||||
|
updateTextMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationBar::hideGoButton()
|
void LocationBar::hideGoButton()
|
||||||
@ -161,6 +163,8 @@ void LocationBar::hideGoButton()
|
|||||||
m_rssIcon->setVisible(m_rssIconVisible);
|
m_rssIcon->setVisible(m_rssIconVisible);
|
||||||
m_bookmarkIcon->show();
|
m_bookmarkIcon->show();
|
||||||
m_goIcon->hide();
|
m_goIcon->hide();
|
||||||
|
|
||||||
|
updateTextMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationBar::showMostVisited()
|
void LocationBar::showMostVisited()
|
||||||
@ -172,6 +176,7 @@ void LocationBar::showMostVisited()
|
|||||||
QKeyEvent event(QEvent::KeyPress, Qt::Key_unknown, Qt::NoModifier, QString(" "));
|
QKeyEvent event(QEvent::KeyPress, Qt::Key_unknown, Qt::NoModifier, QString(" "));
|
||||||
keyPressEvent(&event);
|
keyPressEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_locationCompleter->showMostVisited();
|
m_locationCompleter->showMostVisited();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +201,8 @@ void LocationBar::rssIconClicked()
|
|||||||
void LocationBar::showRSSIcon(bool state)
|
void LocationBar::showRSSIcon(bool state)
|
||||||
{
|
{
|
||||||
m_rssIcon->setVisible(state);
|
m_rssIcon->setVisible(state);
|
||||||
|
|
||||||
|
updateTextMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationBar::showUrl(const QUrl &url)
|
void LocationBar::showUrl(const QUrl &url)
|
||||||
|
@ -31,12 +31,12 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
|
#include <QTimer>
|
||||||
#include <QTextEdit>
|
|
||||||
|
|
||||||
SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
|
SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
|
||||||
: QWidget(0)
|
: QWidget(0)
|
||||||
, m_frame(frame)
|
, m_frame(frame)
|
||||||
|
, m_selectedHtml(selectedHtml)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
setWindowTitle(tr("Source of ") + frame->url().toString());
|
setWindowTitle(tr("Source of ") + frame->url().toString());
|
||||||
@ -72,13 +72,12 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
|
|||||||
menuBar->addMenu(menuFile);
|
menuBar->addMenu(menuFile);
|
||||||
|
|
||||||
QMenu* menuEdit = new QMenu(tr("Edit"));
|
QMenu* menuEdit = new QMenu(tr("Edit"));
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("Undo"), m_sourceEdit, SLOT(undo()))->setShortcut(QKeySequence("Ctrl+Z"));
|
m_actionUndo = menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("Undo"), m_sourceEdit, SLOT(undo()));
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("Redo"), m_sourceEdit, SLOT(redo()))->setShortcut(QKeySequence("Ctrl+Shift+Z"));
|
m_actionRedo = menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("Redo"), m_sourceEdit, SLOT(redo()));
|
||||||
menuEdit->addSeparator();
|
menuEdit->addSeparator();
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("Cut"), m_sourceEdit, SLOT(cut()))->setShortcut(QKeySequence("Ctrl+X"));
|
m_actionCut = menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("Cut"), m_sourceEdit, SLOT(cut()));
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("Copy"), m_sourceEdit, SLOT(copy()))->setShortcut(QKeySequence("Ctrl+C"));
|
m_actionCopy = menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("Copy"), m_sourceEdit, SLOT(copy()));
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("Paste"), m_sourceEdit, SLOT(paste()))->setShortcut(QKeySequence("Ctrl+V"));
|
m_actionPaste = menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("Paste"), m_sourceEdit, SLOT(paste()));
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-delete"), tr("Delete"))->setShortcut(QKeySequence("Del"));
|
|
||||||
menuEdit->addSeparator();
|
menuEdit->addSeparator();
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select All"), m_sourceEdit, SLOT(selectAll()))->setShortcut(QKeySequence("Ctrl+A"));
|
menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select All"), m_sourceEdit, SLOT(selectAll()))->setShortcut(QKeySequence("Ctrl+A"));
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("Find"), this, SLOT(findText()))->setShortcut(QKeySequence("Ctrl+F"));
|
menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("Find"), this, SLOT(findText()))->setShortcut(QKeySequence("Ctrl+F"));
|
||||||
@ -86,6 +85,12 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
|
|||||||
menuEdit->addAction(QIcon::fromTheme("go-jump"), tr("Go to Line..."), this, SLOT(goToLine()))->setShortcut(QKeySequence("Ctrl+L"));
|
menuEdit->addAction(QIcon::fromTheme("go-jump"), tr("Go to Line..."), this, SLOT(goToLine()))->setShortcut(QKeySequence("Ctrl+L"));
|
||||||
menuBar->addMenu(menuEdit);
|
menuBar->addMenu(menuEdit);
|
||||||
|
|
||||||
|
m_actionUndo->setShortcut(QKeySequence("Ctrl+Z"));
|
||||||
|
m_actionRedo->setShortcut(QKeySequence("Ctrl+Shift+Z"));
|
||||||
|
m_actionCut->setShortcut(QKeySequence("Ctrl+X"));
|
||||||
|
m_actionCopy->setShortcut(QKeySequence("Ctrl+C"));
|
||||||
|
m_actionPaste->setShortcut(QKeySequence("Ctrl+V"));
|
||||||
|
|
||||||
QMenu* menuView = new QMenu(tr("View"));
|
QMenu* menuView = new QMenu(tr("View"));
|
||||||
menuView->addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("Reload"), this, SLOT(reload()))->setShortcut(QKeySequence("F5"));
|
menuView->addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("Reload"), this, SLOT(reload()))->setShortcut(QKeySequence("F5"));
|
||||||
menuView->addSeparator();
|
menuView->addSeparator();
|
||||||
@ -96,11 +101,48 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
|
|||||||
|
|
||||||
qz_centerWidgetToParent(this, frame->page()->view());
|
qz_centerWidgetToParent(this, frame->page()->view());
|
||||||
|
|
||||||
m_sourceEdit->setPlainText(frame->toHtml());
|
connect(m_sourceEdit, SIGNAL(copyAvailable(bool)), this, SLOT(copyAvailable(bool)));
|
||||||
|
connect(m_sourceEdit, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailable(bool)));
|
||||||
|
connect(m_sourceEdit, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailable(bool)));
|
||||||
|
connect(menuEdit, SIGNAL(aboutToShow()), this, SLOT(pasteAvailable()));
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, SLOT(loadSource()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceViewer::copyAvailable(bool yes)
|
||||||
|
{
|
||||||
|
m_actionCopy->setEnabled(yes);
|
||||||
|
m_actionCut->setEnabled(yes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceViewer::redoAvailable(bool available)
|
||||||
|
{
|
||||||
|
m_actionRedo->setEnabled(available);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceViewer::undoAvailable(bool available)
|
||||||
|
{
|
||||||
|
m_actionUndo->setEnabled(available);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceViewer::pasteAvailable()
|
||||||
|
{
|
||||||
|
m_actionPaste->setEnabled(m_sourceEdit->canPaste());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceViewer::loadSource()
|
||||||
|
{
|
||||||
|
m_actionUndo->setEnabled(false);
|
||||||
|
m_actionRedo->setEnabled(false);
|
||||||
|
m_actionCut->setEnabled(false);
|
||||||
|
m_actionCopy->setEnabled(false);
|
||||||
|
m_actionPaste->setEnabled(false);
|
||||||
|
|
||||||
|
m_sourceEdit->setPlainText(m_frame.data()->toHtml());
|
||||||
|
|
||||||
//Highlight selectedHtml
|
//Highlight selectedHtml
|
||||||
if (!selectedHtml.isEmpty()) {
|
if (!m_selectedHtml.isEmpty()) {
|
||||||
m_sourceEdit->find(selectedHtml, QTextDocument::FindWholeWords);
|
m_sourceEdit->find(m_selectedHtml, QTextDocument::FindWholeWords);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_sourceEdit->moveCursor(QTextCursor::Start);
|
m_sourceEdit->moveCursor(QTextCursor::Start);
|
||||||
|
@ -36,11 +36,13 @@ public:
|
|||||||
explicit SourceViewer(QWebFrame* frame, const QString &selectedHtml);
|
explicit SourceViewer(QWebFrame* frame, const QString &selectedHtml);
|
||||||
PlainEditWithLines* sourceEdit() { return m_sourceEdit; }
|
PlainEditWithLines* sourceEdit() { return m_sourceEdit; }
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void copyAvailable(bool yes);
|
||||||
|
void redoAvailable(bool available);
|
||||||
|
void undoAvailable(bool available);
|
||||||
|
void pasteAvailable();
|
||||||
|
|
||||||
|
void loadSource();
|
||||||
void save();
|
void save();
|
||||||
void findText();
|
void findText();
|
||||||
void reload();
|
void reload();
|
||||||
@ -53,6 +55,14 @@ private:
|
|||||||
PlainEditWithLines* m_sourceEdit;
|
PlainEditWithLines* m_sourceEdit;
|
||||||
QWeakPointer<QWebFrame> m_frame;
|
QWeakPointer<QWebFrame> m_frame;
|
||||||
QStatusBar* m_statusBar;
|
QStatusBar* m_statusBar;
|
||||||
|
|
||||||
|
QString m_selectedHtml;
|
||||||
|
|
||||||
|
QAction* m_actionUndo;
|
||||||
|
QAction* m_actionRedo;
|
||||||
|
QAction* m_actionCut;
|
||||||
|
QAction* m_actionCopy;
|
||||||
|
QAction* m_actionPaste;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SOURCEVIEWER_H
|
#endif // SOURCEVIEWER_H
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
TipLabel::TipLabel(QWidget* parent)
|
TipLabel::TipLabel(QWidget* parent)
|
||||||
: SqueezeLabelV1(parent)
|
: SqueezeLabelV1(parent)
|
||||||
, p_QupZilla(0)
|
|
||||||
, m_connected(false)
|
, m_connected(false)
|
||||||
{
|
{
|
||||||
setWindowFlags(Qt::ToolTip);
|
setWindowFlags(Qt::ToolTip);
|
||||||
@ -44,21 +43,6 @@ TipLabel::TipLabel(QWidget* parent)
|
|||||||
qApp->installEventFilter(this);
|
qApp->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TipLabel::setMainWindow(QupZilla* main)
|
|
||||||
{
|
|
||||||
p_QupZilla = main;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TipLabel::show()
|
|
||||||
{
|
|
||||||
if (p_QupZilla && !m_connected) {
|
|
||||||
connect(p_QupZilla->tabWidget(), SIGNAL(currentChanged(int)), this, SLOT(hide()));
|
|
||||||
m_connected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SqueezeLabelV1::show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TipLabel::paintEvent(QPaintEvent* ev)
|
void TipLabel::paintEvent(QPaintEvent* ev)
|
||||||
{
|
{
|
||||||
QStylePainter p(this);
|
QStylePainter p(this);
|
||||||
@ -97,7 +81,6 @@ StatusBarMessage::StatusBarMessage(QupZilla* mainClass)
|
|||||||
: p_QupZilla(mainClass)
|
: p_QupZilla(mainClass)
|
||||||
, m_statusBarText(new TipLabel(mainClass))
|
, m_statusBarText(new TipLabel(mainClass))
|
||||||
{
|
{
|
||||||
m_statusBarText->setMainWindow(p_QupZilla);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusBarMessage::showMessage(const QString &message)
|
void StatusBarMessage::showMessage(const QString &message)
|
||||||
@ -128,10 +111,8 @@ void StatusBarMessage::showMessage(const QString &message)
|
|||||||
m_statusBarText->setMaximumWidth(view->width() - verticalScrollSize);
|
m_statusBarText->setMaximumWidth(view->width() - verticalScrollSize);
|
||||||
m_statusBarText->resize(m_statusBarText->sizeHint());
|
m_statusBarText->resize(m_statusBarText->sizeHint());
|
||||||
|
|
||||||
QPoint position;
|
QPoint position(0, view->height() - horizontalScrollSize - m_statusBarText->height());
|
||||||
position.setY(view->height() - horizontalScrollSize - m_statusBarText->height());
|
const QRect &statusRect = QRect(view->mapToGlobal(QPoint(0, position.y())), m_statusBarText->size());
|
||||||
|
|
||||||
QRect statusRect = QRect(view->mapToGlobal(QPoint(0, position.y())), m_statusBarText->size());
|
|
||||||
|
|
||||||
if (statusRect.contains(QCursor::pos())) {
|
if (statusRect.contains(QCursor::pos())) {
|
||||||
position.setY(position.y() - m_statusBarText->height());
|
position.setY(position.y() - m_statusBarText->height());
|
||||||
|
@ -31,10 +31,7 @@ class QT_QUPZILLA_EXPORT TipLabel : public SqueezeLabelV1
|
|||||||
public:
|
public:
|
||||||
TipLabel(QWidget* parent);
|
TipLabel(QWidget* parent);
|
||||||
|
|
||||||
void setMainWindow(QupZilla* main);
|
|
||||||
|
|
||||||
bool eventFilter(QObject* o, QEvent* e);
|
bool eventFilter(QObject* o, QEvent* e);
|
||||||
void show();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent* ev);
|
void paintEvent(QPaintEvent* ev);
|
||||||
|
@ -294,6 +294,30 @@ void WebPage::featurePermissionRequested(QWebFrame* frame, const QWebPage::Featu
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool WebPage::event(QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Leave) {
|
||||||
|
// QWebPagePrivate::leaveEvent():
|
||||||
|
// Fake a mouse move event just outside of the widget, since all
|
||||||
|
// the interesting mouse-out behavior like invalidating scrollbars
|
||||||
|
// is handled by the WebKit event handler's mouseMoved function.
|
||||||
|
|
||||||
|
// However, its implementation fake mouse move event on QCursor::pos()
|
||||||
|
// position that is in global screen coordinates. So instead of
|
||||||
|
// really faking it, it just creates mouse move event somewhere in
|
||||||
|
// page. It can for example focus a link, and then link url gets
|
||||||
|
// stuck in status bar message.
|
||||||
|
|
||||||
|
// So we are faking mouse move event with proper coordinates for
|
||||||
|
// so called "just outside of the widget" position
|
||||||
|
|
||||||
|
QMouseEvent fakeEvent(QEvent::MouseMove, QPoint(0, -1), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||||
|
return QWebPage::event(&fakeEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QWebPage::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void WebPage::setSSLCertificate(const QSslCertificate &cert)
|
void WebPage::setSSLCertificate(const QSslCertificate &cert)
|
||||||
{
|
{
|
||||||
// if (cert != m_SslCert)
|
// if (cert != m_SslCert)
|
||||||
|
@ -95,6 +95,7 @@ private slots:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool event(QEvent* event);
|
||||||
QWebPage* createWindow(QWebPage::WebWindowType type);
|
QWebPage* createWindow(QWebPage::WebWindowType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user