void ExprShortEdit::setExpressionString(const std::string& expression) { edit->setText(QString(expression.c_str())); controlRebuildTimer->setSingleShot(true); controlRebuildTimer->start(0); checkErrors(); emit exprChanged(); }
void ExprShortEdit::controlChanged(int id) { if (controls) { QString newText = getExpression(); controls->updateText(id, newText); edit->setText(newText); checkErrors(); emit exprChanged(); } }
ExprEditor::ExprEditor(QWidget* parent,ExprControlCollection* controls) : QWidget(parent),_updatingText(0),errorHeight(0) { // timers controlRebuildTimer=new QTimer(); previewTimer=new QTimer(); // title and minimum size setWindowTitle("Expression Editor"); setMinimumHeight(100); // expression controls, we need for signal connections this->controls = controls; // make layout QVBoxLayout* exprAndErrors=new QVBoxLayout; exprAndErrors->setMargin(0); setLayout(exprAndErrors); // create text editor widget exprTe = new ExprTextEdit(this); exprTe->setMinimumHeight(50); // calibrate the font size int fontsize = 12; while (QFontMetrics(QFont("Liberation Sans",fontsize)).width("abcdef")<38 && fontsize<20) fontsize++; while (QFontMetrics(QFont("Liberation Sans",fontsize)).width("abcdef")>44 && fontsize>3) fontsize--; exprTe->setFont(QFont("Liberation Sans",fontsize)); exprAndErrors->addWidget(exprTe); // create error widget errorWidget=new QListWidget(); errorWidget->setSelectionMode(QAbstractItemView::SingleSelection); errorWidget->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum)); connect(errorWidget,SIGNAL(itemSelectionChanged()),SLOT(selectError())); clearErrors(); exprAndErrors->addWidget(errorWidget); // wire up signals connect(exprTe, SIGNAL(applyShortcut()), SLOT(sendApply())); connect(exprTe, SIGNAL(nextError()), SLOT(nextError())); connect(exprTe, SIGNAL(textChanged()), SLOT(exprChanged())); connect(controls,SIGNAL(controlChanged(int)),SLOT(controlChanged(int))); connect(controls,SIGNAL(insertString(const std::string&)),SLOT(insertStr(const std::string&))); connect(controlRebuildTimer, SIGNAL(timeout()), SLOT(rebuildControls())); connect(previewTimer, SIGNAL(timeout()), SLOT(sendPreview())); }
void ExprShortEdit::textFinished() { controlRebuildTimer->setSingleShot(true); controlRebuildTimer->start(0); checkErrors(); emit exprChanged(); }