2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_qutils.h"
|
|
|
|
#include "lc_application.h"
|
|
|
|
#include "lc_library.h"
|
|
|
|
#include "pieceinf.h"
|
|
|
|
|
2017-07-27 02:34:25 +02:00
|
|
|
QString lcFormatValue(float Value, int Precision)
|
2015-01-20 00:48:46 +01:00
|
|
|
{
|
2017-07-27 02:34:25 +02:00
|
|
|
QString String = QString::number(Value, 'f', Precision);
|
2015-01-20 00:48:46 +01:00
|
|
|
int Dot = String.indexOf('.');
|
|
|
|
|
|
|
|
if (Dot != -1)
|
|
|
|
{
|
|
|
|
while (String.endsWith('0'))
|
|
|
|
String.chop(1);
|
|
|
|
|
|
|
|
if (String.endsWith('.'))
|
|
|
|
String.chop(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return String;
|
|
|
|
}
|
|
|
|
|
2016-06-13 03:46:50 +02:00
|
|
|
QString lcFormatValueLocalized(float Value)
|
|
|
|
{
|
2016-06-14 01:57:31 +02:00
|
|
|
QLocale Locale = QLocale::system();
|
2016-06-14 02:18:24 +02:00
|
|
|
Locale.setNumberOptions(QLocale::OmitGroupSeparator);
|
2021-07-06 02:00:41 +02:00
|
|
|
QString DecimalPoint = Locale.decimalPoint();
|
2017-07-21 02:57:07 +02:00
|
|
|
QString String = Locale.toString(Value, 'f', 4);
|
2016-06-14 01:57:31 +02:00
|
|
|
|
|
|
|
if (String.indexOf(DecimalPoint) != -1)
|
|
|
|
{
|
|
|
|
while (String.endsWith('0'))
|
|
|
|
String.chop(1);
|
|
|
|
|
|
|
|
if (String.endsWith(DecimalPoint))
|
|
|
|
String.chop(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return String;
|
|
|
|
}
|
|
|
|
|
|
|
|
float lcParseValueLocalized(const QString& Value)
|
|
|
|
{
|
|
|
|
return QLocale::system().toFloat(Value);
|
2016-06-13 03:46:50 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
// Resize all columns to content except for one stretching column. (taken from QT creator)
|
|
|
|
lcQTreeWidgetColumnStretcher::lcQTreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
|
|
|
|
: QObject(treeWidget->header()), m_columnToStretch(columnToStretch)
|
|
|
|
{
|
|
|
|
parent()->installEventFilter(this);
|
|
|
|
QHideEvent fake;
|
|
|
|
lcQTreeWidgetColumnStretcher::eventFilter(parent(), &fake);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lcQTreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev)
|
|
|
|
{
|
|
|
|
if (obj == parent())
|
|
|
|
{
|
|
|
|
if (ev->type() == QEvent::Show)
|
|
|
|
{
|
2021-01-08 19:35:52 +01:00
|
|
|
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(obj);
|
|
|
|
|
|
|
|
for (int i = 0; i < HeaderView->count(); ++i)
|
|
|
|
HeaderView->setSectionResizeMode(i, QHeaderView::Interactive);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
else if (ev->type() == QEvent::Hide)
|
|
|
|
{
|
2021-01-08 19:35:52 +01:00
|
|
|
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(obj);
|
|
|
|
|
|
|
|
for (int i = 0; i < HeaderView->count(); ++i)
|
|
|
|
HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
else if (ev->type() == QEvent::Resize)
|
|
|
|
{
|
2021-01-08 19:35:52 +01:00
|
|
|
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(obj);
|
|
|
|
|
|
|
|
if (HeaderView->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
QResizeEvent *re = static_cast<QResizeEvent*>(ev);
|
|
|
|
int diff = re->size().width() - re->oldSize().width() ;
|
2021-01-08 19:35:52 +01:00
|
|
|
HeaderView->resizeSection(m_columnToStretch, qMax(32, HeaderView->sectionSize(1) + diff));
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|