2013-02-10 12:28:53 +01:00
|
|
|
/* ============================================================
|
2017-01-22 16:12:26 +01:00
|
|
|
* QupZilla - Qt web browser
|
|
|
|
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
|
2013-02-10 12:28:53 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "lineedit.h"
|
2013-02-12 08:16:05 +01:00
|
|
|
#include "qzsettings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-16 13:06:38 +01:00
|
|
|
#include <QMenu>
|
2011-03-02 16:57:41 +01:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QPainter>
|
2014-03-16 13:06:38 +01:00
|
|
|
#include <QClipboard>
|
2011-03-02 16:57:41 +01:00
|
|
|
#include <QFocusEvent>
|
2014-03-16 13:06:38 +01:00
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QApplication>
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
SideWidget::SideWidget(QWidget* parent)
|
2011-03-02 16:57:41 +01:00
|
|
|
: QWidget(parent)
|
|
|
|
{
|
2014-03-16 09:38:28 +01:00
|
|
|
setCursor(Qt::ArrowCursor);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
bool SideWidget::event(QEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (event->type() == QEvent::LayoutRequest) {
|
2011-03-02 16:57:41 +01:00
|
|
|
emit sizeHintChanged();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2014-03-16 09:38:28 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
LineEdit::LineEdit(QWidget* parent)
|
2011-03-02 16:57:41 +01:00
|
|
|
: QLineEdit(parent)
|
|
|
|
, m_leftLayout(0)
|
|
|
|
, m_rightLayout(0)
|
2014-03-16 09:38:28 +01:00
|
|
|
, m_minHeight(0)
|
2013-02-12 08:16:05 +01:00
|
|
|
, m_leftMargin(-1)
|
2013-03-15 11:46:07 +01:00
|
|
|
, m_ignoreMousePress(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::setLeftMargin(int margin)
|
|
|
|
{
|
|
|
|
m_leftMargin = margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::init()
|
|
|
|
{
|
2012-08-11 13:13:37 +02:00
|
|
|
mainLayout = new QHBoxLayout(this);
|
|
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
mainLayout->setSpacing(0);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
m_leftWidget = new SideWidget(this);
|
|
|
|
m_leftWidget->resize(0, 0);
|
|
|
|
m_leftLayout = new QHBoxLayout(m_leftWidget);
|
2014-03-16 09:38:28 +01:00
|
|
|
m_leftLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
m_leftLayout->setDirection(isRightToLeft() ? QBoxLayout::RightToLeft : QBoxLayout::LeftToRight);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_rightWidget = new SideWidget(this);
|
|
|
|
m_rightWidget->resize(0, 0);
|
|
|
|
m_rightLayout = new QHBoxLayout(m_rightWidget);
|
2014-03-16 09:38:28 +01:00
|
|
|
m_rightLayout->setDirection(isRightToLeft() ? QBoxLayout::RightToLeft : QBoxLayout::LeftToRight);
|
2012-08-11 13:13:37 +02:00
|
|
|
m_rightLayout->setContentsMargins(0, 0, 2, 0);
|
|
|
|
|
2012-08-13 15:41:08 +02:00
|
|
|
mainLayout->addWidget(m_leftWidget, 0, Qt::AlignVCenter | Qt::AlignLeft);
|
2014-03-16 09:38:28 +01:00
|
|
|
mainLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
2012-08-13 15:41:08 +02:00
|
|
|
mainLayout->addWidget(m_rightWidget, 0, Qt::AlignVCenter | Qt::AlignRight);
|
2012-08-11 13:13:37 +02:00
|
|
|
mainLayout->setDirection(isRightToLeft() ? QBoxLayout::RightToLeft : QBoxLayout::LeftToRight);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
setWidgetSpacing(3);
|
2014-03-16 09:38:28 +01:00
|
|
|
|
|
|
|
connect(m_leftWidget, SIGNAL(sizeHintChanged()), this, SLOT(updateTextMargins()));
|
|
|
|
connect(m_rightWidget, SIGNAL(sizeHintChanged()), this, SLOT(updateTextMargins()));
|
2014-10-18 16:33:21 +02:00
|
|
|
|
|
|
|
QAction* undoAction = new QAction(QIcon::fromTheme(QSL("edit-undo")), tr("&Undo"), this);
|
|
|
|
undoAction->setShortcut(QKeySequence(QSL("Ctrl+Z")));
|
|
|
|
undoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(undoAction, SIGNAL(triggered()), SLOT(undo()));
|
|
|
|
|
|
|
|
QAction* redoAction = new QAction(QIcon::fromTheme(QSL("edit-redo")), tr("&Redo"), this);
|
|
|
|
redoAction->setShortcut(QKeySequence(QSL("Ctrl+Shift+Z")));
|
|
|
|
redoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(redoAction, SIGNAL(triggered()), SLOT(redo()));
|
|
|
|
|
|
|
|
QAction* cutAction = new QAction(QIcon::fromTheme(QSL("edit-cut")), tr("Cu&t"), this);
|
|
|
|
cutAction->setShortcut(QKeySequence(QSL("Ctrl+X")));
|
|
|
|
cutAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(cutAction, SIGNAL(triggered()), SLOT(cut()));
|
|
|
|
|
|
|
|
QAction* copyAction = new QAction(QIcon::fromTheme(QSL("edit-copy")), tr("&Copy"), this);
|
|
|
|
copyAction->setShortcut(QKeySequence(QSL("Ctrl+C")));
|
|
|
|
copyAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(copyAction, SIGNAL(triggered()), SLOT(copy()));
|
|
|
|
|
|
|
|
QAction* pasteAction = new QAction(QIcon::fromTheme(QSL("edit-paste")), tr("&Paste"), this);
|
|
|
|
pasteAction->setShortcut(QKeySequence(QSL("Ctrl+V")));
|
|
|
|
pasteAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(pasteAction, SIGNAL(triggered()), SLOT(paste()));
|
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
QAction* pasteAndGoAction = new QAction(this);
|
|
|
|
pasteAndGoAction->setShortcut(QKeySequence(QSL("Ctrl+Shift+V")));
|
|
|
|
pasteAndGoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
2014-10-18 16:33:21 +02:00
|
|
|
QAction* deleteAction = new QAction(QIcon::fromTheme(QSL("edit-delete")), tr("Delete"), this);
|
|
|
|
connect(deleteAction, SIGNAL(triggered()), SLOT(slotDelete()));
|
|
|
|
|
|
|
|
QAction* clearAllAction = new QAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear All"), this);
|
|
|
|
connect(clearAllAction, SIGNAL(triggered()), SLOT(clear()));
|
|
|
|
|
|
|
|
QAction* selectAllAction = new QAction(QIcon::fromTheme(QSL("edit-select-all")), tr("Select All"), this);
|
|
|
|
selectAllAction->setShortcut(QKeySequence(QSL("Ctrl+A")));
|
|
|
|
selectAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(selectAllAction, SIGNAL(triggered()), SLOT(selectAll()));
|
|
|
|
|
|
|
|
m_editActions[Undo] = undoAction;
|
|
|
|
m_editActions[Redo] = redoAction;
|
|
|
|
m_editActions[Cut] = cutAction;
|
|
|
|
m_editActions[Copy] = copyAction;
|
|
|
|
m_editActions[Paste] = pasteAction;
|
2014-10-18 16:33:37 +02:00
|
|
|
m_editActions[PasteAndGo] = pasteAndGoAction;
|
2014-10-18 16:33:21 +02:00
|
|
|
m_editActions[Delete] = deleteAction;
|
|
|
|
m_editActions[ClearAll] = clearAllAction;
|
|
|
|
m_editActions[SelectAll] = selectAllAction;
|
|
|
|
|
|
|
|
// Make action shortcuts available for webview
|
|
|
|
addAction(undoAction);
|
|
|
|
addAction(redoAction);
|
|
|
|
addAction(cutAction);
|
|
|
|
addAction(copyAction);
|
|
|
|
addAction(pasteAction);
|
2014-10-18 16:33:37 +02:00
|
|
|
addAction(pasteAndGoAction);
|
2014-10-18 16:33:21 +02:00
|
|
|
addAction(deleteAction);
|
|
|
|
addAction(clearAllAction);
|
|
|
|
addAction(selectAllAction);
|
2014-10-18 16:33:37 +02:00
|
|
|
|
|
|
|
// Connections to update edit actions
|
|
|
|
connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateActions()));
|
|
|
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(updateActions()));
|
2014-11-05 09:51:13 +01:00
|
|
|
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(updatePasteActions()));
|
2014-10-18 16:33:37 +02:00
|
|
|
|
|
|
|
updateActions();
|
2014-11-05 09:51:13 +01:00
|
|
|
updatePasteActions();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
bool LineEdit::event(QEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LayoutDirectionChange) {
|
2013-03-15 11:46:07 +01:00
|
|
|
// By this we undo reversing of layout when direction is RTL.
|
2011-03-02 16:57:41 +01:00
|
|
|
if (isRightToLeft()) {
|
2012-08-11 13:13:37 +02:00
|
|
|
mainLayout->setDirection(QBoxLayout::RightToLeft);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_leftLayout->setDirection(QBoxLayout::RightToLeft);
|
|
|
|
m_rightLayout->setDirection(QBoxLayout::RightToLeft);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-08-11 13:13:37 +02:00
|
|
|
mainLayout->setDirection(QBoxLayout::LeftToRight);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_leftLayout->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
m_rightLayout->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QLineEdit::event(event);
|
|
|
|
}
|
|
|
|
|
2014-03-16 13:55:37 +01:00
|
|
|
#define ACCEL_KEY(k) QLatin1Char('\t') + QKeySequence(k).toString()
|
2014-03-16 13:06:38 +01:00
|
|
|
|
|
|
|
// Modified QLineEdit::createStandardContextMenu to support icons and PasteAndGo action
|
2014-10-18 16:33:37 +02:00
|
|
|
QMenu* LineEdit::createContextMenu()
|
2014-03-16 13:06:38 +01:00
|
|
|
{
|
|
|
|
QMenu* popup = new QMenu(this);
|
|
|
|
popup->setObjectName(QSL("qt_edit_menu"));
|
|
|
|
|
|
|
|
if (!isReadOnly()) {
|
2014-10-18 16:33:37 +02:00
|
|
|
popup->addAction(m_editActions[Undo]);
|
|
|
|
popup->addAction(m_editActions[Redo]);
|
2014-03-16 13:06:38 +01:00
|
|
|
popup->addSeparator();
|
2014-10-18 16:33:37 +02:00
|
|
|
popup->addAction(m_editActions[Cut]);
|
2014-03-16 13:06:38 +01:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
popup->addAction(m_editActions[Copy]);
|
2014-03-16 13:06:38 +01:00
|
|
|
|
|
|
|
if (!isReadOnly()) {
|
2014-10-18 16:33:37 +02:00
|
|
|
popup->addAction(m_editActions[Paste]);
|
2014-03-16 13:06:38 +01:00
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
if (!m_editActions[PasteAndGo]->text().isEmpty())
|
|
|
|
popup->addAction(m_editActions[PasteAndGo]);
|
2014-03-16 13:06:38 +01:00
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
popup->addAction(m_editActions[Delete]);
|
|
|
|
popup->addAction(m_editActions[ClearAll]);
|
2014-03-16 13:06:38 +01:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
popup->addSeparator();
|
|
|
|
popup->addAction(m_editActions[SelectAll]);
|
2014-03-16 13:06:38 +01:00
|
|
|
|
|
|
|
// Hack to get QUnicodeControlCharacterMenu
|
|
|
|
QMenu* tmp = createStandardContextMenu();
|
2014-03-19 22:44:36 +01:00
|
|
|
tmp->setParent(popup);
|
|
|
|
tmp->hide();
|
2014-03-16 13:06:38 +01:00
|
|
|
QAction* lastAction = !tmp->actions().isEmpty() ? tmp->actions().last() : 0;
|
|
|
|
|
|
|
|
if (lastAction && lastAction->menu() && lastAction->menu()->inherits("QUnicodeControlCharacterMenu")) {
|
2014-03-19 22:44:36 +01:00
|
|
|
popup->addAction(lastAction);
|
2014-03-16 13:06:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
void LineEdit::updateActions()
|
|
|
|
{
|
|
|
|
m_editActions[Undo]->setEnabled(!isReadOnly() && isUndoAvailable());
|
|
|
|
m_editActions[Redo]->setEnabled(!isReadOnly() && isRedoAvailable());
|
|
|
|
m_editActions[Cut]->setEnabled(!isReadOnly() && hasSelectedText() && echoMode() == QLineEdit::Normal);
|
|
|
|
m_editActions[Copy]->setEnabled(hasSelectedText() && echoMode() == QLineEdit::Normal);
|
|
|
|
m_editActions[Delete]->setEnabled(!isReadOnly() && hasSelectedText());
|
|
|
|
m_editActions[SelectAll]->setEnabled(!text().isEmpty() && selectedText() != text());
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:51:13 +01:00
|
|
|
void LineEdit::updatePasteActions()
|
|
|
|
{
|
|
|
|
// Paste actions are updated in separate slot because accessing clipboard is expensive
|
|
|
|
bool pasteEnabled = !isReadOnly() && !QApplication::clipboard()->text().isEmpty();
|
|
|
|
|
|
|
|
m_editActions[Paste]->setEnabled(pasteEnabled);
|
|
|
|
m_editActions[PasteAndGo]->setEnabled(pasteEnabled);
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
void LineEdit::slotDelete()
|
|
|
|
{
|
|
|
|
if (hasSelectedText()) {
|
|
|
|
del();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void LineEdit::addWidget(QWidget* widget, WidgetPosition position)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!widget) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
if (position == LeftSide) {
|
|
|
|
m_leftLayout->addWidget(widget);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-08-11 13:13:37 +02:00
|
|
|
m_rightLayout->addWidget(widget);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void LineEdit::removeWidget(QWidget* widget)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!widget) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_leftLayout->removeWidget(widget);
|
|
|
|
m_rightLayout->removeWidget(widget);
|
|
|
|
widget->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::setWidgetSpacing(int spacing)
|
|
|
|
{
|
|
|
|
m_leftLayout->setSpacing(spacing);
|
|
|
|
m_rightLayout->setSpacing(spacing);
|
|
|
|
updateTextMargins();
|
|
|
|
}
|
|
|
|
|
|
|
|
int LineEdit::widgetSpacing() const
|
|
|
|
{
|
|
|
|
return m_leftLayout->spacing();
|
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
int LineEdit::leftMargin() const
|
|
|
|
{
|
|
|
|
return m_leftMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://stackoverflow.com/a/14424003
|
|
|
|
void LineEdit::setTextFormat(const LineEdit::TextFormat &format)
|
|
|
|
{
|
|
|
|
QList<QInputMethodEvent::Attribute> attributes;
|
|
|
|
|
|
|
|
foreach (const QTextLayout::FormatRange &fr, format) {
|
|
|
|
QInputMethodEvent::AttributeType type = QInputMethodEvent::TextFormat;
|
|
|
|
int start = fr.start - cursorPosition();
|
|
|
|
int length = fr.length;
|
|
|
|
QVariant value = fr.format;
|
|
|
|
attributes.append(QInputMethodEvent::Attribute(type, start, length, value));
|
|
|
|
}
|
|
|
|
|
2014-03-16 11:21:24 +01:00
|
|
|
QInputMethodEvent ev(QString(), attributes);
|
|
|
|
event(&ev);
|
2014-03-15 23:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::clearTextFormat()
|
|
|
|
{
|
|
|
|
setTextFormat(TextFormat());
|
|
|
|
}
|
|
|
|
|
2014-03-16 09:38:28 +01:00
|
|
|
int LineEdit::minHeight() const
|
|
|
|
{
|
|
|
|
return m_minHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::setMinHeight(int height)
|
|
|
|
{
|
|
|
|
m_minHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize LineEdit::sizeHint() const
|
|
|
|
{
|
|
|
|
QSize s = QLineEdit::sizeHint();
|
|
|
|
|
|
|
|
if (s.height() < m_minHeight) {
|
|
|
|
s.setHeight(m_minHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:33:21 +02:00
|
|
|
QAction* LineEdit::editAction(EditAction action) const
|
|
|
|
{
|
|
|
|
return m_editActions[action];
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void LineEdit::updateTextMargins()
|
|
|
|
{
|
2014-03-16 09:38:28 +01:00
|
|
|
int left = m_leftWidget->sizeHint().width();
|
2012-08-11 13:13:37 +02:00
|
|
|
int right = m_rightWidget->sizeHint().width();
|
2011-03-02 16:57:41 +01:00
|
|
|
int top = 0;
|
|
|
|
int bottom = 0;
|
2014-03-16 09:38:28 +01:00
|
|
|
|
|
|
|
if (m_leftMargin >= 0) {
|
|
|
|
left = m_leftMargin;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
setTextMargins(left, top, right, bottom);
|
2013-02-10 12:28:53 +01:00
|
|
|
}
|
|
|
|
|
2013-03-15 11:46:07 +01:00
|
|
|
void LineEdit::focusInEvent(QFocusEvent* event)
|
2013-02-12 08:16:05 +01:00
|
|
|
{
|
2013-03-15 11:46:07 +01:00
|
|
|
if (event->reason() == Qt::MouseFocusReason && qzSettings->selectAllOnClick) {
|
|
|
|
m_ignoreMousePress = true;
|
2013-02-12 08:16:05 +01:00
|
|
|
selectAll();
|
2013-03-15 11:46:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QLineEdit::focusInEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (m_ignoreMousePress) {
|
|
|
|
m_ignoreMousePress = false;
|
2013-02-12 08:16:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLineEdit::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-02-10 12:28:53 +01:00
|
|
|
void LineEdit::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
// Workaround issue in QLineEdit::setDragEnabled(true)
|
|
|
|
// It will incorrectly set cursor position at the end
|
|
|
|
// of selection when clicking (and not dragging) into selected text
|
|
|
|
|
|
|
|
if (!dragEnabled()) {
|
|
|
|
QLineEdit::mouseReleaseEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasSelectedText = !selectedText().isEmpty();
|
|
|
|
|
|
|
|
QLineEdit::mouseReleaseEvent(event);
|
|
|
|
|
|
|
|
bool isSelectedText = !selectedText().isEmpty();
|
|
|
|
|
|
|
|
if (wasSelectedText && !isSelectedText) {
|
|
|
|
QMouseEvent ev(QEvent::MouseButtonPress, event->pos(), event->button(),
|
|
|
|
event->buttons(), event->modifiers());
|
|
|
|
mousePressEvent(&ev);
|
|
|
|
}
|
2012-08-11 13:13:37 +02:00
|
|
|
}
|
|
|
|
|
2013-02-12 08:16:05 +01:00
|
|
|
void LineEdit::mouseDoubleClickEvent(QMouseEvent* event)
|
|
|
|
{
|
2014-03-01 14:12:50 +01:00
|
|
|
if (event->buttons() == Qt::LeftButton && qzSettings->selectAllOnDoubleClick) {
|
2013-02-12 08:16:05 +01:00
|
|
|
selectAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLineEdit::mouseDoubleClickEvent(event);
|
|
|
|
}
|
2017-01-22 16:12:26 +01:00
|
|
|
|
|
|
|
void LineEdit::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
QLineEdit::resizeEvent(event);
|
|
|
|
|
|
|
|
m_leftWidget->setFixedHeight(height());
|
|
|
|
m_rightWidget->setFixedHeight(height());
|
|
|
|
}
|