File indexing completed on 2024-05-12 17:11:43

0001 /***************************************************************************
0002  * Copyright (C) 2018 by Renaud Guezennec                                   *
0003  * http://www.rolisteam.org/                                                *
0004  *                                                                          *
0005  *  This file is part of rcse                                               *
0006  *                                                                          *
0007  * rcse is free software; you can redistribute it and/or modify             *
0008  * it under the terms of the GNU General Public License as published by     *
0009  * the Free Software Foundation; either version 2 of the License, or        *
0010  * (at your option) any later version.                                      *
0011  *                                                                          *
0012  * rcse is distributed in the hope that it will be useful,                  *
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
0015  * GNU General Public License for more details.                             *
0016  *                                                                          *
0017  * You should have received a copy of the GNU General Public License        *
0018  * along with this program; if not, write to the                            *
0019  * Free Software Foundation, Inc.,                                          *
0020  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.                 *
0021  ***************************************************************************/
0022 #ifndef TABLECANVASFIELD_H
0023 #define TABLECANVASFIELD_H
0024 
0025 #include <QObject>
0026 #include <memory>
0027 
0028 #include "canvasfield.h"
0029 #include "charactersheet/charactersheetitem.h"
0030 #include "dialog/columndefinitiondialog.h"
0031 
0032 class TableCanvasField;
0033 class LineModel;
0034 class TableField;
0035 
0036 class ButtonCanvas : public QGraphicsObject
0037 {
0038     Q_OBJECT
0039 public:
0040     ButtonCanvas();
0041     QRectF boundingRect() const;
0042     void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
0043     QString msg() const;
0044     void setMsg(const QString& msg);
0045     QRectF rect() const;
0046     void setRect(const QRectF& rect);
0047 
0048 protected:
0049     void mousePressEvent(QGraphicsSceneMouseEvent* event);
0050 
0051 signals:
0052     void clicked();
0053 
0054 private:
0055     QString m_msg;
0056     QRectF m_rect;
0057 };
0058 
0059 class TableCanvasField : public CanvasField
0060 {
0061     Q_OBJECT
0062 public:
0063     explicit TableCanvasField(FieldController* field);
0064     virtual ~TableCanvasField();
0065 
0066     void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* a= nullptr);
0067 
0068     bool hasFocusOrChild();
0069 
0070     int colunmCount() const;
0071     void setColunmCount(int colunmCount);
0072 
0073     int lineCount() const;
0074     void setLineCount(int lineCount);
0075 
0076     int getColumnWidth(int c);
0077     int getLineHeight();
0078 
0079     void fillLineModel(LineModel* model, TableField* parent);
0080 
0081     FieldController* generateSubField(int i);
0082 
0083     void generateSubFields(QTextStream& out);
0084 
0085     void load(QJsonObject& json);
0086     void save(QJsonObject& json);
0087 
0088     TreeSheetItem* getRoot();
0089 
0090 public slots:
0091     void addColumn();
0092     void removeColumn();
0093     void addLine();
0094     void defineColumns();
0095 
0096 protected:
0097     virtual void setMenu(QMenu& menu);
0098 
0099 private:
0100     int m_colunmCount;
0101     int m_lineCount;
0102 
0103     QList<HandleItem*> m_handles;
0104 
0105     ButtonCanvas* m_addColumn= nullptr;
0106     ButtonCanvas* m_addLine= nullptr;
0107     QAction* m_defineColumns= nullptr;
0108 
0109     std::unique_ptr<ColumnDefinitionDialog> m_dialog;
0110     bool m_dataReset;
0111     bool m_columnDefined= false;
0112 };
0113 
0114 #endif // TABLECANVASFIELD_H