2020-02-02 16:33:19 +01:00
|
|
|
|
/*
|
2020-03-08 10:38:49 +01:00
|
|
|
|
Copyright 2006-2020 QElectroTech Team
|
2020-02-02 16:33:19 +01:00
|
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef QetGraphicsTableItem_H
|
|
|
|
|
#define QetGraphicsTableItem_H
|
|
|
|
|
|
|
|
|
|
#include <QFont>
|
|
|
|
|
|
|
|
|
|
#include "qetgraphicsitem.h"
|
|
|
|
|
#include "qetapp.h"
|
|
|
|
|
#include "QetGraphicsItemModeler/qetgraphicshandleritem.h"
|
|
|
|
|
|
|
|
|
|
class QAbstractItemModel;
|
2020-02-20 21:33:26 +01:00
|
|
|
|
class QetGraphicsHeaderItem;
|
2020-02-02 16:33:19 +01:00
|
|
|
|
|
2020-03-08 10:38:49 +01:00
|
|
|
|
/**
|
|
|
|
|
* @brief The QetGraphicsTableItem class
|
|
|
|
|
* This item display a table destined to represent the content of a QAbstractItemModel
|
|
|
|
|
* The table have a few parameters to edit her visual aspect.
|
|
|
|
|
* Margins, to edit the margin between the cell and the text.
|
|
|
|
|
* Text font.
|
|
|
|
|
* Text alignment in the cell
|
|
|
|
|
* These two last parameters are not settable directly with the table but trough the model to be displayed by the table.
|
|
|
|
|
*/
|
2020-02-02 16:33:19 +01:00
|
|
|
|
class QetGraphicsTableItem : public QetGraphicsItem
|
|
|
|
|
{
|
2020-03-08 10:38:49 +01:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
|
|
|
|
|
Q_PROPERTY(QSize size READ size WRITE setSize)
|
|
|
|
|
|
2020-02-02 16:33:19 +01:00
|
|
|
|
public:
|
|
|
|
|
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
|
|
|
|
|
virtual ~QetGraphicsTableItem() override;
|
|
|
|
|
|
2020-02-21 08:55:35 +01:00
|
|
|
|
enum { Type = UserType + 1300 };
|
|
|
|
|
int type() const override { return Type; }
|
|
|
|
|
|
2020-02-02 16:33:19 +01:00
|
|
|
|
void setModel(QAbstractItemModel *model);
|
|
|
|
|
QAbstractItemModel *model() const;
|
2020-02-20 21:33:26 +01:00
|
|
|
|
|
2020-02-02 16:33:19 +01:00
|
|
|
|
virtual QRectF boundingRect() const override;
|
|
|
|
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
2020-03-08 10:38:49 +01:00
|
|
|
|
QMargins margins() const {return m_margin;}
|
|
|
|
|
void setMargins(const QMargins &margins);
|
|
|
|
|
QetGraphicsHeaderItem *headerItem() const {return m_header_item;}
|
|
|
|
|
void setSize(const QSize &size);
|
|
|
|
|
QSize size() const;
|
|
|
|
|
QSize minimumSize() const;
|
2020-02-02 16:33:19 +01:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
|
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void modelReseted();
|
|
|
|
|
void setUpColumnAndRowMinimumSize();
|
|
|
|
|
void setUpBoundingRect();
|
|
|
|
|
void adjustHandlerPos();
|
|
|
|
|
void setUpHandler();
|
|
|
|
|
void handlerMousePressEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
|
void handlerMouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
|
void handlerMouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
|
void adjustColumnsWidth();
|
2020-03-08 10:38:49 +01:00
|
|
|
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
|
|
|
|
void headerSectionResized();
|
|
|
|
|
void adjustSize();
|
2020-02-02 16:33:19 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QAbstractItemModel *m_model= nullptr;
|
|
|
|
|
|
|
|
|
|
QMargins m_margin;
|
2020-03-08 10:38:49 +01:00
|
|
|
|
QVector<int> m_minimum_column_width;
|
|
|
|
|
int m_minimum_row_height;
|
|
|
|
|
QSize m_current_size,
|
|
|
|
|
m_old_size;
|
2020-02-02 16:33:19 +01:00
|
|
|
|
|
|
|
|
|
int m_br_margin= 10;
|
2020-03-08 10:38:49 +01:00
|
|
|
|
QRectF m_bounding_rect;
|
2020-02-02 16:33:19 +01:00
|
|
|
|
|
|
|
|
|
QetGraphicsHandlerItem m_handler_item;
|
2020-02-20 21:33:26 +01:00
|
|
|
|
QetGraphicsHeaderItem *m_header_item = nullptr;
|
2020-02-02 16:33:19 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // QetGraphicsTableItem_H
|