diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 78481ffc2..b3fdaef02 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -300,6 +300,9 @@ void QETTitleBlockTemplateEditor::initActions() { quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this); undo_ = undo_stack_ -> createUndoAction(this); redo_ = undo_stack_ -> createRedoAction(this); + cut_ = new QAction(QET::Icons::EditCut, tr("Co&uper", "menu entry"), this); + copy_ = new QAction(QET::Icons::EditCopy, tr("Cop&ier", "menu entry"), this); + paste_ = new QAction(QET::Icons::EditPaste, tr("C&oller", "menu entry"), this); edit_info_ = new QAction(QET::Icons::UserInformations, tr("\311diter les informations compl\351mentaires", "menu entry"), this); zoom_in_ = new QAction(QET::Icons::ZoomIn, tr("Zoom avant", "menu entry"), this); zoom_out_ = new QAction(QET::Icons::ZoomOut, tr("Zoom arri\350re", "menu entry"), this); @@ -319,6 +322,9 @@ void QETTitleBlockTemplateEditor::initActions() { quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit"))); undo_ -> setShortcut(QKeySequence::Undo); redo_ -> setShortcut(QKeySequence::Redo); + cut_ -> setShortcut(QKeySequence::Cut); + copy_ -> setShortcut(QKeySequence::Copy); + paste_ -> setShortcut(QKeySequence::Paste); edit_info_ -> setShortcut(QKeySequence(tr("Ctrl+Y", "shortcut to edit extra information"))); merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells"))); split_cell_ -> setShortcut(QKeySequence(tr("Ctrl+J", "shortcut to split merged cell"))); @@ -334,6 +340,9 @@ void QETTitleBlockTemplateEditor::initActions() { connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs())); connect(save_as_file_, SIGNAL(triggered()), this, SLOT(saveAsFile())); connect(quit_, SIGNAL(triggered()), this, SLOT(quit())); + connect(cut_, SIGNAL(triggered()), template_edition_area_view_, SLOT(cut())); + connect(copy_, SIGNAL(triggered()), template_edition_area_view_, SLOT(copy())); + connect(paste_, SIGNAL(triggered()), template_edition_area_view_, SLOT(paste())); connect(zoom_in_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomIn())); connect(zoom_out_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomOut())); connect(zoom_fit_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomFit())); @@ -363,7 +372,10 @@ void QETTitleBlockTemplateEditor::initMenus() { edit_menu_ -> addAction(undo_); edit_menu_ -> addAction(redo_); edit_menu_ -> addSeparator(); - + edit_menu_ -> addAction(cut_); + edit_menu_ -> addAction(copy_); + edit_menu_ -> addAction(paste_); + edit_menu_ -> addSeparator(); edit_menu_ -> addAction(merge_cells_); edit_menu_ -> addAction(split_cell_); edit_menu_ -> addAction(edit_info_); diff --git a/sources/titleblock/qettemplateeditor.h b/sources/titleblock/qettemplateeditor.h index 9ca10404c..60367886e 100644 --- a/sources/titleblock/qettemplateeditor.h +++ b/sources/titleblock/qettemplateeditor.h @@ -49,7 +49,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow { QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_*/; /// actions QAction *new_, *open_, *open_from_file_, *save_, *save_as_, *save_as_file_, *quit_; - QAction *undo_, *redo_, *edit_info_, *merge_cells_, *split_cell_; + QAction *undo_, *redo_, *cut_, *copy_, *paste_, *edit_info_, *merge_cells_, *split_cell_; QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_; /// Location of the currently edited template TitleBlockTemplateLocation location_; diff --git a/sources/titleblock/templateview.cpp b/sources/titleblock/templateview.cpp index de66ed127..2d4f3ed17 100644 --- a/sources/titleblock/templateview.cpp +++ b/sources/titleblock/templateview.cpp @@ -130,6 +130,38 @@ void TitleBlockTemplateView::zoomReset() { resetMatrix(); } +/** + Export currently selected cells to the clipboard before setting them as + empty. +*/ +void TitleBlockTemplateView::cut() { + /// TODO +} + +/** + Export currently selected cells to the clipboard. +*/ +void TitleBlockTemplateView::copy() { + if (!tbtemplate_) return; + + QDomDocument xml_export; + QDomElement tbtpartial = xml_export.createElement("titleblocktemplate-partial"); + xml_export.appendChild(tbtpartial); + foreach (TitleBlockCell *cell, selectedCells()) { + tbtemplate_ -> exportCellToXml(cell, tbtpartial); + } + + QClipboard *clipboard = QApplication::clipboard(); + clipboard -> setText(xml_export.toString()); +} + +/** + Import the cells described in the clipboard. +*/ +void TitleBlockTemplateView::paste() { + /// TODO +} + /** Add a column right before the last index selected when calling the context menu. diff --git a/sources/titleblock/templateview.h b/sources/titleblock/templateview.h index e8825f915..b72968a98 100644 --- a/sources/titleblock/templateview.h +++ b/sources/titleblock/templateview.h @@ -58,6 +58,9 @@ class TitleBlockTemplateView : public QGraphicsView { void zoomOut(); void zoomFit(); void zoomReset(); + void cut(); + void copy(); + void paste(); void addColumnBefore(); void addRowBefore(); void addColumnAfter(); diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 6dd0a63a2..2ffd94385 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -165,6 +165,14 @@ bool TitleBlockTemplate::saveToXmlElement(QDomElement &xml_element) const { return(true); } +/** + @param xml_element Parent XML element to be used when exporting \a cell + @param cell Cell to export +*/ +void TitleBlockTemplate::exportCellToXml(TitleBlockCell *cell, QDomElement &xml_element) const { + saveCell(cell, xml_element, true); +} + /** @return a deep copy of the current title block template (i.e. title block cells are duplicated too and associated with their parent template). @@ -552,10 +560,13 @@ void TitleBlockTemplate::saveCells(QDomElement &xml_element) const { Export a specific cell as XML @param cell Cell to be exported as XML @param xml_element XML element under which the \ element will be attached + @param save_empty If true, the cell will be saved even if it is an empty one */ -void TitleBlockTemplate::saveCell(TitleBlockCell *cell, QDomElement &xml_element) const { - if (!cell || cell -> cell_type == TitleBlockCell::EmptyCell) return; +void TitleBlockTemplate::saveCell(TitleBlockCell *cell, QDomElement &xml_element, bool save_empty) const { + if (!cell) return; if (cell -> spanner_cell) return; + if (!save_empty && cell -> cell_type == TitleBlockCell::EmptyCell) return; + QDomElement cell_elmt = xml_element.ownerDocument().createElement("cell"); cell_elmt.setAttribute("name", cell -> value_name); @@ -564,7 +575,9 @@ void TitleBlockTemplate::saveCell(TitleBlockCell *cell, QDomElement &xml_element if (cell -> row_span) cell_elmt.setAttribute("rowspan", cell -> row_span); if (cell -> col_span) cell_elmt.setAttribute("colspan", cell -> col_span); - if (cell -> type() == TitleBlockCell::LogoCell) { + if (cell -> type() == TitleBlockCell::EmptyCell) { + cell_elmt.setTagName("empty"); + } else if (cell -> type() == TitleBlockCell::LogoCell) { cell_elmt.setTagName("logo"); cell_elmt.setAttribute("resource", cell -> logo_reference); } else { diff --git a/sources/titleblocktemplate.h b/sources/titleblocktemplate.h index f1a577ddd..b477c4751 100644 --- a/sources/titleblocktemplate.h +++ b/sources/titleblocktemplate.h @@ -49,6 +49,7 @@ class TitleBlockTemplate : public QObject { bool loadFromXmlElement(const QDomElement &); bool saveToXmlFile(const QString &); bool saveToXmlElement(QDomElement &) const; + void exportCellToXml(TitleBlockCell *,QDomElement &) const; TitleBlockTemplate *clone() const; QString name() const; QString information() const; @@ -108,7 +109,7 @@ class TitleBlockTemplate : public QObject { void saveLogo(const QString &, QDomElement &) const; void saveGrid(QDomElement &) const; void saveCells(QDomElement &) const; - void saveCell(TitleBlockCell *, QDomElement &) const; + void saveCell(TitleBlockCell *, QDomElement &, bool = false) const; QList createCellsList(int); private: