[qet] [1563] Cut/Copy/Paste menu entries are now enabled/ disabled according to the current state of editor, selection and clipboard.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1563
Author:   xavier
Date:     2012-03-11 17:06:48 +0100 (Sun, 11 Mar 2012)
Log Message:
-----------
Cut/Copy/Paste menu entries are now enabled/disabled according to the current state of editor, selection and clipboard.

Modified Paths:
--------------
    branches/0.3/sources/titleblock/qettemplateeditor.cpp
    branches/0.3/sources/titleblock/templateview.cpp
    branches/0.3/sources/titleblock/templateview.h

Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-03-11 16:06:46 UTC (rev 1562)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-03-11 16:06:48 UTC (rev 1563)
@@ -452,6 +452,7 @@
 		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 @@
 	
 	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);
 }

Modified: branches/0.3/sources/titleblock/templateview.cpp
===================================================================
--- branches/0.3/sources/titleblock/templateview.cpp	2012-03-11 16:06:46 UTC (rev 1562)
+++ branches/0.3/sources/titleblock/templateview.cpp	2012-03-11 16:06:48 UTC (rev 1563)
@@ -169,6 +169,15 @@
 }
 
 /**
+	@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("<titleblocktemplate-partial"));
+}
+
+/**
 	Import the cells described in the clipboard.
 */
 void TitleBlockTemplateView::paste() {
@@ -385,8 +394,9 @@
 /**
 	@param can_merge If non-zero, will be changed to reflect whether selected cells may be merged
 	@param can_merge If non-zero, will be changed to reflect whether selected cells may be splitted
+	@param count     If non-zero, will be changed to reflect the number of selected cells
 */
-void TitleBlockTemplateView::analyzeSelectedCells(bool *can_merge, bool *can_split) {
+void TitleBlockTemplateView::analyzeSelectedCells(bool *can_merge, bool *can_split, int *count) {
 	if (!can_merge && !can_split) return;
 	
 	if (!tbtemplate_) {
@@ -404,6 +414,9 @@
 	if (can_split) {
 		*can_split = SplitCellsCommand::canSplit(selected_cells, tbtemplate_);
 	}
+	if (count) {
+		*count = selectedCellsSet().count();
+	}
 }
 
 /**

Modified: branches/0.3/sources/titleblock/templateview.h
===================================================================
--- branches/0.3/sources/titleblock/templateview.h	2012-03-11 16:06:46 UTC (rev 1562)
+++ branches/0.3/sources/titleblock/templateview.h	2012-03-11 16:06:48 UTC (rev 1563)
@@ -46,7 +46,7 @@
 	virtual QList<TitleBlockCell *> 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 @@
 	void zoomReset();
 	QList<TitleBlockCell *> cut();
 	QList<TitleBlockCell *> copy();
+	bool mayPaste();
 	void paste();
 	void addColumnBefore();
 	void addRowBefore();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/