LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
clearlineeditaddon.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
clearlineeditaddon.h
"
10
#include <QLineEdit>
11
#include <QToolButton>
12
#include <QApplication>
13
#include <QStyle>
14
#include <QShortcut>
15
#include "
lineeditbuttonmanager.h
"
16
#include "
interfaces/core/iiconthememanager.h
"
17
18
namespace
LC::Util
19
{
20
ClearLineEditAddon::ClearLineEditAddon
(
const
ICoreProxy_ptr
& proxy, QLineEdit *edit)
21
:
ClearLineEditAddon
{ proxy, edit, new
LineEditButtonManager
{ edit } }
22
{
23
}
24
25
ClearLineEditAddon::ClearLineEditAddon
(
const
ICoreProxy_ptr
& proxy,
26
QLineEdit *edit,
LineEditButtonManager
*mgr)
27
: QObject { edit }
28
, Button_ { new QToolButton { edit } }
29
, EscShortcut_ { new QShortcut { Qt::Key_Escape, edit, SLOT (clear ()), nullptr, Qt::WidgetShortcut } }
30
{
31
const
bool
isRtl = QApplication::layoutDirection () == Qt::RightToLeft;
32
const
auto
& icon = proxy->
GetIconThemeManager
()->
GetIcon
(isRtl ?
33
QStringLiteral (
"edit-clear-locationbar-ltr"
) :
34
QStringLiteral (
"edit-clear-locationbar-rtl"
));
35
36
Button_->setIconSize (QSize (16, 16));
37
Button_->setIcon (icon);
38
Button_->setCursor (Qt::ArrowCursor);
39
Button_->setStyleSheet (QStringLiteral (
"QToolButton { border: none; padding: 0px; }"
));
40
Button_->hide ();
41
42
connect (Button_,
43
&QToolButton::clicked,
44
edit,
45
&QLineEdit::clear);
46
47
connect (edit,
48
&QLineEdit::textChanged,
49
this
,
50
[
this
] (
const
QString& str) { Button_->setVisible (!str.isEmpty ()); });
51
Button_->setVisible (!edit->text ().isEmpty ());
52
53
mgr->
Add
(Button_);
54
}
55
56
void
ClearLineEditAddon::SetEscClearsEdit
(
bool
clears)
57
{
58
EscShortcut_->setEnabled (clears);
59
}
60
}
ICoreProxy::GetIconThemeManager
virtual IIconThemeManager * GetIconThemeManager() const =0
Returns the icon theme manager.
IIconThemeManager::GetIcon
virtual QIcon GetIcon(const QString &on, const QString &off=QString())=0
Returns the current theme's icon for the given on and off states.
LC::Util::ClearLineEditAddon::SetEscClearsEdit
void SetEscClearsEdit(bool clears)
Toggles whether Esc button clears the line edit.
Definition
clearlineeditaddon.cpp:56
LC::Util::ClearLineEditAddon::ClearLineEditAddon
ClearLineEditAddon(const ICoreProxy_ptr &proxy, QLineEdit *edit)
Creates the addon and installs it on the given edit.
Definition
clearlineeditaddon.cpp:20
LC::Util::LineEditButtonManager
Manages additional overlay buttons in a QLineEdit.
Definition
lineeditbuttonmanager.h:37
LC::Util::LineEditButtonManager::Add
void Add(QToolButton *button)
Adds a button to the line edit.
Definition
lineeditbuttonmanager.cpp:42
clearlineeditaddon.h
ICoreProxy_ptr
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition
icoreproxy.h:177
iiconthememanager.h
lineeditbuttonmanager.h
LC::Util
Definition
icoreproxy.h:34
src
util
gui
clearlineeditaddon.cpp
Generated by
1.17.0