[qet] [1540] The title block template editor now displays a tooltip with the edited template 's minimum and maximum widths.

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


Revision: 1540
Author:   xavier
Date:     2012-02-28 19:54:34 +0100 (Tue, 28 Feb 2012)
Log Message:
-----------
The title block template editor now displays a tooltip with the edited template's minimum and maximum widths.

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

Modified: branches/0.3/sources/titleblock/templateview.cpp
===================================================================
--- branches/0.3/sources/titleblock/templateview.cpp	2012-02-27 18:31:47 UTC (rev 1539)
+++ branches/0.3/sources/titleblock/templateview.cpp	2012-02-28 18:54:34 UTC (rev 1540)
@@ -465,6 +465,8 @@
 		).arg(total_applied_width - preview_width_);
 		total_width_helper_cell_ -> split_size = total_applied_width - preview_width_;
 	}
+	
+	updateDisplayedMinMaxWidth();
 }
 
 /**
@@ -736,6 +738,35 @@
 }
 
 /**
+	Update the tooltip that displays the minimum and/or maximum width of the
+	template.
+*/
+void TitleBlockTemplateView::updateDisplayedMinMaxWidth() {
+	if (!tbtemplate_) return;
+	int min_width = tbtemplate_ -> minimumWidth();
+	int max_width = tbtemplate_ -> maximumWidth();
+	
+	QString min_max_width_sentence;
+	if (max_width != -1) {
+		min_max_width_sentence = QString(
+			tr(
+				"Minimum width: %1px\nMaximum width: %2px\n",
+				"tooltip showing the minimum and/or maximum width of the edited template"
+			)
+		).arg(min_width).arg(max_width);
+	} else {
+		min_max_width_sentence = QString(
+			tr(
+				"Minimum width: %1px\n",
+				"tooltip showing the minimum width of the edited template"
+			)
+		).arg(min_width);
+	}
+	
+	total_width_helper_cell_ -> setToolTip(makePrettyToolTip(min_max_width_sentence));
+}
+
+/**
 	@param read_only whether this view should be read only.
 	
 */
@@ -848,6 +879,20 @@
 	return(set);
 }
 
+/*
+	@param a text string
+	@return an HTML string that can be passed to setToolTip()
+*/
+QString TitleBlockTemplateView::makePrettyToolTip(const QString &string) {
+	QString css_style = QString("white-space: pre;");
+	
+	QString final_tooltip_content = QString(
+		"<div style=\"%1\">%2</div>"
+	).arg(css_style).arg(string);
+	
+	return(final_tooltip_content);
+}
+
 /**
 	Stores \a last_context_menu_cell as being the last helper cell the context
 	menu was triggered on.

Modified: branches/0.3/sources/titleblock/templateview.h
===================================================================
--- branches/0.3/sources/titleblock/templateview.h	2012-02-27 18:31:47 UTC (rev 1539)
+++ branches/0.3/sources/titleblock/templateview.h	2012-02-28 18:54:34 UTC (rev 1540)
@@ -73,6 +73,7 @@
 	void updateLayout();
 	void rowsDimensionsChanged();
 	void columnsDimensionsChanged();
+	void updateDisplayedMinMaxWidth();
 	void setReadOnly(bool);
 	
 	protected slots:
@@ -105,6 +106,7 @@
 	int indexOf(QGraphicsLayoutItem *);
 	void removeItem(QGraphicsLayoutItem *);
 	TitleBlockTemplateCellsSet makeCellsSetFromGraphicsItems(const QList<QGraphicsItem *> &) const;
+	QString makePrettyToolTip(const QString &);
 	
 	private slots:
 	void updateLastContextMenuCell(HelperCell *);

Modified: branches/0.3/sources/titleblocktemplate.cpp
===================================================================
--- branches/0.3/sources/titleblocktemplate.cpp	2012-02-27 18:31:47 UTC (rev 1539)
+++ branches/0.3/sources/titleblocktemplate.cpp	2012-02-28 18:54:34 UTC (rev 1540)
@@ -795,6 +795,69 @@
 }
 
 /**
+	@param a column type
+	@return the count of \a type columns 
+*/
+int TitleBlockTemplate::columnTypeCount(QET::TitleBlockColumnLength type) {
+	int count = 0;
+	
+	for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+		if (columns_width_.at(i).type == type) ++ count;
+	}
+	
+	return(count);
+}
+
+/**
+	@param a column type
+	@return the sum of values attached to \a type columns 
+*/
+int TitleBlockTemplate::columnTypeTotal(QET::TitleBlockColumnLength type) {
+	int total = 0;
+	
+	for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+		if (columns_width_.at(i).type == type) {
+			total += columns_width_.at(i).value;
+		}
+	}
+	
+	return(total);
+}
+
+/**
+	@return the minimum width for this template
+*/
+int TitleBlockTemplate::minimumWidth() {
+	// Abbreviations: ABS: absolute, RTT: relative to total, RTR: relative to
+	// remaining, TOT: total diagram/TBT width (variable).
+	
+	// Minimum size may be enforced by ABS and RTT widths:
+	// TOT >= ((sum(REL)/100)*TOT)+sum(ABS)
+	// => (1 - (sum(REL)/100))TOT >= sum(ABS)
+	// => TOT >= sum(ABS) / (1 - (sum(REL)/100))
+	// => TOT >= sum(ABS) / ((100 - sum(REL))/100))
+	return(
+		qRound(
+			columnTypeTotal(QET::Absolute)
+			/
+			((100.0 - columnTypeTotal(QET::RelativeToTotalLength)) / 100.0)
+		)
+	);
+}
+
+/**
+	@return the maximum width for this template, or -1 if it does not have any.
+*/
+int TitleBlockTemplate::maximumWidth() {
+	if (columnTypeCount(QET::Absolute) == columns_width_.count()) {
+		// The template is composed of absolute widths only,
+		// therefore it may not extend beyond their sum.
+		return(columnTypeTotal(QET::Absolute));
+	}
+	return(-1);
+}
+
+/**
 	@return the total effective width of this template
 	@param total_width The total width initially planned for the rendering
 */

Modified: branches/0.3/sources/titleblocktemplate.h
===================================================================
--- branches/0.3/sources/titleblocktemplate.h	2012-02-27 18:31:47 UTC (rev 1539)
+++ branches/0.3/sources/titleblocktemplate.h	2012-02-28 18:54:34 UTC (rev 1540)
@@ -59,6 +59,10 @@
 	int rowsCount() const;
 	QList<int> columnsWidth(int) const;
 	QList<int> rowsHeights() const;
+	int columnTypeCount(QET::TitleBlockColumnLength);
+	int columnTypeTotal(QET::TitleBlockColumnLength);
+	int minimumWidth();
+	int maximumWidth();
 	int width(int);
 	int height() const;
 	


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