1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2003 Scott Wheeler <wheeler@kde.org>
4 SPDX-FileCopyrightText: 2005 Rafal Rzepecki <divide@users.sourceforge.net>
5 SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-only
8*/
9
10#include "ktreewidgetsearchlinewidget.h"
11#include "ktreewidgetsearchline.h"
12
13#include <QHBoxLayout>
14#include <QTreeWidget>
15
16class KTreeWidgetSearchLineWidgetPrivate
17{
18public:
19 QTreeWidget *treeWidget = nullptr;
20 KTreeWidgetSearchLine *searchLine = nullptr;
21};
22
23KTreeWidgetSearchLineWidget::KTreeWidgetSearchLineWidget(QWidget *parent, QTreeWidget *treeWidget)
24 : QWidget(parent)
25 , d(new KTreeWidgetSearchLineWidgetPrivate)
26{
27 d->treeWidget = treeWidget;
28
29 // can't call createWidgets directly because it calls virtual functions
30 // that might not work if called directly from here due to how inheritance works
31 QMetaObject::invokeMethod(obj: this, member: "createWidgets", c: Qt::QueuedConnection);
32}
33
34KTreeWidgetSearchLineWidget::~KTreeWidgetSearchLineWidget() = default;
35
36KTreeWidgetSearchLine *KTreeWidgetSearchLineWidget::createSearchLine(QTreeWidget *treeWidget) const
37{
38 return new KTreeWidgetSearchLine(const_cast<KTreeWidgetSearchLineWidget *>(this), treeWidget);
39}
40
41void KTreeWidgetSearchLineWidget::createWidgets()
42{
43 searchLine()->show();
44
45 QHBoxLayout *layout = new QHBoxLayout(this);
46 layout->setContentsMargins(left: 0, top: 0, right: 0, bottom: 0);
47 layout->addWidget(d->searchLine);
48 setFocusProxy(searchLine());
49}
50
51KTreeWidgetSearchLine *KTreeWidgetSearchLineWidget::searchLine() const
52{
53 if (!d->searchLine) {
54 d->searchLine = createSearchLine(treeWidget: d->treeWidget);
55 }
56
57 return d->searchLine;
58}
59
60#include "moc_ktreewidgetsearchlinewidget.cpp"
61

source code of kitemviews/src/ktreewidgetsearchlinewidget.cpp