LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
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
10#include <QLineEdit>
11#include <QToolButton>
12#include <QApplication>
13#include <QStyle>
14#include <QShortcut>
17
18namespace LC::Util
19{
21 : ClearLineEditAddon { proxy, edit, new LineEditButtonManager { edit } }
22 {
23 }
24
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
57 {
58 EscShortcut_->setEnabled (clears);
59 }
60}
virtual IIconThemeManager * GetIconThemeManager() const =0
Returns the icon theme manager.
virtual QIcon GetIcon(const QString &on, const QString &off=QString())=0
Returns the current theme's icon for the given on and off states.
Provides a "clear text" action for line edits.
void SetEscClearsEdit(bool clears)
Toggles whether Esc button clears the line edit.
ClearLineEditAddon(const ICoreProxy_ptr &proxy, QLineEdit *edit)
Creates the addon and installs it on the given edit.
Manages additional overlay buttons in a QLineEdit.
void Add(QToolButton *button)
Adds a button to the line edit.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition icoreproxy.h:181