Ref T30, font settings component and same as dialog

This commit is contained in:
Klaus Basan
2017-07-05 02:38:14 +02:00
committed by Mathew Sutcliffe
parent c0fb236b25
commit bf573f0f20
6 changed files with 531 additions and 0 deletions

View File

@@ -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 <QColorDialog>
#include <QPushButton>
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

View File

@@ -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 <QFrame>
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::CSettingsFontComponent> 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

View File

@@ -0,0 +1,203 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSettingsFontComponent</class>
<widget class="QFrame" name="CSettingsFontComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>326</width>
<height>84</height>
</rect>
</property>
<property name="windowTitle">
<string>Font settings</string>
</property>
<layout class="QGridLayout" name="gl_FontSettings">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="0" column="1" colspan="6">
<widget class="QFontComboBox" name="cb_SettingsGuiFont">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_SettingsGuiFontSize">
<property name="text">
<string>Size/Style:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_SettingsGuiFont">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cb_SettingsGuiFontSize">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Font size in pt</string>
</property>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
<item>
<property name="text">
<string>11</string>
</property>
</item>
<item>
<property name="text">
<string>12</string>
</property>
</item>
<item>
<property name="text">
<string>14</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
</widget>
</item>
<item row="1" column="4">
<widget class="QToolButton" name="tb_SettingsGuiFontColor">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="le_SettingsGuiFontColor">
<property name="maxLength">
<number>200</number>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1" colspan="5">
<widget class="QWidget" name="wi_Buttons" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<layout class="QHBoxLayout" name="vl_Buttons">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pb_Ok">
<property name="text">
<string>ok</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_CancelOrReset">
<property name="text">
<string>cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="cb_SettingsGuiFontStyle">
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>normal</string>
</property>
</item>
<item>
<property name="text">
<string>bold</string>
</property>
</item>
<item>
<property name="text">
<string>italic</string>
</property>
</item>
<item>
<property name="text">
<string>bold italic</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -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

View File

@@ -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 <QDialog>
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::CSettingsFontDialog> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSettingsFontDialog</class>
<widget class="QDialog" name="CSettingsFontDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>125</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>125</height>
</size>
</property>
<property name="windowTitle">
<string>Font settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="BlackGui::Components::CSettingsFontComponent" name="comp_FontSettings">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CSettingsFontComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/settingsfontcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>