29 #define DEFAULT_PREVIEW_WIDTH 600 30 #define DEFAULT_PREVIEW_HELPER_CELL_HEIGHT 15 31 #define DEFAULT_COLS_HELPER_CELLS_HEIGHT 15 32 #define DEFAULT_ROWS_HELPER_CELLS_WIDTH 50 41 QGraphicsView(parent),
46 apply_columns_widths_count_(0),
47 apply_rows_heights_count_(0),
48 first_activation_(true),
59 QGraphicsView(scene, parent),
63 apply_columns_widths_count_(0),
64 apply_rows_heights_count_(0),
65 first_activation_(true),
114 scale(zoom_factor, zoom_factor);
122 fitInView(scene() -> sceneRect(), Qt::KeepAspectRatio);
139 if (!
tbtemplate_)
return(QList<TitleBlockCell *>());
140 QList<TitleBlockCell *> copied_cells =
copy();
142 if (!copied_cells.isEmpty()) {
144 cut_command -> setCutCells(copied_cells);
147 return(copied_cells);
155 if (!
tbtemplate_)
return(QList<TitleBlockCell *>());
158 QDomDocument xml_export;
159 QDomElement tbtpartial = xml_export.createElement(
"titleblocktemplate-partial");
160 xml_export.appendChild(tbtpartial);
163 tbtpartial.setAttribute(
"row", cell -> num_row);
164 tbtpartial.setAttribute(
"col", cell -> num_col);
165 tbtpartial.setAttribute(
"row_span", cell -> row_span);
166 tbtpartial.setAttribute(
"col_span", cell -> col_span);
169 QClipboard *clipboard = QApplication::clipboard();
170 clipboard -> setText(xml_export.toString());
172 return(copied_cells);
180 QClipboard *clipboard = QApplication::clipboard();
181 return(clipboard -> text().contains(
"<titleblocktemplate-partial"));
188 QList<TitleBlockCell> pasted_cells;
191 QClipboard *clipboard = QApplication::clipboard();
192 QDomDocument xml_import;
194 if (!xml_import.setContent(clipboard -> text().trimmed())) {
195 return(pasted_cells);
199 if (xml_import.documentElement().tagName() !=
"titleblocktemplate-partial") {
200 return(pasted_cells);
204 QDomElement paste_root = xml_import.documentElement();
205 for (QDomElement e = paste_root.firstChildElement() ; !e.isNull() ; e = e.nextSiblingElement()) {
206 if (e.tagName() ==
"empty" || e.tagName() ==
"field" || e.tagName() ==
"logo") {
209 int row_num = -1, col_num = -1, row_span = -1, col_span = -1;
227 pasted_cells << cell;
230 return(pasted_cells);
238 QList<TitleBlockCell> pasted_cells =
pastedCells();
239 if (!pasted_cells.count())
return;
243 if (!selected_cell)
return;
245 if (!erased_cell)
return;
248 normalizeCells(pasted_cells, erased_cell -> num_row, erased_cell -> num_col);
253 if (!erased_cell)
continue;
254 paste_command -> addCell(erased_cell, *erased_cell, cell);
283 if (index == -1)
return;
294 if (index == -1)
return;
305 if (index == -1)
return;
316 if (index == -1)
return;
327 if (index == -1)
return;
332 dialog.setWindowTitle(
tr(
"Changer la largeur de la colonne",
"window title when changing a column with"));
333 dialog.
label() -> setText(
tr(
"Largeur :",
"text before the spinbox to change a column width"));
335 int user_answer = dialog.exec();
336 if (!
read_only_ && user_answer == QDialog::Accepted) {
338 command -> setType(
false);
339 command -> setIndex(index);
340 command -> setDimensionBefore(dimension_before);
341 command -> setDimensionAfter(dialog.
value());
353 if (index == -1)
return;
358 dialog.setWindowTitle(
tr(
"Changer la hauteur de la ligne",
"window title when changing a row height"));
359 dialog.
label() -> setText(
tr(
"Hauteur :",
"text before the spinbox to change a row height"));
361 int user_answer = dialog.exec();
362 if (!
read_only_ && user_answer == QDialog::Accepted) {
364 command -> setType(
true);
365 command -> setIndex(index);
366 command -> setDimensionBefore(dimension_before);
367 command -> setDimensionAfter(dialog.
value());
377 if (index == -1)
return;
386 if (index == -1)
return;
417 QGraphicsView::drawBackground(painter, rect);
441 QPolygonF mapped_rect(
form_ -> mapToScene(rect));
442 QList<QGraphicsItem *> items = scene() -> items(mapped_rect, Qt::IntersectsItemShape);
452 if (!can_merge && !can_split)
return;
455 if (can_merge) *can_merge =
false;
456 if (can_split) *can_split =
false;
513 if (e -> modifiers() & Qt::ControlModifier) {
514 if (e -> delta() > 0) {
520 QAbstractScrollArea::wheelEvent(e);
539 edit_column_dim_ =
new QAction(
tr(
"Modifier les dimensions de cette colonne",
"context menu"),
this);
540 edit_row_dim_ =
new QAction(
tr(
"Modifier les dimensions de cette ligne",
"context menu"),
this);
555 setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
556 setBackgroundBrush(QBrush(QColor(248, 255, 160)));
569 tbgrid_ -> setColumnSpacing(0, 0);
573 int total_applied_width = 0;
574 for (
int i = 0 ; i < widths.count() ; ++ i) {
575 int applied_width = qMax(0, widths.at(i));
583 animation -> setActsOnRows(
false);
584 animation -> setStartValue(QVariant(
tbgrid_ -> columnMinimumWidth(
COL_OFFSET + i)));
585 animation -> setEndValue(QVariant(1.0 * applied_width));
586 animation -> setDuration(500);
588 animation -> start(QAbstractAnimation::DeleteWhenStopped);
590 total_applied_width += applied_width;
608 tr(
"[%1px]",
"content of the extra cell added when the total width of cells is less than the preview width")
618 tr(
"[%1px]",
"content of the extra helper cell added when the total width of cells is greather than the preview width")
634 tbgrid_ -> setRowSpacing(0, 0);
637 tbgrid_ -> setRowSpacing(1, 0);
640 for (
int i = 0 ; i < heights.count() ; ++ i) {
648 animation -> setActsOnRows(
true);
649 animation -> setStartValue(QVariant(
tbgrid_ -> rowMinimumHeight(
ROW_OFFSET + i)));
650 animation -> setEndValue(QVariant(1.0 * heights.at(i)));
651 animation -> setDuration(500);
653 animation -> start(QAbstractAnimation::DeleteWhenStopped);
667 for (
int i = 0 ; i < row_count ; ++ i) {
669 if (current_row_cell) {
671 current_row_cell -> setLabel(QString(
tr(
"%1px",
"format displayed in rows helper cells")).arg(heights.at(i)));
681 for (
int i = 0 ; i < col_count ; ++ i) {
684 if (current_col_cell) {
685 current_col_cell -> setType(current_col_dim.
type);
686 current_col_cell -> setLabel(current_col_dim.
toString());
715 for (
int i = 0 ; i < col_count ; ++ i) {
718 current_col_cell -> setType(current_col_dim.
type);
719 current_col_cell -> setLabel(current_col_dim.
toString());
722 current_col_cell -> index = i;
730 for (
int i = 0 ; i < row_count ; ++ i) {
733 current_row_cell -> setLabel(QString(
tr(
"%1px")).arg(heights.at(i)));
735 current_row_cell -> index = i;
743 for (
int i = 0 ; i < col_count ; ++ i) {
744 for (
int j = 0 ; j < row_count ; ++ j) {
746 if (cell -> spanner_cell)
continue;
750 int row_span = 0, col_span = 0;
752 row_span = cell -> applied_row_span;
753 col_span = cell -> applied_col_span;
766 if (row_count < 1 || col_count < 1)
return;
768 for (
int i = 0 ; i < col_count ; ++ i) {
769 for (
int j = 0 ; j < row_count ; ++ j) {
771 if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(item)) {
784 dialog.setWindowTitle(
tr(
"Changer la largeur de l'aperçu"));
785 dialog.
label() -> setText(
tr(
"Largeur de l'aperçu :"));
787 if (dialog.exec() == QDialog::Accepted) {
798 if (row_count < 1 || col_count < 1)
return;
800 for (
int i = 0 ; i < col_count ; ++ i) {
801 for (
int j = 0 ; j < row_count ; ++ j) {
805 qDebug() << Q_FUNC_INFO <<
"target_cell" << target_cell;
806 cell_item -> setTemplateCell(
tbtemplate_, target_cell);
818 QTimer::singleShot(250,
this, SLOT(
zoomFit()));
821 return(QGraphicsView::event(
event));
829 if (!
cells.count())
return;
831 int min_row =
cells.at(0).num_row;
832 int min_col =
cells.at(0).num_col;
833 for (
int i = 1 ; i <
cells.count() ; ++ i) {
834 if (
cells.at(i).num_row < min_row) min_row =
cells.at(i).num_row;
835 if (
cells.at(i).num_col < min_col) min_col =
cells.at(i).num_col;
837 for (
int i = 0 ; i <
cells.count() ; ++ i) {
838 cells[i].num_row =
cells[i].num_row - min_row + x;
839 cells[i].num_col =
cells[i].num_col - min_col + y;
853 form_ -> deleteLater();
862 tbgrid_ =
new QGraphicsGridLayout();
863 tbgrid_ -> setContentsMargins(0, 0, 0, 0);
873 form_ =
new QGraphicsWidget();
875 form_ -> setLayoutDirection(Qt::LeftToRight);
877 scene() -> addItem(
form_);
930 QString min_max_width_sentence;
931 if (max_width != -1) {
932 min_max_width_sentence = QString(
934 "Longueur minimale : %1px\nLongueur maximale : %2px\n",
935 "tooltip showing the minimum and/or maximum width of the edited template" 937 ).arg(min_width).arg(max_width);
939 min_max_width_sentence = QString(
941 "Longueur minimale : %1px\n",
942 "tooltip showing the minimum width of the edited template" 949 min_max_width_sentence +=
"---\n";
996 "Largeur totale pour cet aperçu : %1px",
997 "displayed at the top of the preview when editing a title block template" 1009 if (!command)
return;
1010 command -> setView(
this);
1030 for (
int i = 0 ; i <
tbgrid_ -> count() ; ++i) {
1031 if (item ==
tbgrid_ -> itemAt(i))
return(i);
1045 if (QGraphicsScene *current_scene = scene()) {
1046 if (QGraphicsItem *qgi = item -> graphicsItem()) {
1059 foreach (QGraphicsItem *item, items) {
1061 if (cell_view -> cell() && cell_view -> cell() -> num_row != -1) {
1074 QString css_style = QString(
"white-space: pre;");
1076 QString final_tooltip_content = QString(
1077 "<div style=\"%1\">%2</div>" 1078 ).arg(css_style).arg(
string);
1080 return(final_tooltip_content);
1095 QRectF old_scene_rect = scene() -> sceneRect();
1099 scene() -> setSceneRect(bounding_rect);
1102 scene() -> update(old_scene_rect.united(bounding_rect));
virtual qreal templateHeight() const
QAction * add_column_after_
void updateLastContextMenuCell(HelperCell *)
int apply_columns_widths_count_
bool attributeIsAnInteger(const QDomElement &, const QString &, int *=nullptr)
void updateDisplayedMinMaxWidth()
~TitleBlockTemplateView() override
virtual qreal templateWidth() const
virtual void normalizeCells(QList< TitleBlockCell > &, int x=0, int y=0) const
void changePreviewWidth()
bool read_only_
Boolean stating whether this view allows template edition.
int indexOf(QGraphicsLayoutItem *)
QIcon EditTableInsertRowAbove
QAction * edit_column_dim_
QIcon EditTableDeleteColumn
QString makePrettyToolTip(const QString &)
HelperCell * last_context_menu_cell_
virtual TitleBlockTemplateCellsSet cells(const QRectF &) const
the length is absolute and should be applied as is
int num_col
x coordinate of the cell within its parent title block template grid
virtual void fillWithEmptyCells()
void selectedCellsChanged(QList< TitleBlockCell *>)
QAction * add_column_before_
QIcon EditTableInsertColumnRight
HelperCell * extra_cells_width_helper_cell_
#define DEFAULT_PREVIEW_HELPER_CELL_HEIGHT
TitleBlockTemplate * tbtemplate_
void mergeSelectedCells()
int apply_rows_heights_count_
SplittedHelperCell * total_width_helper_cell_
void previewWidthChanged(int, int)
static bool canMerge(const TitleBlockTemplateCellsSet &, TitleBlockTemplate *)
TitleBlockTemplateView(QWidget *=nullptr)
virtual void updateRowsHelperCells()
void setTitleBlockTemplate(TitleBlockTemplate *)
virtual void applyRowsHeights(bool=true)
static bool canSplit(const TitleBlockTemplateCellsSet &splitted_cells, TitleBlockTemplate *tbtemplate)
int row_span
number of extra rows spanned by this cell
virtual void analyzeSelectedCells(bool *, bool *, int *)
QIcon EditTableInsertRowUnder
#define DEFAULT_PREVIEW_WIDTH
virtual void updateColumnsHelperCells()
virtual void applyColumnsWidths(bool=true)
TitleBlockTemplateCellsSet makeCellsSetFromGraphicsItems(const QList< QGraphicsItem *> &) const
void drawBackground(QPainter *, const QRectF &) override
void wheelEvent(QWheelEvent *) override
int lastContextMenuCellIndex() const
void gridModificationRequested(TitleBlockTemplateCommand *)
TitleBlockTemplate * titleBlockTemplate() const
void removeItem(QGraphicsLayoutItem *)
TitleBlockTemplateVisualCell * topLeftCell() const
QAction * add_row_before_
void updateTotalWidthLabel()
QList< TitleBlockCell * > cut()
QAction * change_preview_width_
virtual qreal zoomFactor() const
QGraphicsGridLayout * tbgrid_
static ModifyTemplateGridCommand * deleteRow(TitleBlockTemplate *, int=-1)
void editColumn(HelperCell *=nullptr)
QList< QAction * > columnsActions() const
QList< TitleBlockCell * > copy()
static ModifyTemplateGridCommand * addRow(TitleBlockTemplate *, int=-1)
virtual void loadTemplate(TitleBlockTemplate *)
virtual TitleBlockTemplateCellsSet selectedCellsSet() const
the cell span parameters should not applied at all
#define DEFAULT_COLS_HELPER_CELLS_HEIGHT
static ModifyTemplateGridCommand * deleteColumn(TitleBlockTemplate *, int=-1)
void rowsDimensionsChanged()
static ModifyTemplateGridCommand * addColumn(TitleBlockTemplate *, int=-1)
virtual QList< TitleBlockCell * > selectedCells() const
bool first_activation_
Boolean used to detect the first display of this widget.
void editRow(HelperCell *=nullptr)
void loadContentFromXml(const QDomElement &)
virtual QSizeF templateSize() const
QIcon EditTableInsertColumnLeft
QList< QAction * > rowsActions() const
void requestGridModification(TitleBlockTemplateCommand *)
bool event(QEvent *) override
void setPreviewWidth(int)
QList< TitleBlockCell > pastedCells()
#define DEFAULT_ROWS_HELPER_CELLS_WIDTH
void columnsDimensionsChanged()
int col_span
number of extra columns spanned by this cell
int num_row
y coordinate of the cell within its parent title block template grid
QET::TitleBlockColumnLength type
Kind of length.