File indexing completed on 2024-05-05 04:38:44

0001 /*
0002     SPDX-FileCopyrightText: 2018 Anton Anikin <anton@anikin.xyz>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef EXPANDABLE_LINE_EDIT_H
0008 #define EXPANDABLE_LINE_EDIT_H
0009 
0010 #include "utilexport.h"
0011 #include <QLineEdit>
0012 
0013 /** This class implements a line edit widget which tries to expand its
0014  * width to fit typed text. When no text typed or text is too short
0015  * the widget's width is defined by the preferredWidth() value
0016  * (default is 200 px).
0017  */
0018 
0019 class KDEVPLATFORMUTIL_EXPORT KExpandableLineEdit : public QLineEdit
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     explicit KExpandableLineEdit(QWidget* parent = nullptr);
0025 
0026     ~KExpandableLineEdit() override;
0027 
0028     int preferredWidth() const;
0029     void setPreferredWidth(int width);
0030 
0031     QSize sizeHint() const override;
0032 
0033 protected:
0034     int m_preferredWidth = 200;
0035 };
0036 
0037 #endif