You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.6 KiB
C++
136 lines
3.6 KiB
C++
#include "cfontview.h"
|
|
#include "ui_cfontview.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
cFontView::cFontView(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::cFontView)
|
|
{
|
|
ui->setupUi(this);
|
|
ui->m_lpSampleText->setAutoFillBackground(true);
|
|
this->setMouseTracking(true);
|
|
this->setAttribute(Qt::WA_Hover);
|
|
|
|
QPalette palette = this->palette();
|
|
// m_defaultColor = palette.color(this->backgroundRole());
|
|
m_defaultColor = palette.color(QPalette::Window);
|
|
m_selectedColor = palette.color(QPalette::Highlight);
|
|
|
|
connect(ui->m_lpFontName, &cCheckBox::windowEntered, this, &cFontView::windowEntered);
|
|
connect(ui->m_lpFontName, &cCheckBox::windowLeft, this, &cFontView::windowLeft);
|
|
|
|
connect(ui->m_lpSampleText, &cLabel::windowEntered, this, &cFontView::windowEntered);
|
|
connect(ui->m_lpSampleText, &cLabel::windowLeft, this, &cFontView::windowLeft);
|
|
}
|
|
|
|
cFontView::~cFontView()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void cFontView::setText(const QString& text)
|
|
{
|
|
ui->m_lpSampleText->setText(text);
|
|
}
|
|
|
|
void cFontView::setFont(const QFont& font)
|
|
{
|
|
// qDebug() << "family: " << font.family();
|
|
// qDebug() << "capitalization: " << font.capitalization();
|
|
// qDebug() << "defaultFamily: " << font.defaultFamily();
|
|
// qDebug() << "families: " << font.families();
|
|
// qDebug() << "family: " << font.family();
|
|
// qDebug() << "fixedPitch: " << font.fixedPitch();
|
|
// qDebug() << "hintingPreference: " << font.hintingPreference();
|
|
// qDebug() << "italic: " << font.italic();
|
|
// qDebug() << "kerning: " << font.kerning();
|
|
// qDebug() << "key: " << font.key();
|
|
// qDebug() << "letterSpacing: " << font.letterSpacing();
|
|
// qDebug() << "letterSpacingType: " << font.letterSpacingType();
|
|
// qDebug() << "overline: " << font.overline();
|
|
// qDebug() << "stretch: " << font.stretch();
|
|
// qDebug() << "strikeOut: " << font.strikeOut();
|
|
// qDebug() << "style: " << font.style();
|
|
// qDebug() << "styleHint: " << font.styleHint();
|
|
// qDebug() << "styleName: " << font.styleName();
|
|
// qDebug() << "styleStrategy: " << font.styleStrategy();
|
|
// qDebug() << "toString: " << font.toString();
|
|
// qDebug() << "underline: " << font.underline();
|
|
// qDebug() << "weight: " << font.weight();
|
|
// qDebug() << "wordSpacing: " << font.wordSpacing();
|
|
// qDebug() << "substitutions: " << font.substitutions();
|
|
// qDebug() << "--------------------";
|
|
|
|
ui->m_lpFontName->setText(font.family() + "(" + font.styleName() + ")");
|
|
ui->m_lpSampleText->setFont(font);
|
|
}
|
|
|
|
void cFontView::setBackground(const QColor& color)
|
|
{
|
|
m_backgroundColor = color;
|
|
setColor();
|
|
}
|
|
|
|
void cFontView::setForeground(const QColor& color)
|
|
{
|
|
m_foregroundColor = color;
|
|
setColor();
|
|
}
|
|
|
|
void cFontView::setColor()
|
|
{
|
|
QString foreground;
|
|
QString background;
|
|
|
|
if(m_foregroundColor.isValid())
|
|
foreground = "color: " + color2rgba(m_foregroundColor) + "; ";
|
|
|
|
if(m_backgroundColor.isValid())
|
|
background = "background-color: " + color2rgba(m_backgroundColor) + "; ";
|
|
|
|
if(!foreground.isEmpty() || !background.isEmpty())
|
|
ui->m_lpSampleText->setStyleSheet("QLabel { " + foreground + background + " }");
|
|
}
|
|
|
|
void cFontView::enterEvent(QEvent* /*ev*/)
|
|
{
|
|
windowEntered();
|
|
}
|
|
|
|
void cFontView::leaveEvent(QEvent* /*ev*/)
|
|
{
|
|
windowLeft();
|
|
}
|
|
|
|
void cFontView::windowEntered()
|
|
{
|
|
ui->m_lpFontName->setStyleSheet("QCheckBox { background-color: " + color2rgba(m_selectedColor) + "; }");
|
|
}
|
|
|
|
void cFontView::windowLeft()
|
|
{
|
|
ui->m_lpFontName->setStyleSheet("QCheckBox { background-color: " + color2rgba(m_defaultColor) + "; }");
|
|
}
|
|
|
|
cFontViewList::cFontViewList(QObject* parent) :
|
|
QObject(parent)
|
|
{
|
|
}
|
|
|
|
void cFontViewList::add(cFontView* fontView)
|
|
{
|
|
this->append(fontView);
|
|
}
|
|
|
|
void cFontViewList::clearAll()
|
|
{
|
|
for(int i = 0;i < count();i++)
|
|
delete at(i);
|
|
|
|
clear();
|
|
}
|