File indexing completed on 2024-05-05 05:13:11

0001 /*
0002     This file is part of Akregator.
0003 
0004     SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #pragma once
0010 
0011 #include "articlematcher.h"
0012 #include "widgets/statussearchline.h"
0013 #include <QSharedPointer>
0014 #include <QTimer>
0015 #include <QWidget>
0016 #include <vector>
0017 
0018 namespace Akregator
0019 {
0020 namespace Filters
0021 {
0022 class AbstractMatcher;
0023 }
0024 
0025 class SearchBar : public QWidget
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit SearchBar(QWidget *parent = nullptr);
0031     ~SearchBar() override;
0032 
0033     [[nodiscard]] QString text() const;
0034     [[nodiscard]] StatusSearchLine::Status status() const;
0035 
0036     void setDelay(int ms);
0037     [[nodiscard]] int delay() const;
0038 
0039     void setFocusSearchLine();
0040     [[nodiscard]] std::vector<QSharedPointer<const Filters::AbstractMatcher>> matchers() const;
0041     void updateQuickSearchLineText(const QString &searchLine);
0042 
0043 Q_SIGNALS:
0044     /** emitted when the text and status filters were updated. Params are textfilter, statusfilter */
0045     void signalSearch(const std::vector<QSharedPointer<const Akregator::Filters::AbstractMatcher>> &);
0046     void forceLostFocus();
0047 
0048 public Q_SLOTS:
0049     void slotClearSearch();
0050     void slotSetStatus(int status);
0051     void slotSetText(const QString &text);
0052 
0053 private Q_SLOTS:
0054     void slotSearchStringChanged(const QString &search);
0055     void slotStopActiveSearch();
0056     void slotActivateSearch();
0057     void slotStatusChanged(Akregator::StatusSearchLine::Status);
0058 
0059 private:
0060     void triggerTimer();
0061 
0062     QString m_searchText;
0063     QTimer m_timer;
0064     StatusSearchLine *const m_searchLine;
0065     int m_delay;
0066     std::vector<QSharedPointer<const Filters::AbstractMatcher>> m_matchers;
0067 };
0068 } // namespace Akregator