s.notify("ShowStyleButtons", this, SLOT(setShowStyleButtons(QVariant)));
setShowStyleButtons(s.value("ShowStyleButtons", true));
+ s.notify("EnablePerChatHistory", this, SLOT(setEnablePerChatHistory(QVariant)));
+ setEnablePerChatHistory(s.value("EnablePerChatHistory", true));
+
s.notify("MaxNumLines", this, SLOT(setMaxLines(QVariant)));
setMaxLines(s.value("MaxNumLines", 5));
ui.showStyleButton->setVisible(v.toBool());
}
+void InputWidget::setEnablePerChatHistory(const QVariant &v) {
+ _perChatHistory = v.toBool();
+}
+
void InputWidget::setMaxLines(const QVariant &v) {
ui.inputEdit->setMaxHeight(v.toInt());
}
}
void InputWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
- Q_UNUSED(previous)
+ BufferId currentBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+ BufferId previousBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
+
+ if (_perChatHistory) {
+ //backup
+ historyMap[previousBufferId].history = inputLine()->history();
+ historyMap[previousBufferId].tempHistory = inputLine()->tempHistory();
+ historyMap[previousBufferId].idx = inputLine()->idx();
+ historyMap[previousBufferId].inputLine = inputLine()->html();
+
+ //restore
+ inputLine()->setHistory(historyMap[currentBufferId].history);
+ inputLine()->setTempHistory(historyMap[currentBufferId].tempHistory);
+ inputLine()->setIdx(historyMap[currentBufferId].idx);
+ inputLine()->setHtml(historyMap[currentBufferId].inputLine);
+ inputLine()->moveCursor(QTextCursor::End,QTextCursor::MoveAnchor);
+ }
+
NetworkId networkId = current.data(NetworkModel::NetworkIdRole).value<NetworkId>();
if(networkId == _networkId)
return;
void setEnableSpellCheck(const QVariant &);
void setShowNickSelector(const QVariant &);
void setShowStyleButtons(const QVariant &);
+ void setEnablePerChatHistory(const QVariant &);
void setMaxLines(const QVariant &);
void setMultiLineEnabled(const QVariant &);
void setScrollBarsEnabled(const QVariant &);
QIcon createColorToolButtonIcon(const QIcon &icon, const QColor &color);
QTextCharFormat getFormatOfWordOrSelection();
void setFormatOnSelection(const QTextCharFormat &format);
+
+ bool _perChatHistory;
+ struct HistoryState {
+ QStringList history;
+ QHash<int, QString> tempHistory;
+ qint32 idx;
+ QString inputLine;
+ };
+
+ QMap<BufferId, HistoryState> historyMap;
};
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="enablePerBufferHistory">
+ <property name="text">
+ <string>Enable per chat history</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="settingsKey" stdset="0">
+ <string>EnablePerChatHistory</string>
+ </property>
+ <property name="defaultValue" stdset="0">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
<item>
<widget class="QCheckBox" name="showNickSelector">
<property name="text">
#else
QTextEdit(parent),
#endif
- idx(0),
+ _idx(0),
_mode(SingleLine),
_singleLine(true),
_minHeight(1),
void MultiLineEdit::historyMoveBack() {
addToHistory(convertRichtextToMircCodes(), true);
- if(idx > 0) {
- idx--;
+ if(_idx > 0) {
+ _idx--;
showHistoryEntry();
}
}
void MultiLineEdit::historyMoveForward() {
addToHistory(convertRichtextToMircCodes(), true);
- if(idx < history.count()) {
- idx++;
- if(idx < history.count() || tempHistory.contains(idx)) // tempHistory might have an entry for idx == history.count() + 1
+ if(_idx < _history.count()) {
+ _idx++;
+ if(_idx < _history.count() || _tempHistory.contains(_idx)) // tempHistory might have an entry for idx == history.count() + 1
showHistoryEntry();
else
reset(); // equals clear() in this case
if(text.isEmpty())
return false;
- Q_ASSERT(0 <= idx && idx <= history.count());
+ Q_ASSERT(0 <= _idx && _idx <= _history.count());
if(temporary) {
// if an entry of the history is changed, we remember it and show it again at this
// position until a line was actually sent
// sent lines get appended to the history
- if(history.isEmpty() || text != history[idx - (int)(idx == history.count())]) {
- tempHistory[idx] = text;
+ if(_history.isEmpty() || text != _history[_idx - (int)(_idx == _history.count())]) {
+ _tempHistory[_idx] = text;
return true;
}
} else {
- if(history.isEmpty() || text != history.last()) {
- history << text;
- tempHistory.clear();
+ if(_history.isEmpty() || text != _history.last()) {
+ _history << text;
+ _tempHistory.clear();
return true;
}
}
emit textEntered(line);
}
reset();
- tempHistory.clear();
+ _tempHistory.clear();
} else {
emit noTextEntered();
}
void MultiLineEdit::reset() {
// every time the MultiLineEdit is cleared we also reset history index
- idx = history.count();
+ _idx = _history.count();
clear();
QTextBlockFormat format = textCursor().blockFormat();
format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
void MultiLineEdit::showHistoryEntry() {
// if the user changed the history, display the changed line
- setHtml(convertMircCodesToHtml(tempHistory.contains(idx) ? tempHistory[idx] : history[idx]));
+ setHtml(convertMircCodesToHtml(_tempHistory.contains(_idx) ? _tempHistory[_idx] : _history[_idx]));
QTextCursor cursor = textCursor();
QTextBlockFormat format = cursor.blockFormat();
format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
inline QMap<QString, QString> mircColorMap() const { return _mircColorMap; }
+ inline QStringList history() { return _history; }
+ inline QHash<int, QString> tempHistory() { return _tempHistory; }
+ inline qint32 idx() { return _idx; }
+
public slots:
void setMode(Mode mode);
void setMinHeight(int numLines);
// Note: Enabling wrap will make isSingleLine() not work correctly, so only use this if minHeight() > 1!
void setWordWrapEnabled(bool enable = true);
+ inline void setHistory(QStringList history) { _history = history; }
+ inline void setTempHistory(QHash<int, QString> tempHistory) { _tempHistory = tempHistory; }
+ inline void setIdx(qint32 idx) { _idx = idx; }
+
signals:
void textEntered(const QString &text);
void noTextEntered();
bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
private:
- QStringList history;
- QHash<int, QString> tempHistory;
- qint32 idx;
+ QStringList _history;
+ QHash<int, QString> _tempHistory;
+ qint32 _idx;
Mode _mode;
bool _singleLine;
int _minHeight;