void RPCConsole::on_lineEdit_returnPressed() { QString cmd = ui->lineEdit->text(); ui->lineEdit->clear(); if(!cmd.isEmpty()) { message(CMD_REQUEST, cmd); emit cmdRequest(cmd); // Truncate history from current position history.erase(history.begin() + historyPtr, history.end()); // Append command to history history.append(cmd); // Enforce maximum history size while(history.size() > CONSOLE_HISTORY) history.removeFirst(); // Set pointer to end of history historyPtr = history.size(); // Scroll console view to end scrollToEnd(); } }
void RPCConsole::on_lineEdit_returnPressed() { QString cmd = ui->lineEdit->text(); ui->lineEdit->clear(); if(!cmd.isEmpty()) { message(CMD_REQUEST, cmd); emit cmdRequest(cmd); // Remove command, if already in history history.removeOne(cmd); // Append command to history history.append(cmd); // Enforce maximum history size while(history.size() > CONSOLE_HISTORY) history.removeFirst(); // Set pointer to end of history historyPtr = history.size(); // Scroll console view to end scrollToEnd(); } }
void ChatTab::AppendMessage (Plugins::IMessage *msg) { Plugins::ICLEntry *other = qobject_cast<Plugins::ICLEntry*> (msg->OtherPart ()); if (!other && msg->OtherPart ()) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetObject () << msg->OtherPart (); return; } if (msg->GetDirection () == Plugins::IMessage::DOut && other->GetEntryType () == Plugins::ICLEntry::ETMUC) return; QWebFrame *frame = Ui_.View_->page ()->mainFrame (); bool shouldScrollFurther = (frame->scrollBarMaximum (Qt::Vertical) == frame->scrollBarValue (Qt::Vertical)); QString body = FormatBody (msg->GetBody (), msg); QString string = QString ("%1 ") .arg (FormatDate (msg->GetDateTime (), msg)); string.append (' '); switch (msg->GetDirection ()) { case Plugins::IMessage::DIn: { switch (msg->GetMessageType ()) { case Plugins::IMessage::MTChatMessage: case Plugins::IMessage::MTMUCMessage: { QString entryName = Qt::escape (other->GetEntryName ()); entryName = FormatNickname (entryName, msg); if (body.startsWith ("/me ")) { body = body.mid (3); string.append ("*** "); string.append (entryName); string.append (' '); } else { string.append (entryName); string.append (": "); } break; } case Plugins::IMessage::MTEventMessage: string.append ("! "); break; } break; } case Plugins::IMessage::DOut: string.append (FormatNickname ("R", msg)); string.append (": "); break; } string.append (body); QWebElement elem = frame->findFirstElement ("body"); elem.appendInside (QString ("<div>%1</div").arg (string)); if (shouldScrollFurther) QTimer::singleShot (100, this, SLOT (scrollToEnd ())); }
/************************************************************************* Handler called when when the toEnd button clicked *************************************************************************/ bool FalagardChatHistory::handleToEndBtnClick(const EventArgs& e) { scrollToEnd(); return true; }
void SystemFrame::addLine(const LogMessagePtr& aMessageData) { ctrlPad.SetRedraw(FALSE); POINT pt = { 0 }; bool scroll = !lButtonDown && scrollIsAtEnd(); ctrlPad.GetScrollPos(&pt); int curPos = ctrlPad.CharFromPos(pt); //current scroll position by character pos LONG SavedBegin, SavedEnd; LONG Begin = 0; LONG End = 0; ctrlPad.GetSel(SavedBegin, SavedEnd); End = Begin = ctrlPad.GetTextLengthEx(GTL_NUMCHARS); tstring Text = Text::toT(aMessageData->getText()) + _T(" \r\n"); tstring time = Text::toT(" [" + Util::getTimeStamp(aMessageData->getTime()) + "] "); tstring line = time + Text; LONG limitText = ctrlPad.GetLimitText(); LONG TextLength = End + line.size(); if((TextLength +1) > limitText) { dcdebug("textlength %s \n", Util::toString(TextLength).c_str()); LONG RemoveEnd = 0; RemoveEnd = ctrlPad.LineIndex(ctrlPad.LineFromChar(2000)); End = Begin -=RemoveEnd; SavedBegin -= RemoveEnd; SavedEnd -= RemoveEnd; //fix the scroll position if text was removed from the start POINT p = { 0 }; curPos -= RemoveEnd; p = ctrlPad.PosFromChar(curPos); pt.y = p.y; ctrlPad.SetSel(0, RemoveEnd); ctrlPad.ReplaceSel(_T("")); } ctrlPad.AppendText(line.c_str()); End += time.size() -1; ctrlPad.SetSel(Begin, End); ctrlPad.SetSelectionCharFormat(WinUtil::m_TextStyleTimestamp); if (aMessageData->getSeverity() == LogMessage::SEV_ERROR) { ctrlPad.SetSel(End, End+Text.length()-1); CHARFORMAT2 ec = WinUtil::m_ChatTextGeneral; ec.crTextColor = SETTING(ERROR_COLOR); ctrlPad.SetSelectionCharFormat(ec); } Colorize(Text, End+1); //timestamps should always be timestamps right? ctrlPad.SetSel(Begin, Begin); switch(aMessageData->getSeverity()) { case LogMessage::SEV_INFO: CImageDataObject::InsertBitmap(ctrlPad.GetOleInterface(),hbInfo, false); break; case LogMessage::SEV_WARNING: CImageDataObject::InsertBitmap(ctrlPad.GetOleInterface(), hbWarning, false); break; case LogMessage::SEV_ERROR: CImageDataObject::InsertBitmap(ctrlPad.GetOleInterface(), hbError, false); if(!errorNotified && !getActive()) { setIcon(tabError); errorNotified = true; } break; default: break; } ctrlPad.SetSel(SavedBegin, SavedEnd); //restore the user selection if(scroll/* && (SavedBegin == SavedEnd)*/) { scrollToEnd(); } else { ctrlPad.SetScrollPos(&pt); } ctrlPad.SetRedraw(TRUE); ctrlPad.InvalidateRect(NULL); }