+
+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);