leocad/qt/lc_qutils.h

68 lines
1.3 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
{
public:
lcQTreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch);
virtual bool eventFilter(QObject *obj, QEvent *ev);
const int m_columnToStretch;
};
2017-11-14 02:24:36 +01:00
class lcTransformLineEdit : public QLineEdit
{
public:
lcTransformLineEdit()
: QLineEdit()
{
}
virtual QSize sizeHint() const override
2017-11-14 02:24:36 +01:00
{
QFontMetrics FontMetrics(font());
int Width = FontMetrics.width(QLatin1Char('x')) * 10;
return QLineEdit::sizeHint() - QSize(Width, 0);
}
protected:
virtual bool event(QEvent* Event) override
{
if (Event->type() == QEvent::ShortcutOverride)
{
QKeyEvent* KeyEvent = (QKeyEvent*)Event;
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
};