예제 #1
0
void TextEditor::paintEvent(QPaintEvent *e) {
   int width = viewport()->width(), height = fontMetrics().height();
   QRect cRect(0, cursorRect().y(), viewport()->width(), height);
   const int cursorPos = textCursor().block().position();
   
   QPainter p(viewport());
   // good for highlighting line during paused execution:
   p.fillRect(cRect, QBrush(QColor(215, 227, 255)));
   
   if (m_pc != NULL && m_program->getStatus() == PAUSED) {
      QColor highlightColor = QColor(255, 240, 117); // yellow
      highlightLine(p, m_pc, highlightColor, width, height);
      
//      highlightColor = highlightColor.lighter(105);
//      cerr << "<<<Painting: size = " << m_lastInstructions.size() << endl;
      foreach(ParseNode *parseNode, m_lastInstructions) {
         highlightColor = highlightColor.lighter(120);
         if (highlightColor == Qt::white) {
            //cerr << "\t" << i << " painted!\n";
            break;
         }
         
         if (!parseNode->isValid())
            continue;
         
         const QTextBlock *block = parseNode->getTextBlock();
         if (block != NULL && block->isValid() && parseNode != m_pc && cursorPos != block->position())
            highlightLine(p, parseNode, highlightColor, width, height);
      }
예제 #2
0
void Inorder::obidji_lkd(VisualTreeElement* e){
    if(e){
        obidji_lkd(e->getLeft());

        m_operations.push_back([=, this] () {
            emit highlightLine(3);
            QString order;
//            If animation is going forward:
            if (isGoingForward()) {
                if (e != getRoot()->nadji_minimum(getRoot(), 5000))//control coma (don't wanna : , first_reached)
                    m_explanationText->setPlainText(QString(m_explanationText->toPlainText()) + ", "+ QString::number(e->getValue()));
                else
                    m_explanationText->setPlainText(QString(m_explanationText->toPlainText()) + QString::number(e->getValue()));
            }
//            Animation going backward:
            else {
                order= m_explanationText->toPlainText();
                if (e != getRoot())
                    order= order.mid(0, order.lastIndexOf(","));
                else
                    order= "Nodes are reached in order: ";
                m_explanationText->setPlainText(order);
            }

            visit_node(e);
        });


        obidji_lkd(e->getRight());
}
}
예제 #3
0
void Highlighter::highlightBlock(const QString &text)
{
    int initialState = previousBlockState();
    if (initialState == -1)
        initialState = 0;
    setCurrentBlockState(highlightLine(text, initialState));
}
예제 #4
0
void fileviewer::Next_ButtonClick(bool checked)
{
	if (m_fileDataList.isEmpty())
	{
		m_pushButtonPrev->setEnabled(false);
		m_pushButtonNext->setEnabled(false);
		return;
	}
	if((m_iter == m_fileDataList.end() - 1)||
		(m_iter == m_fileDataList.end()))
	{
		m_pushButtonNext->setEnabled(false);
		return;
	}
	if (!checked)
	{
		QVector<filedata>::iterator it = m_iter;
		m_iter++;
		if (m_iter->compareFilenameOnly(*it))
		{
			highlightLine(m_iter->linenum.toInt());
			updateFilePathLabel();			
		}
		else
		{
			updateTextEdit();
		}
		m_pushButtonPrev->setEnabled(m_iter != m_fileDataList.begin());
		m_pushButtonNext->setEnabled(m_iter != m_fileDataList.end() - 1);
	}
}
예제 #5
0
 void CodeEditor::highlightLine(int index, const QColor &color) {
     QTextCursor cur(document());
     for (int i = 0; i < index; ++i) {
         cur.movePosition(QTextCursor::Down);
     }
     highlightLine(cur,color);
 }
예제 #6
0
void CSTimeHelp::mouseMove(Common::Point &pos) {
	bool mouseIsDown = _vm->getEventManager()->getButtonState() & 1;

	for (uint i = 0; i < _qars.size(); i++) {
		Common::Rect thisRect = _vm->getInterface()->_dialogTextRect;
		thisRect.top += 1 + i*15;
		thisRect.bottom = thisRect.top + 15;
		if (!thisRect.contains(pos))
			continue;

		if (mouseIsDown) {
			if (i != _currEntry)
				break;
			highlightLine(i);
		}

		_vm->getInterface()->cursorOverHotspot();
		_currHover = i;
		return;
	}

	if (_currHover != 0xffff) {
		if (_vm->getInterface()->cursorGetShape() != 3) {
			unhighlightLine(_currHover);
			_vm->getInterface()->cursorSetShape(1);
		}
		_currHover = 0xffff;
	}
}
예제 #7
0
SparqlTextEdit::SparqlTextEdit(QWidget *parent) :
    QPlainTextEdit(parent)
{
    setLineWrapMode(QPlainTextEdit::NoWrap);

    QFont monospace("monospace");
    monospace.setStyleHint(QFont::TypeWriter);
    document()->setDefaultFont(monospace);

    new SparqlHighlighter(document());

    connect(this, SIGNAL(blockCountChanged(int)), SLOT(repaintLineNumbers()));
    connect(this, SIGNAL(updateRequest(QRect,int)),
            SLOT(updateRequested(QRect,int)));

    connect(this, SIGNAL(cursorPositionChanged()), SLOT(highlightLine()));
    connect(this, SIGNAL(selectionChanged()), SLOT(highlightLine()));
    highlightLine();
}
예제 #8
0
void fileviewer::updateTextEdit(void)
{
	if (m_iter == m_fileDataList.end()) return;
	QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
	m_textEditSource->clear();

	QFile file(m_iter->filename);
	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QApplication::restoreOverrideCursor();
		return;
	}
	QTextStream in(&file);

	int lang = enHighlightCPP; // default

	QRegExp rx1("\\.py$", Qt::CaseInsensitive);
	int pos = rx1.indexIn(m_iter->filename);
	if (pos != -1) lang = enHighlightPython;

	QRegExp rx2("\\.java$", Qt::CaseInsensitive);
	pos = rx2.indexIn(m_iter->filename);
	if (pos != -1) lang = enHighlightJava;

	QRegExp rx3("\\.rb$", Qt::CaseInsensitive);
	pos = rx3.indexIn(m_iter->filename);
	if (pos != -1) lang = enHighlightRuby;

	QRegExp rx4("\\.js$", Qt::CaseInsensitive);
	pos = rx4.indexIn(m_iter->filename);
	if (pos != -1) lang = enHighlightJavascript;

	m_currentlang = lang;
	setLexer(lang);

	QString alltext;
	while (!in.atEnd())
	{
		alltext = in.readAll();
	}
	m_textEditSource->setText(alltext);
	m_textEditSource->setMarginWidth(0,  QString::number(m_textEditSource->lines() * 10));
	highlightLine(m_iter->linenum.toInt());
	updateFilePathLabel();
	m_pushButtonGoToLine->setEnabled(true);
	m_pushButtonOpenInEditor->setEnabled(true);
	m_pushButtonTextShrink->setEnabled(true);
	m_pushButtonTextEnlarge->setEnabled(true);
	m_listWidgetFunc->clear();
	if (m_iter->fileid < 0)	{emit requestFuncList_filename(m_iter->filename);}
	else {emit requestFuncList_fileid(m_iter->fileid);}
	QApplication::restoreOverrideCursor();
}
예제 #9
0
void CSTimeHelp::mouseDown(Common::Point &pos) {
	for (uint i = 0; i < _qars.size(); i++) {
		Common::Rect thisRect = _vm->getInterface()->_dialogTextRect;
		thisRect.top += 1 + i*15;
		thisRect.bottom = thisRect.top + 15;
		if (!thisRect.contains(pos))
			continue;

		_currEntry = i;
		highlightLine(i);
		_vm->getInterface()->cursorSetShape(5);
	}
}
예제 #10
0
void ShellSort::initializeAnimation() {
//    Drawing some nice text to help with gap size:
    m_explanationText= new QGraphicsTextItem("Current gap size is: "+QString::number(arrayElements().size()/2));
    m_explanationText->setFont(QFont("Arial", 16, -1, true));
    m_explanationText->setProperty("pos", QPointF(0, this->height()-m_explanationText->boundingRect().height()));
    this->addItem(m_explanationText);
//    Continuing with animation initialization:
    vector<double> varray= values();
    int n=varray.size();
    for (int gap = n/2; gap > 0; gap /= 2) {
        m_operations.push_back([=, this](){ setCurrentGapText(gap);});
        for (int i = gap; i < n; i++) {
            for (int j=i-gap; j>=0; j-=gap) {
                m_operations.push_back([=,this](){operationCompareElements(j, j+gap); highlightLine(13);});
                if (varray[j] > varray[j+gap]) {
                    m_operations.push_back([=,this](){operationSwapElements(j, j+gap); highlightLine(14);});
                    double tmp=varray[j];
                    varray[j]=varray[j+gap];
                    varray[j+gap]=tmp;
                }
                else
                    break;
            }
        }
    }
    m_animationInitialized=true;
    m_currentStepInAnimation= 0;
    m_numberOfStepsInAnimation= m_operations.size();
}
예제 #11
0
void fileviewer::GoToLine_ButtonClick(bool checked)
{
	if (!checked) highlightLine(m_iter->linenum.toInt());
}
예제 #12
0
void fileviewer::fileToBeOpened(QString filename, QString linenum)
{
	filename.replace(QString("$HOME"), QDir::homePath());
#ifdef _WIN32
	filename.replace("/", "\\");
#endif
	if (!(QFile::exists(filename)))
	{
		m_labelFilePath->setText(tr("File not found"));
		handleFileCannotBeOpenedCase();
		return;
	}
	QFile file(filename);
	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		m_labelFilePath->setText(tr("File could not be opened"));
		handleFileCannotBeOpenedCase();
		return;
	}
	file.close();

	QFileInfo fi(filename);
	if ((m_DBtimestamp < fi.lastModified())&&(m_timestampMismatchWarned == false))
	{
		
		m_timestampMismatchWarned = true;
		QMessageBox msgBox((QWidget*)mw);
		msgBox.setIcon(QMessageBox::Warning);
		msgBox.setStandardButtons(QMessageBox::Ok);
		msgBox.setText(tr("The source file to be viewed is newer than the CodeQuery database file. You are recommended to manually regenerate the CodeQuery database file."));
		msgBox.exec();
	}
	filedata fd(filename, linenum);
	if (m_fileDataList.isEmpty())
	{
		m_fileDataList.push_back(fd);
		m_iter = m_fileDataList.end() - 1;
		m_pushButtonPrev->setEnabled(false);
		m_pushButtonNext->setEnabled(false);
		updateTextEdit();
		return;
	}
	else if (m_iter == m_fileDataList.end())
	{
		// previous file not found
		m_fileDataList.push_back(fd);
		m_iter = m_fileDataList.end() - 1;
		m_pushButtonPrev->setEnabled(m_iter != m_fileDataList.begin());
		m_pushButtonNext->setEnabled(false);
		updateTextEdit();		
	}
	else if (m_iter->compare(fd))
	{
		// the same filename and line number
		updateFilePathLabel();
		return;
	}
	else if (m_iter->compareFilenameOnly(fd))
	{
		// same file, different line number
		m_fileDataList.push_back(fd);
		m_iter = m_fileDataList.end() - 1;
		m_pushButtonPrev->setEnabled(true);
		m_pushButtonNext->setEnabled(false);
		highlightLine(fd.linenum.toInt());
		updateFilePathLabel();
	}
	else
	{
		// different file
		m_fileDataList.push_back(fd);
		m_iter = m_fileDataList.end() - 1;
		m_pushButtonPrev->setEnabled(true);
		m_pushButtonNext->setEnabled(false);
		updateTextEdit();
	}
	QVector<filedata>::iterator it = m_fileDataList.begin();
	while ((it != m_fileDataList.end() - 1)&&(it != m_fileDataList.end()))
	{
		if (it->compare(fd)) m_fileDataList.erase(it);
		else it++;
	}
	if (m_fileDataList.size() > 20) m_fileDataList.erase(m_fileDataList.begin());
}
예제 #13
0
 void CodeEditor::highlightCurrentLine() {
    highlightLine(textCursor(),defaultSelectionColor);
 }
예제 #14
0
 void CodeEditor::clearSelection() {
    highlightLine(0,backGroundColor);
 }
예제 #15
0
CodeEditor::CodeEditor(QWidget *parent) :
    QTextEdit(parent)
{


    setAcceptRichText(false);
    setTabStopWidth(40);
    SHL = new SyntaxHL(this); //Adding syntax highlighter.

    //Auto-complete setup:

    compList << "add"
             << "addu"
             << "sub"
             << "subu"
             << "and"
             << "or"
             << "xor"
             << "srlv"
             << "sllv"
             << "srav"
             << "slt"
             << "sltu"
             << "addi"
             << "addiu"
             << "andi"
             << "ori"
             << "nori"
             << "xori"
             << "srl"
             << "sll"
             << "sra"
             << "slti"
             << "sltiu"
             << "beq"
             << "bne"
             << "lui"
             << "sb"
             << "lb"
             << "lbu"
             << "sh"
             << "lh"
             << "lhu"
             << "sw"
             << "lw"
             << "lwl"
             << "lwr"
             << "swl"
             << "swr"
             <<"ll"
            << "sc"
            << "jr"
            << "jalr"
            << "mfhi"
            << "mflo"
            << "mthi"
            << "mtlo"
            << "mult"
            << "multu"
            << "div"
            << "divu"
            << "j"
            << "jal"
            << "syscall"
            << "nop";

    //for (int i = 0; i < 32; i++) compList.append(QString("$" + QString::number(i)));
    compList << "$0"
             << "$zero"
             << "$at"
             << "$v0"
             << "$v1"
             <<"$a0"
            << "$a1"
            << "$a2"
            << "$a3"
            << "$t0"
            << "$t1"
            << "$t2"
            << "$t3"
            << "$t4"
            << "$t5"
            << "$t6"
            << "$t7"
            << "$s0"
            << "$s1"
            << "$s2"
            << "$s3"
            << "$s4"
            << "$s5"
            << "$s6"
            << "$s7"
            << "$t8"
            << "$t9"
            << "$gp"
            << "$fp"
            << "$ra"
            << "$sp";

    compList << "blt"  <<  "bgt"
             <<  "ble"
             <<  "bge"
             <<  "bltu"
             <<  "bgtu"
             <<  "bleu"
             <<  "bgeu"
             <<  "blti"
             <<  "bgti"
             <<  "blei"
             <<  "bgei"
             <<  "bltiu"
             <<  "bgtiu"
             <<  "bleiu"
             <<  "bgeiu"
             <<  "beqz"
             <<  "bnez"
             <<  "bltz"
             <<  "bgtz"
             <<  "blez"
             <<  "bgez"
             <<  "li"
             <<  "ror"
             <<  "rol"
             <<  "not"
             <<  "neg"
             <<  "move"
             <<  "abs"
             <<  "mul"
             <<  "div"
             <<  "rem"
             <<  "clear"
             <<  "subi"
             <<  "la"
             << ".align" << ".ascii" << ".asciiz" << ".byte" << ".double" <<".float" << ".half" << ".space" << ".word";

    lCounter = NULL;

    model = new QStringListModel(compList, this);

    codeCompleter = new QCompleter(model, this);
    codeCompleter->setCompletionMode(QCompleter::PopupCompletion);
    CompleterList *cl = new CompleterList(this);
    codeCompleter->setPopup(cl);
    codeCompleter->setCaseSensitivity(Qt::CaseInsensitive);
    codeCompleter->setWidget(this);

    QObject::connect(codeCompleter, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString)));
    QObject::connect(this, SIGNAL(textChanged()), this, SLOT(updateCounter()));
    QObject::connect(this, SIGNAL(textChanged()), this, SLOT(refreshScroll()));
    QObject::connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(refreshScroll()));
    QObject::connect(this, SIGNAL(textChanged()), this, SLOT(completerPop()));    
    QObject::connect(this, SIGNAL(selectionChanged()), this, SLOT(highlightLine()));
    QObject::connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightLine()));
    QObject::connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateCounterFormat()));
    QObject::connect(this, SIGNAL(textChanged()), this, SLOT(updateCounterFormat()));
    selectionStart = selectionEnd = 0;

}
예제 #16
0
void BFS::initializeAnimation(){
    setMenu(false);
    int r=255, g=255, b=0;
    int color_step= 25;
    m_operations.push_back([=,this](){ getNode(_currentNode)->setColor(QColor(r, g, b));colorNode(_currentNode); });
    r-=color_step;
    g-=color_step;
    QQueue<int> queue;
    queue.append(_currentNode);
    getNode(_currentNode)->setVisited(true);
    while(!queue.empty()){
        int curr = queue.at(0);
        queue.pop_front();
        NodeList list = getNeighbours(curr);
        for (auto iter : list){
            if(!getNode(iter)->visited()){
                getNode(iter)->setVisited(true);
                m_operations.push_back([=,this](){getEdge(curr, iter)->setColor(QColor(r,g,b)); colorEdge(curr, iter); emit highlightLine(10);});
            m_operations.push_back([=,this](){getNode(iter)->setColor(QColor(r,g,b)); colorNode(iter);});
                queue.append(iter);
            }
        }
        r-=color_step;
        g-=color_step;
    }

    m_animationInitialized= true;
    m_currentStepInAnimation= 0;
    m_numberOfStepsInAnimation= m_operations.size();
}