void SeparateChatWindow::addMessage(const QString &message_raw, bool in, const QDateTime &message_date, bool history) { if ( m_log ) { quint64 tmp_position = m_log->textCursor().position(); QString color_from = "#FF0000"; QString color_to = "#0000FF"; QString color_timestamp = "#808080"; int timestamp_font_size = -2; QString message_header_format = " <b><font color=\"%1\">%2</font></b><br>"; QString message_body_format = "<font color=\"%1\" size=\"%2\">%3</font> %4<br>"; QString message_timestamp_format = "h:mm"; QString message_html; message_html += message_header_format .arg(in?color_from:color_to) // header font color .arg(in?m_contact_name:m_own_name); // name message_html += message_body_format .arg(color_timestamp) // timestamp font color .arg(timestamp_font_size) // timestamp font size .arg(message_date.toString(message_timestamp_format)) // timestamp .arg(message_raw); // message body m_current_scroll_position = m_log->verticalScrollBar()->value(); m_scroll_at_max = m_log->verticalScrollBar()->maximum() == m_current_scroll_position; moveCursorToEnd(); m_log->textCursor().insertImage(":/icons/crystal_project/message.png"); m_log->insertHtml(message_html); moveCursorToEnd(); if ( m_remove_message_after ) { if ( m_message_positions.count() >= m_remove_count ) { int message_length = m_message_positions.at(0); QTextCursor cursor = m_log->textCursor(); cursor.clearSelection(); cursor.setPosition(0, QTextCursor::MoveAnchor); cursor.setPosition(message_length, QTextCursor::KeepAnchor); cursor.removeSelectedText(); m_message_positions.removeAt(0); foreach( int icon_number, m_message_position_offset.keys() ) { int old_position = m_message_position_offset.value(icon_number); m_message_position_offset.remove(icon_number); m_message_position_offset.insert(icon_number, old_position - message_length); } } m_message_positions.append(m_log->textCursor().position() - tmp_position); } }
/** * Paste in code and execute as new lines are encountered */ void CommandLineInterpreter::paste() { const QClipboard *clipboard = QApplication::clipboard(); m_pastedText = clipboard->text(); if(m_pastedText.isEmpty()) return; const int lastLineIndex = indexOfLastLine(); if(indexOfCursorLine() != lastLineIndex) { moveCursorToEnd(); } int dummy(-1), offset(0); getCursorPosition(&dummy, &offset); if(containsNewlines(m_pastedText)) { processPastedCodeWithNewlines(offset); } else { // If no newlines just insert the text at the current position setText(lastLineIndex,m_pastedText,offset); } }
void SeparateConference::addServiceMessage(const QString &message, const QString &date) { if ( m_text_browser ) { m_current_scroll_position = m_text_browser->verticalScrollBar()->value(); m_scroll_at_max = m_text_browser->verticalScrollBar()->maximum() == m_current_scroll_position; QString modified_message; modified_message= AbstractChatLayer::instance().findUrls(Qt::escape(message)).replace("\n", "<br>"); m_text_browser->moveCursor(QTextCursor::End); m_text_browser->insertHtml(QString("<font size='-1' color=#808080>[%1] %2</font><br>") .arg(date) .arg(modified_message)); moveCursorToEnd(); } moveCursorToEnd(); }
void Editor::historyBack() { if (!m_history.count()) return; if (!m_currentHistoryIndex) return; if (m_currentHistoryIndex == m_history.count()) m_savedCurrentEditor = toPlainText(); --m_currentHistoryIndex; setText(m_history.at(m_currentHistoryIndex)); moveCursorToEnd(this); ensureCursorVisible(); }
void Editor::historyForward() { if (!m_history.count()) return; if (m_currentHistoryIndex == m_history.count()) return; m_currentHistoryIndex++; if (m_currentHistoryIndex == m_history.count()) setText(m_savedCurrentEditor); else setText(m_history.at(m_currentHistoryIndex)); moveCursorToEnd(this); ensureCursorVisible(); }
void SeparateConference::addMessage(const QString &from, const QString &message, const QString &date, bool history) { if ( !history ) checkForActive(message); if ( m_text_browser ) { quint64 tmp_position = m_text_browser->textCursor().position(); QString add_text; add_text.append(m_mine_nick != from ?QString("<b><font color=#0000FF>"):QString("<b><font color=#FF0000>")); if (message.contains(m_mine_nick)) qDebug() << "message.contains(m_mine_nick)"; if (m_mine_nick != from) qDebug() << "m_mine_nick != from"; if ((message.contains(m_mine_nick)) && (m_mine_nick != from)) Vibrate(); add_text.append(QString("[%1]").arg(date)); /* if ( m_show_names )*/ { add_text.append(QString(" %1").arg(Qt::escape(from))); } add_text.append(": </font></b>"); add_text.append(QString("%1<br>").arg(checkForEmoticons(message))); m_current_scroll_position = m_text_browser->verticalScrollBar()->value(); m_scroll_at_max = m_text_browser->verticalScrollBar()->maximum() == m_current_scroll_position; m_text_browser->moveCursor(QTextCursor::End); m_text_browser->insertHtml(add_text); moveCursorToEnd(); if ( m_remove_message_after ) { if ( m_message_positions.count() >= m_remove_count ) { int message_length = m_message_positions.at(0); QTextCursor cursor = m_text_browser->textCursor(); cursor.clearSelection(); cursor.setPosition(0, QTextCursor::MoveAnchor); cursor.setPosition(message_length, QTextCursor::KeepAnchor); cursor.removeSelectedText(); m_message_positions.removeAt(0); } m_message_positions.append(m_text_browser->textCursor().position() - tmp_position); } } /* if (m_mine_nick != from && message.contains(m_mine_nick)) { m_tab_compl->setLastReferrer(from); }*/ }
void SeparateConference::checkForActive(const QString &message) { if ( (!isActiveWindow() || isMinimized()) && !m_already_hred ) { if ( m_text_browser ) { m_text_browser->append("<hr><br>"); moveCursorToEnd(); } setWindowTitle("*" + m_conference_name); m_already_hred = true; } if ( message.contains(m_mine_nick)) { qApp->alert(this, 0); } }
void KexiComboBoxTableEdit::moveCursorToEndInInternalEditor() { moveCursorToEnd(); }