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

0001 /*
0002     SPDX-FileCopyrightText: 2001 Felix Rodriguez <frodriguez@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002-2011 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMYMONEYCOMBO_H
0009 #define KMYMONEYCOMBO_H
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 // ----------------------------------------------------------------------------
0015 // KDE Includes
0016 
0017 #include <KComboBox>
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 class KMyMoneyCompletion;
0023 class KMyMoneySelector;
0024 
0025 /**
0026   * @author Thomas Baumgart
0027   */
0028 class KMyMoneyComboPrivate;
0029 class KMyMoneyCombo : public KComboBox
0030 {
0031     Q_OBJECT
0032     Q_DISABLE_COPY(KMyMoneyCombo)
0033     Q_PROPERTY(QString selectedItem READ selectedItem WRITE setSelectedItem STORED false)
0034 
0035 public:
0036     explicit KMyMoneyCombo(QWidget *parent = nullptr);
0037     explicit KMyMoneyCombo(bool rw = false, QWidget *parent = nullptr);
0038     virtual ~KMyMoneyCombo();
0039 
0040     /**
0041       * This method is used to turn on/off the hint display and to setup the appropriate text.
0042       * The hint text is shown in a lighter color if the field is otherwise empty and does
0043       * not have the keyboard focus.
0044       *
0045       * @param hint reference to text. If @a hint is empty, no hint will be shown.
0046       */
0047     void setPlaceholderText(const QString& hint) const;
0048 
0049     /**
0050       * overridden for internal reasons.
0051       *
0052       * @param editable make combo box editable (@a true) or selectable only (@a false).
0053       */
0054     void setEditable(bool editable);
0055 
0056     /**
0057       * This method returns a pointer to the completion object of the combo box.
0058       *
0059       * @return pointer to KMyMoneyCompletion or derivative.
0060       */
0061     KMyMoneyCompletion* completion() const;
0062 
0063     /**
0064       * This method returns a pointer to the completion object's selector.
0065       *
0066       * @return pointer to KMyMoneySelector or derivative.
0067       */
0068     KMyMoneySelector* selector() const;
0069 
0070     /**
0071       * This method returns the ids of the currently selected items
0072       */
0073     void selectedItems(QStringList& list) const;
0074 
0075     /**
0076       * This method returns the id of the first selected item.
0077       * Usage makes usually only sense when the selection mode
0078       * of the associated KMyMoneySelector is QListView::Single.
0079       *
0080       * @sa KMyMoneySelector::setSelectionMode()
0081       *
0082       * @return reference to QString containing the id. If no item
0083       *         is selected the QString will be empty.
0084       */
0085     QString selectedItem() const;
0086 
0087     /**
0088       * This method selects the item with the respective @a id.
0089       *
0090       * @param id reference to QString containing the id
0091       */
0092     void setSelectedItem(const QString& id);
0093 
0094     /**
0095       * This method checks if the position @a pos is part of the
0096       * area of the drop down arrow.
0097       */
0098     bool isInArrowArea(const QPoint& pos) const;
0099 
0100     void setSuppressObjectCreation(bool suppress);
0101 
0102     /**
0103       * overridden for internal reasons, no API change
0104       */
0105     void setCurrentText(const QString& txt);
0106     void setCurrentText();
0107 
0108     /**
0109      * Overridden to support our own completion box
0110      */
0111     QSize sizeHint() const override;
0112 
0113 protected Q_SLOTS:
0114     virtual void slotItemSelected(const QString& id);
0115 
0116 protected:
0117     /**
0118       * reimplemented to support our own popup widget
0119       */
0120     void mousePressEvent(QMouseEvent *e) override;
0121 
0122     /**
0123       * reimplemented to support our own popup widget
0124       */
0125     void keyPressEvent(QKeyEvent *e) override;
0126 
0127     /**
0128       * reimplemented to support our own popup widget
0129       */
0130     void paintEvent(QPaintEvent *) override;
0131 
0132     /**
0133       * reimplemented to support detection of new items
0134       */
0135     void focusOutEvent(QFocusEvent*) override;
0136 
0137     /**
0138       * set the widgets text area based on the item with the given @a id.
0139       */
0140     virtual void setCurrentTextById(const QString& id);
0141 
0142     /**
0143       * Overridden for internal reasons, no API change
0144       */
0145     void connectNotify(const QMetaMethod & signal) override;
0146 
0147     /**
0148       * Overridden for internal reasons, no API change
0149       */
0150     void disconnectNotify(const QMetaMethod & signal) override;
0151 
0152 protected:
0153     KMyMoneyComboPrivate * const d_ptr;
0154     KMyMoneyCombo(KMyMoneyComboPrivate &dd, bool rw = false, QWidget *parent = 0);
0155 
0156 Q_SIGNALS:
0157     void itemSelected(const QString& id);
0158     void objectCreation(bool);
0159     void createItem(const QString&, QString&);
0160 
0161 private:
0162     Q_DECLARE_PRIVATE(KMyMoneyCombo)
0163 };
0164 
0165 #endif