File: templateview.h

package info (click to toggle)
qelectrotech 1%3A0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 91,680 kB
  • sloc: cpp: 62,335; xml: 750; sh: 264; perl: 258; makefile: 6
file content (143 lines) | stat: -rw-r--r-- 4,796 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
	Copyright 2006-2019 The QElectroTech Team
	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 TITLEBLOCK_SLASH_TEMPLATE_VIEW_H
#define TITLEBLOCK_SLASH_TEMPLATE_VIEW_H
#include <QGraphicsView>
#include "titleblocktemplate.h"
class HelperCell;
class SplittedHelperCell;
class TitleBlockTemplateCommand;
class TitleBlockTemplateCellsSet;

/**
	This QGraphicsView subclass is used in the title block template editor to
	offer a graphical preview of the template being edited, but also to handle
	cell selection and various actions.
*/
class TitleBlockTemplateView : public QGraphicsView {
	Q_OBJECT
	
	// constructors, destructor
	public:
	TitleBlockTemplateView(QWidget * = nullptr);
	TitleBlockTemplateView(QGraphicsScene *, QWidget * = nullptr);
	~TitleBlockTemplateView() override;
	private:
	TitleBlockTemplateView(const TitleBlockTemplateView &);
	
	// methods and slots
	public:
	TitleBlockTemplate *titleBlockTemplate() const;
	virtual QList<TitleBlockCell *> selectedCells() const;
	virtual TitleBlockTemplateCellsSet selectedCellsSet() const;
	virtual TitleBlockTemplateCellsSet cells(const QRectF &) const;
	virtual void analyzeSelectedCells(bool *, bool *, int *);
	virtual QSizeF templateSize() const;
	virtual qreal templateWidth() const;
	virtual qreal templateHeight() const;
	
	public slots:
	void setTitleBlockTemplate(TitleBlockTemplate *);
	void selectionChanged();
	void zoomIn();
	void zoomOut();
	void zoomFit();
	void zoomReset();
	QList<TitleBlockCell *> cut();
	QList<TitleBlockCell *> copy();
	bool mayPaste();
	QList<TitleBlockCell> pastedCells();
	void paste();
	void addColumnAtEnd();
	void addRowAtEnd();
	void addColumnBefore();
	void addRowBefore();
	void addColumnAfter();
	void addRowAfter();
	void editColumn(HelperCell * = nullptr);
	void editRow(HelperCell * = nullptr);
	void deleteColumn();
	void deleteRow();
	void mergeSelectedCells();
	void splitSelectedCell();
	void refresh();
	void changePreviewWidth();
	void setPreviewWidth(int);
	void updateLayout();
	void rowsDimensionsChanged();
	void columnsDimensionsChanged();
	void updateDisplayedMinMaxWidth();
	void setReadOnly(bool);
	
	protected slots:
	virtual void applyColumnsWidths(bool = true);
	virtual void applyRowsHeights(bool = true);
	virtual void updateRowsHelperCells();
	virtual void updateColumnsHelperCells();
	
	protected:
	void drawBackground(QPainter *, const QRectF &) override;
	virtual void addCells();
	virtual void loadTemplate(TitleBlockTemplate *);
	virtual void init();
	void wheelEvent(QWheelEvent *) override;
	virtual qreal zoomFactor() const;
	virtual void fillWithEmptyCells();
	bool event(QEvent *) override;
	virtual void normalizeCells(QList<TitleBlockCell> &, int x = 0, int y = 0) const;
	
	signals:
	void selectedCellsChanged(QList<TitleBlockCell *>);
	void gridModificationRequested(TitleBlockTemplateCommand *);
	void previewWidthChanged(int, int);
	
	private:
	QList<QAction *> rowsActions() const;
	QList<QAction *> columnsActions() const;
	void updateTotalWidthLabel();
	void requestGridModification(TitleBlockTemplateCommand *);
	int lastContextMenuCellIndex() const;
	int indexOf(QGraphicsLayoutItem *);
	void removeItem(QGraphicsLayoutItem *);
	TitleBlockTemplateCellsSet makeCellsSetFromGraphicsItems(const QList<QGraphicsItem *> &) const;
	QString makePrettyToolTip(const QString &);
	
	private slots:
	void updateLastContextMenuCell(HelperCell *);
	void adjustSceneRect();
	
	// attributes
	private:
	TitleBlockTemplate *tbtemplate_;
	QGraphicsGridLayout *tbgrid_;
	QGraphicsWidget *form_;
	int preview_width_;
	SplittedHelperCell *total_width_helper_cell_;
	HelperCell *extra_cells_width_helper_cell_;
	QAction *add_column_before_, *add_row_before_;
	QAction *add_column_after_, *add_row_after_;
	QAction *edit_column_dim_, *edit_row_dim_;
	QAction *delete_column_, *delete_row_;
	QAction *change_preview_width_;
	HelperCell *last_context_menu_cell_;
	int apply_columns_widths_count_;
	int apply_rows_heights_count_;
	bool first_activation_;                ///< Boolean used to detect the first display of this widget
	bool read_only_;                       ///< Boolean stating whether this view allows template edition
};
#endif