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

Auto selection on focus in search toolbar's line edit.

closes #381
This commit is contained in:
nowrep 2012-04-19 15:58:23 +02:00
parent 018a4d5d7b
commit cdf73b01b5
9 changed files with 119 additions and 12 deletions

View File

@ -206,7 +206,6 @@ void AdBlockDialog::itemChanged(QTreeWidgetItem* item)
m_itemChangingBlock = false;
}
void AdBlockDialog::addCustomRule()
{
QString newRule = QInputDialog::getText(this, tr("Add Custom Rule"), tr("Please write your rule here:"));

View File

@ -1376,13 +1376,13 @@ void QupZilla::searchOnPage()
return;
}
search->searchLine()->setFocus();
search->focusSearchLine();
return;
}
SearchToolBar* search = new SearchToolBar(this);
m_mainLayout->insertWidget(3, search);
search->searchLine()->setFocus();
search->focusSearchLine();
}
void QupZilla::openFile()

View File

@ -169,7 +169,8 @@ SOURCES += \
other/checkboxdialog.cpp \
network/schemehandler.cpp \
tools/plaineditwithlines.cpp \
webview/websettings.cpp
webview/websettings.cpp \
tools/focusselectlineedit.cpp
HEADERS += \
webview/tabpreview.h \
@ -311,7 +312,8 @@ HEADERS += \
network/schemehandler.h \
tools/plaineditwithlines.h \
sidebar/sidebarinterface.h \
webview/websettings.h
webview/websettings.h \
tools/focusselectlineedit.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -44,7 +44,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<widget class="FocusSelectLineEdit" name="lineEdit">
<property name="placeholderText">
<string>Search...</string>
</property>
@ -97,6 +97,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FocusSelectLineEdit</class>
<extends>QLineEdit</extends>
<header>focusselectlineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,51 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "focusselectlineedit.h"
#include <QFocusEvent>
FocusSelectLineEdit::FocusSelectLineEdit(QWidget *parent)
: QLineEdit(parent)
, m_mouseFocusReason(false)
{
}
void FocusSelectLineEdit::setFocus()
{
selectAll();
QLineEdit::setFocus();
}
void FocusSelectLineEdit::focusInEvent(QFocusEvent *event)
{
m_mouseFocusReason = event->reason() == Qt::MouseFocusReason;
selectAll();
QLineEdit::focusInEvent(event);
}
void FocusSelectLineEdit::mousePressEvent(QMouseEvent *event)
{
if (m_mouseFocusReason) {
m_mouseFocusReason = false;
return;
}
QLineEdit::mousePressEvent(event);
}

View File

@ -0,0 +1,40 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef FOCUSSELECTLINEEDIT_H
#define FOCUSSELECTLINEEDIT_H
#include <QLineEdit>
class FocusSelectLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit FocusSelectLineEdit(QWidget *parent = 0);
public slots:
void setFocus();
protected:
void focusInEvent(QFocusEvent *event);
void mousePressEvent(QMouseEvent *event);
bool m_mouseFocusReason;
};
#endif // FOCUSSELECTLINEEDIT_H

View File

@ -55,9 +55,9 @@ SearchToolBar::SearchToolBar(QupZilla* mainClass, QWidget* parent)
mainClass->installEventFilter(this);
}
QLineEdit* SearchToolBar::searchLine()
void SearchToolBar::focusSearchLine()
{
return ui->lineEdit;
ui->lineEdit->setFocus();
}
void SearchToolBar::hide()
@ -146,12 +146,13 @@ void SearchToolBar::searchText(const QString &text)
bool SearchToolBar::eventFilter(QObject* obj, QEvent* event)
{
Q_UNUSED(obj);
if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) {
hide();
return false;
}
return AnimatedWidget::eventFilter(obj, event);
return false;
}
SearchToolBar::~SearchToolBar()

View File

@ -40,7 +40,7 @@ public:
explicit SearchToolBar(QupZilla* mainClass, QWidget* parent = 0);
~SearchToolBar();
QLineEdit* searchLine();
void focusSearchLine();
bool eventFilter(QObject* obj, QEvent* event);
signals:

View File

@ -38,7 +38,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<widget class="FocusSelectLineEdit" name="lineEdit">
<property name="minimumSize">
<size>
<width>100</width>
@ -127,6 +127,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FocusSelectLineEdit</class>
<extends>QLineEdit</extends>
<header>focusselectlineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>