From 14221e08bc156b0d7cea377896bc828ca7973779 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 23 Sep 2018 03:34:49 +0200 Subject: [PATCH] Ref T369, text message style component --- .../components/settingstextmessagestyle.cpp | 77 +++++++++++++++++++ .../components/settingstextmessagestyle.h | 70 +++++++++++++++++ .../components/settingstextmessagestyle.ui | 67 ++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 src/blackgui/components/settingstextmessagestyle.cpp create mode 100644 src/blackgui/components/settingstextmessagestyle.h create mode 100644 src/blackgui/components/settingstextmessagestyle.ui diff --git a/src/blackgui/components/settingstextmessagestyle.cpp b/src/blackgui/components/settingstextmessagestyle.cpp new file mode 100644 index 000000000..ddd0e166c --- /dev/null +++ b/src/blackgui/components/settingstextmessagestyle.cpp @@ -0,0 +1,77 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "settingstextmessagestyle.h" +#include "ui_settingstextmessagestyle.h" +#include "settingsfontdialog.h" +#include "texteditdialog.h" + +#include +#include + +namespace BlackGui +{ + namespace Components + { + CSettingsTextMessageStyle::CSettingsTextMessageStyle(QWidget *parent) : + QFrame(parent), + ui(new Ui::CSettingsTextMessageStyle) + { + ui->setupUi(this); + + connect(ui->pb_Font, &QPushButton::released, this, &CSettingsTextMessageStyle::changeFont); + connect(ui->pb_Style, &QPushButton::released, this, &CSettingsTextMessageStyle::changeStyle); + connect(ui->pb_Reset, &QPushButton::released, this, &CSettingsTextMessageStyle::resetStyle); + connect(ui->pb_Reset, &QPushButton::released, this, &CSettingsTextMessageStyle::changed); + } + + CSettingsTextMessageStyle::~CSettingsTextMessageStyle() + { } + + QStringList CSettingsTextMessageStyle::getFamilySizeStyle() const + { + if (m_fontSettingsDialog) { return m_fontSettingsDialog->getFamilySizeStyle(); } + + static const QStringList empty({"", "", ""}); + return empty; + } + + void CSettingsTextMessageStyle::changeFont() + { + if (!m_fontSettingsDialog) + { + m_fontSettingsDialog = new CSettingsFontDialog(this); + m_fontSettingsDialog->setWithColorSelection(false); + } + + const QDialog::DialogCode r = static_cast(m_fontSettingsDialog->exec()); + if (r == QDialog::Accepted) + { + emit this->changed(); + } + } + + void CSettingsTextMessageStyle::changeStyle() + { + if (!m_textEditDialog) + { + m_textEditDialog = new CTextEditDialog(this); + m_textEditDialog->resize(400, 300); + } + + m_textEditDialog->textEdit()->setPlainText(m_style); + const QDialog::DialogCode r = static_cast(m_textEditDialog->exec()); + if (r == QDialog::Accepted) + { + m_style = m_textEditDialog->textEdit()->toPlainText(); + emit this->changed(); + } + } + } // ns +} // ns diff --git a/src/blackgui/components/settingstextmessagestyle.h b/src/blackgui/components/settingstextmessagestyle.h new file mode 100644 index 000000000..7871d5f14 --- /dev/null +++ b/src/blackgui/components/settingstextmessagestyle.h @@ -0,0 +1,70 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_SETTINGSTEXTMESSAGESTYLE_H +#define BLACKGUI_COMPONENTS_SETTINGSTEXTMESSAGESTYLE_H + +#include +#include +#include + +namespace Ui { class CSettingsTextMessageStyle; } +namespace BlackGui +{ + namespace Components + { + class CSettingsFontDialog; + class CTextEditDialog; + + //! Text message style + class CSettingsTextMessageStyle : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CSettingsTextMessageStyle(QWidget *parent = nullptr); + + //! Destructor + virtual ~CSettingsTextMessageStyle(); + + //! Fmily, size and style + QStringList getFamilySizeStyle() const; + + //! Style + const QString &getStyle() { return m_style; } + + //! Style + void setStyle(const QString &style) { m_style = style; } + + //! Reset style + void resetStyle() { m_style.clear(); } + + signals: + //! Font or style changed from within the component + void changed(); + + private: + QScopedPointer ui; + CSettingsFontDialog *m_fontSettingsDialog = nullptr; + CTextEditDialog *m_textEditDialog = nullptr; + QString m_style; + + //! Change font + void changeFont(); + + //! Change style + void changeStyle(); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/settingstextmessagestyle.ui b/src/blackgui/components/settingstextmessagestyle.ui new file mode 100644 index 000000000..77f21ac26 --- /dev/null +++ b/src/blackgui/components/settingstextmessagestyle.ui @@ -0,0 +1,67 @@ + + + CSettingsTextMessageStyle + + + + 0 + 0 + 301 + 26 + + + + Frame + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + reset + + + + + + + style + + + + + + + font + + + + + + + +