diff --git a/graphics.qrc b/graphics.qrc index c51a80cf..5169b369 100644 --- a/graphics.qrc +++ b/graphics.qrc @@ -51,5 +51,13 @@ img/buttonIconsWhite/text.png img/configBlack/colorize.png img/configWhite/colorize.png + img/configWhite/format_bold.png + img/configWhite/format_italic.png + img/configWhite/format_strikethrough.png + img/configWhite/format_underlined.png + img/configBlack/format_bold.png + img/configBlack/format_italic.png + img/configBlack/format_strikethrough.png + img/configBlack/format_underlined.png diff --git a/img/configBlack/format_bold.png b/img/configBlack/format_bold.png new file mode 100644 index 00000000..540150d8 Binary files /dev/null and b/img/configBlack/format_bold.png differ diff --git a/img/configBlack/format_bold.svg b/img/configBlack/format_bold.svg new file mode 100755 index 00000000..ca6b4b63 --- /dev/null +++ b/img/configBlack/format_bold.svg @@ -0,0 +1,4 @@ + + + + diff --git a/img/configBlack/format_italic.png b/img/configBlack/format_italic.png new file mode 100644 index 00000000..394aaf63 Binary files /dev/null and b/img/configBlack/format_italic.png differ diff --git a/img/configBlack/format_italic.svg b/img/configBlack/format_italic.svg new file mode 100755 index 00000000..fa65b97d --- /dev/null +++ b/img/configBlack/format_italic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/img/configBlack/format_strikethrough.png b/img/configBlack/format_strikethrough.png new file mode 100644 index 00000000..6c3c226e Binary files /dev/null and b/img/configBlack/format_strikethrough.png differ diff --git a/img/configBlack/format_strikethrough.svg b/img/configBlack/format_strikethrough.svg new file mode 100755 index 00000000..15151054 --- /dev/null +++ b/img/configBlack/format_strikethrough.svg @@ -0,0 +1,4 @@ + + + + diff --git a/img/configBlack/format_underlined.png b/img/configBlack/format_underlined.png new file mode 100644 index 00000000..5a0da6c6 Binary files /dev/null and b/img/configBlack/format_underlined.png differ diff --git a/img/configBlack/format_underlined.svg b/img/configBlack/format_underlined.svg new file mode 100755 index 00000000..8615187f --- /dev/null +++ b/img/configBlack/format_underlined.svg @@ -0,0 +1,4 @@ + + + + diff --git a/img/configWhite/format_bold.png b/img/configWhite/format_bold.png new file mode 100644 index 00000000..e16a9f2e Binary files /dev/null and b/img/configWhite/format_bold.png differ diff --git a/img/configWhite/format_bold.svg b/img/configWhite/format_bold.svg new file mode 100755 index 00000000..94eb2fa1 --- /dev/null +++ b/img/configWhite/format_bold.svg @@ -0,0 +1,58 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/img/configWhite/format_italic.png b/img/configWhite/format_italic.png new file mode 100644 index 00000000..1a6422c9 Binary files /dev/null and b/img/configWhite/format_italic.png differ diff --git a/img/configWhite/format_italic.svg b/img/configWhite/format_italic.svg new file mode 100755 index 00000000..14cbd711 --- /dev/null +++ b/img/configWhite/format_italic.svg @@ -0,0 +1,58 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/img/configWhite/format_strikethrough.png b/img/configWhite/format_strikethrough.png new file mode 100644 index 00000000..c4f641c9 Binary files /dev/null and b/img/configWhite/format_strikethrough.png differ diff --git a/img/configWhite/format_strikethrough.svg b/img/configWhite/format_strikethrough.svg new file mode 100755 index 00000000..812c02be --- /dev/null +++ b/img/configWhite/format_strikethrough.svg @@ -0,0 +1,58 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/img/configWhite/format_underlined.png b/img/configWhite/format_underlined.png new file mode 100644 index 00000000..ca485a68 Binary files /dev/null and b/img/configWhite/format_underlined.png differ diff --git a/img/configWhite/format_underlined.svg b/img/configWhite/format_underlined.svg new file mode 100755 index 00000000..f0cc574e --- /dev/null +++ b/img/configWhite/format_underlined.svg @@ -0,0 +1,58 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/tools/text/textconfig.cpp b/src/tools/text/textconfig.cpp index 6f586aae..078124e1 100644 --- a/src/tools/text/textconfig.cpp +++ b/src/tools/text/textconfig.cpp @@ -16,9 +16,90 @@ // along with Flameshot. If not, see . #include "textconfig.h" +#include "src/utils/colorutils.h" +#include "src/utils/pathinfo.h" +#include +#include +#include +#include +#include TextConfig::TextConfig(QWidget *parent) : QWidget(parent) { + m_layout = new QVBoxLayout(this); + QFontDatabase fontDB; + QComboBox *fontsCB = new QComboBox(); + connect(fontsCB, &QComboBox::currentTextChanged, + this, &TextConfig::fontFamilyChanged); + fontsCB->addItems(fontDB.families()); + // TODO save family in config + int index = fontsCB->findData(QFont().family()); + if ( index != -1 ) { + fontsCB->setCurrentIndex(index); + } + + QColor bgColor(palette().background().color()); + QString iconPrefix = ColorUtils::colorIsDark(bgColor) ? + PathInfo::whiteConfigIconPath() : + PathInfo::blackConfigIconPath(); + + m_strikeOutButton = new QPushButton( + QIcon(iconPrefix + "format_strikethrough.png"), ""); + m_strikeOutButton->setCheckable(true); + connect(m_strikeOutButton, &QPushButton::clicked, + this, &TextConfig::fontStrikeOutChanged); + m_strikeOutButton->setToolTip(tr("StrikeOut")); + + m_underlineButton = new QPushButton( + QIcon(iconPrefix + "format_underlined.png"), ""); + m_underlineButton->setCheckable(true); + connect(m_underlineButton, &QPushButton::clicked, + this, &TextConfig::fontUnderlineChanged); + m_underlineButton->setToolTip(tr("Underline")); + + m_weightButton = new QPushButton( + QIcon(iconPrefix + "format_bold.png"), ""); + m_weightButton->setCheckable(true); + connect(m_weightButton, &QPushButton::clicked, + this, &TextConfig::weightButtonPressed); + m_weightButton->setToolTip(tr("Bold")); + + m_italicButton = new QPushButton( + QIcon(iconPrefix + "format_italic.png"), ""); + m_italicButton->setCheckable(true); + connect(m_italicButton, &QPushButton::clicked, + this, &TextConfig::fontItalicChanged); + m_italicButton->setToolTip(tr("Italic")); + QHBoxLayout *modifiersLayout = new QHBoxLayout(); + + m_layout->addWidget(fontsCB); + modifiersLayout->addWidget(m_strikeOutButton); + modifiersLayout->addWidget(m_underlineButton); + modifiersLayout->addWidget(m_weightButton); + modifiersLayout->addWidget(m_italicButton); + m_layout->addLayout(modifiersLayout); } -// https://doc.qt.io/qt-5/qfontdatabase.html#details +void TextConfig::setUnderline(const bool u) { + m_underlineButton->setChecked(u); +} + +void TextConfig::setStrikeOut(const bool s) { + m_strikeOutButton->setChecked(s); +} + +void TextConfig::setWeight(const int w) { + m_weightButton->setChecked(static_cast(w) == QFont::Bold); +} + +void TextConfig::setItalic(const bool i) { + m_italicButton->setChecked(i); +} + +void TextConfig::weightButtonPressed(const bool w) { + if (w) { + emit fontWeightChanged(QFont::Bold); + } else { + emit fontWeightChanged(QFont::Normal); + } +} diff --git a/src/tools/text/textconfig.h b/src/tools/text/textconfig.h index c5854eda..c9f15932 100644 --- a/src/tools/text/textconfig.h +++ b/src/tools/text/textconfig.h @@ -19,13 +19,35 @@ #include +class QVBoxLayout; +class QPushButton; + class TextConfig : public QWidget { Q_OBJECT public: explicit TextConfig(QWidget *parent = nullptr); + void setUnderline(const bool u); + void setStrikeOut(const bool s); + void setWeight(const int w); + void setItalic(const bool i); + signals: void fontFamilyChanged(const QString &f); + void fontUnderlineChanged(const bool underlined); + void fontStrikeOutChanged(const bool dashed); + void fontWeightChanged(const QFont::Weight w); + void fontItalicChanged(const bool italic); public slots: + +private slots: + void weightButtonPressed(const bool w); + +private: + QVBoxLayout *m_layout; + QPushButton *m_strikeOutButton; + QPushButton *m_underlineButton; + QPushButton *m_weightButton; + QPushButton *m_italicButton; }; diff --git a/src/tools/text/texttool.cpp b/src/tools/text/texttool.cpp index e933a667..e5066abc 100644 --- a/src/tools/text/texttool.cpp +++ b/src/tools/text/texttool.cpp @@ -21,8 +21,8 @@ #define BASE_POINT_SIZE 8 -TextTool::TextTool(QObject *parent) : CaptureTool(parent) { +TextTool::TextTool(QObject *parent) : CaptureTool(parent) { } bool TextTool::isValid() const { @@ -66,17 +66,42 @@ QWidget *TextTool::widget() { connect(w, &TextWidget::textUpdated, this, &TextTool::updateText); m_widget = w; - return w; -} - -QWidget *TextTool::configurationWidget() { - TextConfig *w = nullptr;//new TextConfig(); - // TODO CONNECT return w; } +QWidget *TextTool::configurationWidget() { + m_confW = new TextConfig(); + connect(m_confW, &TextConfig::fontFamilyChanged, + this, &TextTool::updateFamily); + connect(m_confW, &TextConfig::fontItalicChanged, + this, &TextTool::updateFontItalic); + connect(m_confW, &TextConfig::fontStrikeOutChanged, + this, &TextTool::updateFontStrikeOut); + connect(m_confW, &TextConfig::fontUnderlineChanged, + this, &TextTool::updateFontUnderline); + connect(m_confW, &TextConfig::fontWeightChanged, + this, &TextTool::updateFontWeight); + m_confW->setItalic(m_font.italic()); + m_confW->setUnderline(m_font.underline()); + m_confW->setStrikeOut(m_font.strikeOut()); + m_confW->setWeight(m_font.weight()); + return m_confW; +} + CaptureTool *TextTool::copy(QObject *parent) { - return new TextTool(parent); + TextTool *tt = new TextTool(parent); + connect(m_confW, &TextConfig::fontFamilyChanged, + tt, &TextTool::updateFamily); + connect(m_confW, &TextConfig::fontItalicChanged, + tt, &TextTool::updateFontItalic); + connect(m_confW, &TextConfig::fontStrikeOutChanged, + tt, &TextTool::updateFontStrikeOut); + connect(m_confW, &TextConfig::fontUnderlineChanged, + tt, &TextTool::updateFontUnderline); + connect(m_confW, &TextConfig::fontWeightChanged, + tt, &TextTool::updateFontWeight); + tt->m_font = m_font; + return tt; } void TextTool::undo(QPixmap &pixmap) { @@ -85,7 +110,6 @@ void TextTool::undo(QPixmap &pixmap) { } void TextTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) { - // TODO updateBackup() of others if (m_text.isEmpty()) { return; } @@ -149,3 +173,38 @@ void TextTool::setFont(const QFont &f) { m_widget->setFont(f); } } + +void TextTool::updateFamily(const QString &s) { + m_font.setFamily(s); + if (m_widget) { + m_widget->setFont(m_font); + } +} + +void TextTool::updateFontUnderline(const bool underlined) { + m_font.setUnderline(underlined); + if (m_widget) { + m_widget->setFont(m_font); + } +} + +void TextTool::updateFontStrikeOut(const bool s) { + m_font.setStrikeOut(s); + if (m_widget) { + m_widget->setFont(m_font); + } +} + +void TextTool::updateFontWeight(const QFont::Weight w) { + m_font.setWeight(w); + if (m_widget) { + m_widget->setFont(m_font); + } +} + +void TextTool::updateFontItalic(const bool italic) { + m_font.setItalic(italic); + if (m_widget) { + m_widget->setFont(m_font); + } +} diff --git a/src/tools/text/texttool.h b/src/tools/text/texttool.h index 2f78dc0d..66cca95c 100644 --- a/src/tools/text/texttool.h +++ b/src/tools/text/texttool.h @@ -21,6 +21,7 @@ #include class TextWidget; +class TextConfig; class TextTool : public CaptureTool { public: @@ -57,13 +58,19 @@ public slots: private slots: void updateText(const QString &s); void setFont(const QFont &f); + void updateFamily(const QString &s); + void updateFontUnderline(const bool underlined); + void updateFontStrikeOut(const bool s); + void updateFontWeight(const QFont::Weight w); + void updateFontItalic(const bool italic); private: - QString m_text; QFont m_font; + QString m_text; int m_size; QColor m_color; QPixmap m_pixmapBackup; QRect m_backupArea; QPointer m_widget; + QPointer m_confW; }; diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 6fd44a26..49958802 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -291,6 +291,7 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) { } } m_activeTool = m_activeButton->tool()->copy(this); + connect(this, &CaptureWidget::colorChanged, m_activeTool, &CaptureTool::colorChanged); connect(this, &CaptureWidget::thicknessChanged, @@ -573,13 +574,12 @@ void CaptureWidget::setState(CaptureButton *b) { if (m_toolWidget) { m_toolWidget->deleteLater(); if (m_activeTool->isValid()) { - auto mod = new ModificationCommand( - &m_context.screenshot, m_activeTool); - m_undoStack.push(mod); - m_activeTool = nullptr; + pushToolToStack(); } } - processTool(b->tool()); + if (m_activeButton != b) { + processTool(b->tool()); + } // Only close activated from button if (b->tool()->closeOnButtonPressed()) { close(); @@ -587,12 +587,15 @@ void CaptureWidget::setState(CaptureButton *b) { if (b->tool()->isSelectable()) { if (m_activeButton != b) { + QWidget *confW = b->tool()->configurationWidget(); + m_panel->addToolWidget(confW); if (m_activeButton) { m_activeButton->setColor(m_uiColor); } m_activeButton = b; m_activeButton->setColor(m_contrastUiColor); } else if (m_activeButton) { + m_panel->clearToolWidget(); m_activeButton->setColor(m_uiColor); m_activeButton = nullptr; } @@ -606,10 +609,6 @@ void CaptureWidget::processTool(CaptureTool *t) { m_activeTool = t; t->pressed(m_context); m_activeTool = backup; - QWidget *cw = t->configurationWidget(); - if (cw) { - m_panel->addToolWidget(t->configurationWidget()); - } } void CaptureWidget::handleButtonSignal(CaptureTool::Request r) { @@ -797,11 +796,14 @@ void CaptureWidget::updateCursor() { void CaptureWidget::pushToolToStack() { auto mod = new ModificationCommand( &m_context.screenshot, m_activeTool); - m_undoStack.push(mod); disconnect(this, &CaptureWidget::colorChanged, m_activeTool, &CaptureTool::colorChanged); disconnect(this, &CaptureWidget::thicknessChanged, m_activeTool, &CaptureTool::thicknessChanged); + if (m_panel->toolWidget()) { + disconnect(m_panel->toolWidget(), nullptr, m_activeTool, nullptr); + } + m_undoStack.push(mod); m_activeTool = nullptr; } diff --git a/src/widgets/capture/notifierbox.cpp b/src/widgets/capture/notifierbox.cpp index d38fef71..b018449d 100644 --- a/src/widgets/capture/notifierbox.cpp +++ b/src/widgets/capture/notifierbox.cpp @@ -60,3 +60,7 @@ void NotifierBox::showMessage(const QString &msg) { show(); m_timer->start(); } + +void NotifierBox::showColor(const QColor &color) { + m_message = ""; +} diff --git a/src/widgets/capture/notifierbox.h b/src/widgets/capture/notifierbox.h index b67be07f..06b5a594 100644 --- a/src/widgets/capture/notifierbox.h +++ b/src/widgets/capture/notifierbox.h @@ -32,6 +32,7 @@ protected: public slots: void showMessage(const QString &msg); + void showColor(const QColor &color); private: QTimer *m_timer; diff --git a/src/widgets/panel/utilitypanel.cpp b/src/widgets/panel/utilitypanel.cpp index fac598ed..48b4a7aa 100644 --- a/src/widgets/panel/utilitypanel.cpp +++ b/src/widgets/panel/utilitypanel.cpp @@ -45,14 +45,26 @@ UtilityPanel::UtilityPanel(QWidget *parent) : QWidget(parent) { m_internalPanel, &QWidget::hide); } +QWidget *UtilityPanel::toolWidget() const { + return m_toolWidget; +} + void UtilityPanel::addToolWidget(QWidget *w) { if (m_toolWidget) { m_toolWidget->deleteLater(); + } + if (w) { m_toolWidget = w; m_upLayout->addWidget(w); } } +void UtilityPanel::clearToolWidget() { + if (m_toolWidget) { + m_toolWidget->deleteLater(); + } +} + void UtilityPanel::pushWidget(QWidget *w) { m_layout->addWidget(w); } diff --git a/src/widgets/panel/utilitypanel.h b/src/widgets/panel/utilitypanel.h index 0228a67a..e3edce59 100644 --- a/src/widgets/panel/utilitypanel.h +++ b/src/widgets/panel/utilitypanel.h @@ -35,7 +35,9 @@ class UtilityPanel : public QWidget { public: explicit UtilityPanel(QWidget *parent = nullptr); + QWidget* toolWidget() const; void addToolWidget(QWidget *w); + void clearToolWidget(); void pushWidget(QWidget *w); signals: