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

0001 /*
0002     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0003     SPDX-FileCopyrightText: 2019-2020 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-FileCopyrightText: 2020 Robert Szczesiak <dev.rszczesiak@gmail.com>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMYMONEYVIEWBASEPRIVATE_H
0009 #define KMYMONEYVIEWBASEPRIVATE_H
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 #include <QHash>
0015 #include <QLabel>
0016 #include <QString>
0017 class QAction;
0018 
0019 // ----------------------------------------------------------------------------
0020 // KDE Includes
0021 
0022 // ----------------------------------------------------------------------------
0023 // Project Includes
0024 
0025 #include "menuenums.h"
0026 #include "selectedobjects.h"
0027 #include <accountsmodel.h>
0028 #include <kmymoneysettings.h>
0029 #include <mymoneyfile.h>
0030 #include <mymoneymoney.h>
0031 #include <mymoneysecurity.h>
0032 #include <mymoneyutils.h>
0033 
0034 class KMyMoneyViewBase;
0035 class KMyMoneyViewBasePrivate
0036 {
0037 public:
0038     explicit KMyMoneyViewBasePrivate(KMyMoneyViewBase* parent)
0039         : q_ptr(parent)
0040         , m_focusWidget(nullptr)
0041         , m_isActiveView(false)
0042         , m_needsRefresh(false)
0043         , m_havePendingChanges(false)
0044     {}
0045 
0046     virtual ~KMyMoneyViewBasePrivate() {}
0047 
0048     /**
0049     * @brief Sets label text and font
0050     * @param label pointer to a QLabel object to update
0051     * @param labelText reference to a QString object to set as label text
0052     */
0053     void updateViewLabel(QLabel* label, const QString& labelText)
0054     {
0055         label->setFont(KMyMoneySettings::listCellFontEx());
0056         label->setText(labelText);
0057     }
0058 
0059     /**
0060      * @brief Returns formatted rich text
0061      * @param value reference to a MyMoneyMoney object containing the value to be formatted
0062      * @param scheme reference to a QColor object containing color scheme
0063      * @return Qstring representing label value with added formatting
0064      */
0065     QString formatViewLabelValue(const MyMoneyMoney& value, const QColor& scheme)
0066     {
0067         const QString colorDef = QStringLiteral("#%1%2%3").arg(scheme.red(), 2, 16, QLatin1Char('0')).arg(scheme.green(), 2, 16, QLatin1Char('0')).arg(scheme.blue(), 2, 16, QLatin1Char('0'));
0068 
0069         QString s(MyMoneyUtils::formatMoney(value, MyMoneyFile::instance()->baseCurrency()));
0070         s.prepend(QStringLiteral("<b><font color=\"%1\">").arg(colorDef));
0071         s.append(QLatin1String("</font></b>"));
0072 
0073         return s;
0074     }
0075 
0076     QString formatViewLabelValue(const MyMoneyMoney& value)
0077     {
0078         const QColor scheme = KMyMoneySettings::schemeColor(value.isNegative() ? SchemeColor::Negative : SchemeColor::Positive).convertTo(QColor::Rgb);
0079         return formatViewLabelValue(value, scheme);
0080     }
0081 
0082     bool isActiveView() const
0083     {
0084         return m_isActiveView;
0085     }
0086 
0087     KMyMoneyViewBase* q_ptr;
0088     QWidget* m_focusWidget;
0089     SelectedObjects m_selections;
0090     QHash<eMenu::Action, QAction*> m_sharedToolbarActions;
0091     bool m_isActiveView;
0092     bool m_needsRefresh;
0093     bool m_havePendingChanges;
0094 };
0095 
0096 #endif