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