Exemplo n.º 1
0
RegWidget::RegWidget(const char *name, IGui *gui, QWidget *parent) 
    : QWidget(parent) {
    igui_ = gui;
    value_ = 0;

    name_ = QString(name);
    while (name_.size() < 3) {
        name_ += tr(" ");
    }

    std::string t1 = "reg " + std::string(name);
    cmdRead_.make_string(t1.c_str());

    QFont font = QFont("Courier");
    font.setStyleHint(QFont::Monospace);
    font.setPointSize(8);
    font.setFixedPitch(true);
    setFont(font);
    QFontMetrics fm(font);

    QHBoxLayout *pLayout = new QHBoxLayout;
    pLayout->setContentsMargins(4, 1, 4, 1);
    setLayout(pLayout);

    QLabel *label = new QLabel(this);
    QSizePolicy labelSizePolicy(QSizePolicy::Preferred, 
                                QSizePolicy::Preferred);
    labelSizePolicy.setHorizontalStretch(0);
    labelSizePolicy.setVerticalStretch(0);
    labelSizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
    label->setSizePolicy(labelSizePolicy);
    label->setText(name_);
    label->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    pLayout->addWidget(label);

    edit_ = new QLineEdit(this);
    pLayout->addWidget(edit_);
    respValue_ = value_ = 0xfeedfaceull;

    char tstr[64];
    RISCV_sprintf(tstr, sizeof(tstr), "%016" RV_PRI64 "x", value_);
    QString text(tstr);
    edit_->setText(text);
    edit_->setMaxLength(19);
    edit_->setFixedWidth(fm.width(text) + 8);
    edit_->setFixedHeight(fm.height() + 2);

    setMinimumWidth(edit_->width() + fm.width(name_) + 16);
    setMinimumHeight(edit_->height());
}
Exemplo n.º 2
0
void coEditorTextValueWidget::setValue(const QString &valueName, const QString &value,
                                       const QString &readableAttrRule,
                                       const QString &attributeDescription,
                                       bool, const QRegExp &rx)
{
    fvariable = valueName;
    fvalue = value;

    QHBoxLayout *layout;
    QLabel *valueLabel;
    QSpacerItem *spacerItem;

    setObjectName(widgetName);
    setMaximumSize(QSize(16777215, 100));
    setBaseSize(QSize(400, 25));
    setToolTip(attributeDescription);

    layout = new QHBoxLayout(this);
    layout->setSpacing(0);
    layout->setMargin(0);
    layout->setObjectName(QString::fromUtf8("layout"));
    valueLabel = new QLabel(this);
    valueLabel->setText(valueName);
    valueLabel->setObjectName(QString::fromUtf8("valueLabel"));
    valueLabel->setBaseSize(QSize(150, 22));

    QSizePolicy labelSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    labelSizePolicy.setHorizontalStretch(1);
    labelSizePolicy.setVerticalStretch(0);
    labelSizePolicy.setHeightForWidth(valueLabel->sizePolicy().hasHeightForWidth());
    valueLabel->setSizePolicy(labelSizePolicy);

    spacerItem = new QSpacerItem(30, 20, QSizePolicy::Preferred, QSizePolicy::Minimum);

    valueLineEdit = new coEditorValidatedQLineEdit(this);
    valueLineEdit->setObjectName(valueName);
    valueLineEdit->setStatusTip(readableAttrRule);
    QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(3), static_cast<QSizePolicy::Policy>(0));
    sizePolicy.setHorizontalStretch(2);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(valueLineEdit->sizePolicy().hasHeightForWidth());
    valueLineEdit->setSizePolicy(sizePolicy);
    valueLineEdit->setMaximumSize(QSize(16777215, 22));
    valueLineEdit->setBaseSize(QSize(200, 22));
    valueLineEdit->setAlignment(Qt::AlignRight);
    valueLineEdit->setDragEnabled(true);

    if (!rx.isEmpty())
    {
        QValidator *validator = new QRegExpValidator(rx, this);
        valueLineEdit->setValidator(validator);
    }
    // returnPressed is only send, if expression is valid. then we need to call coConfigEntry->setValue
    // connect(valueLineEdit, SIGNAL(returnPressed()), this, SLOT(commitNewEntryValueData()));
    valueLineEdit->setText(value); //setText does not call validate
    valueLineEdit->setModified(false);

    //create Contextmenu - Delete value
    deleteValueAction = new QAction(tr("Delete this Value ?"), valueLabel);
    deleteValueAction->setStatusTip(tr("Delete this value ?"));
    addAction(deleteValueAction);
    setContextMenuPolicy(Qt::ActionsContextMenu);

    if (getType() == coEditorValueWidget::Info || getType() == coEditorValueWidget::InfoName
                                                  /*value.isEmpty() &&*/ /*&& !required*/)
    {
        defaultValue = value;
        //
        valueLineEdit->setStyleSheet("background-color: aliceblue");
        connect(deleteValueAction, SIGNAL(triggered()), this, SLOT(explainShowInfoButton()));
    }
    else
    {
        //is valid checks, and sets background color to red if check fails
        /* if (!empty)*/
        valueLineEdit->isValid();
        connect(deleteValueAction, SIGNAL(triggered()), this, SLOT(suicide()));
    }

    valueLineEdit->adjustSize();

    QSize size(250, 45);
    size = size.expandedTo(minimumSizeHint());
    resize(size);

    //connect to save
    connect(valueLineEdit, SIGNAL(editingFinished()), this, SLOT(save()));
    //    connect ( valueLineEdit, SIGNAL (returnPressed() ), this, SLOT (save() ) );
    //NOTE if we want a nasty nagscreen, connect it here
    //connect ( valueLineEdit, SIGNAL (notValid() ),  , SLOT ( ) );
    connect(valueLineEdit, SIGNAL(notValid()), this, SIGNAL(notValid()));

    layout->addWidget(valueLabel);
    layout->addItem(spacerItem);
    layout->addWidget(valueLineEdit);

    setLayout(layout);
}