ChatWindow::ChatWindow(AbstractChat * chat) : QWidget(), m_chat(chat), m_filename("%1/%2.html") { m_preferences = PreferencesManager::getInstance(); if (m_chat == NULL) { qFatal("ChatWindow with NULL chat"); } m_warnedEmoteUnavailable = false; m_hasUnseenMessage = false; // static members if (m_keyWordList.size() == 0) { m_keyWordList << "e" << "em" << "me" << "emote"; } setupUi(); connect(m_editionZone, SIGNAL(textValidated(bool,QString)), this, SLOT(emettreTexte(bool,QString))); connect(m_editionZone, SIGNAL(ctrlUp()), this, SLOT(upSelectPerson())); connect(m_editionZone, SIGNAL(ctrlDown()), this, SLOT(downSelectPerson())); //connect(m_mainWindow, SIGNAL(closing()), this, SLOT(save())); connect(m_chat, SIGNAL(changedMembers()), this, SLOT(scheduleUpdateChatMembers())); m_toggleViewAction = new QAction(this); m_toggleViewAction->setCheckable(true); m_diceParser = new DiceParser(); m_diceParser->setPathToHelp(tr("<a href=\"http://wiki.rolisteam.org/index.php/Dice_Rolling\">http://wiki.rolisteam.org/index.php/Dice_Rolling</a>")); m_operatorMap = new QMap<QString,CHAT_OPERATOR>(); m_operatorMap->insert("/",COMMAND); m_operatorMap->insert("!",DICEROLL); m_operatorMap->insert("&",SECRET_DICEROLL); }
void ImprovedTextEdit::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Return: case Qt::Key_Enter: { /// @warning changing the method to get the text QString textHtml = toHtml().trimmed(); QString text = toPlainText().trimmed(); if (!text.isEmpty()) { m_history.append(text); while (m_history.size() > MaxHistorySize) { m_history.removeFirst(); } m_histPos = m_history.size(); QString result = text; QString result2 = text.replace(QRegularExpression("((?:https?)://\\S+)"), "<a href=\"\\1\">\\1</a>"); Q_UNUSED(result2) if(text==result) { text.replace(QRegularExpression("((?:www)\\S+)"), "<a href=\"http://\\1\">\\1</a>"); } emit textValidated(textHtml,text); clear(); } } break; case Qt::Key_Up: if (e->modifiers() & Qt::ControlModifier) { emit ctrlUp(); } else if ((m_histPos > 0)&&(!m_history.empty())) { /// @warning changing the method to get the text QString text = toHtml().trimmed(); if (!text.isEmpty()) { if (m_histPos == m_history.size()) m_history.append(text); else m_history.replace(m_histPos, text); } m_histPos -= 1; //setHtml(m_history[m_histPos]); setText(m_history[m_histPos]); } break; case Qt::Key_Down: if (e->modifiers() & Qt::ControlModifier) { emit ctrlDown(); } else if(!m_history.empty()) { /// @warning changing the method to get the text QString text = toHtml().trimmed(); if((!text.isEmpty())) { if (m_histPos == m_history.size()) m_history.append(text); else m_history.replace(m_histPos, text); } if (m_histPos < m_history.size()) m_histPos += 1; if (m_histPos < m_history.size()) setText(m_history[m_histPos]); else clear(); } break; default: QTextEdit::keyPressEvent(e); }