diff --git a/src/blackgui/components/settingsfontcomponent.cpp b/src/blackgui/components/settingsfontcomponent.cpp new file mode 100644 index 000000000..92d651ba3 --- /dev/null +++ b/src/blackgui/components/settingsfontcomponent.cpp @@ -0,0 +1,119 @@ +/* Copyright (C) 2017 + * 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 "blackgui/guiapplication.h" +#include "blackmisc/logmessage.h" +#include "settingsfontcomponent.h" +#include "ui_settingsfontcomponent.h" + +#include +#include + +using namespace BlackMisc; + +namespace BlackGui +{ + namespace Components + { + CSettingsFontComponent::CSettingsFontComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CSettingsFontComponent) + { + ui->setupUi(this); + + // Font + const QFont font = this->font(); + m_cancelFont = font; + m_cancelColor = QColor(sGui->getStyleSheetUtility().fontColor()); + this->setMode(CSettingsFontComponent::DirectUpdate); + this->initUiValues(); + + connect(ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsFontComponent::fontColorDialog); + connect(ui->pb_Ok, &QPushButton::clicked, this, &CSettingsFontComponent::changeFont); + connect(ui->pb_CancelOrReset, &QToolButton::pressed, this, &CSettingsFontComponent::resetFont); + } + + CSettingsFontComponent::~CSettingsFontComponent() + { } + + void CSettingsFontComponent::setMode(CSettingsFontComponent::Mode m) + { + m_mode = m; + if (m == CSettingsFontComponent::DirectUpdate) + { + ui->pb_CancelOrReset->setText("reset"); + } + else + { + ui->pb_CancelOrReset->setText("cancel"); + } + } + + void CSettingsFontComponent::setCurrentFont(const QFont &font) + { + m_cancelFont = font; + this->resetFont(); + } + + void CSettingsFontComponent::changeFont() + { + const QString fontSize = ui->cb_SettingsGuiFontSize->currentText().append("pt"); + const QString fontFamily = ui->cb_SettingsGuiFont->currentFont().family(); + const QString fontStyleCombined = ui->cb_SettingsGuiFontStyle->currentText(); + QString fontColor = this->m_selectedColor.name(); + if (!this->m_selectedColor.isValid() || this->m_selectedColor.name().isEmpty()) + { + fontColor = sGui->getStyleSheetUtility().fontColor(); + } + ui->le_SettingsGuiFontColor->setText(fontColor); + m_qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor); + if (m_mode == CSettingsFontComponent::DirectUpdate) + { + const bool ok = sGui->updateFont(m_qss); + if (ok) + { + CLogMessage(this).info("Updated font style"); + } + else + { + CLogMessage(this).warning("Updating style failed"); + } + } + emit this->accept(); + } + + void CSettingsFontComponent::fontColorDialog() + { + const QColor c = QColorDialog::getColor(this->m_selectedColor, this, "Font color"); + if (c == this->m_selectedColor) return; + this->m_selectedColor = c; + ui->le_SettingsGuiFontColor->setText(this->m_selectedColor.name()); + } + + void CSettingsFontComponent::initUiValues() + { + ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(m_cancelFont)); + ui->cb_SettingsGuiFont->setCurrentFont(m_cancelFont); + ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(m_cancelFont.pointSize())); + ui->le_SettingsGuiFontColor->setText(this->m_cancelColor.name()); + m_selectedColor = m_cancelColor; + m_qss.clear(); + } + + void CSettingsFontComponent::resetFont() + { + this->initUiValues(); + if (m_mode == CSettingsFontComponent::DirectUpdate) + { + sGui->resetFont(); + } + emit this->reject(); + } + } // ns +} // ns diff --git a/src/blackgui/components/settingsfontcomponent.h b/src/blackgui/components/settingsfontcomponent.h new file mode 100644 index 000000000..d3a802843 --- /dev/null +++ b/src/blackgui/components/settingsfontcomponent.h @@ -0,0 +1,75 @@ +/* Copyright (C) 2017 + * 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_SETTINGSFONTCOMPONENT_H +#define BLACKGUI_COMPONENTS_SETTINGSFONTCOMPONENT_H + +#include + +namespace Ui { class CSettingsFontComponent; } +namespace BlackGui +{ + namespace Components + { + /*! + * Font settings + */ + class CSettingsFontComponent : public QFrame + { + Q_OBJECT + + public: + //! How to update + enum Mode + { + DirectUpdate, + GenerateQssOnly + }; + + //! Constructor + explicit CSettingsFontComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CSettingsFontComponent(); + + //! Set mode + void setMode(Mode m); + + //! Get the stylesheet + const QString &getQss() const { return m_qss; } + + //! Set the current font + void setCurrentFont(const QFont &font); + + signals: + //! To be used with dialogs + void accept(); + + //! To be used with dialogs + void reject(); + + private: + QScopedPointer ui; + QColor m_selectedColor; + QColor m_cancelColor; + QFont m_cancelFont; + QString m_qss; + Mode m_mode = DirectUpdate; + + void changeFont(); + void resetFont(); + void fontColorDialog(); + void initUiValues(); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/settingsfontcomponent.ui b/src/blackgui/components/settingsfontcomponent.ui new file mode 100644 index 000000000..6b8c93df3 --- /dev/null +++ b/src/blackgui/components/settingsfontcomponent.ui @@ -0,0 +1,203 @@ + + + CSettingsFontComponent + + + + 0 + 0 + 326 + 84 + + + + Font settings + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + QComboBox::AdjustToMinimumContentsLength + + + + + + + Size/Style: + + + + + + + Font: + + + + + + + + 40 + 0 + + + + + 150 + 16777215 + + + + Font size in pt + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 14 + + + + + 16 + + + + + + + + ... + + + + + + + 200 + + + true + + + + + + + + 0 + 20 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + ok + + + + + + + cancel + + + + + + + + + + + 150 + 16777215 + + + + + normal + + + + + bold + + + + + italic + + + + + bold italic + + + + + + + + + diff --git a/src/blackgui/components/settingsfontdialog.cpp b/src/blackgui/components/settingsfontdialog.cpp new file mode 100644 index 000000000..89ab314f7 --- /dev/null +++ b/src/blackgui/components/settingsfontdialog.cpp @@ -0,0 +1,41 @@ +/* Copyright (C) 2017 + * 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 "settingsfontdialog.h" +#include "ui_settingsfontdialog.h" + +namespace BlackGui +{ + namespace Components + { + CSettingsFontDialog::CSettingsFontDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CSettingsFontDialog) + { + ui->setupUi(this); + ui->comp_FontSettings->setMode(CSettingsFontComponent::GenerateQssOnly); + + connect(ui->comp_FontSettings, &CSettingsFontComponent::accept, this, &CSettingsFontDialog::accept); + connect(ui->comp_FontSettings, &CSettingsFontComponent::reject, this, &CSettingsFontDialog::reject); + } + + CSettingsFontDialog::~CSettingsFontDialog() + { } + + const QString &CSettingsFontDialog::getQss() const + { + return ui->comp_FontSettings->getQss(); + } + + void CSettingsFontDialog::setCurrentFont(const QFont &font) + { + ui->comp_FontSettings->setCurrentFont(font); + } + } // ns +} // ns diff --git a/src/blackgui/components/settingsfontdialog.h b/src/blackgui/components/settingsfontdialog.h new file mode 100644 index 000000000..2a3f698db --- /dev/null +++ b/src/blackgui/components/settingsfontdialog.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2017 + * 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_SETTINGSFONTDIALOG_H +#define BLACKGUI_COMPONENTS_SETTINGSFONTDIALOG_H + +#include + +namespace Ui { class CSettingsFontDialog; } +namespace BlackGui +{ + namespace Components + { + /*! + * Dialog to edit fonts + * \see BlackMisc::Components::CSettingsFontComponent + */ + class CSettingsFontDialog : public QDialog + { + Q_OBJECT + + public: + //! Constructor + explicit CSettingsFontDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CSettingsFontDialog(); + + //! Get stylesheet + const QString &getQss() const; + + //! Set the current font + void setCurrentFont(const QFont &font); + + private: + QScopedPointer ui; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/settingsfontdialog.ui b/src/blackgui/components/settingsfontdialog.ui new file mode 100644 index 000000000..db25a4eb0 --- /dev/null +++ b/src/blackgui/components/settingsfontdialog.ui @@ -0,0 +1,45 @@ + + + CSettingsFontDialog + + + + 0 + 0 + 300 + 125 + + + + + 300 + 125 + + + + Font settings + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + BlackGui::Components::CSettingsFontComponent + QFrame +
blackgui/components/settingsfontcomponent.h
+ 1 +
+
+ + +