diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index a2fcf5170..b19095a96 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -453,10 +453,10 @@ void LocationBar::mouseDoubleClickEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton && qzSettings->selectAllOnDoubleClick) { selectAll(); + return; } - else { - QLineEdit::mouseDoubleClickEvent(event); - } + + QLineEdit::mouseDoubleClickEvent(event); } void LocationBar::mousePressEvent(QMouseEvent* event) @@ -469,6 +469,24 @@ void LocationBar::mousePressEvent(QMouseEvent* event) LineEdit::mousePressEvent(event); } +void LocationBar::mouseReleaseEvent(QMouseEvent* event) +{ + // Workaround issue in QLineEdit::setDragEnabled + // It will incorrectly set cursor position at the end + // of selection when clicking into selected text + bool wasSelectedText = !selectedText().isEmpty(); + + LineEdit::mouseReleaseEvent(event); + + bool isSelectedText = !selectedText().isEmpty(); + + if (wasSelectedText && !isSelectedText) { + QMouseEvent ev(QEvent::MouseButtonPress, event->pos(), event->button(), + event->buttons(), event->modifiers()); + mousePressEvent(&ev); + } +} + void LocationBar::keyPressEvent(QKeyEvent* event) { switch (event->key()) { diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index 4324b5246..2ff3fca28 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -95,6 +95,7 @@ private: void focusOutEvent(QFocusEvent* event); void mouseDoubleClickEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* event); void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); void dropEvent(QDropEvent* event); diff --git a/src/lib/navigation/websearchbar.cpp b/src/lib/navigation/websearchbar.cpp index 54a97bf82..5ede196cc 100644 --- a/src/lib/navigation/websearchbar.cpp +++ b/src/lib/navigation/websearchbar.cpp @@ -387,3 +387,21 @@ void WebSearchBar::keyPressEvent(QKeyEvent* event) LineEdit::keyPressEvent(event); } + +void WebSearchBar::mouseReleaseEvent(QMouseEvent* event) +{ + // Workaround issue in QLineEdit::setDragEnabled + // It will incorrectly set cursor position at the end + // of selection when clicking into selected text + bool wasSelectedText = !selectedText().isEmpty(); + + LineEdit::mouseReleaseEvent(event); + + bool isSelectedText = !selectedText().isEmpty(); + + if (wasSelectedText && !isSelectedText) { + QMouseEvent ev(QEvent::MouseButtonPress, event->pos(), event->button(), + event->buttons(), event->modifiers()); + mousePressEvent(&ev); + } +} diff --git a/src/lib/navigation/websearchbar.h b/src/lib/navigation/websearchbar.h index c57e476f2..bfa96c8b4 100644 --- a/src/lib/navigation/websearchbar.h +++ b/src/lib/navigation/websearchbar.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -76,6 +76,7 @@ private: void focusOutEvent(QFocusEvent* e); void dropEvent(QDropEvent* event); void keyPressEvent(QKeyEvent* event); + void mouseReleaseEvent(QMouseEvent* event); void completeMenuWithAvailableEngines(QMenu* menu); void contextMenuEvent(QContextMenuEvent* event);