Exemplo n.º 1
0
void ChatView::appendHtml(const QString &html)
{
	bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
	prepareBlock().insertHtml(html);
	if (atBottom)
		verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
Exemplo n.º 2
0
bool Log::BlockBuffer::toMem(uint32_t blockId, void *dest, size_t size) {
  if (!prepareBlock(blockId)) return false;

  memcpy(dest, block, size);

  return true;
}
Exemplo n.º 3
0
bool Log::BlockBuffer::readHeader(uint32_t blockId, BlockHeader *header) {
  if (!prepareBlock(blockId)) return false;

  *header = asBlock()->header;

  return true;
}
Exemplo n.º 4
0
bool Log::BlockBuffer::writeHeader(uint32_t blockId, const BlockHeader& header) {
  if (!prepareBlock(blockId)) return false;

  asBlock()->header = header;
  dirty = true;

  return true;
}
Exemplo n.º 5
0
bool Log::BlockBuffer::fromMem(uint32_t blockId, const void *src, size_t size) {
  if (!prepareBlock(blockId)) return false;

  memset(block, 0, BLOCK_SIZE);
  memcpy(block, src, size);

  dirty = true;

  return true;
}
Exemplo n.º 6
0
bool Log::BlockBuffer::readEntry(uint32_t blockId,
                                 uint32_t entryId,
                                 Entry *entry) {
  if (!isValidEntryId(entryId)) return false;
  if (!prepareBlock(blockId)) return false;

  *entry = asBlock()->entries[entryId];

  return true;
}
Exemplo n.º 7
0
bool Log::BlockBuffer::writeEntry(uint32_t blockId,
                                  uint32_t entryId,
                                  const Entry& entry) {
  if (!isValidEntryId(entryId)) return false;
  if (!prepareBlock(blockId)) return false;

  asBlock()->entries[entryId] = entry;
  dirty = true;

  return true;
}
Exemplo n.º 8
0
void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold, QString optionalFontColor)
{
    bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();

    QString htmlText = "<font color=" + ((optionalFontColor.size() > 0) ? optionalFontColor : SERVER_MESSAGE_COLOR) + ">" + QDateTime::currentDateTime().toString("[hh:mm:ss] ")+ html + "</font>";

    if (optionalIsBold)
        htmlText = "<b>" + htmlText + "</b>";

    prepareBlock().insertHtml(htmlText);
    if (atBottom)
        verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
Exemplo n.º 9
0
void ChatView::appendMessage(QString message, QString sender, UserLevelFlags userLevel, bool playerBold)
{
	bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
	bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
	QTextCursor cursor = prepareBlock(sameSender);
	lastSender = sender;
	
	if (showTimestamps && !sameSender) {
		QTextCharFormat timeFormat;
		timeFormat.setForeground(Qt::black);
		cursor.setCharFormat(timeFormat);
		cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
	}
	
	QTextCharFormat senderFormat;
	if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
		senderFormat.setFontWeight(QFont::Bold);
		senderFormat.setForeground(Qt::red);
	} else {
		senderFormat.setForeground(Qt::blue);
		if (playerBold)
			senderFormat.setFontWeight(QFont::Bold);
	}
	senderFormat.setAnchor(true);
	senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
	if (!sameSender) {
		if (!sender.isEmpty()) {
			const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
			cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel));
			cursor.insertText(" ");
		}
		cursor.setCharFormat(senderFormat);
		if (!sender.isEmpty())
			sender.append(": ");
		cursor.insertText(sender);
	} else
		cursor.insertText("    ");
	
	QTextCharFormat messageFormat;
	if (sender.isEmpty())
		messageFormat.setForeground(Qt::darkGreen);
	cursor.setCharFormat(messageFormat);
	
	int from = 0, index = 0;
	while ((index = message.indexOf('[', from)) != -1) {
		cursor.insertText(message.left(index));
		message = message.mid(index);
		if (message.isEmpty())
			break;
		
		if (message.startsWith("[card]")) {
			message = message.mid(6);
			int closeTagIndex = message.indexOf("[/card]");
			QString cardName = message.left(closeTagIndex);
			if (closeTagIndex == -1)
				message.clear();
			else
				message = message.mid(closeTagIndex + 7);
			
			QTextCharFormat tempFormat = messageFormat;
			tempFormat.setForeground(Qt::blue);
			tempFormat.setAnchor(true);
			tempFormat.setAnchorHref("card://" + cardName);
			
			cursor.setCharFormat(tempFormat);
			cursor.insertText(cardName);
			cursor.setCharFormat(messageFormat);
		} else if (message.startsWith("[url]")) {
			message = message.mid(5);
			int closeTagIndex = message.indexOf("[/url]");
			QString url = message.left(closeTagIndex);
			if (closeTagIndex == -1)
				message.clear();
			else
				message = message.mid(closeTagIndex + 6);
			
			if (!url.contains("://"))
				url.prepend("http://");
			
			QTextCharFormat tempFormat = messageFormat;
			tempFormat.setForeground(Qt::blue);
			tempFormat.setAnchor(true);
			tempFormat.setAnchorHref(url);
			
			cursor.setCharFormat(tempFormat);
			cursor.insertText(url);
			cursor.setCharFormat(messageFormat);
		} else
			from = 1;
	}
	if (!message.isEmpty())
		cursor.insertText(message);
	
	if (atBottom)
		verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
Exemplo n.º 10
0
void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType, QString sender, UserLevelFlags userLevel, QString UserPrivLevel, bool playerBold)
{
    bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
    bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
    QTextCursor cursor = prepareBlock(sameSender);
    lastSender = sender;
    
    // timestamp
    if (showTimestamps && (!sameSender || sender.toLower() == "servatrice") && !sender.isEmpty()) {
        QTextCharFormat timeFormat;
        timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR));
        if (sender.isEmpty())
            timeFormat.setFontWeight(QFont::Bold);
        cursor.setCharFormat(timeFormat);
        cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] "));
    }

    // nickname
    if (sender.toLower() != "servatrice") {
        QTextCharFormat senderFormat;
        if (tabSupervisor && tabSupervisor->getUserInfo() &&
            (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
            senderFormat.setForeground(QBrush(getCustomMentionColor()));
            senderFormat.setFontWeight(QFont::Bold);
        } else {
            senderFormat.setForeground(QBrush(OTHER_USER_COLOR));
            if (playerBold)
                senderFormat.setFontWeight(QFont::Bold);
        }
        senderFormat.setAnchor(true);
        senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
        if (sameSender) {
            cursor.insertText("    ");
        } else {
            if (!sender.isEmpty() && tabSupervisor->getUserListsTab()) {
                const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
                QMap<QString, UserListTWI *> buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers();
                cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, buddyList.contains(sender), UserPrivLevel).toImage());
                cursor.insertText(" ");
            }
            cursor.setCharFormat(senderFormat);
            if (!sender.isEmpty())
                sender.append(": ");
            cursor.insertText(sender);
        }
    }

    // use different color for server messages 
    defaultFormat = QTextCharFormat();
    if (sender.isEmpty()) {
        switch (messageType) {
            case Event_RoomSay::Welcome:
                defaultFormat.setForeground(Qt::darkGreen);
                defaultFormat.setFontWeight(QFont::Bold);
                break;
            case Event_RoomSay::ChatHistory:
                defaultFormat.setForeground(Qt::gray);
                defaultFormat.setFontWeight(QFont::Light);
                defaultFormat.setFontItalic(true);
                break;
            default:
                defaultFormat.setForeground(Qt::darkGreen);
                defaultFormat.setFontWeight(QFont::Bold);
        }
    } else if (sender.toLower() == "servatrice") {
        defaultFormat.setForeground(Qt::darkGreen);
        defaultFormat.setFontWeight(QFont::Bold);
    }
    cursor.setCharFormat(defaultFormat);

    bool mentionEnabled = settingsCache->getChatMention();
    highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts);

    // parse the message
    while (message.size())
    {
        QChar c = message.at(0);    
        switch(c.toLatin1())
        {
            case '[':
                checkTag(cursor, message);
                break;
            case '@':
                if(mentionEnabled) {
                    checkMention(cursor, message, sender, userLevel);
                } else {
                    cursor.insertText(c, defaultFormat);
                    message = message.mid(1);
                }
                break;
            case ' ':
                cursor.insertText(c, defaultFormat);
                message = message.mid(1);
                break;
            default:
                if(c.isLetterOrNumber()) {
                    checkWord(cursor, message);
                } else {
                    cursor.insertText(c, defaultFormat);
                    message = message.mid(1);
                }
                break;
        }
    }

    if (atBottom)
        verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
Exemplo n.º 11
0
void ChatView::appendMessage(QString sender, QString message, QColor playerColor, bool playerBold)
{
    bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
    bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
    QTextCursor cursor = prepareBlock(sameSender);
    lastSender = sender;

    if (showTimestamps && !sameSender) {
        QTextCharFormat timeFormat;
        timeFormat.setForeground(Qt::black);
        cursor.setCharFormat(timeFormat);
        cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
    }

    QTextCharFormat senderFormat;
    if (sender == ownName) {
        senderFormat.setFontWeight(QFont::Bold);
        senderFormat.setForeground(Qt::red);
    } else {
        if (playerColor == QColor())
            senderFormat.setForeground(QColor(0, 0, 254));
        else
            senderFormat.setForeground(playerColor);
        if (playerBold)
            senderFormat.setFontWeight(QFont::Bold);
    }
    if (!sameSender) {
        cursor.setCharFormat(senderFormat);
        if (!sender.isEmpty())
            sender.append(": ");
        cursor.insertText(sender);
    } else
        cursor.insertText("    ");

    QTextCharFormat messageFormat;
    if (sender.isEmpty())
        messageFormat.setForeground(Qt::darkGreen);
    cursor.setCharFormat(messageFormat);

    int from = 0, index = 0;
    while ((index = message.indexOf('[', from)) != -1) {
        cursor.insertText(message.left(index));
        message = message.mid(index);
        if (message.isEmpty())
            break;

        if (message.startsWith("[card]")) {
            message = message.mid(6);
            QTextCharFormat tempFormat = messageFormat;
            tempFormat.setForeground(Qt::blue);
            cursor.setCharFormat(tempFormat);
            int closeTagIndex = message.indexOf("[/card]");
            cursor.insertText(message.left(closeTagIndex));
            cursor.setCharFormat(messageFormat);
            if (closeTagIndex == -1)
                message.clear();
            else
                message = message.mid(closeTagIndex + 7);
        } else if (message.startsWith("[url]")) {
            message = message.mid(5);
            int closeTagIndex = message.indexOf("[/url]");
            QString url = message.left(closeTagIndex);
            if (!url.startsWith("http://"))
                url.prepend("http://");
            QTextCharFormat tempFormat = messageFormat;
            tempFormat.setForeground(QColor(0, 0, 254));
            tempFormat.setAnchor(true);
            tempFormat.setAnchorHref(url);
            cursor.setCharFormat(tempFormat);
            cursor.insertText(url);
            cursor.setCharFormat(messageFormat);
            if (closeTagIndex == -1)
                message.clear();
            else
                message = message.mid(closeTagIndex + 6);
        } else
            from = 1;
    }
    if (!message.isEmpty())
        cursor.insertText(message);

    if (atBottom)
        verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}