File indexing completed on 2024-07-14 03:54:54

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2003 Scott Wheeler <wheeler@kde.org>
0004     SPDX-FileCopyrightText: 2005 Rafal Rzepecki <divide@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-only
0008 */
0009 
0010 #include "ktreewidgetsearchlinewidget.h"
0011 #include "ktreewidgetsearchline.h"
0012 
0013 #include <QHBoxLayout>
0014 #include <QTreeWidget>
0015 
0016 class KTreeWidgetSearchLineWidgetPrivate
0017 {
0018 public:
0019     QTreeWidget *treeWidget = nullptr;
0020     KTreeWidgetSearchLine *searchLine = nullptr;
0021 };
0022 
0023 KTreeWidgetSearchLineWidget::KTreeWidgetSearchLineWidget(QWidget *parent, QTreeWidget *treeWidget)
0024     : QWidget(parent)
0025     , d(new KTreeWidgetSearchLineWidgetPrivate)
0026 {
0027     d->treeWidget = treeWidget;
0028 
0029     // can't call createWidgets directly because it calls virtual functions
0030     // that might not work if called directly from here due to how inheritance works
0031     QMetaObject::invokeMethod(this, "createWidgets", Qt::QueuedConnection);
0032 }
0033 
0034 KTreeWidgetSearchLineWidget::~KTreeWidgetSearchLineWidget() = default;
0035 
0036 KTreeWidgetSearchLine *KTreeWidgetSearchLineWidget::createSearchLine(QTreeWidget *treeWidget) const
0037 {
0038     return new KTreeWidgetSearchLine(const_cast<KTreeWidgetSearchLineWidget *>(this), treeWidget);
0039 }
0040 
0041 void KTreeWidgetSearchLineWidget::createWidgets()
0042 {
0043     searchLine()->show();
0044 
0045     QHBoxLayout *layout = new QHBoxLayout(this);
0046     layout->setContentsMargins(0, 0, 0, 0);
0047     layout->addWidget(d->searchLine);
0048     setFocusProxy(searchLine());
0049 }
0050 
0051 KTreeWidgetSearchLine *KTreeWidgetSearchLineWidget::searchLine() const
0052 {
0053     if (!d->searchLine) {
0054         d->searchLine = createSearchLine(d->treeWidget);
0055     }
0056 
0057     return d->searchLine;
0058 }
0059 
0060 #include "moc_ktreewidgetsearchlinewidget.cpp"