File indexing completed on 2024-05-12 16:35:09

0001 /* This file is part of the KDE project
0002    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2006 Thomas Zander <zander@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef CALLIGRA_SHEETS_CHART_DIALOG
0022 #define CALLIGRA_SHEETS_CHART_DIALOG
0023 
0024 #include <KoShapeConfigFactoryBase.h>
0025 
0026 #include <kpagedialog.h>
0027 
0028 #include <QCheckBox>
0029 #include <QList>
0030 
0031 namespace KoChart
0032 {
0033 class ChartShape;
0034 }
0035 
0036 namespace Calligra
0037 {
0038 namespace Sheets
0039 {
0040 class Map;
0041 
0042 /// A dialog for showing and altering frame properties
0043 class ChartDialog : public KPageDialog
0044 {
0045     Q_OBJECT
0046 public:
0047     /**
0048      * Constructor.
0049      * @param selectedCharts all charts that this dialog will show for user modification
0050      * @param parent a parent widget for the purpose of centering the dialog
0051      */
0052     explicit ChartDialog(const QList<KoChart::ChartShape*> &selectedCharts, QWidget *parent = 0);
0053     ~ChartDialog() override;
0054 
0055     /**
0056      * Create a list of factories that will be able to create widgets to configure shapes.
0057      * @param map the parent document these panels will work for.
0058      */
0059     static QList<KoShapeConfigFactoryBase*> panels(Map *map);
0060 
0061 private Q_SLOTS:
0062     void okClicked();
0063     void cancelClicked();
0064 
0065 private:
0066 };
0067 
0068 /// A simple class useful for finding out if a series of data object will cause a
0069 /// normal or a tri-state checkbox. For example.
0070 class GuiHelper
0071 {
0072 public:
0073     /// the different states
0074     enum State {
0075         Unset, ///< start value
0076         On,     ///< on
0077         Off,    ///< off
0078         TriState ///< Both on and off
0079     };
0080     /// constructor
0081     GuiHelper() : m_state(Unset) { }
0082     /// Add a new state
0083     void addState(State state) {
0084         if (m_state == Unset)
0085             m_state = state;
0086         else if (m_state != state)
0087             m_state = TriState;
0088     }
0089 
0090     /**
0091      * Based on all the added states initialize the checkbox.
0092      * @param checkbox the checkbox to set.
0093      * @param hide if true the checkbox will be hidden when there was no 'addState' called
0094      */
0095     void updateCheckBox(QCheckBox *checkbox, bool hide) {
0096         if (m_state == Unset) {
0097             if (hide)
0098                 checkbox->setVisible(false);
0099             checkbox->setEnabled(false);
0100             checkbox->setTristate(true);
0101             checkbox->setCheckState(Qt::PartiallyChecked);
0102         } else if (m_state == TriState) {
0103             checkbox->setTristate(true);
0104             checkbox->setCheckState(Qt::PartiallyChecked);
0105         } else {
0106             checkbox->setCheckState(m_state == On ? Qt::Checked : Qt::Unchecked);
0107         }
0108     }
0109 
0110     State m_state; ///< the current state
0111 };
0112 
0113 } // namespace Sheets
0114 } // namespace Calligra
0115 
0116 #endif // CALLIGRA_SHEETS_CHART_DIALOG