diff --git a/ChangeLog.txt b/ChangeLog.txt index 7f390c610..5e5b3c291 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -35,6 +35,7 @@ - Fix dialog for tool Point along perpendicular. No memory of line color settings. - Fix crash after uniting three pieces in sequence. - Incorrect conversion to newer curve format. +- Elide a variable description in the formula wizard. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui b/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui index 7b861987c..fa9c4c89a 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.ui @@ -9,8 +9,8 @@ 0 0 - 448 - 478 + 542 + 481 @@ -23,7 +23,7 @@ true - + @@ -172,34 +172,173 @@ - + - + - + - - - - 0 - 0 - - - - Input data + + + + + + 0 + 0 + + + + Input data + + + + + + + + 0 + 0 + + + + Measurements + + + true + + + + + + + + 0 + 0 + + + + Increments + + + + + + + Preview calculations + + + + + + + true + + + + 0 + 0 + + + + Length of lines + + + + + + + true + + + + 0 + 0 + + + + Length of curves + + + + + + + true + + + + 0 + 0 + + + + Angle of lines + + + + + + + + 0 + 0 + + + + Radius of arcs + + + + + + + + 0 + 0 + + + + Angles of curves + + + + + + + Lengths to control points + + + + + + + + 0 + 0 + + + + Functions + + + + + + + + + + + + + Filter list by keyword - - - - 0 - 0 - - + - Measurements + Hide empty measurements true @@ -207,117 +346,26 @@ - - - - 0 - 0 - + + + + 0 + 0 + - - Increments - - - - - - - Preview calculations - - - - - - - true - - - - 0 - 0 - - - - Length of lines - - - - - - - true - - - - 0 - 0 - - - - Length of curves - - - - - - - true - - - - 0 - 0 - - - - Angle of lines - - - - - - - - 0 - 0 - - - - Radius of arcs - - - - - - - - 0 - 0 - - - - Angles of curves - - - - - - - Lengths to control points - - - - - - - - 0 - 0 - - - - Functions + + PointingHandCursor + + + Name + + + + + Full name + + @@ -325,63 +373,25 @@ - - - - - Filter list by keyword - - - - - - - Hide empty measurements - - - true - - - - - - - - 0 - 0 - - - - PointingHandCursor - - - - Name - - - - - Full name - - - - - + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + - - - - - - - true - - - @@ -400,6 +410,12 @@ QPlainTextEdit
vplaintextedit.h
+ + VElidedLabel + QFrame +
velidedlabel.h
+ 1 +
toolButtonPutHere diff --git a/src/libs/vwidgets/velidedlabel.cpp b/src/libs/vwidgets/velidedlabel.cpp new file mode 100644 index 000000000..30f79ceea --- /dev/null +++ b/src/libs/vwidgets/velidedlabel.cpp @@ -0,0 +1,151 @@ +/************************************************************************ + ** + ** @file velidedlabel.cpp + ** @author Roman Telezhynskyi + ** @date 8 5, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "velidedlabel.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VElidedLabel::VElidedLabel(QWidget *parent) + : QFrame(parent) +{ + // reserve size for one line of text + setMinimumHeight(fontMetrics().lineSpacing()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VElidedLabel::VElidedLabel(const QString &text, QWidget *parent) + : QFrame(parent), + m_content(text) +{ + // reserve size for one line of text + setMinimumHeight(fontMetrics().lineSpacing()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VElidedLabel::setText(const QString &newText) +{ + m_content = newText; + update(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VElidedLabel::paintEvent(QPaintEvent *event) +{ + QFrame::paintEvent(event); + + QPainter painter(this); + bool didElide = false; + int y = 0; + + // QTextLayout works with paragraphs + QStringList paragraphs = m_content.split('\n'); + for (int i = 0; i < paragraphs.size(); ++i) + { + if (not DrawParagraph(painter, paragraphs.at(i), y, didElide)) + { + // It text has empty strings a user will not see elided string, but we still want to show a tooltip. + if (i != paragraphs.size()-1 && !didElide) + { + didElide = true; + } + break; + } + } + + if (didElide != m_elided) + { + m_elided = didElide; + + if (m_showElided) + { + if (m_elided) + { + // Show a tooltip in case we cannot show a whole text in the widget + // Use dumb html tag to separate paragraphs. + QString toolTip; + for(int i = 0; i < paragraphs.size(); ++i) + { + if (i != 0) + { + toolTip.append(QString("
")); + } + toolTip.append(QString("%1").arg(paragraphs.at(i))); + } + setToolTip(toolTip); + } + else + { + setToolTip(QString()); + } + } + emit ElisionChanged(didElide); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VElidedLabel::DrawParagraph(QPainter &painter, const QString& paragraph, int &y, bool &didElide) +{ + QFontMetrics fontMetrics = painter.fontMetrics(); + + int lineSpacing = fontMetrics.lineSpacing(); + bool ok = true; + + QTextLayout textLayout(paragraph, painter.font()); + textLayout.beginLayout(); + forever + { + QTextLine line = textLayout.createLine(); + + if (!line.isValid()) + { + break; + } + + line.setLineWidth(width()); + int nextLineY = y + lineSpacing; + + if (height() >= nextLineY + lineSpacing) + { + line.draw(&painter, QPoint(0, y)); + y = nextLineY; + } + else + { + QString lastLine = paragraph.mid(line.textStart()); + QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width()); + painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine); + y = nextLineY; + ok = false; + didElide = lastLine != elidedLastLine; + break; + } + } + textLayout.endLayout(); + return ok; +} diff --git a/src/libs/vwidgets/velidedlabel.h b/src/libs/vwidgets/velidedlabel.h new file mode 100644 index 000000000..6a1906cc1 --- /dev/null +++ b/src/libs/vwidgets/velidedlabel.h @@ -0,0 +1,90 @@ +/************************************************************************ + ** + ** @file velidedlabel.h + ** @author Roman Telezhynskyi + ** @date 8 5, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef VELIDEDLABEL_H +#define VELIDEDLABEL_H + +#include + +class VElidedLabel : public QFrame +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(bool IsElided READ IsElided) + Q_PROPERTY(bool showElided READ ShowElided WRITE SetShowElided) +public: + explicit VElidedLabel(QWidget *parent = nullptr); + explicit VElidedLabel(const QString &text, QWidget *parent = nullptr); + + void setText(const QString &text); + const QString& text() const; + + bool IsElided() const; + + bool ShowElided() const; + void SetShowElided(bool showElided); + +protected: + virtual void paintEvent(QPaintEvent *event) override; + +signals: + void ElisionChanged(bool m_elided); + +private: + Q_DISABLE_COPY(VElidedLabel) + bool m_elided{false}; + bool m_showElided{true}; + QString m_content{}; + + bool DrawParagraph(QPainter &painter, const QString& paragraph, int &y, bool &didElide); +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline const QString &VElidedLabel::text() const +{ + return m_content; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VElidedLabel::IsElided() const +{ + return m_elided; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VElidedLabel::ShowElided() const +{ + return m_showElided; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VElidedLabel::SetShowElided(bool showElided) +{ + m_showElided = showElided; +} + +#endif // VELIDEDLABEL_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 437b60d4f..b6023d48c 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -2,6 +2,7 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/velidedlabel.cpp \ $$PWD/vmaingraphicsscene.cpp \ $$PWD/vmaingraphicsview.cpp \ $$PWD/vwidgetpopup.cpp \ @@ -30,6 +31,7 @@ SOURCES += \ HEADERS += \ $$PWD/stable.h \ + $$PWD/velidedlabel.h \ $$PWD/vmaingraphicsscene.h \ $$PWD/vmaingraphicsview.h \ $$PWD/vwidgetpopup.h \