mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
The title block template editor now displays a tooltip with the edited template's minimum and maximum widths.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1540 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -465,6 +465,8 @@ void TitleBlockTemplateView::applyColumnsWidths(bool animate) {
|
||||
).arg(total_applied_width - preview_width_);
|
||||
total_width_helper_cell_ -> split_size = total_applied_width - preview_width_;
|
||||
}
|
||||
|
||||
updateDisplayedMinMaxWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -735,6 +737,35 @@ void TitleBlockTemplateView::columnsDimensionsChanged() {
|
||||
applyColumnsWidths();
|
||||
}
|
||||
|
||||
/**
|
||||
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 @@ TitleBlockTemplateCellsSet TitleBlockTemplateView::makeCellsSetFromGraphicsItems
|
||||
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.
|
||||
|
||||
@@ -73,6 +73,7 @@ class TitleBlockTemplateView : public QGraphicsView {
|
||||
void updateLayout();
|
||||
void rowsDimensionsChanged();
|
||||
void columnsDimensionsChanged();
|
||||
void updateDisplayedMinMaxWidth();
|
||||
void setReadOnly(bool);
|
||||
|
||||
protected slots:
|
||||
@@ -105,6 +106,7 @@ class TitleBlockTemplateView : public QGraphicsView {
|
||||
int indexOf(QGraphicsLayoutItem *);
|
||||
void removeItem(QGraphicsLayoutItem *);
|
||||
TitleBlockTemplateCellsSet makeCellsSetFromGraphicsItems(const QList<QGraphicsItem *> &) const;
|
||||
QString makePrettyToolTip(const QString &);
|
||||
|
||||
private slots:
|
||||
void updateLastContextMenuCell(HelperCell *);
|
||||
|
||||
@@ -794,6 +794,69 @@ QList<int> TitleBlockTemplate::rowsHeights() const {
|
||||
return(rows_heights_);
|
||||
}
|
||||
|
||||
/**
|
||||
@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
|
||||
|
||||
@@ -59,6 +59,10 @@ class TitleBlockTemplate : public QObject {
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user