Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+357
@@ -0,0 +1,357 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
*
|
||||
* Widgets that change from Label to * if clicked (and not read only)
|
||||
*
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "rwwidgets.h"
|
||||
#include <QStackedWidget>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <LtsWidgets/lts_bitfield_widget.h>
|
||||
|
||||
void MyLabel::mousePressEvent(QMouseEvent *ev)
|
||||
{
|
||||
Q_UNUSED(ev)
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
||||
ResizableStackedWidget::ResizableStackedWidget(QWidget *parent)
|
||||
: QStackedWidget(parent)
|
||||
{
|
||||
connect(this, &ResizableStackedWidget::currentChanged,
|
||||
this, &ResizableStackedWidget::onCurrentChanged);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
}
|
||||
|
||||
int ResizableStackedWidget::addWigdet(QWidget *widget)
|
||||
{
|
||||
widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
return QStackedWidget::addWidget(widget);
|
||||
}
|
||||
|
||||
int ResizableStackedWidget::insertWidget(int index, QWidget *widget)
|
||||
{
|
||||
widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
return QStackedWidget::insertWidget(index, widget);
|
||||
}
|
||||
|
||||
void ResizableStackedWidget::onCurrentChanged(int index)
|
||||
{
|
||||
QWidget *w = widget(index);
|
||||
Q_ASSERT(w);
|
||||
w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
w->adjustSize();
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
||||
RWWidget::RWWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_label(new MyLabel(this))
|
||||
, m_stackedWidget(new ResizableStackedWidget(this))
|
||||
, m_editableWidget(nullptr)
|
||||
{
|
||||
QVBoxLayout *l = new QVBoxLayout(this);
|
||||
l->setMargin(0);
|
||||
l->setSpacing(0);
|
||||
l->addWidget(m_stackedWidget);
|
||||
m_stackedWidget->insertWidget(0, m_label);
|
||||
|
||||
connect(m_label, &MyLabel::clicked, this, &RWWidget::onSetWritablePrivate);
|
||||
}
|
||||
|
||||
void RWWidget::setToolTip(const QString &string)
|
||||
{
|
||||
m_label->setToolTip(string);
|
||||
if (m_editableWidget)
|
||||
m_editableWidget->setToolTip(string);
|
||||
}
|
||||
|
||||
void RWWidget::onSetWritable()
|
||||
{
|
||||
if (m_editableWidget)
|
||||
m_stackedWidget->setCurrentWidget(m_editableWidget);
|
||||
}
|
||||
|
||||
void RWWidget::onSetWritablePrivate()
|
||||
{
|
||||
onSetWritable();
|
||||
if (m_editableWidget)
|
||||
emit writableRequested();
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
||||
RWSpinBox::RWSpinBox(RwMode readOnly, QWidget *parent)
|
||||
: RWWidget(parent)
|
||||
, m_spinBox(readOnly == RwMode::ReadOnly ? nullptr : new QSpinBox(this))
|
||||
{
|
||||
if(!m_spinBox)
|
||||
return;
|
||||
|
||||
m_editableWidget = m_spinBox;
|
||||
m_spinBox->setMinimum(std::numeric_limits<int>::min());
|
||||
m_spinBox->setMaximum(std::numeric_limits<int>::max());
|
||||
m_stackedWidget->insertWidget(1, m_editableWidget);
|
||||
onSetWritable();
|
||||
}
|
||||
|
||||
void RWSpinBox::setMinimum(int min)
|
||||
{
|
||||
if (m_spinBox)
|
||||
m_spinBox->setMinimum(min);
|
||||
}
|
||||
|
||||
void RWSpinBox::setMaximum(int max)
|
||||
{
|
||||
if (m_spinBox)
|
||||
m_spinBox->setMaximum(max);
|
||||
}
|
||||
|
||||
void RWSpinBox::setValue(int val)
|
||||
{
|
||||
m_label->setText(QString::number(val));
|
||||
if (m_spinBox)
|
||||
m_spinBox->setValue(val);
|
||||
}
|
||||
|
||||
int RWSpinBox::value() const
|
||||
{
|
||||
return m_spinBox ? m_spinBox->value() : m_label->text().toInt();
|
||||
}
|
||||
|
||||
/*****************************************************/
|
||||
|
||||
|
||||
RWDoubleSpinBox::RWDoubleSpinBox(RwMode readOnly, QWidget *parent)
|
||||
: RWWidget(parent)
|
||||
, m_doubleSpinBox(readOnly == RwMode::ReadOnly ? nullptr : new QDoubleSpinBox(this))
|
||||
, m_precision(8)
|
||||
{
|
||||
if(!m_doubleSpinBox)
|
||||
return;
|
||||
|
||||
m_editableWidget = m_doubleSpinBox;
|
||||
m_stackedWidget->insertWidget(1, m_editableWidget);
|
||||
setDecimals(m_precision);
|
||||
connect(m_doubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &RWDoubleSpinBox::valueChanged);
|
||||
onSetWritable();
|
||||
}
|
||||
|
||||
void RWDoubleSpinBox::setMinimum(double min)
|
||||
{
|
||||
if (m_doubleSpinBox)
|
||||
m_doubleSpinBox->setMinimum(min);
|
||||
}
|
||||
|
||||
void RWDoubleSpinBox::setMaximum(double max)
|
||||
{
|
||||
if (m_doubleSpinBox)
|
||||
m_doubleSpinBox->setMaximum(max);
|
||||
}
|
||||
|
||||
void RWDoubleSpinBox::setDecimals(int prec)
|
||||
{
|
||||
m_precision = prec;
|
||||
if (m_doubleSpinBox)
|
||||
m_doubleSpinBox->setDecimals(prec);
|
||||
m_label->setText(QString::number(m_label->text().toDouble(), 'f', prec));
|
||||
}
|
||||
|
||||
void RWDoubleSpinBox::setValue(double val)
|
||||
{
|
||||
m_label->setText(QString::number(val, 'f', m_precision));
|
||||
if (m_doubleSpinBox)
|
||||
m_doubleSpinBox->setValue(val);
|
||||
emit valueChanged();
|
||||
}
|
||||
|
||||
double RWDoubleSpinBox::value() const
|
||||
{
|
||||
return m_doubleSpinBox ? m_doubleSpinBox->value() : m_label->text().toDouble();
|
||||
}
|
||||
|
||||
/*****************************************************/
|
||||
|
||||
|
||||
RWCheckBox::RWCheckBox(RwMode readOnly, QWidget *parent)
|
||||
: RWWidget(parent)
|
||||
, m_checkBox(readOnly == RwMode::ReadOnly ? nullptr : new QCheckBox(this))
|
||||
{
|
||||
if(!m_checkBox)
|
||||
return;
|
||||
|
||||
m_editableWidget = m_checkBox;
|
||||
m_stackedWidget->insertWidget(1, m_editableWidget);
|
||||
onSetWritable();
|
||||
}
|
||||
|
||||
void RWCheckBox::setChecked(bool val)
|
||||
{
|
||||
m_label->setText(val ? tr("Yes") : tr("No"));
|
||||
if (m_checkBox)
|
||||
m_checkBox->setChecked(val);
|
||||
}
|
||||
|
||||
bool RWCheckBox::isChecked() const
|
||||
{
|
||||
return m_checkBox ? m_checkBox->isChecked() : (m_label->text() == tr("Yes"));
|
||||
}
|
||||
|
||||
/*****************************************************/
|
||||
|
||||
|
||||
RWLineEdit::RWLineEdit(RwMode readOnly, QWidget *parent)
|
||||
: RWWidget(parent)
|
||||
, m_lineEdit(readOnly == RwMode::ReadOnly ? nullptr : new QLineEdit(this))
|
||||
{
|
||||
if(!m_lineEdit)
|
||||
return;
|
||||
|
||||
m_editableWidget = m_lineEdit;
|
||||
m_stackedWidget->insertWidget(1, m_editableWidget);
|
||||
onSetWritable();
|
||||
}
|
||||
|
||||
void RWLineEdit::setMaxLength(int length)
|
||||
{
|
||||
if (m_lineEdit)
|
||||
m_lineEdit->setMaxLength(length);
|
||||
}
|
||||
|
||||
void RWLineEdit::setText(const QString &val)
|
||||
{
|
||||
m_label->setText(val);
|
||||
if (m_lineEdit)
|
||||
m_lineEdit->setText(val);
|
||||
}
|
||||
|
||||
QString RWLineEdit::text() const
|
||||
{
|
||||
return m_lineEdit ? m_lineEdit->text() : m_label->text();
|
||||
}
|
||||
|
||||
/*****************************************************/
|
||||
|
||||
|
||||
RWComboBox::RWComboBox(RwMode readOnly, QWidget *parent)
|
||||
: RWWidget(parent)
|
||||
, m_comboBox(readOnly == RwMode::ReadOnly ? nullptr : new QComboBox(this))
|
||||
{
|
||||
if(!m_comboBox)
|
||||
return;
|
||||
|
||||
m_editableWidget = m_comboBox;
|
||||
m_stackedWidget->insertWidget(1, m_editableWidget);
|
||||
onSetWritable();
|
||||
}
|
||||
|
||||
void RWComboBox::addItem(const QString &text, int ordinal)
|
||||
{
|
||||
if (m_comboBox)
|
||||
m_comboBox->addItem(text, ordinal);
|
||||
m_values.insert(ordinal, text);
|
||||
}
|
||||
|
||||
void RWComboBox::insertItem(int index, const QString &text, int ordinal)
|
||||
{
|
||||
if (m_comboBox)
|
||||
m_comboBox->insertItem(index, text, ordinal);
|
||||
m_values.insert(ordinal, text);
|
||||
}
|
||||
|
||||
int RWComboBox::count() const
|
||||
{
|
||||
return (m_comboBox ? m_comboBox->count() : 0);
|
||||
}
|
||||
|
||||
//int RWComboBox::currentIndex() const
|
||||
//{
|
||||
// return (m_comboBox ? m_comboBox->currentIndex() : 0);
|
||||
//}
|
||||
|
||||
int RWComboBox::currentValue() const
|
||||
{
|
||||
return (m_comboBox ? m_comboBox->itemData(m_comboBox->currentIndex()).toInt() : m_values.key(m_label->text()));
|
||||
}
|
||||
|
||||
QString RWComboBox::currentText() const
|
||||
{
|
||||
return (m_comboBox ? m_comboBox->currentText() : m_label->text());
|
||||
}
|
||||
|
||||
//void RWComboBox::setCurrentIndex(int index)
|
||||
//{
|
||||
// if (m_comboBox)
|
||||
// {
|
||||
// m_comboBox->setCurrentIndex(index);
|
||||
// m_label->setText(m_comboBox->currentText());
|
||||
// }
|
||||
// // Impossible for readOnly! Map is not indexed...
|
||||
//}
|
||||
|
||||
void RWComboBox::setCurrentValue(int ordinal)
|
||||
{
|
||||
if (m_comboBox)
|
||||
m_comboBox->setCurrentIndex(m_comboBox->findData(ordinal));
|
||||
m_label->setText(m_values.value(ordinal));
|
||||
}
|
||||
|
||||
/*****************************************************/
|
||||
|
||||
RWBitfieldWidget::RWBitfieldWidget(RwMode readOnly, QWidget *parent)
|
||||
: RWWidget(parent)
|
||||
, m_bitfield(readOnly == RwMode::ReadOnly ? nullptr : new LtsWidgets::LtsBitfieldWidget(parent, 0))
|
||||
{
|
||||
if(!m_bitfield)
|
||||
return;
|
||||
|
||||
m_editableWidget = m_bitfield;
|
||||
m_stackedWidget->insertWidget(1, m_editableWidget);
|
||||
connect(m_bitfield, &LtsWidgets::LtsBitfieldWidget::valueChanged , this, &RWBitfieldWidget::valueChanged);
|
||||
connect(m_bitfield, &LtsWidgets::LtsBitfieldWidget::hasCaptionChanged, this, &RWBitfieldWidget::hasCaptionChanged);
|
||||
onSetWritable();
|
||||
}
|
||||
|
||||
void RWBitfieldWidget::setValue(quint8 val)
|
||||
{
|
||||
m_label->setText(QLatin1Literal("0b") + QString::number(val,2));
|
||||
if (m_bitfield)
|
||||
m_bitfield->setValue(val);
|
||||
}
|
||||
|
||||
quint8 RWBitfieldWidget::value()
|
||||
{
|
||||
if(!m_bitfield)
|
||||
return m_label->text().remove(0,2).toUInt(nullptr,2);
|
||||
|
||||
return m_bitfield->value();
|
||||
}
|
||||
|
||||
void RWBitfieldWidget::setHasCaption(bool option)
|
||||
{
|
||||
if (m_bitfield)
|
||||
m_bitfield->setHasCaption(option);
|
||||
}
|
||||
|
||||
bool RWBitfieldWidget::hasCaption()
|
||||
{
|
||||
return m_bitfield ? m_bitfield->hasCaption() : false;
|
||||
}
|
||||
|
||||
|
||||
Executable
+202
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
*
|
||||
* Widgets that change from QLabel to Q* if clicked (and not read only)
|
||||
*
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QStackedWidget>
|
||||
#include <QMap>
|
||||
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
class QCheckBox;
|
||||
class QLineEdit;
|
||||
class QComboBox;
|
||||
|
||||
namespace LtsWidgets {
|
||||
class LtsBitfieldWidget;
|
||||
}
|
||||
|
||||
enum class RwMode {
|
||||
ReadOnly,
|
||||
WriteOnly,
|
||||
ReadWrite
|
||||
};
|
||||
|
||||
class MyLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using QLabel::QLabel;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *ev);
|
||||
|
||||
};
|
||||
|
||||
class ResizableStackedWidget : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResizableStackedWidget(QWidget *parent = nullptr);
|
||||
|
||||
int addWigdet(QWidget *widget);
|
||||
int insertWidget(int index, QWidget *widget);
|
||||
|
||||
private slots:
|
||||
void onCurrentChanged(int index);
|
||||
|
||||
};
|
||||
|
||||
class RWWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWWidget(QWidget *parent = nullptr);
|
||||
|
||||
void setToolTip(const QString &string);
|
||||
|
||||
public slots:
|
||||
void onSetWritable();
|
||||
|
||||
private slots:
|
||||
void onSetWritablePrivate();
|
||||
|
||||
signals:
|
||||
void writableRequested();
|
||||
|
||||
protected:
|
||||
MyLabel *m_label;
|
||||
ResizableStackedWidget *m_stackedWidget;
|
||||
QWidget *m_editableWidget;
|
||||
|
||||
};
|
||||
|
||||
class RWSpinBox : public RWWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWSpinBox(RwMode readOnly = RwMode::ReadWrite, QWidget *parent = nullptr);
|
||||
|
||||
void setMinimum(int min);
|
||||
void setMaximum(int max);
|
||||
|
||||
void setValue(int val);
|
||||
int value() const;
|
||||
|
||||
private:
|
||||
QSpinBox *m_spinBox;
|
||||
|
||||
};
|
||||
|
||||
class RWDoubleSpinBox : public RWWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWDoubleSpinBox(RwMode readOnly = RwMode::ReadWrite, QWidget *parent = nullptr);
|
||||
|
||||
void setMinimum(double min);
|
||||
void setMaximum(double max);
|
||||
void setDecimals(int prec);
|
||||
|
||||
void setValue(double val);
|
||||
double value() const;
|
||||
|
||||
signals:
|
||||
void valueChanged();
|
||||
private:
|
||||
QDoubleSpinBox *m_doubleSpinBox;
|
||||
int m_precision;
|
||||
|
||||
};
|
||||
|
||||
class RWCheckBox : public RWWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWCheckBox(RwMode readOnly = RwMode::ReadWrite, QWidget *parent = nullptr);
|
||||
|
||||
void setChecked(bool val);
|
||||
bool isChecked() const;
|
||||
|
||||
private:
|
||||
QCheckBox *m_checkBox;
|
||||
|
||||
};
|
||||
|
||||
class RWLineEdit : public RWWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWLineEdit(RwMode readOnly = RwMode::ReadWrite, QWidget *parent = nullptr);
|
||||
|
||||
void setMaxLength(int length);
|
||||
|
||||
void setText(const QString &text);
|
||||
QString text() const;
|
||||
|
||||
private:
|
||||
QLineEdit *m_lineEdit;
|
||||
|
||||
};
|
||||
|
||||
class RWComboBox : public RWWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWComboBox(RwMode readOnly = RwMode::ReadWrite, QWidget *parent = nullptr);
|
||||
|
||||
void addItem(const QString &text, int ordinal = -1);
|
||||
void insertItem(int index, const QString &text, int ordinal = -1);
|
||||
int count() const;
|
||||
// int currentIndex() const; //Shouldn't be used...
|
||||
int currentValue() const;
|
||||
QString currentText() const;
|
||||
// void setCurrentIndex(int index); //Shouldn't be used...
|
||||
void setCurrentValue(int ordinal);
|
||||
|
||||
|
||||
private:
|
||||
QComboBox *m_comboBox;
|
||||
QMap<int, QString> m_values; // For ReadOnly without ComboBox
|
||||
|
||||
};
|
||||
|
||||
class RWBitfieldWidget : public RWWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RWBitfieldWidget(RwMode readOnly = RwMode::ReadWrite, QWidget *parent = nullptr);
|
||||
|
||||
void setValue(quint8 val);
|
||||
quint8 value();
|
||||
|
||||
void setHasCaption(bool option);
|
||||
bool hasCaption();
|
||||
|
||||
signals:
|
||||
void valueChanged(quint8 newValue);
|
||||
void hasCaptionChanged(bool option);
|
||||
|
||||
private:
|
||||
LtsWidgets::LtsBitfieldWidget *m_bitfield;
|
||||
};
|
||||
Reference in new issue
Block a user