2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
2017-07-27 02:34:25 +02:00
|
|
|
QString lcFormatValue(float Value, int Precision);
|
2016-06-13 03:46:50 +02:00
|
|
|
QString lcFormatValueLocalized(float Value);
|
2016-06-14 01:57:31 +02:00
|
|
|
float lcParseValueLocalized(const QString& Value);
|
2015-01-20 00:48:46 +01:00
|
|
|
|
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:
|
2020-03-22 23:44:41 +01:00
|
|
|
lcQTreeWidgetColumnStretcher(QTreeWidget* TreeWidget, int ColumnToStretch);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2020-03-22 23:44:41 +01:00
|
|
|
bool eventFilter(QObject* Object, QEvent* Event) override;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2022-09-07 17:58:26 +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;
|
2022-09-08 08:45:17 +02:00
|
|
|
bool m_interactiveResize;
|
2022-09-07 17:58:26 +02:00
|
|
|
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:
|
2020-03-22 23:44:41 +01:00
|
|
|
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
|
2018-01-01 19:14:05 +01:00
|
|
|
|
|
|
|
protected:
|
2020-03-22 23:44:41 +01:00
|
|
|
bool event(QEvent* Event) override
|
2018-01-01 19:14:05 +01:00
|
|
|
{
|
|
|
|
if (Event->type() == QEvent::ShortcutOverride)
|
|
|
|
{
|
2021-11-15 03:34:24 +01:00
|
|
|
const QKeyEvent* KeyEvent = (QKeyEvent*)Event;
|
|
|
|
const int Key = KeyEvent->key();
|
2018-01-01 19:14:05 +01:00
|
|
|
|
|
|
|
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
|
|
|
};
|
2023-12-31 21:55:35 +01:00
|
|
|
|
|
|
|
class lcStepValidator : public QIntValidator
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
lcStepValidator(lcStep Min, lcStep Max, bool AllowEmpty, QObject* Parent)
|
|
|
|
: QIntValidator(1, INT_MAX, Parent), mMin(Min), mMax(Max), mAllowEmpty(AllowEmpty)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QValidator::State validate(QString& Input, int& Pos) const override
|
|
|
|
{
|
|
|
|
if (mAllowEmpty && Input.isEmpty())
|
|
|
|
return Acceptable;
|
|
|
|
|
|
|
|
bool Ok;
|
|
|
|
lcStep Step = Input.toUInt(&Ok);
|
|
|
|
|
|
|
|
if (Ok)
|
|
|
|
return (Step >= mMin && Step <= mMax) ? Acceptable : Invalid;
|
|
|
|
|
|
|
|
return QIntValidator::validate(Input, Pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
lcStep mMin;
|
|
|
|
lcStep mMax;
|
|
|
|
bool mAllowEmpty;
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcElidableToolButton : public QToolButton
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
lcElidableToolButton(QWidget* Parent)
|
|
|
|
: QToolButton(Parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize sizeHint() const override
|
|
|
|
{
|
|
|
|
QSize Size = QToolButton::sizeHint();
|
|
|
|
|
|
|
|
Size.setWidth(0);
|
|
|
|
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent*)
|
|
|
|
{
|
|
|
|
QStylePainter Painter(this);
|
|
|
|
QStyleOptionToolButton Option;
|
|
|
|
initStyleOption(&Option);
|
|
|
|
|
|
|
|
QRect Button = style()->subControlRect(QStyle::CC_ToolButton, &Option, QStyle::SC_ToolButton, this);
|
|
|
|
int Frame = style()->proxy()->pixelMetric(QStyle::PixelMetric::PM_DefaultFrameWidth, &Option, this);
|
|
|
|
Button = Button.adjusted(Frame, Frame, -Frame, -Frame);
|
|
|
|
|
|
|
|
QFontMetrics Metrics(font());
|
|
|
|
QString ElidedText = Metrics.elidedText(text(), Qt::ElideMiddle, Button.width());
|
|
|
|
|
|
|
|
Option.text = ElidedText;
|
|
|
|
Painter.drawComplexControl(QStyle::CC_ToolButton, Option);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcPieceIdStringModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
lcPieceIdStringModel(lcModel* Model, QObject* Parent);
|
|
|
|
|
|
|
|
QModelIndex Index(PieceInfo* Info) const;
|
|
|
|
std::vector<bool> GetFilteredRows(const QString& FilterText) const;
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& Parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex& Index, int Role = Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<PieceInfo*> mSortedPieces;
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcPieceIdPickerPopup : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
lcPieceIdPickerPopup(lcModel* Model, PieceInfo* Current, QWidget* Parent);
|
|
|
|
|
|
|
|
bool eventFilter(QObject* Object, QEvent* Event) override;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void PieceIdSelected(PieceInfo* Info);
|
|
|
|
|
|
|
|
protected slots:
|
|
|
|
void ListViewDoubleClicked(const QModelIndex& Index);
|
|
|
|
void FilterEdited(const QString& Text);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void EmitSelectedEvent(const QModelIndex& Index);
|
|
|
|
|
|
|
|
QListView* mListView = nullptr;
|
|
|
|
QLineEdit* mFilterEdit = nullptr;
|
|
|
|
};
|