+
+ // we reset the nick selecter as we have no confirmation yet, that this will succeed.
+ // if the action succeeds it will be properly updated anyways.
+ updateNickSelector();
+ Client::userInput(BufferInfo::fakeStatusBuffer(net->networkId()), QString("/NICK %1").arg(newNick));
+}
+
+void InputWidget::on_inputEdit_textEntered(const QString &text) const {
+ Client::userInput(currentBufferInfo(), text);
+ ui.boldButton->setChecked(false);
+ ui.underlineButton->setChecked(false);
+ ui.italicButton->setChecked(false);
+
+ QTextCharFormat fmt;
+ fmt.setFontWeight(QFont::Normal);
+ fmt.setFontUnderline(false);
+ fmt.setFontItalic(false);
+ fmt.clearForeground();
+ fmt.clearBackground();
+ inputLine()->setCurrentCharFormat(fmt);
+}
+
+void InputWidget::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
+ QTextCursor cursor = inputLine()->textCursor();
+ if (!cursor.hasSelection())
+ cursor.select(QTextCursor::WordUnderCursor);
+ cursor.mergeCharFormat(format);
+ inputLine()->mergeCurrentCharFormat(format);
+}
+
+void InputWidget::setFormatOnWordOrSelection(const QTextCharFormat &format) {
+ QTextCursor cursor = inputLine()->textCursor();
+ if (!cursor.hasSelection())
+ cursor.select(QTextCursor::WordUnderCursor);
+ cursor.setCharFormat(format);
+ inputLine()->setCurrentCharFormat(format);
+}
+
+QTextCharFormat InputWidget::getFormatOfWordOrSelection() {
+ QTextCursor cursor = inputLine()->textCursor();
+ return cursor.charFormat();
+}
+
+void InputWidget::currentCharFormatChanged(const QTextCharFormat &format) {
+ fontChanged(format.font());
+
+ if (format.foreground().isOpaque())
+ colorChanged(format.foreground().color());
+ else
+ colorChanged(Qt::transparent);
+ if (format.background().isOpaque())
+ colorHighlightChanged(format.background().color());
+ else
+ colorHighlightChanged(Qt::transparent);
+}
+
+void InputWidget::on_boldButton_clicked(bool checked) {
+ QTextCharFormat fmt;
+ fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void InputWidget::on_underlineButton_clicked(bool checked) {
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(checked);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void InputWidget::on_italicButton_clicked(bool checked) {
+ QTextCharFormat fmt;
+ fmt.setFontItalic(checked);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void InputWidget::fontChanged(const QFont &f)
+{
+ ui.boldButton->setChecked(f.bold());
+ ui.italicButton->setChecked(f.italic());
+ ui.underlineButton->setChecked(f.underline());
+}
+
+void InputWidget::colorChosen(QAction *action) {
+ QTextCharFormat fmt;
+ QColor color;
+ if (qVariantValue<QString>(action->data()) == "") {
+ color = Qt::transparent;
+ fmt = getFormatOfWordOrSelection();
+ fmt.clearForeground();
+ setFormatOnWordOrSelection(fmt);
+ }
+ else {
+ color = QColor(inputLine()->rgbColorFromMirc(qVariantValue<QString>(action->data())));
+ fmt.setForeground(color);
+ mergeFormatOnWordOrSelection(fmt);
+ }
+ ui.textcolorButton->setDefaultAction(action);
+ ui.textcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-text-color"), color));
+}
+
+void InputWidget::colorHighlightChosen(QAction *action) {
+ QTextCharFormat fmt;
+ QColor color;
+ if (qVariantValue<QString>(action->data()) == "") {
+ color = Qt::transparent;
+ fmt = getFormatOfWordOrSelection();
+ fmt.clearBackground();
+ setFormatOnWordOrSelection(fmt);
+ }
+ else {
+ color = QColor(inputLine()->rgbColorFromMirc(qVariantValue<QString>(action->data())));
+ fmt.setBackground(color);
+ mergeFormatOnWordOrSelection(fmt);
+ }
+ ui.highlightcolorButton->setDefaultAction(action);
+ ui.highlightcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-fill-color"), color));
+}
+
+void InputWidget::colorChanged(const QColor &fg) {
+ if (fg == Qt::transparent)
+ ui.textcolorButton->setDefaultAction(_colorMenu->actions().last());
+ else
+ ui.textcolorButton->setDefaultAction(_colorMenu->actions().value(inputLine()->mircColorFromRGB(fg.name()).toInt()));
+
+ ui.textcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-text-color"), fg));
+}
+
+void InputWidget::colorHighlightChanged(const QColor &bg) {
+ if (bg == Qt::transparent)
+ ui.highlightcolorButton->setDefaultAction(_colorFillMenu->actions().last());
+ else
+ ui.highlightcolorButton->setDefaultAction(_colorFillMenu->actions().value(inputLine()->mircColorFromRGB(bg.name()).toInt()));
+
+ ui.highlightcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-fill-color"), bg));