+void InputWidget::clearFormat()
+{
+ // Clear all formatting for selection (not global)
+ setFormatClear(false);
+}
+
+void InputWidget::setNetwork(NetworkId networkId)
+{
+ if (_networkId == networkId)
+ return;
+
+ const Network* previousNet = Client::network(_networkId);
+ if (previousNet) {
+ disconnect(previousNet, nullptr, this, nullptr);
+ if (previousNet->me())
+ disconnect(previousNet->me(), nullptr, this, nullptr);
+ }
+
+ _networkId = networkId;
+
+ const Network* network = Client::network(networkId);
+ if (network) {
+ connect(network, &Network::identitySet, this, &InputWidget::setIdentity);
+ connectMyIrcUser();
+ setIdentity(network->identity());
+ }
+ else {
+ setIdentity(0);
+ _networkId = 0;
+ }
+}
+
+void InputWidget::connectMyIrcUser()
+{
+ const Network* network = currentNetwork();
+ if (network->me()) {
+ connect(network->me(), &IrcUser::nickSet, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesSet, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesAdded, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesRemoved, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::awaySet, this, &InputWidget::updateNickSelector);
+ disconnect(network, &Network::myNickSet, this, &InputWidget::connectMyIrcUser);
+ updateNickSelector();
+ }
+ else {
+ connect(network, &Network::myNickSet, this, &InputWidget::connectMyIrcUser);
+ }
+}
+
+void InputWidget::setIdentity(IdentityId identityId)
+{
+ if (_identityId == identityId)
+ return;
+
+ const Identity* previousIdentity = Client::identity(_identityId);
+ if (previousIdentity)
+ disconnect(previousIdentity, nullptr, this, nullptr);
+
+ _identityId = identityId;
+
+ const Identity* identity = Client::identity(identityId);
+ if (identity) {
+ connect(identity, &Identity::nicksSet, this, &InputWidget::updateNickSelector);
+ }
+ else {
+ _identityId = 0;
+ }
+ updateNickSelector();
+}
+
+void InputWidget::updateNickSelector() const
+{
+ ui.ownNick->clear();
+
+ const Network* net = currentNetwork();
+ if (!net)
+ return;
+
+ const Identity* identity = Client::identity(net->identity());
+ if (!identity) {
+ qWarning() << "InputWidget::updateNickSelector(): can't find Identity for Network" << net->networkId()
+ << "IdentityId:" << net->identity();
+ return;
+ }
+
+ int nickIdx;
+ QStringList nicks = identity->nicks();
+ if ((nickIdx = nicks.indexOf(net->myNick())) == -1) {
+ nicks.prepend(net->myNick());
+ nickIdx = 0;
+ }
+
+ if (nicks.isEmpty())
+ return;
+
+ IrcUser* me = net->me();
+ if (me) {
+ nicks[nickIdx] = net->myNick();
+ if (!me->userModes().isEmpty())
+ nicks[nickIdx] += QString(" (+%1)").arg(me->userModes());
+ }
+
+ ui.ownNick->addItems(nicks);
+
+ if (me && me->isAway())
+ ui.ownNick->setItemData(nickIdx, icon::get({"im-user-away", "user-away"}), Qt::DecorationRole);
+
+ ui.ownNick->setCurrentIndex(nickIdx);
+}
+
+void InputWidget::changeNick(const QString& newNick) const
+{
+ const Network* net = currentNetwork();
+ if (!net || net->isMyNick(newNick))
+ return;
+
+ // 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::onTextEntered(const QString& text)
+{
+ Client::userInput(currentBufferInfo(), text);
+
+ // Remove formatting from entered text
+ // TODO: Offer a way to convert pasted text to mIRC formatting codes
+ setFormatClear(true);
+}
+
+void InputWidget::setFormatClear(const bool global)
+{
+ // Apply formatting
+ QTextCharFormat fmt;
+ fmt.setFontWeight(QFont::Normal);
+ fmt.setFontUnderline(false);
+ fmt.setFontStrikeOut(false);
+ fmt.setFontItalic(false);
+ fmt.clearForeground();
+ fmt.clearBackground();
+ if (global) {
+ inputLine()->setCurrentCharFormat(fmt);
+ }
+ else {
+ setFormatOnSelection(fmt);
+ }
+
+ // Make sure UI state follows
+ ui.boldButton->setChecked(false);
+ ui.italicButton->setChecked(false);
+ ui.underlineButton->setChecked(false);
+ ui.strikethroughButton->setChecked(false);
+}
+
+void InputWidget::setFormatBold(const bool bold)
+{
+ // Apply formatting
+ QTextCharFormat fmt;
+ fmt.setFontWeight(bold ? QFont::Bold : QFont::Normal);
+ mergeFormatOnSelection(fmt);
+ // Make sure UI state follows
+ ui.boldButton->setChecked(bold);
+}
+
+void InputWidget::setFormatItalic(const bool italic)
+{
+ // Apply formatting
+ QTextCharFormat fmt;
+ fmt.setFontItalic(italic);
+ mergeFormatOnSelection(fmt);
+ // Make sure UI state follows
+ ui.italicButton->setChecked(italic);
+}
+
+void InputWidget::setFormatUnderline(const bool underline)
+{
+ // Apply formatting
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(underline);
+ mergeFormatOnSelection(fmt);
+ // Make sure UI state follows
+ ui.underlineButton->setChecked(underline);
+}
+
+void InputWidget::setFormatStrikethrough(const bool strike)
+{
+ // Apply formatting
+ QTextCharFormat fmt;
+ fmt.setFontStrikeOut(strike);
+ mergeFormatOnSelection(fmt);
+ // Make sure UI state follows
+ ui.strikethroughButton->setChecked(strike);
+}
+
+void InputWidget::mergeFormatOnSelection(const QTextCharFormat& format)
+{
+ QTextCursor cursor = inputLine()->textCursor();
+ cursor.mergeCharFormat(format);
+ inputLine()->mergeCurrentCharFormat(format);
+}
+
+void InputWidget::setFormatOnSelection(const QTextCharFormat& format)
+{
+ QTextCursor cursor = inputLine()->textCursor();
+ cursor.setCharFormat(format);
+ inputLine()->setCurrentCharFormat(format);
+}
+
+QTextCharFormat InputWidget::getFormatOfWordOrSelection()
+{
+ QTextCursor cursor = inputLine()->textCursor();
+ return cursor.charFormat();
+}
+
+void InputWidget::setStyleOptionsExpanded(bool expanded)
+{
+ ui.styleFrame->setVisible(expanded);
+ if (expanded) {
+ ui.showStyleButton->setArrowType(Qt::LeftArrow);
+ ui.showStyleButton->setToolTip(tr("Hide formatting options"));
+ }
+ else {
+ ui.showStyleButton->setArrowType(Qt::RightArrow);
+ ui.showStyleButton->setToolTip(tr("Show formatting options"));
+ }
+}
+
+void InputWidget::currentCharFormatChanged(const QTextCharFormat& format)
+{
+ fontChanged(format.font());
+}
+
+void InputWidget::on_boldButton_clicked(bool checked)
+{
+ setFormatBold(checked);
+}
+
+void InputWidget::on_underlineButton_clicked(bool checked)
+{
+ setFormatUnderline(checked);
+}
+
+void InputWidget::on_strikethroughButton_clicked(bool checked)
+{
+ setFormatStrikethrough(checked);
+}
+
+void InputWidget::on_italicButton_clicked(bool checked)