Fix issue. Elide a variable description in the formula wizard.
This commit is contained in:
parent
d6f8a2b8c6
commit
56ec62580c
|
@ -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.
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>448</width>
|
||||
<height>478</height>
|
||||
<width>542</width>
|
||||
<height>481</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -23,7 +23,7 @@
|
|||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item alignment="Qt::AlignLeft">
|
||||
|
@ -172,6 +172,8 @@
|
|||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="3,1">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
|
@ -369,17 +371,25 @@
|
|||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelDescription">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<widget class="VElidedLabel" name="labelDescription">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -400,6 +410,12 @@
|
|||
<extends>QPlainTextEdit</extends>
|
||||
<header location="global">vplaintextedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>VElidedLabel</class>
|
||||
<extends>QFrame</extends>
|
||||
<header location="global">velidedlabel.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>toolButtonPutHere</tabstop>
|
||||
|
|
151
src/libs/vwidgets/velidedlabel.cpp
Normal file
151
src/libs/vwidgets/velidedlabel.cpp
Normal 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;
|
||||
}
|
90
src/libs/vwidgets/velidedlabel.h
Normal file
90
src/libs/vwidgets/velidedlabel.h
Normal 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
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in New Issue
Block a user