File indexing completed on 2024-05-19 05:08:33
0001 /* 0002 SPDX-FileCopyrightText: 2006-2010 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 KMYMONEYCATEGORY_H 0008 #define KMYMONEYCATEGORY_H 0009 0010 #include "kmm_base_widgets_export.h" 0011 0012 // ---------------------------------------------------------------------------- 0013 // QT Includes 0014 0015 // ---------------------------------------------------------------------------- 0016 // KDE Includes 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 #include "kmymoneycombo.h" 0022 0023 class QPushButton; 0024 class KMyMoneyAccountSelector; 0025 0026 /** 0027 * This class implements a text based account/category selector. 0028 * When initially used, the widget has the functionality of a KComboBox object. 0029 * Whenever a key is pressed, the set of loaded accounts is searched for 0030 * accounts which match the currently entered text. 0031 * 0032 * If any match is found a list selection box is opened and the user can use 0033 * the up/down, page-up/page-down keys or the mouse to navigate in the list. If 0034 * an account is selected, the selection box is closed. Other key-strokes are 0035 * directed to the parent object to manipulate the text. The visible contents of 0036 * the selection box is updated with every key-stroke. 0037 * 0038 * This object is a replacement of the KMyMoneyCategory object and should be used 0039 * for new code. 0040 * 0041 * @author Thomas Baumgart 0042 */ 0043 class KMyMoneyCategoryPrivate; 0044 class KMM_BASE_WIDGETS_EXPORT KMyMoneyCategory : public KMyMoneyCombo 0045 { 0046 Q_OBJECT 0047 Q_DISABLE_COPY(KMyMoneyCategory) 0048 0049 public: 0050 /** 0051 * Standard constructor for the account selection object. 0052 * 0053 * If parameter @a splitButton is @a true, the widget 0054 * will construct a surrounding QFrame and reparent itself to be a child of this 0055 * QFrame. It also adds a QPushButton with the "Split" icon to the right of the 0056 * input field. In this case it is important not to use the pointer to this widget 0057 * but it's parent when placing the object in a QLayout, QTable or some such. The 0058 * parent widget (the QFrame in this case) can be extracted with the parentWidget() 0059 * method. 0060 * 0061 * Reparenting is handled by the object transparently for both cases. 0062 * 0063 * Standard usage example (no split button): 0064 * 0065 * @code 0066 * KMyMoneyCategory* category = new KMyMoneyCategory; 0067 * category->reparent(newParent); 0068 * layout->addWidget(category); 0069 * table->setCellWidget(category); 0070 * @endcode 0071 * 0072 * Enhanced usage example (with split button): 0073 * 0074 * @code 0075 * KMyMoneyCategory* category = new KMyMoneyCategory(0, true); 0076 * category->reparent(newParent); 0077 * layout->addWidget(category->parentWidget()); 0078 * table->setCellWidget(category->parentWidget()); 0079 * @endcode 0080 */ 0081 explicit KMyMoneyCategory(bool splitButton = false, QWidget* parent = nullptr); 0082 ~KMyMoneyCategory() override; 0083 0084 /** 0085 * This member returns a pointer to the completion object. 0086 * 0087 * @return pointer to completion's selector object 0088 */ 0089 KMyMoneyAccountSelector* selector() const; 0090 0091 /** 0092 * This member returns a pointer to the split button. In case the @a splitButton parameter 0093 * of the constructor was @a false, this method prints a warning to stderr and returns 0. 0094 */ 0095 QPushButton* splitButton() const; 0096 0097 /** 0098 * Reimplemented for internal reasons. No API change 0099 */ 0100 virtual void reparent(QWidget *parent, Qt::WindowFlags, const QPoint &, bool showIt = false); 0101 0102 /** 0103 * Reimplemented for internal reasons. No API change. 0104 */ 0105 virtual void setPalette(const QPalette& palette); 0106 0107 /** 0108 * Force the text field to show the text for split transaction. 0109 */ 0110 void setSplitTransaction(); 0111 0112 /** 0113 * Check if the text field contains the text for a split transaction 0114 */ 0115 bool isSplitTransaction() const; 0116 0117 /** 0118 * overridden for internal reasons, no API change 0119 */ 0120 void setCurrentText(const QString& txt); 0121 void setCurrentText(); 0122 0123 bool eventFilter(QObject *o, QEvent *ev) override; 0124 0125 protected: 0126 /** 0127 * Reimplemented to support protected category text ("split transactions") 0128 * 0129 * @sa focusIn() 0130 */ 0131 void focusInEvent(QFocusEvent* ev) override; 0132 0133 /** 0134 * Reimplemented to support protected category text ("split transactions") 0135 */ 0136 void focusOutEvent(QFocusEvent* ev) override; 0137 0138 /** 0139 * set the widgets text area based on the item with the given @a id. 0140 */ 0141 void setCurrentTextById(const QString& id) override; 0142 0143 public Q_SLOTS: 0144 void slotItemSelected(const QString& id) override; 0145 0146 Q_SIGNALS: 0147 /** 0148 * Signal to inform other objects that this object has reached focus. 0149 * Used for e.g. to open the split dialog when the focus reaches this 0150 * object and it contains the text 'Split transaction'. 0151 * 0152 * @sa focusInEvent() 0153 */ 0154 void focusIn(); 0155 0156 private: 0157 Q_DECLARE_PRIVATE(KMyMoneyCategory) 0158 }; 0159 0160 0161 class KMM_BASE_WIDGETS_EXPORT KMyMoneySecurity : public KMyMoneyCategory 0162 { 0163 Q_OBJECT 0164 Q_DISABLE_COPY(KMyMoneySecurity) 0165 0166 public: 0167 explicit KMyMoneySecurity(QWidget* parent = nullptr); 0168 ~KMyMoneySecurity() override; 0169 0170 /** 0171 * overridden for internal reasons, no API change 0172 */ 0173 void setCurrentText(const QString& txt); 0174 void setCurrentText(); 0175 0176 protected: 0177 /** 0178 * set the widgets text area based on the item with the given @a id. 0179 */ 0180 void setCurrentTextById(const QString& id) override; 0181 }; 0182 0183 #endif