1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Select all on (double) click also available for websearchbar.

Closes #752
This commit is contained in:
nowrep 2013-02-12 08:16:05 +01:00
parent e069da55e3
commit 789b4c8600
4 changed files with 23 additions and 61 deletions

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "lineedit.h"
#include "qzsettings.h"
#include <QEvent>
#include <QLayout>
@ -23,7 +24,6 @@
#include <QPainter>
#include <QFocusEvent>
#include <qdebug.h>
SideWidget::SideWidget(QWidget* parent)
: QWidget(parent)
{
@ -41,7 +41,7 @@ LineEdit::LineEdit(QWidget* parent)
: QLineEdit(parent)
, m_leftLayout(0)
, m_rightLayout(0)
, m_leftMargin(0)
, m_leftMargin(-1)
{
init();
}
@ -186,13 +186,7 @@ int LineEdit::textMargin(WidgetPosition position) const
void LineEdit::updateTextMargins()
{
int left;
if (m_leftMargin == 0) {
left = m_leftWidget->sizeHint().width();
}
else {
left = m_leftMargin;
}
int left = m_leftMargin < 0 ? m_leftWidget->sizeHint().width() : m_leftMargin;
int right = m_rightWidget->sizeHint().width();
int top = 0;
int bottom = 0;
@ -200,6 +194,16 @@ void LineEdit::updateTextMargins()
// updateSideWidgetLocations();
}
void LineEdit::mousePressEvent(QMouseEvent* event)
{
if (cursorPosition() == 0 && qzSettings->selectAllOnClick) {
selectAll();
return;
}
QLineEdit::mousePressEvent(event);
}
void LineEdit::mouseReleaseEvent(QMouseEvent* event)
{
// Workaround issue in QLineEdit::setDragEnabled(true)
@ -224,34 +228,12 @@ void LineEdit::mouseReleaseEvent(QMouseEvent* event)
}
}
//void LineEdit::updateSideWidgetLocations()
//{
// QStyleOptionFrameV2 opt;
// initStyleOption(&opt);
// QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
// int spacing = m_rightLayout->spacing();
// textRect.adjust(spacing, 0, -spacing, 0);
void LineEdit::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && qzSettings->selectAllOnDoubleClick) {
selectAll();
return;
}
// int left = textMargin(LineEdit::LeftSide);
// int midHeight = textRect.center().y() + 1;
// if (m_leftLayout->count() > 0) {
// int leftHeight = midHeight - m_leftWidget->height() / 2;
// int leftWidth = m_leftWidget->width();
// if (leftWidth == 0) {
// leftHeight = midHeight - m_leftWidget->sizeHint().height() / 2;
// }
// m_leftWidget->move(textRect.x(), leftHeight);
// }
// textRect.setX(left);
// textRect.setY(midHeight - m_rightWidget->sizeHint().height() / 2);
// textRect.setHeight(m_rightWidget->sizeHint().height());
// m_rightWidget->setGeometry(textRect);
//}
//void LineEdit::resizeEvent(QResizeEvent* event)
//{
// updateSideWidgetLocations();
// QLineEdit::resizeEvent(event);
//}
QLineEdit::mouseDoubleClickEvent(event);
}

View File

@ -89,7 +89,9 @@ public slots:
void updateTextMargins();
protected:
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
// void resizeEvent(QResizeEvent* event);
bool event(QEvent* event);

View File

@ -410,26 +410,6 @@ void LocationBar::focusOutEvent(QFocusEvent* event)
}
}
void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && qzSettings->selectAllOnDoubleClick) {
selectAll();
return;
}
QLineEdit::mouseDoubleClickEvent(event);
}
void LocationBar::mousePressEvent(QMouseEvent* event)
{
if (cursorPosition() == 0 && qzSettings->selectAllOnClick) {
selectAll();
return;
}
LineEdit::mousePressEvent(event);
}
void LocationBar::keyPressEvent(QKeyEvent* event)
{
switch (event->key()) {

View File

@ -89,8 +89,6 @@ private:
void contextMenuEvent(QContextMenuEvent* event);
void focusInEvent(QFocusEvent* event);
void focusOutEvent(QFocusEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
void dropEvent(QDropEvent* event);