Fix issue. Elide a variable description in the formula wizard.

This commit is contained in:
Roman Telezhynskyi 2020-05-08 19:15:29 +03:00
parent d6f8a2b8c6
commit 56ec62580c
5 changed files with 444 additions and 184 deletions

View File

@ -35,6 +35,7 @@
- Fix dialog for tool Point along perpendicular. No memory of line color settings. - Fix dialog for tool Point along perpendicular. No memory of line color settings.
- Fix crash after uniting three pieces in sequence. - Fix crash after uniting three pieces in sequence.
- Incorrect conversion to newer curve format. - Incorrect conversion to newer curve format.
- Elide a variable description in the formula wizard.
# Version 0.6.1 October 23, 2018 # Version 0.6.1 October 23, 2018
- [#885] Regression. Broken support for multi size measurements. - [#885] Regression. Broken support for multi size measurements.

View File

@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>448</width> <width>542</width>
<height>478</height> <height>481</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -23,7 +23,7 @@
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_5">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">
@ -172,6 +172,8 @@
</property> </property>
</widget> </widget>
<widget class="QWidget" name=""> <widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="3,1">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -369,17 +371,25 @@
</layout> </layout>
</item> </item>
</layout> </layout>
</widget>
</widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labelDescription"> <widget class="VElidedLabel" name="labelDescription">
<property name="text"> <property name="sizePolicy">
<string/> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="wordWrap"> <property name="frameShape">
<bool>true</bool> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item> <item>
@ -400,6 +410,12 @@
<extends>QPlainTextEdit</extends> <extends>QPlainTextEdit</extends>
<header location="global">vplaintextedit.h</header> <header location="global">vplaintextedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>VElidedLabel</class>
<extends>QFrame</extends>
<header location="global">velidedlabel.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>toolButtonPutHere</tabstop> <tabstop>toolButtonPutHere</tabstop>

View File

@ -0,0 +1,151 @@
/************************************************************************
**
** @file velidedlabel.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "velidedlabel.h"
#include <QPainter>
#include <QTextLayout>
//---------------------------------------------------------------------------------------------------------------------
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("<br>"));
}
toolTip.append(QString("<font>%1</font>").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;
}

View File

@ -0,0 +1,90 @@
/************************************************************************
**
** @file velidedlabel.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VELIDEDLABEL_H
#define VELIDEDLABEL_H
#include <QFrame>
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

View File

@ -2,6 +2,7 @@
# This need for corect working file translations.pro # This need for corect working file translations.pro
SOURCES += \ SOURCES += \
$$PWD/velidedlabel.cpp \
$$PWD/vmaingraphicsscene.cpp \ $$PWD/vmaingraphicsscene.cpp \
$$PWD/vmaingraphicsview.cpp \ $$PWD/vmaingraphicsview.cpp \
$$PWD/vwidgetpopup.cpp \ $$PWD/vwidgetpopup.cpp \
@ -30,6 +31,7 @@ SOURCES += \
HEADERS += \ HEADERS += \
$$PWD/stable.h \ $$PWD/stable.h \
$$PWD/velidedlabel.h \
$$PWD/vmaingraphicsscene.h \ $$PWD/vmaingraphicsscene.h \
$$PWD/vmaingraphicsview.h \ $$PWD/vmaingraphicsview.h \
$$PWD/vwidgetpopup.h \ $$PWD/vwidgetpopup.h \