From 8daa1bebcec46f54180cc8d6e653f4190d5f84e3 Mon Sep 17 00:00:00 2001 From: xavier Date: Sun, 11 Mar 2012 16:06:48 +0000 Subject: [PATCH] Cut/Copy/Paste menu entries are now enabled/disabled according to the current state of editor, selection and clipboard. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1563 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/titleblock/qettemplateeditor.cpp | 7 ++++++- sources/titleblock/templateview.cpp | 15 ++++++++++++++- sources/titleblock/templateview.h | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index b3fdaef02..f6bde000e 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -452,6 +452,7 @@ void QETTitleBlockTemplateEditor::initWidgets() { SLOT(savePreviewWidthToApplicationSettings(int, int)) ); connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(updateEditorTitle())); + connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(updateActions())); } /** @@ -578,9 +579,13 @@ void QETTitleBlockTemplateEditor::updateActions() { bool can_merge; bool can_split; + int count; if (!read_only_) { - template_edition_area_view_ -> analyzeSelectedCells(&can_merge, &can_split); + template_edition_area_view_ -> analyzeSelectedCells(&can_merge, &can_split, &count); } + cut_ -> setEnabled(!read_only_ && count); + copy_ -> setEnabled(count); + paste_ -> setEnabled(!read_only_ && count && template_edition_area_view_ -> mayPaste()); merge_cells_ -> setEnabled(!read_only_ && can_merge); split_cell_ -> setEnabled(!read_only_ && can_split); } diff --git a/sources/titleblock/templateview.cpp b/sources/titleblock/templateview.cpp index eced55200..11ec727c2 100644 --- a/sources/titleblock/templateview.cpp +++ b/sources/titleblock/templateview.cpp @@ -168,6 +168,15 @@ QList TitleBlockTemplateView::copy() { return(copied_cells); } +/** + @return true if the content of the clipboard looks interesting +*/ +bool TitleBlockTemplateView::mayPaste() { + // retrieve the clipboard content + QClipboard *clipboard = QApplication::clipboard(); + return(clipboard -> text().contains(" selectedCells() const; virtual TitleBlockTemplateCellsSet selectedCellsSet() const; virtual TitleBlockTemplateCellsSet cells(const QRectF &) const; - virtual void analyzeSelectedCells(bool *, bool *); + virtual void analyzeSelectedCells(bool *, bool *, int *); virtual QSizeF templateSize() const; virtual qreal templateWidth() const; virtual qreal templateHeight() const; @@ -60,6 +60,7 @@ class TitleBlockTemplateView : public QGraphicsView { void zoomReset(); QList cut(); QList copy(); + bool mayPaste(); void paste(); void addColumnBefore(); void addRowBefore();