Exemplo n.º 1
0
void TabWidget::setText(const QString &text,int ind){
    if(ind==-1){
        ind=this->currentIndex();
    }
    CodeEditor *e = codeEditor(ind);
    if(e){
        e->setPlainText(text);
    }
}
Exemplo n.º 2
0
void MainWindow::on_mainDirectoryTree_fileClicked(ProjectTreeItem *item)
{
    for (int i = 0; i < ui->tabWidget->count(); i++) {
        CodeEditor *editor = static_cast<CodeEditor*>(ui->tabWidget->widget(i));
        if (!editor->getFileInfo()->absoluteFilePath().compare(item->getFileInfo()->absoluteFilePath())) {
            int index = ui->tabWidget->indexOf(editor);
            ui->tabWidget->setCurrentIndex(index);
            return;
        }
    }

    QFile file(item->getFileInfo()->absoluteFilePath());

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    QFileInfo fileInfo(item->getFileInfo()->absoluteFilePath());
    CodeEditor *codeEditor = new CodeEditor(ui->tabWidget, fileInfo);
    ClangHighlighter *highlighter = new ClangHighlighter();
    codeEditor->setSyntaxHighlighter(highlighter);
    codeEditor->setPlainText(file.readAll());
    file.close();
    ui->tabWidget->setCurrentIndex(ui->tabWidget->insertTab(0, codeEditor, item->getFileInfo()->fileName()));
}