File indexing completed on 2024-05-12 16:44:02

0001 /*
0002     SPDX-FileCopyrightText: 2004-2011 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KMYMONEYCOMPLETION_H
0008 #define KMYMONEYCOMPLETION_H
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QWidget>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 class QTreeWidgetItem;
0022 class QTreeWidget;
0023 
0024 class KMyMoneySelector;
0025 
0026 /**
0027   * @author Thomas Baumgart
0028   */
0029 
0030 class KMyMoneyCompletionPrivate;
0031 class KMyMoneyCompletion : public QWidget
0032 {
0033     Q_OBJECT
0034     Q_DISABLE_COPY(KMyMoneyCompletion)
0035 
0036 public:
0037 
0038     explicit  KMyMoneyCompletion(QWidget* parent = nullptr);
0039     virtual ~KMyMoneyCompletion();
0040 
0041     /**
0042       * Re-implemented for internal reasons.  API is unaffected.
0043       */
0044     virtual void hide();
0045 
0046     /**
0047       * This method sets the current account with id @p id as
0048       * the current selection.
0049       *
0050       * @param id id of account to be selected
0051       */
0052     void setSelected(const QString& id);
0053 
0054     KMyMoneySelector* selector() const;
0055 
0056 public Q_SLOTS:
0057     void slotMakeCompletion(const QString& txt);
0058 
0059     void slotItemSelected(QTreeWidgetItem *item, int col);
0060 
0061 protected:
0062     /**
0063       * Reimplemented from KMyMoneyAccountSelector to get events from the viewport (to hide
0064       * this widget on mouse-click, Escape-presses, etc.
0065       */
0066     bool eventFilter(QObject *, QEvent *) override;
0067 
0068     /**
0069       * Re-implemented for internal reasons.  API is unaffected.
0070       */
0071     void showEvent(QShowEvent*) override;
0072 
0073     /**
0074       * This method resizes the widget to show a maximum of @p count
0075       * or @a MAX_ITEMS items.
0076       *
0077       * @param count maximum number to be shown if < MAX_ITEMS
0078       */
0079     void adjustSize(const int count);
0080 
0081     /**
0082       * This method counts the number of items currently visible and
0083       * calls adjustSize(count).
0084       */
0085     void adjustSize();
0086 
0087     void connectSignals(QWidget *widget, QTreeWidget* lv);
0088 
0089     void show(bool presetSelected);
0090 
0091 Q_SIGNALS:
0092     void itemSelected(const QString& id);
0093 
0094 protected:
0095     KMyMoneyCompletionPrivate * const d_ptr;
0096     KMyMoneyCompletion(KMyMoneyCompletionPrivate &dd, QWidget* parent = nullptr);
0097     Q_DECLARE_PRIVATE(KMyMoneyCompletion)
0098 };
0099 
0100 #endif