+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.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);
+}
+
+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::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_italicButton_clicked(bool checked)
+{
+ setFormatItalic(checked);
+}
+
+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 (action->data().value<QString>() == "") {
+ color = Qt::transparent;
+ fmt = getFormatOfWordOrSelection();
+ fmt.clearForeground();
+ setFormatOnSelection(fmt);
+ }
+ else {
+ color = QColor(inputLine()->rgbColorFromMirc(action->data().value<QString>()));
+ fmt.setForeground(color);
+ mergeFormatOnSelection(fmt);
+ }
+ ui.textcolorButton->setDefaultAction(action);
+ ui.textcolorButton->setIcon(createColorToolButtonIcon(icon::get("format-text-color"), color));
+}
+
+void InputWidget::colorHighlightChosen(QAction* action)
+{
+ QTextCharFormat fmt;
+ QColor color;
+ if (action->data().value<QString>() == "") {
+ color = Qt::transparent;
+ fmt = getFormatOfWordOrSelection();
+ fmt.clearBackground();
+ setFormatOnSelection(fmt);
+ }
+ else {
+ color = QColor(inputLine()->rgbColorFromMirc(action->data().value<QString>()));
+ fmt.setBackground(color);
+ mergeFormatOnSelection(fmt);
+ }
+ ui.highlightcolorButton->setDefaultAction(action);
+ ui.highlightcolorButton->setIcon(createColorToolButtonIcon(icon::get("format-fill-color"), color));
+}
+
+void InputWidget::on_showStyleButton_toggled(bool checked)
+{
+ setStyleOptionsExpanded(checked);
+}
+
+QIcon InputWidget::createColorToolButtonIcon(const QIcon& icon, const QColor& color)
+{
+ QPixmap pixmap(16, 16);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ QPixmap image = icon.pixmap(16, 16);
+ QRect target(0, 0, 16, 14);
+ QRect source(0, 0, 16, 14);
+ painter.fillRect(QRect(0, 14, 16, 16), color);
+ painter.drawPixmap(target, image, source);
+
+ return QIcon(pixmap);
+}
+
+// MOUSE WHEEL FILTER
+MouseWheelFilter::MouseWheelFilter(QObject* parent)
+ : QObject(parent)
+{}
+
+bool MouseWheelFilter::eventFilter(QObject* obj, QEvent* event)
+{
+ if (event->type() != QEvent::Wheel)
+ return QObject::eventFilter(obj, event);
+ else
+ return true;