+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)
+{
+ setFormatItalic(checked);
+}
+
+void InputWidget::fontChanged(const QFont& f)
+{
+ ui.boldButton->setChecked(f.bold());
+ ui.italicButton->setChecked(f.italic());
+ ui.underlineButton->setChecked(f.underline());
+ ui.strikethroughButton->setChecked(f.strikeOut());
+}
+
+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)