// Append command with new line and log time stamp
void OutputWindowPlainTextEdit::appendCommand(const QString &text)
{
    setCurrentCharFormat(m_commandFormat);
    const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
    appendLines(timeStamp + text);
    setCurrentCharFormat(m_defaultFormat);
}
void ConsoleWidget::handleColor(const QColor &color)
{
    QTextCharFormat tf = currentCharFormat();
    if (color!=tf.foreground().color())
    {
        tf.setForeground(color);
        setCurrentCharFormat(tf);
    }
}
示例#3
0
void ConsoleWidget::handleColor(const QColor &color)
{
    if (color!=m_color)
    {
        QTextCharFormat tf = currentCharFormat();
        tf.setForeground(color);
        setCurrentCharFormat(tf);
        m_color = color;
    }
}
void OutputWindowPlainTextEdit::setFormat(enum VcsOutputWindow::MessageStyle style)
{
    switch (style) {
    case VcsOutputWindow::Warning:
        setCurrentCharFormat(m_warningFormat);
        break;
    case VcsOutputWindow::Error:
        setCurrentCharFormat(m_errorFormat);
        break;
    case VcsOutputWindow::Message:
        setCurrentCharFormat(m_messageFormat);
        break;
    case VcsOutputWindow::Command:
        setCurrentCharFormat(m_commandFormat);
        break;
    default:
    case VcsOutputWindow::None:
        setCurrentCharFormat(m_defaultFormat);
        break;
    }
}
示例#5
0
void CQExpressionWidget::slotSelectObject()
{
  const CCopasiObject * pObject =
    CCopasiSelectionDialog::getObjectSingle(this, mObjectClasses);

  if (pObject)
    {
      // Check whether the object is valid
      if (!CQSimpleSelectionTree::filter(mObjectClasses, pObject))
        {
          CQMessageBox::critical(this, "Invalid Selection",
                                 "The use of the selected object is not allowed in this type of expression.");
          return;
        }

      std::string Insert = pObject->getObjectDisplayName();

      // We need to escape >
      std::string::size_type pos = Insert.find_first_of("}");

      while (pos != std::string::npos)
        {
          Insert.insert(pos, "\\");
          pos += 2;
          pos = Insert.find_first_of("}", pos);
        }

      mParseList[Insert] = pObject;

      QTextCharFormat f1;
      f1.setForeground(QColor(0, 0, 0));

      QTextCharFormat f = mpExpressionHighlighter->mObjectDisplayFormat;
      //QColor color2 = f.foreground().color();

      setCurrentCharFormat(f);
      insertPlainText(FROM_UTF8("{" + Insert + "}"));
      setCurrentCharFormat(f1);
    }
}
void OutputWindowPlainTextEdit::appendLinesWithStyle(QString const& s, enum VcsOutputWindow::MessageStyle style, const QString &repository)
{
    setFormat(style);

    if (style == VcsOutputWindow::Command) {
        const QString timeStamp = QTime::currentTime().toString(QLatin1String("\nHH:mm "));
        appendLines(timeStamp + s, repository);
    }
    else {
        appendLines(s, repository);
    }

    setCurrentCharFormat(m_defaultFormat);
}
void PythonQtScriptingConsole::setCurrentFont(const QColor& color, bool bold) {

  QTextCharFormat charFormat(_defaultTextCharacterFormat);

  QFont font(charFormat.font());
  font.setBold(bold);
  charFormat.setFont(font);

  QBrush brush(charFormat.foreground());
  brush.setColor(color);
  charFormat.setForeground(brush);

  setCurrentCharFormat(charFormat);
}
示例#8
0
void CQExpressionWidget::setFunction(const std::string & function)
{
  if (mpValidatorFunction == NULL)
    {
      mpValidatorFunction = new CQValidatorFunction(this, "");
      mpValidatorFunction->revalidate();
    }

  // clear the text edit
  clear();

  mCursor = textCursor();

  QTextCharFormat f1;
  f1.setForeground(QColor(0, 0, 0));

  setCurrentCharFormat(f1);
  insertPlainText(FROM_UTF8(function));
}
void OutputWindowPlainTextEdit::appendWarning(const QString &text)
{
    setCurrentCharFormat(m_warningFormat);
    appendLines(text);
    setCurrentCharFormat(m_defaultFormat);
}
void OutputWindowPlainTextEdit::appendMessage(const QString &text)
{
    setCurrentCharFormat(m_messageFormat);
    appendLines(text);
    setCurrentCharFormat(m_defaultFormat);
}
示例#11
0
void CQExpressionWidget::keyPressEvent(QKeyEvent * e)
{
  int Left;
  int Right;
  bool isAdvancedEditing = CCopasiRootContainer::getConfiguration()->useAdvancedEditing();

  if (e == QKeySequence::SelectNextChar && !isAdvancedEditing)
    {
      mCursor = textCursor();
      mCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);

      if (objectBoundaries(mCursor.position(), Left, Right))
        {
          mCursor.setPosition(Right - 1, QTextCursor::KeepAnchor);
          setTextCursor(mCursor);
        }

      QTextEdit::keyPressEvent(e);

      return;
    }

  if (e == QKeySequence::SelectPreviousChar  && !isAdvancedEditing)
    {
      mCursor = textCursor();
      mCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);

      if (objectBoundaries(mCursor.position(), Left, Right))
        {
          mCursor.setPosition(Left + 1, QTextCursor::KeepAnchor);
          setTextCursor(mCursor);
        }

      QTextEdit::keyPressEvent(e);

      return;
    }

  switch (e->key())
    {
      case Qt::Key_Backspace:

        if (isAdvancedEditing) break;

        mCursor = textCursor();

        if (mCursor.selectedText().isEmpty())
          {
            mCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);

            if (objectBoundaries(mCursor.position(), Left, Right))
              {
                mCursor.setPosition(Left + 1, QTextCursor::KeepAnchor);
                mCursor.deleteChar();
                setTextCursor(mCursor);
              }
          }

        // delete the selected object or just the character
        QTextEdit::keyPressEvent(e);

        return;
        break;

      case Qt::Key_Delete:

        if (isAdvancedEditing) break;

        mCursor = textCursor();

        if (mCursor.selectedText().isEmpty())
          {
            mCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);

            if (objectBoundaries(mCursor.position(), Left, Right))
              {
                mCursor.setPosition(Right - 1, QTextCursor::KeepAnchor);
                mCursor.deleteChar();
                setTextCursor(mCursor);
              }
          }

        // delete the selected object or just the character
        QTextEdit::keyPressEvent(e);

        return;
        break;

      case Qt::Key_Left:

        if (isAdvancedEditing) break;

        mCursor = textCursor();

        // We check whether the new position is in an object.
        mCursor.movePosition(QTextCursor::PreviousCharacter);

        if (objectBoundaries(mCursor.position(), Left, Right))
          {
            mCursor.setPosition(Left + 1, QTextCursor::KeepAnchor);
            setTextCursor(mCursor);
          }

        QTextEdit::keyPressEvent(e);

        return;
        break;

      case Qt::Key_Right:

        if (isAdvancedEditing) break;

        mCursor = textCursor();

        // We check whether the new position is in an object.
        mCursor.movePosition(QTextCursor::NextCharacter);

        if (objectBoundaries(mCursor.position(), Left, Right))
          {
            mCursor.setPosition(Right - 1, QTextCursor::KeepAnchor);
            setTextCursor(mCursor);
          }

        QTextEdit::keyPressEvent(e);

        return;
        break;

      case Qt::Key_BraceLeft:
      case Qt::Key_BraceRight:

        if (isAdvancedEditing) break;

        e->ignore();
        return;
        break;
    }

  if (!e->text().isEmpty())
    {
      // set format original
      QTextCharFormat f;
      f.setForeground(QColor(0, 0, 0));

      setCurrentCharFormat(f);
      QTextEdit::keyPressEvent(e);

      return;
    }

  QTextEdit::keyPressEvent(e);
}
示例#12
0
//	WChatInput::QObject::event()
bool
WChatInput::event(QEvent * pEvent)
	{
	QEvent::Type eEventType = pEvent->type();
	//MessageLog_AppendTextFormatSev(eSeverityNoise, "WChatInput::event(type=$i)\n", eEventType);
	if (eEventType == QEvent::KeyPress)
		{
		QKeyEvent * pEventKey = static_cast<QKeyEvent *>(pEvent);
		const Qt::Key eKey = (Qt::Key)pEventKey->key();
		//MessageLog_AppendTextFormatSev(eSeverityNoise, "WChatInput::event(QEvent::KeyPress, key=0x$p, modifiers=$x)\n", eKey, pEventKey->modifiers());
		if ((eKey & d_kmKeyboardSpecialKeys) == 0)
			{
			// The user typed something other than a special key
			m_ttcBeforeChatStatePaused = d_ttcChatStateEventPaused;
			if (m_tidChatStateComposing == d_zNA)
				{
				m_tidChatStateComposing = startTimer(d_ttiChatState);	// Create a timer to determine when the user 'stopped' typing
				m_pwLayoutChatLog->Socket_WriteXmlChatState(eChatState_zComposing);
				}
			}
		if ((pEventKey->modifiers() & ~Qt::KeypadModifier) == Qt::NoModifier)
			{
			ITreeItemChatLogEvents * pContactOrGroup = m_pwLayoutChatLog->PGetContactOrGroup_NZ();
			pContactOrGroup->TreeItem_IconUpdateOnMessagesRead();	// Any key pressed in the message input assumes the user read the message history
			//m_pwLayoutChatLog->TreeItem_UpdateIconMessageRead();	// Any key pressed in the message input assumes the user read the message history
			if (eKey == Qt::Key_Enter || eKey == Qt::Key_Return)
				{
				EUserCommand eUserCommand = eUserCommand_ComposingStopped;	// Pretend the text message was sent
				CStr strText = *this;
				if (!strText.FIsEmptyString())
					{
					m_strTextLastWritten = strText;
					if (m_pEventEdit == NULL)
						eUserCommand = pContactOrGroup->Xmpp_EParseUserCommandAndSendEvents(IN_MOD_INV strText);	// This is the typical case of a new message
					else
						{
						// The user was editing an existing message
						m_pEventEdit->EventUpdateMessageText(strText, INOUT m_pwLayoutChatLog);
						m_pEventEdit = NULL;
						}
					ChatStateComposingCancelTimer((BOOL)eUserCommand);	// After sending a message, cancel (reset) the timer to, so a new 'composing' notification will be sent when the user starts typing again. BTW, there is no need to send a 'pause' command since receiving a text message automatically implies a pause.
					} // if

				if (eUserCommand != eUserCommand_Error)
					{
					clear();	// Clear the chat text
					setCurrentCharFormat(QTextCharFormat());
					}
				return true;
				} // if (enter)
			if (eKey == Qt::Key_Up)
				{
				// Set the previous text if there is notning in the edit box
				CStr strText = *this;
				if (strText.FIsEmptyString())
					{
					//EditEventText(pContactOrGroup->Vault_PGetEventLastMessageSentEditable_YZ());
					m_pEventEdit = pContactOrGroup->Vault_PFindEventLastMessageTextSentMatchingText(IN m_strTextLastWritten);
					if (m_pEventEdit != NULL)
						{
						MessageLog_AppendTextFormatSev(eSeverityNoise, "Editing Event ID $t\n", m_pEventEdit->m_tsEventID);
						}
					setPlainText(m_strTextLastWritten);
					moveCursor(QTextCursor::End);
					return true;
					}
				}
			if (eKey == Qt::Key_Escape)
				{
				m_pEventEdit = NULL;
				clear();	// Clear the chat text
				return TRUE;
				}
			} // if
		}
	else if (eEventType == QEvent::FocusIn)
		{
		//m_pwLayoutChatLog->OnEventFocusIn();
		m_pwLayoutChatLog->PGetContactOrGroup_NZ()->TreeItem_IconUpdateOnMessagesRead();
		}
	return WEditTextArea::event(pEvent);
	} // event()
示例#13
0
void HaiQTextEdit::process_key(QKeyEvent event) {
	if ((event.text()!="")&&(textCursor().selectedText().count()<=1)) { 
		///this is to avoid spreading of marker highlighting
		bool holdmodified=document()->isModified();
		QTextCharFormat format=currentCharFormat();
		format.clearBackground();
		setCurrentCharFormat(format);
		document()->setModified(holdmodified);
	}
	if ((event.key()==Qt::Key_Tab)||(event.key()==Qt::Key_Backtab)||(event.text()=="\t")) {
		process_tab(event);
	}
        else if (event.key()==Qt::Key_Insert && QApplication::keyboardModifiers() == Qt::NoModifier) {
		setOverwriteMode(!overwriteMode());
	}
	else if ((event.key()==Qt::Key_Home)&&((event.modifiers()==Qt::NoModifier)||(event.modifiers()==Qt::ShiftModifier))) {
		bool shift_key=(event.modifiers()==Qt::ShiftModifier);
		QTextCursor cursor=textCursor();
		int col=cursor.columnNumber();
		QString txt=cursor.block().text();
		if (shift_key)
			cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor);
		else
			cursor.movePosition(QTextCursor::StartOfLine);
		int ct=0;
		while ((ct<txt.count())&&((txt[ct]==' ')||(txt[ct]=='\t'))) {
			if (shift_key)
				cursor.movePosition(QTextCursor::Right,QTextCursor::KeepAnchor);
			else
				cursor.movePosition(QTextCursor::Right);
			ct++;
		}
		int col2=cursor.columnNumber();
		if (col2==col) { //moved nowhere
			if (shift_key)
				cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor);
			else
				cursor.movePosition(QTextCursor::StartOfLine);
		}
		setTextCursor(cursor);
	}
	else if (event.key()==Qt::Key_Backspace) {
		process_backspace();
		return;
	}
	else if ((event.key()==Qt::Key_Space)&&(event.modifiers()==Qt::ControlModifier)) {
		return; // don't process a space, because Ctrl+Space is for completion
	}
	else {
		QTextEdit::keyPressEvent(&event);
	}

	if ((event.key()==Qt::Key_Enter)||(event.key()==Qt::Key_Return)) {
		indent_to_previous_line();
		QTextCursor cursor=textCursor();
		do_marker_highlighting(cursor);
		QString line=cursor.block().previous().text();
		QStringList symbols=split_into_symbols(line);
		if ((symbols.count()>0)&&
		    ( (symbols[symbols.count()-1]=="{") || (((symbols[symbols.count()-1]!=";"))&&((symbols[0]=="if") || (symbols[0]=="else") || (symbols[0]=="while") || (symbols[0]=="do") || (symbols[0]=="for"))) ) 
		    ) {
			QString line2=cursor.block().text();
			QStringList symbols2=split_into_symbols(line2);
			if ((symbols2.count()==0)||(symbols2[0]!="}")) //only indent if there is not a "{" starting the line
				cursor.insertText(tab_text(cursor));
		}
		//kind of a hack
		if (!blocks_highlighted_for_braces.isEmpty()) {
			blocks_highlighted_for_braces << textCursor().block();
		}
	}
	if (event.text()=="}") {
		QTextCursor cursor=textCursor();
		QString line=cursor.block().text();
		QStringList symbols=split_into_symbols(line);
		if (symbols.count()==1) {
			//unindent to last brace
			QTextBlock block=cursor.block();
			bool found=false;
			int braces_level=1;
			while ((!found)&&(block.isValid())) {
				block=block.previous();
				QString line2=block.text();
				QStringList symbols=split_into_symbols(line2);
				
				for (int j=symbols.count()-1; j>=0; j--) {
					if (symbols[j]=="{")
						braces_level--;
					if (symbols[j]=="}")
						braces_level++;
					if (braces_level==0)
						found=true;
				}
			}
			if (found) {
				QString line2=block.text();
				
				for (int j=0; j<line.count(); j++)
					cursor.deletePreviousChar();
				int j=0;
				while ((j<line2.count())&&((line2[j]==' ')||(line2[j]=='\t'))) {
					cursor.insertText(QString(line2[j]));
					j++;
				}
				cursor.insertText("}");
			}
		}
	}
	if ((event.text()==")")||(event.text()=="}")/*||(event.text()==">")*/) {
		highlight_braces(event.text(),true);
	}
	if ((event.text()=="(")||(event.text()=="{")/*||(event.text()=="<")*/) {
		highlight_braces(event.text(),false);
	}
}