+
+void InputWidget::currentCharFormatChanged(const QTextCharFormat &format)
+{
+ fontChanged(format.font());
+}
+
+
+void InputWidget::on_boldButton_clicked(bool checked)
+{
+ QTextCharFormat fmt;
+ fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
+ mergeFormatOnSelection(fmt);
+}
+
+
+void InputWidget::on_underlineButton_clicked(bool checked)
+{
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(checked);
+ mergeFormatOnSelection(fmt);
+}
+
+
+void InputWidget::on_italicButton_clicked(bool checked)
+{
+ QTextCharFormat fmt;
+ fmt.setFontItalic(checked);
+ mergeFormatOnSelection(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 (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(QIcon::fromTheme("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(QIcon::fromTheme("format-fill-color"), color));
+}
+
+
+void InputWidget::on_showStyleButton_toggled(bool checked)
+{
+ ui.styleFrame->setVisible(checked);
+ if (checked) {
+ ui.showStyleButton->setArrowType(Qt::LeftArrow);
+ }
+ else {
+ ui.showStyleButton->setArrowType(Qt::RightArrow);
+ }
+}
+
+
+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);