/** * Constructor */ ScriptManagerWidget::ScriptManagerWidget(ScriptingEnv *env, QWidget *parent, bool interpreter_mode) : QTabWidget(parent), Scripted(env), m_last_dir(""), m_script_runners(), m_cursor_pos(), m_findrep_dlg(NULL), m_interpreter_mode(interpreter_mode) { //Create actions for this widget initActions(); // Execution state change connect(this, SIGNAL(ScriptIsActive(bool)), this, SLOT(setScriptIsRunning(bool))); // Start with a blank tab newTab(); QString group; if( interpreter_mode ) { tabBar()->hide(); setContextMenuPolicy(Qt::NoContextMenu); ScriptEditor *editor = currentEditor(); connect(editor, SIGNAL(executeLine(const QString&)), this, SLOT(executeInterpreter(const QString &))); connect(this, SIGNAL(MessageToPrint(const QString&, bool,bool)), editor, SLOT(displayOutput(const QString&,bool))); connect(editor, SIGNAL(compile(const QString&)), this, SLOT(compile(const QString &))); connect(editor, SIGNAL(executeMultiLine()), this, SLOT(executeMultiLine())); group = "ScriptInterpreter"; } else {
void MainTab::tabChangedST(int){ if (oldEditor) oldEditor->deactivated(); PolicyEditor* editor = currentEditor(); oldEditor = editor; editor->activated(); }
void MainUI::openReplace(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } ui->groupReplace->setVisible(true); ui->line_find->setText( cur->textCursor().selectedText() ); ui->line_replace->setText(""); ui->line_replace->setFocus(); }
void toPLSQLEditor::compile(void) { // compile only current editor/tab QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); currentEditor()->editor()->compile(toPLSQLText::Production); QApplication::restoreOverrideCursor(); // refresh(); }
int frmSearchReplace::selectAll(QString string, SearchHelpers::SearchMode searchMode, SearchHelpers::SearchOptions searchOptions) { QString rawSearch = SearchString::format(string, searchMode, searchOptions); QList<QVariant> data = QList<QVariant>(); data.append(rawSearch); data.append(regexModifiersFromSearchOptions(searchOptions)); QVariant count = currentEditor()->asyncSendMessageWithResult("C_FUN_SEARCH_SELECT_ALL", QVariant::fromValue(data)).get(); return count.toInt(); }
void MainUI::tabChanged(){ //update the buttons/menus based on the current widget PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } //should never happen though bool changes = cur->hasChange(); ui->actionSave_File->setEnabled(changes); this->setWindowTitle( ui->tabWidget->tabText( ui->tabWidget->currentIndex() ) ); if(!ui->line_find->hasFocus() && !ui->line_replace->hasFocus()){ ui->tabWidget->currentWidget()->setFocus(); } }
void MainUI::findNext(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); if(!found){ //Try starting back at the top of the file cur->moveCursor(QTextCursor::Start); cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); } }
QString MainUI::currentFileDir(){ PlainTextEditor* cur = currentEditor(); QString dir; if(cur!=0){ if(cur->currentFile().startsWith("/")){ dir = cur->currentFile().section("/",0,-2); } } return dir; }
void MainUI::findPrev(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively | QTextDocument::FindBackward : QTextDocument::FindBackward ); if(!found){ //Try starting back at the bottom of the file cur->moveCursor(QTextCursor::End); cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively | QTextDocument::FindBackward : QTextDocument::FindBackward ); } }
void MainTab::editSelectAllST(){ int index = currentIndex(); if (index > 0){ PolicyEditor* editor = currentEditor(); editor->selectAll(); } else{ MainWindow::instance()->alertsListLV->selectAll(); } }
void toPLSQLEditor::describe() { QString owner, table; toHighlightedText * marked = currentEditor()->editor(); marked->tableAtCursor(owner, table); if (owner.isNull()) owner = Schema->currentText(); toDescribe * d = new toDescribe(this); d->changeParams(owner, table); }
int frmSearchReplace::replaceAll(QString string, QString replacement, SearchHelpers::SearchMode searchMode, SearchHelpers::SearchOptions searchOptions) { QString rawSearch = rawSearchString(string, searchMode, searchOptions); QList<QVariant> data = QList<QVariant>(); data.append(rawSearch); data.append(regexModifiersFromSearchOptions(searchOptions)); data.append(replacement); data.append(QString::number(static_cast<int>(searchMode))); QVariant count = currentEditor()->sendMessageWithResult("C_FUN_REPLACE_ALL", QVariant::fromValue(data)); return count.toInt(); }
void toPLSQLEditor::updateCurrent() { try { toPLSQLWidget *editor = currentEditor(); editor->editor()->readData(connection()/*, StackTrace*/); editor->editor()->setFocus(); } TOCATCH }
void MainTab::editClearSelectionST(){ int index = currentIndex(); if (index > 0){ PolicyEditor* editor = currentEditor(); QTextCursor cursor = editor->textCursor(); cursor.clearSelection(); editor->setTextCursor(cursor); } else{ MainWindow::instance()->alertsListLV->clearSelection(); } }
void TextEdit::filePrint() { if ( !currentEditor() ) return; #ifndef QT_NO_PRINTER QPrinter printer; printer.setFullPage(TRUE); QPaintDeviceMetrics screen( this ); printer.setResolution( screen.logicalDpiY() ); if ( printer.setup( this ) ) { QPainter p( &printer ); QPaintDeviceMetrics metrics( p.device() ); int dpix = metrics.logicalDpiX(); int dpiy = metrics.logicalDpiY(); const int margin = 72; // pt QRect body( margin * dpix / 72, margin * dpiy / 72, metrics.width() - margin * dpix / 72 * 2, metrics.height() - margin * dpiy / 72 * 2 ); QFont font( "times", 10 ); QSimpleRichText richText( currentEditor()->text(), font, currentEditor()->context(), currentEditor()->styleSheet(), currentEditor()->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.setFont( font ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } #endif }
void MainUI::UpdateHighlighting(QAction *act){ if(act!=0){ //Single-editor change PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } cur->LoadSyntaxRule(act->text()); }else{ //Have every editor reload the syntax rules (color changes) for(int i=0; i<ui->tabWidget->count(); i++){ static_cast<PlainTextEditor*>(ui->tabWidget->widget(i))->updateSyntaxColors(); } } }
void MainTab::editCopyST(){ PolicyEditor* editor = currentEditor(); if (currentIndex() != 0){ editor->copy(); return; } if (editor->textCursor().hasSelection()){ editor->copy(); return; } QString text; text = editor->toPlainText(); QApplication::clipboard()->setText(text); }
void TextEdit::textStyle( int i ) { if ( !currentEditor() ) return; if ( i == 0 ) currentEditor()->setParagType( QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc ); else if ( i == 1 ) currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc ); else if ( i == 2 ) currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListCircle ); else if ( i == 3 ) currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListSquare ); else if ( i == 4 ) currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDecimal ); else if ( i == 5 ) currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListLowerAlpha ); else if ( i == 6 ) currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListUpperAlpha ); currentEditor()->viewport()->setFocus(); }
void frmSearchReplace::on_btnLookInBrowse_clicked() { QString defaultDir = ui->cmbLookIn->currentText(); if (defaultDir.isEmpty()) { QFileInfo file(currentEditor()->fileName().toLocalFile()); defaultDir = file.absolutePath(); } QString dir = QFileDialog::getExistingDirectory(this, tr("Look in"), defaultDir, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!dir.isEmpty()) { ui->cmbLookIn->setCurrentText(dir); } }
void frmSearchReplace::search(QString string, SearchHelpers::SearchMode searchMode, bool forward, SearchHelpers::SearchOptions searchOptions) { if (!string.isEmpty()) { QString rawSearch = SearchString::format(string, searchMode, searchOptions); Editor *editor = currentEditor(); if (searchOptions.SearchFromStart) { editor->setCursorPosition(0, 0); } QList<QVariant> data = QList<QVariant>(); data.append(rawSearch); data.append(regexModifiersFromSearchOptions(searchOptions)); data.append(forward); editor->sendMessage("C_FUN_SEARCH", QVariant::fromValue(data)); } }
void MainUI::replaceOne(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } //See if the current selection matches the find field first bool done = false; if(cur->textCursor().selectedText()==ui->line_find->text()){ cur->insertPlainText(ui->line_replace->text()); //done = true; }//else{ //Find/replace the next occurance of the string bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); //if(found){ cur->insertPlainText(ui->line_replace->text()); done = true;} //} /*if(done){ //Re-highlight the newly-inserted text cur->find( ui->line_replace->text(), QTextDocument::FindCaseSensitively | QTextDocument::FindBackward); }*/ }
void frmSearchReplace::on_searchStringEdited(const QString &/*text*/) { QSettings s; if (s.value("Search/SearchAsIType", true).toBool()) { if (ui->actionFind->isChecked()) { Editor *editor = currentEditor(); QList<Editor::Selection> selections = editor->selections(); if (selections.length() > 0) { editor->setCursorPosition( std::min(selections[0].from, selections[0].to)); } findFromUI(true); } } }
void frmSearchReplace::replace(QString string, QString replacement, SearchHelpers::SearchMode searchMode, bool forward, SearchHelpers::SearchOptions searchOptions) { if (!string.isEmpty()) { QString rawSearch = rawSearchString(string, searchMode, searchOptions); Editor *editor = currentEditor(); if (searchOptions.SearchFromStart) { editor->setCursorPosition(0, 0); } QList<QVariant> data = QList<QVariant>(); data.append(rawSearch); data.append(regexModifiersFromSearchOptions(searchOptions)); data.append(forward); data.append(replacement); data.append(QString::number(static_cast<int>(searchMode))); editor->sendMessage("C_FUN_REPLACE", QVariant::fromValue(data)); } }
void CodeEditorBox::setDocument(Document *doc, int pos, int selectionLength) { if (!doc) return; GenericCodeEditor *editor = currentEditor(); bool switchEditor = !editor || editor->document() != doc; if (switchEditor) { editor = editorForDocument(doc); if (!editor) { editor = doc->isPlainText() ? new GenericCodeEditor(doc) : new ScCodeEditor(doc); editor->installEventFilter(this); mHistory.prepend(editor); mLayout->addWidget(editor); connect(this, SIGNAL(activeChanged(bool)), editor, SLOT(setActiveAppearance(bool))); } else {
void frmSearchReplace::on_searchStringEdited(const QString &/*text*/) { NqqSettings& s = NqqSettings::getInstance(); if (s.Search.getSearchAsIType()) { if (ui->actionFind->isChecked()) { Editor *editor = currentEditor(); QList<Editor::Selection> selections = editor->selections(); if (selections.length() > 0) { editor->setCursorPosition( std::min(selections[0].from, selections[0].to)); } findFromUI(true); } } // Workaround. See comment in setSearchText(). ui->cmbSearch->setAutoCompletion(true); }
void TextEdit::filePrint() { if ( !currentEditor() ) return; #ifndef QT_NO_PRINTER QPrinter printer( QPrinter::HighResolution ); printer.setFullPage(TRUE); if ( printer.setup( this ) ) { QPainter p( &printer ); // Check that there is a valid device to print to. if ( !p.device() ) return; QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins QRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QFont font( currentEditor()->QWidget::font() ); font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing QSimpleRichText richText( currentEditor()->text(), font, currentEditor()->context(), currentEditor()->styleSheet(), currentEditor()->mimeSourceFactory(), view.height() ); richText.setWidth( &p, view.width() ); int page = 1; do { richText.draw( &p, margin, margin, view, colorGroup() ); view.moveBy( 0, view.height() ); p.translate( 0 , -view.height() ); p.setFont( font ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() - margin >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } #endif }
void TextEdit::editPaste() { if ( !currentEditor() ) return; currentEditor()->paste(); }
void TextEdit::textBold() { if ( !currentEditor() ) return; currentEditor()->setBold( actionTextBold->isOn() ); }
void TextEdit::textItalic() { if ( !currentEditor() ) return; currentEditor()->setItalic( actionTextItalic->isOn() ); }
void TextEdit::textUnderline() { if ( !currentEditor() ) return; currentEditor()->setUnderline( actionTextUnderline->isOn() ); }