File indexing completed on 2024-05-19 05:08:33

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