int mrutils::ColChooser::get() { if (!init_ && !(init_ = init())) { return -1; } if (building >= 0) build(); if (active == -1) { active = 0; if (!data[0].choices.empty()) data[0].highlight(0); } attrset(ATR_INPUT); int c; for (;;) { c = getch(); if (enteringSearch) { switch (c) { case '/': case '\n': enteringSearch = false; printPrompt(name.c_str()); break; case '?': enteringSearch = false; data[active].applySearch = false; data[active].resetSearch(); data[active].highlight( 0 ); break; case KEY_ESC: enteringSearch = data[active].applySearch = false; data[active].resetSearch(); data[active].highlight(0); break; case KEY_BACKSPACE: case KEY_DELETE: if (inputP == data[active].search) { enteringSearch = data[active].applySearch = false; data[active].resetSearch(); data[active].highlight(0); } else { *(--inputP) = '\0'; data[active].resetSearch(); data[active].highlight(0); printPrompt(data[active].search,"/"); } break; default: *inputP++ = c; *inputP = '\0'; data[active].resetSearch(); data[active].highlight(0); printPrompt(data[active].search,"/"); } } else { if (c == 'q' || c == ';') break; switch(c) { case KEY_ESC: case '?': if (data[active].applySearch) { data[active].applySearch = false; data[active].resetSearch(); data[active].highlight( 0 ); } break; case 'o': if (active == data.size()-1 && openFn != NULL) { (openFn)(*this,openData); redraw(); break; } case '\n': { if (!acceptReturn) break; selectNumber = 0; if (active == data.size()-1) { return depth[active]; } else { nextColumn(); } break; } case KEY_MOUSE: selectNumber = 0; if ((c = mouse()) >= 0) { if (!acceptReturn) break; return c; } break; case 'L': redraw(); break; case 'l': selectNumber = 0; nextColumn(); break; case 'h': selectNumber = 0; prevColumn(); break; case 'j': selectNumber = 0; data[active].highlightNext(); break; case 'k': selectNumber = 0; data[active].highlightPrev(); break; case '.': // repeat last command if (lastCommand[0] == '\0') break; strcpy(data[active].search, lastCommand); printPrompt(data[active].search, "sent command "); return -1; case 'x': case 'm': if (active == data.size()-1) { toggleTargetInternal(depth[active]); } break; case '>': selectNumber = 0; printPrompt(">"); enteringText = true; wattrset((WINDOW*)chooserWin,ATR_INPUT); getnstr(data[active].search,sizeof(data[active].search)); mrutils::compress(data[active].search); strcpy(lastCommand, data[active].search); if (data[active].search[0] == '\0') { resetPrompt(); enteringText = false; break; } enteringText = false; return -1; case 'p': case 'u': selectNumber = 0; data[active].pageUp(); break; case 'd': case 'n': case ' ': selectNumber = 0; data[active].pageDn(); break; case '/': inputP = data[active].search; data[active].applySearch = true; enteringSearch = true; printPrompt("search for..."); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': { if (data[active].choices.empty()) break; if (selectNumber == 0) inputP = data[active].search; int tmp = 10 * selectNumber + (c - '0'); if (tmp >= data[active].choices.size() + startIndex) { printPrompt(data[active].search); break; } else { *inputP++ = c; *inputP = '\0'; selectNumber = tmp; if (selectNumber >= data[active].head+startIndex && selectNumber <= data[active].tail+startIndex) data[active].highlight(selectNumber - startIndex, false, false); printPrompt(data[active].search); } break; } case KEY_BACKSPACE: case KEY_DELETE: if (data[active].choices.empty()) break; if (selectNumber == 0) { resetPrompt(); break; } selectNumber -= *(--inputP) - '0'; selectNumber /= 10; *inputP = '\0'; if (data[active].search[0] == '\0') { resetPrompt(); } else { if (selectNumber >= data[active].head && selectNumber <= data[active].tail) data[active].highlight(selectNumber, false, false); printPrompt(data[active].search); } break; default: resetPrompt(); } } } data[active].search[0] = '\0'; done(); return -1; }
setColValuesDialog::setColValuesDialog( ScriptingEnv *env, QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { scriptEnv = env; if ( !name ) setName( "setColValuesDialog" ); setCaption( tr( "QtiPlot - Set column values" ) ); setFocusPolicy( QDialog::StrongFocus ); QHBox *hbox1=new QHBox (this, "hbox1"); hbox1->setSpacing (5); QVBox *box1=new QVBox (hbox1, "box2"); box1->setSpacing (5); explain = new QTextEdit(box1, "explain" ); explain->setReadOnly (true); explain->setPaletteBackgroundColor(QColor(197, 197, 197)); colNameLabel = new QLabel(box1, "colNameLabel" ); QVBox *box2=new QVBox (hbox1, "box2"); box2->setMargin(5); box2->setFrameStyle (QFrame::Box); QHBox *hbox2=new QHBox (box2, "hbox2"); hbox2->setMargin(5); hbox2->setSpacing (5); QLabel *TextLabel1 = new QLabel(hbox2, "TextLabel1" ); TextLabel1->setText( tr( "For row (i)" ) ); start = new QSpinBox(hbox2, "start" ); QLabel *TextLabel2 = new QLabel(hbox2, "TextLabel2" ); TextLabel2->setText( tr( "to" ) ); end = new QSpinBox(hbox2, "end" ); start->setMinValue(1); end->setMinValue(1); if (sizeof(int)==2) { // 16 bit signed integer start->setMaxValue(0x7fff); end->setMaxValue(0x7fff); } else { // 32 bit signed integer start->setMaxValue(0x7fffffff); end->setMaxValue(0x7fffffff); } QButtonGroup *GroupBox0 = new QButtonGroup(2,QGroupBox::Horizontal,tr( "" ),box2, "GroupBox0" ); GroupBox0->setLineWidth(0); GroupBox0->setFlat(true); functions = new QComboBox( FALSE, GroupBox0, "functions" ); PushButton3 = new QPushButton(GroupBox0, "PushButton3" ); PushButton3->setText( tr( "Add function" ) ); boxColumn = new QComboBox( FALSE, GroupBox0, "boxColumn" ); PushButton4 = new QPushButton(GroupBox0, "PushButton4" ); PushButton4->setText( tr( "Add column" ) ); QHBox *hbox6=new QHBox (GroupBox0, "hbox6"); hbox6->setSpacing (5); buttonPrev = new QPushButton( hbox6, "buttonPrev" ); buttonPrev->setText("&<<"); buttonNext = new QPushButton( hbox6, "buttonNext" ); buttonNext->setText("&>>"); addCellButton = new QPushButton(GroupBox0, "addCellButton" ); addCellButton->setText( tr( "Add cell" ) ); QHBox *hbox3=new QHBox (this, "hbox3"); hbox3->setSpacing (5); commandes = new ScriptEdit( env, hbox3, "commandes" ); commandes->setGeometry( QRect(10, 100, 260, 70) ); commandes->setFocus(); QVBox *box3=new QVBox (hbox3,"box3"); box3->setSpacing (5); btnOk = new QPushButton(box3, "btnOk" ); btnOk->setText( tr( "OK" ) ); btnApply = new QPushButton(box3, "btnApply" ); btnApply->setText( tr( "Apply" ) ); btnCancel = new QPushButton( box3, "btnCancel" ); btnCancel->setText( tr( "Cancel" ) ); QVBoxLayout* layout = new QVBoxLayout(this,5,5, "hlayout3"); layout->addWidget(hbox1); layout->addWidget(hbox3); setFunctions(); insertExplain(0); connect(PushButton3, SIGNAL(clicked()),this, SLOT(insertFunction())); connect(PushButton4, SIGNAL(clicked()),this, SLOT(insertCol())); connect(addCellButton, SIGNAL(clicked()),this, SLOT(insertCell())); connect(btnOk, SIGNAL(clicked()),this, SLOT(accept())); connect(btnApply, SIGNAL(clicked()),this, SLOT(apply())); connect(btnCancel, SIGNAL(clicked()),this, SLOT(close())); connect(functions, SIGNAL(activated(int)),this, SLOT(insertExplain(int))); connect(buttonPrev, SIGNAL(clicked()), this, SLOT(prevColumn())); connect(buttonNext, SIGNAL(clicked()), this, SLOT(nextColumn())); }
SetColValuesDialog::SetColValuesDialog( ScriptingEnv *env, QWidget* parent, Qt::WFlags fl ) : QDialog( parent, fl ), scripted(env) { setName( "SetColValuesDialog" ); setWindowTitle( tr( "QtiPlot - Set column values" ) ); setSizeGripEnabled(true); QHBoxLayout *hbox1 = new QHBoxLayout(); hbox1->addWidget(new QLabel(tr("For row (i)"))); start = new QSpinBox(); start->setMinValue(1); hbox1->addWidget(start); hbox1->addWidget(new QLabel(tr("to"))); end = new QSpinBox(); end->setMinValue(1); hbox1->addWidget(end); if (sizeof(int)==2) { // 16 bit signed integer start->setMaxValue(0x7fff); end->setMaxValue(0x7fff); } else { // 32 bit signed integer start->setMaxValue(0x7fffffff); end->setMaxValue(0x7fffffff); } QGridLayout *gl1 = new QGridLayout(); functions = new QComboBox(false); gl1->addWidget(functions, 0, 0); btnAddFunction = new QPushButton(tr( "Add function" )); gl1->addWidget(btnAddFunction, 0, 1); boxColumn = new QComboBox(false); gl1->addWidget(boxColumn, 1, 0); btnAddCol = new QPushButton(tr( "Add column" )); gl1->addWidget(btnAddCol, 1, 1); QHBoxLayout *hbox3 = new QHBoxLayout(); hbox3->addStretch(); buttonPrev = new QPushButton("&<<"); hbox3->addWidget(buttonPrev); buttonNext = new QPushButton("&>>"); hbox3->addWidget(buttonNext); gl1->addLayout(hbox3, 2, 0); addCellButton = new QPushButton(tr( "Add cell" )); gl1->addWidget(addCellButton, 2, 1); QGroupBox *gb = new QGroupBox(); QVBoxLayout *vbox1 = new QVBoxLayout(); vbox1->addLayout(hbox1); vbox1->addLayout(gl1); gb->setLayout(vbox1); gb->setSizePolicy(QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred)); explain = new QTextEdit(); explain->setReadOnly (true); explain->setSizePolicy(QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred)); QPalette palette = explain->palette(); palette.setColor(QPalette::Active, QPalette::Base, Qt::lightGray); explain->setPalette(palette); QHBoxLayout *hbox2 = new QHBoxLayout(); hbox2->addWidget(explain); hbox2->addWidget(gb); commands = new ScriptEdit( scriptEnv); QVBoxLayout *vbox2 = new QVBoxLayout(); btnApply = new QPushButton(tr( "&Apply" )); vbox2->addWidget(btnApply); btnCancel = new QPushButton(tr( "&Close" )); vbox2->addWidget(btnCancel); vbox2->addStretch(); QHBoxLayout *hbox4 = new QHBoxLayout(); hbox4->addWidget(commands); hbox4->addLayout(vbox2); QVBoxLayout* vbox3 = new QVBoxLayout(); vbox3->addLayout(hbox2); #ifdef SCRIPTING_PYTHON boxMuParser = NULL; if (env->name() != QString("muParser")){ boxMuParser = new QCheckBox(tr("Use built-in muParser (much faster)")); boxMuParser->setChecked(true); vbox3->addWidget(boxMuParser); } #endif colNameLabel = new QLabel(); vbox3->addWidget(colNameLabel); vbox3->addLayout(hbox4); setLayout(vbox3); setFocusProxy (commands); commands->setFocus(); functions->insertStringList(scriptEnv->mathFunctions(), -1); if (functions->count() > 0) insertExplain(0); connect(btnAddFunction, SIGNAL(clicked()),this, SLOT(insertFunction())); connect(btnAddCol, SIGNAL(clicked()),this, SLOT(insertCol())); connect(addCellButton, SIGNAL(clicked()),this, SLOT(insertCell())); connect(btnApply, SIGNAL(clicked()),this, SLOT(apply())); connect(btnCancel, SIGNAL(clicked()),this, SLOT(close())); connect(functions, SIGNAL(activated(int)),this, SLOT(insertExplain(int))); connect(buttonPrev, SIGNAL(clicked()), this, SLOT(prevColumn())); connect(buttonNext, SIGNAL(clicked()), this, SLOT(nextColumn())); }
TableDialog::TableDialog(Table *t, QWidget* parent, Qt::WFlags fl ) : QDialog( parent, fl), d_table(t) { setName( "TableDialog" ); setWindowTitle( tr( "MantidPlot - Column options" ) ); setSizeGripEnabled(true); QHBoxLayout *hboxa = new QHBoxLayout(); hboxa->addWidget(new QLabel(tr( "Column Name:" ))); colName = new QLineEdit(); hboxa->addWidget(colName); enumerateAllBox = new QCheckBox(tr("Enumerate all to the right" )); buttonPrev = new QPushButton("&<<"); buttonPrev->setAutoDefault(false); buttonPrev->setMaximumWidth(40); buttonNext = new QPushButton("&>>"); buttonNext->setAutoDefault(false); buttonNext->setMaximumWidth(40); QHBoxLayout *hboxb = new QHBoxLayout(); hboxb->addWidget(buttonPrev); hboxb->addWidget(buttonNext); hboxb->addStretch(); QVBoxLayout *vbox1 = new QVBoxLayout(); vbox1->addLayout(hboxa); vbox1->addWidget(enumerateAllBox); vbox1->addLayout(hboxb); buttonOk = new QPushButton(tr( "&OK" )); buttonOk->setDefault(true); buttonApply = new QPushButton(tr("&Apply")); buttonApply->setAutoDefault(false); buttonCancel = new QPushButton(tr( "&Cancel" )); buttonCancel->setAutoDefault(false); QVBoxLayout *vbox2 = new QVBoxLayout(); vbox2->setSpacing(5); vbox2->setMargin(5); vbox2->addWidget(buttonOk); vbox2->addWidget(buttonApply); vbox2->addWidget(buttonCancel); QHBoxLayout *hbox1 = new QHBoxLayout(); hbox1->setSpacing(5); hbox1->addLayout(vbox1); hbox1->addLayout(vbox2); QGridLayout *gl1 = new QGridLayout(); gl1->addWidget(new QLabel( tr("Plot Designation:")), 0, 0); columnsBox = new QComboBox(); columnsBox->addItem(tr("None")); columnsBox->addItem(tr("X (abscissae)")); columnsBox->addItem(tr("Y (ordinates)")); columnsBox->addItem(tr("Z (height)")); columnsBox->addItem(tr("X Error")); columnsBox->addItem(tr("Y Error")); columnsBox->addItem(tr("Label")); gl1->addWidget(columnsBox, 0, 1); gl1->addWidget(new QLabel(tr("Display")), 1, 0); displayBox = new QComboBox(); displayBox->addItem(tr("Numeric")); displayBox->addItem(tr("Text")); displayBox->addItem(tr("Date")); displayBox->addItem(tr("Time")); displayBox->addItem(tr("Month")); displayBox->addItem(tr("Day of Week")); gl1->addWidget(displayBox, 1, 1); labelFormat = new QLabel(tr( "Format:" )); gl1->addWidget(labelFormat, 2, 0); formatBox = new QComboBox(); gl1->addWidget(formatBox, 2, 1); labelNumeric = new QLabel(tr( "Precision:" )); gl1->addWidget(labelNumeric, 3, 0); precisionBox = new QSpinBox(); precisionBox->setRange(0, 13); gl1->addWidget(precisionBox, 3, 1); boxReadOnly = new QCheckBox(tr("&Read-only" )); gl1->addWidget(boxReadOnly, 4, 0); boxHideColumn = new QCheckBox(tr("&Hidden" )); gl1->addWidget(boxHideColumn, 4, 1); applyToRightCols = new QCheckBox(tr( "Apply to all columns to the right" )); QVBoxLayout *vbox3 = new QVBoxLayout(); vbox3->addLayout(gl1); vbox3->addWidget(applyToRightCols); QGroupBox *gb = new QGroupBox(tr("Options")); gb->setLayout(vbox3); QHBoxLayout *hbox2 = new QHBoxLayout(); hbox2->addWidget(new QLabel(tr( "Column Width:" ))); colWidth = new QSpinBox(); colWidth->setRange(0, 1000); colWidth->setSingleStep(10); hbox2->addWidget(colWidth); applyToAllBox = new QCheckBox(tr( "Apply to all" )); hbox2->addWidget(applyToAllBox); comments = new QTextEdit(); boxShowTableComments = new QCheckBox(tr("&Display Comments in Header")); boxShowTableComments->setChecked(d_table->commentsEnabled()); QVBoxLayout* vbox4 = new QVBoxLayout(); vbox4->addLayout(hbox1); vbox4->addWidget(gb); vbox4->addLayout(hbox2); vbox4->addWidget(new QLabel(tr( "Comment:" ))); vbox4->addWidget(comments); vbox4->addWidget(boxShowTableComments); setLayout(vbox4); setFocusProxy (colName); updateColumn(d_table->selectedColumn()); // signals and slots connections connect(colWidth, SIGNAL(valueChanged(int)), this, SLOT(setColumnWidth(int))); connect(buttonApply, SIGNAL(clicked()), this, SLOT(apply())); connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); connect(buttonCancel, SIGNAL( clicked() ), this, SLOT( close() ) ); connect(columnsBox, SIGNAL(activated(int)), this, SLOT(setPlotDesignation(int)) ); connect(displayBox, SIGNAL(activated(int)), this, SLOT(updateDisplay(int))); connect(buttonPrev, SIGNAL(clicked()), this, SLOT(prevColumn())); connect(buttonNext, SIGNAL(clicked()), this, SLOT(nextColumn())); connect(formatBox, SIGNAL(activated(int)), this, SLOT(enablePrecision(int)) ); connect(precisionBox, SIGNAL(valueChanged(int)), this, SLOT(updatePrecision(int))); connect(boxShowTableComments, SIGNAL(toggled(bool)), d_table, SLOT(showComments(bool))); }
SetColValuesDialog::SetColValuesDialog(ScriptingEnv *env, Table *t, Qt::WFlags fl) : QDialog(t, fl), Scripted(env) { setObjectName("SetColValuesDialog"); setWindowTitle(tr("MantidPlot - Set column values")); setSizeGripEnabled(true); QHBoxLayout *hbox1 = new QHBoxLayout(); hbox1->addWidget(new QLabel(tr("For row (i)"))); start = new QSpinBox(); start->setMinimum(1); hbox1->addWidget(start); hbox1->addWidget(new QLabel(tr("to"))); end = new QSpinBox(); end->setMinimum(1); hbox1->addWidget(end); // Ideally this would be checked at compile time. Until we have 'constexpr if` // on all platforms, the added complexity and minimal cost isn't worthwhile. if (sizeof(int) == 2) { // 16 bit signed integer start->setMaximum(0x7fff); end->setMaximum(0x7fff); } else { // 32 bit signed integer start->setMaximum(0x7fffffff); end->setMaximum(0x7fffffff); } QGridLayout *gl1 = new QGridLayout(); boxColumn = new QComboBox(); gl1->addWidget(boxColumn, 1, 0); btnAddCol = new QPushButton(tr("Add column")); gl1->addWidget(btnAddCol, 1, 1); QHBoxLayout *hbox3 = new QHBoxLayout(); hbox3->addStretch(); buttonPrev = new QPushButton("&<<"); hbox3->addWidget(buttonPrev); buttonNext = new QPushButton("&>>"); hbox3->addWidget(buttonNext); gl1->addLayout(hbox3, 2, 0); addCellButton = new QPushButton(tr("Add cell")); gl1->addWidget(addCellButton, 2, 1); QGroupBox *gb = new QGroupBox(); QVBoxLayout *vbox1 = new QVBoxLayout(); vbox1->addLayout(hbox1); vbox1->addLayout(gl1); gb->setLayout(vbox1); gb->setSizePolicy( QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); explain = new QTextEdit(); explain->setReadOnly(true); explain->setSizePolicy( QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); QPalette palette = explain->palette(); palette.setColor(QPalette::Active, QPalette::Base, Qt::lightGray); explain->setPalette(palette); QHBoxLayout *hbox2 = new QHBoxLayout(); hbox2->addWidget(explain); hbox2->addWidget(gb); commands = new ScriptEditor(this, scriptingEnv()->createCodeLexer()); QVBoxLayout *vbox2 = new QVBoxLayout(); btnApply = new QPushButton(tr("&Apply")); vbox2->addWidget(btnApply); btnCancel = new QPushButton(tr("&Close")); vbox2->addWidget(btnCancel); vbox2->addStretch(); QHBoxLayout *hbox4 = new QHBoxLayout(); hbox4->addWidget(commands); hbox4->addLayout(vbox2); QVBoxLayout *vbox3 = new QVBoxLayout(); vbox3->addLayout(hbox2); colNameLabel = new QLabel(); vbox3->addWidget(colNameLabel); vbox3->addLayout(hbox4); setLayout(vbox3); setFocusProxy(commands); commands->setFocus(); connect(btnAddCol, SIGNAL(clicked()), this, SLOT(insertCol())); connect(addCellButton, SIGNAL(clicked()), this, SLOT(insertCell())); connect(btnApply, SIGNAL(clicked()), this, SLOT(apply())); connect(btnCancel, SIGNAL(clicked()), this, SLOT(close())); connect(buttonPrev, SIGNAL(clicked()), this, SLOT(prevColumn())); connect(buttonNext, SIGNAL(clicked()), this, SLOT(nextColumn())); setTable(t); }