87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
|
|
#include "rm_text_edit.h"
|
|
#if (USE_JSON_SETTINGS)
|
|
#include <QJsonObject>
|
|
#include <QStyleOption>
|
|
#include <QPainter>
|
|
#include "rm_settings_cfg.h"
|
|
RMTextEdit::RMTextEdit(QWidget *parent,QString title, int index) : QWidget(parent), RMValueSelector(index)
|
|
{
|
|
setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
layout = new QHBoxLayout(this);
|
|
layout->setAlignment(Qt::AlignLeading | Qt::AlignVCenter);
|
|
layout->setContentsMargins(0,2,8,2);
|
|
layout->setSpacing(3);
|
|
|
|
if(!title.isEmpty())
|
|
{
|
|
titleLabel = new QLabel(this);
|
|
titleLabel->setObjectName("text_normal_label");
|
|
titleLabel->setText(title);
|
|
layout->addWidget(titleLabel);
|
|
}
|
|
else
|
|
{
|
|
titleLabel = NULL;
|
|
}
|
|
QJsonObject obj = CFG::items.at(index).toObject();
|
|
edit = new QLineEdit(this);
|
|
edit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
edit->setObjectName("file");
|
|
edit->setText(obj.value("current").toString());
|
|
|
|
/*
|
|
if(obj.contains("regex")) {
|
|
QRegExp re(obj.value("regex").toString());
|
|
QRegExpValidator *validator = new QRegExpValidator(re, this);
|
|
edit->setValidator(validator);
|
|
}
|
|
|
|
if(obj.contains("input_mask")) {
|
|
edit->setInputMask(obj.value("input_mask").toString());
|
|
}
|
|
*/
|
|
connect(edit,SIGNAL(textChanged(const QString &)),SLOT(onTextChanged(const QString &)));
|
|
layout->addWidget(edit);
|
|
connect(RMValueUpdater::instance(),SIGNAL(updateByValues()),SLOT(onUpdateByValue()));
|
|
}
|
|
void RMTextEdit::onTextChanged(const QString &text) {
|
|
QJsonObject obj = CFG::items.at(_object).toObject();
|
|
obj.insert("current",QJsonValue(text));
|
|
CFG::items.replace(_object,obj);
|
|
//qInfo() << text << __FUNCTION__;
|
|
}
|
|
void RMTextEdit::paintEvent(QPaintEvent *pe)
|
|
{
|
|
Q_UNUSED(pe);
|
|
QStyleOption o;
|
|
o.initFrom(this);
|
|
QPainter p(this);
|
|
style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
|
|
}
|
|
void RMTextEdit::onUpdateByValue()
|
|
{
|
|
QJsonObject obj = CFG::items.at(_object).toObject();
|
|
edit->setText(obj.value("current").toString());
|
|
}
|
|
RMGroupTextEdit::RMGroupTextEdit(QWidget *parent,int index) : QGroupBox(parent)
|
|
{
|
|
setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
setObjectName("settings");
|
|
QJsonObject obj = CFG::items.at(index).toObject();
|
|
if(obj.contains("title")) {
|
|
setTitle(obj.value("title").toString());
|
|
}
|
|
|
|
layout = new QVBoxLayout(this);
|
|
layout->setAlignment(Qt::AlignVCenter | Qt::AlignLeading);
|
|
layout->setContentsMargins(8,2,8,2);
|
|
layout->setSpacing(3);
|
|
|
|
|
|
text = new RMTextEdit(this,"",index);
|
|
layout->addWidget(text);
|
|
}
|
|
|
|
#endif // #if (USE_JSON_SETTINGS)
|