leocad/qt/lc_qutils.h

82 lines
1.6 KiB
C
Raw Normal View History

#pragma once
2013-08-09 06:57:18 +02:00
#include <QObject>
QString lcFormatValue(float Value, int Precision);
QString lcFormatValueLocalized(float Value);
float lcParseValueLocalized(const QString& Value);
2013-08-09 06:57:18 +02:00
class lcQTreeWidgetColumnStretcher : public QObject
{
2021-01-07 02:45:38 +01:00
Q_OBJECT
2013-08-09 06:57:18 +02:00
public:
lcQTreeWidgetColumnStretcher(QTreeWidget* TreeWidget, int ColumnToStretch);
2013-08-09 06:57:18 +02:00
bool eventFilter(QObject* Object, QEvent* Event) override;
2013-08-09 06:57:18 +02:00
private slots:
void sectionResized(int LogicalIndex, int OldSize, int NewSize);
private:
2013-08-09 06:57:18 +02:00
const int m_columnToStretch;
bool m_interactiveResize;
int m_stretchWidth;
2013-08-09 06:57:18 +02:00
};
2021-01-07 02:45:38 +01:00
class lcSmallLineEdit : public QLineEdit
2017-11-14 02:24:36 +01:00
{
2021-01-07 02:45:38 +01:00
Q_OBJECT
2017-11-14 02:24:36 +01:00
2021-01-07 02:45:38 +01:00
public:
QSize sizeHint() const override
2017-11-14 02:24:36 +01:00
{
QFontMetrics FontMetrics(font());
2020-12-11 23:51:46 +01:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
2021-11-15 03:34:24 +01:00
const int Width = FontMetrics.horizontalAdvance(QLatin1Char('x')) * 10;
2020-12-11 23:51:46 +01:00
#else
2021-11-15 03:34:24 +01:00
const int Width = FontMetrics.width(QLatin1Char('x')) * 10;
2020-12-11 23:51:46 +01:00
#endif
2017-11-14 02:24:36 +01:00
return QLineEdit::sizeHint() - QSize(Width, 0);
}
2021-01-07 02:45:38 +01:00
};
class lcTransformLineEdit : public lcSmallLineEdit
{
Q_OBJECT
protected:
bool event(QEvent* Event) override
{
if (Event->type() == QEvent::ShortcutOverride)
{
2021-11-15 03:34:24 +01:00
const QKeyEvent* KeyEvent = (QKeyEvent*)Event;
const int Key = KeyEvent->key();
if (KeyEvent->modifiers() == Qt::NoModifier && Key >= Qt::Key_A && Key <= Qt::Key_Z)
Event->accept();
switch (Key)
{
case Qt::Key_Down:
case Qt::Key_Up:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Home:
case Qt::Key_End:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
case Qt::Key_Plus:
case Qt::Key_Minus:
case Qt::Key_Enter:
Event->accept();
break;
}
}
return QLineEdit::event(Event);
}
2017-11-14 02:24:36 +01:00
};