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 #include "expandablelineedit.h" 0008 0009 KExpandableLineEdit::KExpandableLineEdit(QWidget* parent) 0010 : QLineEdit(parent) 0011 { 0012 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 0013 0014 connect(this, &KExpandableLineEdit::textChanged, this, &KExpandableLineEdit::updateGeometry); 0015 } 0016 0017 KExpandableLineEdit::~KExpandableLineEdit() 0018 { 0019 } 0020 0021 int KExpandableLineEdit::preferredWidth() const 0022 { 0023 return m_preferredWidth; 0024 } 0025 0026 void KExpandableLineEdit::setPreferredWidth(int width) 0027 { 0028 if (m_preferredWidth != width) { 0029 m_preferredWidth = width; 0030 updateGeometry(); 0031 } 0032 } 0033 0034 QSize KExpandableLineEdit::sizeHint() const 0035 { 0036 auto idealSize = QLineEdit::sizeHint(); 0037 0038 int idealWidth = fontMetrics().horizontalAdvance(text()); 0039 if (isClearButtonEnabled()) { 0040 idealWidth += 2 * idealSize.height(); 0041 } 0042 idealSize.setWidth(qMax(idealWidth, m_preferredWidth)); 0043 0044 return idealSize; 0045 } 0046 0047 #include "moc_expandablelineedit.cpp"