first commit
This commit is contained in:
@@ -0,0 +1,457 @@
|
||||
#include "fontsetwidget.h"
|
||||
#include "ui_fontsetwidget.h"
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextBlock>
|
||||
#include <QDebug>
|
||||
|
||||
FontSetWidget::FontSetWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::FontSetWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
lineSpaceEdit = ui->lineSpaceEdit;
|
||||
lineSpaceMinusBtn = ui->lineSpaceMinusBtn;
|
||||
lineSpacePlusBtn = ui->lineSpacePlusBtn;
|
||||
charSpaceEdit = ui->charSpaceEdit;
|
||||
charSpaceMinusBtn = ui->charSpaceMinusBtn;
|
||||
charSpacePlusBtn = ui->charSpacePlusBtn;
|
||||
fontCBox = ui->comboBoxFont;
|
||||
|
||||
// 勾选按钮
|
||||
connect(ui->m_BtnClose, &QPushButton::clicked, [this]() {
|
||||
emit sendButtonClickedSignal(1);
|
||||
onDialogLineSpaceAccepted();
|
||||
on_buttonSelectFont_pressed();
|
||||
});
|
||||
|
||||
flagOfLeft = false;
|
||||
flagOfRight = false;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void FontSetWidget::init(){
|
||||
// 应用样式表
|
||||
applyStyleSheet();
|
||||
|
||||
// 连接数值调整按钮
|
||||
connect(lineSpaceMinusBtn, &QPushButton::clicked, [this]() { adjustValue(lineSpaceEdit, -1); });
|
||||
connect(lineSpacePlusBtn, &QPushButton::clicked, [this]() { adjustValue(lineSpaceEdit, 1); });
|
||||
connect(charSpaceMinusBtn, &QPushButton::clicked, [this]() { adjustValue(charSpaceEdit, -1); });
|
||||
connect(charSpacePlusBtn, &QPushButton::clicked, [this]() { adjustValue(charSpaceEdit, 1); });
|
||||
|
||||
// 为了方便设置控件
|
||||
comboxIndexMap.insert(5, 0);
|
||||
comboxIndexMap.insert(7, 1);
|
||||
comboxIndexMap.insert(9, 2);
|
||||
comboxIndexMap.insert(12, 3);
|
||||
comboxIndexMap.insert(16, 4);
|
||||
comboxIndexMap.insert(24, 5);
|
||||
comboxIndexMap.insert(32, 6);
|
||||
|
||||
getValueFont();
|
||||
}
|
||||
|
||||
FontSetWidget::~FontSetWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FontSetWidget::bindTxTEdit(QTextEdit* textEdit){
|
||||
m_textEdit = textEdit;
|
||||
}
|
||||
|
||||
void FontSetWidget::bindSysPara(SysPara *sysPara){
|
||||
this->sysPara = sysPara;
|
||||
|
||||
}
|
||||
|
||||
void FontSetWidget::on_buttonSelectFont_pressed(){
|
||||
|
||||
// int fontSize;
|
||||
QString fontFamily;
|
||||
// getValueFont(&fontSize);
|
||||
fontFamily = getFontFamily();
|
||||
// if(ui->checkBoxBold->isChecked())
|
||||
// fontFamily = getFamilyName(fontSize);
|
||||
// ui->labFontFamily->setText(fontFamily);
|
||||
#ifdef EnableArabic
|
||||
bool switchArabicFlag=false;
|
||||
bool arabicSelect=fontFamily.contains("arabic");
|
||||
if((fontFamily=="biyang" || fontFamily=="wenquanyi")&&(fontSize==7 || fontSize==9)){
|
||||
switchArabicFlag=true;
|
||||
emit EnableSwitchArabicFlag(switchArabicFlag);
|
||||
}else {
|
||||
emit EnableSwitchArabicFlag(switchArabicFlag);
|
||||
}
|
||||
dialogSaveFile->setFileNameEnglishOrArabic(false);
|
||||
emit fontSizeArabicSelect(arabicSelect);
|
||||
#endif
|
||||
// if(sysPara){
|
||||
// sysPara->para.fontPixelSize = fontSize;
|
||||
// }
|
||||
// ui->labelFontSize->setText(QString::number(fontSize));
|
||||
setFontFormat(fontSize,fontFamily);
|
||||
m_textEdit->setFocus();
|
||||
// emit fontSizeChange(fontSize);
|
||||
// bool flagBangal=false;
|
||||
// if(dialogFontSize->getFontFamily() == "bangla")
|
||||
// flagBangal = true;
|
||||
// emit switchBengalLanguage(flagBangal);
|
||||
|
||||
// toggleVirtualKeyboard();
|
||||
|
||||
}
|
||||
|
||||
void FontSetWidget::setFontFormat(int fontsize,QString fontfamily){
|
||||
//if(sysPara){
|
||||
|
||||
//qreal pixelSize = ui->labelFontSize->text().toFloat();
|
||||
qreal pixelSize = fontsize;
|
||||
// if(pixelSize < Public::getMinFontPixelSize())
|
||||
// pixelSize = sysPara->para.fontPixelSize;
|
||||
|
||||
// if(pixelSize < Public::getMinFontPixelSize()){
|
||||
// pixelSize = Public::getMinFontPixelSize();
|
||||
// }
|
||||
|
||||
if (pixelSize >= 0) {
|
||||
QTextCharFormat fmt;
|
||||
int DPI = m_textEdit->logicalDpiX();
|
||||
DPI = DPI?DPI:1;
|
||||
qreal pointSize = pixelSize*72/DPI; //Pixel = DPI * Point / 72
|
||||
fmt.setFontPointSize(pointSize);
|
||||
|
||||
#ifdef VNLGXX
|
||||
QString fontFamily = dialogFontSize->getFontFamily();
|
||||
|
||||
#else
|
||||
// QString fontFamily = ui->labFontFamily->text();
|
||||
QString fontFamily = fontfamily;
|
||||
fontFamily = getFontFamily();
|
||||
|
||||
// if(ui->checkBoxBold->isChecked())
|
||||
// fontFamily = getFamilyName(pixelSize);
|
||||
// ui->labFontFamily->setText(fontFamily);
|
||||
#endif
|
||||
|
||||
fmt.setFontFamily(fontFamily);
|
||||
fmt.setFontWeight(0 && (pixelSize<=16)? QFont::Bold:QFont::Normal);
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
void FontSetWidget::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
|
||||
{
|
||||
|
||||
QTextCursor cursor = m_textEdit->textCursor();
|
||||
//if (!cursor.hasSelection())
|
||||
// cursor.select(QTextCursor::WordUnderCursor);
|
||||
//cursor.mergeCharFormat(format);
|
||||
//textEdit->setTextCursor(cursor);
|
||||
//qDebug()<<"mergeFormatOnWordOrSelection"<<format;
|
||||
//qDebug()<<cursor;
|
||||
m_textEdit->mergeCurrentCharFormat(format);
|
||||
}
|
||||
|
||||
int FontSetWidget::getValueFont(){
|
||||
fontSize = comboxIndexMap.key(fontCBox->currentIndex());
|
||||
|
||||
QList<int> sizeList = comboxIndexMap.keys();
|
||||
if (sizeList.contains(fontSize)) {
|
||||
if(flagOfLeft){
|
||||
font.setFamily("wenquanyiL");
|
||||
}
|
||||
else if(flagOfRight){
|
||||
font.setFamily("wenquanyiR");
|
||||
}
|
||||
else {
|
||||
QString familyStr = QString("WenQuanYi%1").arg(fontSize);
|
||||
font.setFamily(familyStr);
|
||||
}
|
||||
} else {
|
||||
fontSize = 12;
|
||||
font.setFamily("WenQuanYi12");
|
||||
}
|
||||
|
||||
font.setPixelSize(fontSize);
|
||||
ui->lineEdit->setFont(font); // 设置预览字体
|
||||
return fontSize;
|
||||
}
|
||||
|
||||
void FontSetWidget::setValueFont(int value)
|
||||
{
|
||||
int index = comboxIndexMap.value(value);
|
||||
fontCBox->setCurrentIndex(index);
|
||||
return;
|
||||
}
|
||||
|
||||
QString FontSetWidget::getFontFamily()
|
||||
{
|
||||
return ui->lineEdit->font().family();
|
||||
}
|
||||
|
||||
QFont FontSetWidget::getFont()
|
||||
{
|
||||
return ui->lineEdit->font();
|
||||
}
|
||||
|
||||
void FontSetWidget::onDialogLineSpaceAccepted(){
|
||||
|
||||
QTextCursor cursor = m_textEdit->textCursor();
|
||||
int position = cursor.position();
|
||||
// qDebug()<<"position line:"<<position;
|
||||
|
||||
getValueLineSpace(&sysPara->para.textEditLineSpace,&sysPara->para.textEditCharSpace);
|
||||
sysPara->para.textEditLineSpace=sysPara->para.textEditLineSpace+1;//新系统行间距需要加1
|
||||
for(QTextBlock textBlock = m_textEdit->document()->begin();textBlock != m_textEdit->document()->end(); textBlock = textBlock.next()){
|
||||
QTextBlockFormat textBlockFormat = textBlock.blockFormat();
|
||||
textBlockFormat.setAlignment(Qt::AlignBottom);
|
||||
textBlockFormat.setTopMargin(-1);
|
||||
textBlockFormat.setForeground(QColor("red"));
|
||||
textBlockFormat.setBottomMargin(sysPara->para.textEditLineSpace-1);
|
||||
QTextCursor textCursor = m_textEdit->textCursor();
|
||||
textCursor.setPosition(textBlock.position());
|
||||
textCursor.setBlockFormat(textBlockFormat);
|
||||
m_textEdit->setTextCursor(textCursor);
|
||||
}
|
||||
|
||||
QFont font = m_textEdit->font();
|
||||
font.setLetterSpacing(QFont::AbsoluteSpacing,sysPara->para.textEditCharSpace);
|
||||
m_textEdit->setFont(font);
|
||||
|
||||
cursor = m_textEdit->textCursor();
|
||||
// position = cursor.position();
|
||||
// qDebug()<<"position line2:"<<position;
|
||||
cursor = m_textEdit->textCursor();
|
||||
cursor.setPosition(position);
|
||||
// qDebug()<<"position2:"<<position;
|
||||
m_textEdit->setTextCursor(cursor);
|
||||
|
||||
}
|
||||
|
||||
void FontSetWidget::getValueLineSpace(int *lineSpace,int *charSpace){
|
||||
*lineSpace = 0;
|
||||
*charSpace = 0;
|
||||
bool ok;
|
||||
int valuelinespace = lineSpaceEdit->text().toInt(&ok);
|
||||
if (ok) {
|
||||
*lineSpace = valuelinespace;
|
||||
}
|
||||
int charlinespace = charSpaceEdit->text().toInt(&ok);
|
||||
if (ok) {
|
||||
*charSpace = charlinespace;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FontSetWidget::setValueLineSpace(int lineSpace,int charSpace){
|
||||
if(lineSpace>0)
|
||||
lineSpace = lineSpace-1; //新系统行间距需要加1
|
||||
if(lineSpace > 7 || lineSpace < 0)
|
||||
lineSpace = 0;
|
||||
lineSpaceEdit->setText(QString::number(lineSpace));
|
||||
|
||||
if(charSpace > 5 || charSpace < 0)
|
||||
charSpace = 0;
|
||||
charSpaceEdit->setText(QString::number(charSpace));
|
||||
}
|
||||
|
||||
|
||||
void FontSetWidget::adjustValue(QLineEdit* edit, int delta)
|
||||
{
|
||||
bool ok;
|
||||
int value = edit->text().toInt(&ok);
|
||||
if(value==0 && delta==-1)
|
||||
return;
|
||||
if(value==6 && delta==1)
|
||||
return;
|
||||
if (ok) {
|
||||
edit->setText(QString::number(value + delta));
|
||||
}
|
||||
}
|
||||
|
||||
void FontSetWidget::updateFontSelect(int index){
|
||||
if(index<ui->comboBoxFont->count())
|
||||
ui->comboBoxFont->setCurrentIndex(index);
|
||||
|
||||
m_textEdit->clear();
|
||||
on_buttonSelectFont_pressed();
|
||||
}
|
||||
|
||||
void FontSetWidget::applyStyleSheet()
|
||||
{
|
||||
QString styleSheet = R"(
|
||||
QTabWidget {
|
||||
border: none;
|
||||
background-color: #7B838E;
|
||||
}
|
||||
|
||||
QTabWidget::tab-bar {
|
||||
background-color: #7B838E;
|
||||
alignment: left;
|
||||
height: 80px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
QTabBar {
|
||||
background-color: #7B838E;
|
||||
border: none;
|
||||
width: 100%;
|
||||
min-width: 100%;
|
||||
height: 80px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
QTabBar::tab {
|
||||
width: 140px;
|
||||
height: 80px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #000000;
|
||||
border: none;
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
alignment: center bottom;
|
||||
padding-top: 0;
|
||||
}
|
||||
QTabBar::tab {
|
||||
margin-left: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
QTabBar::tab:!selected {
|
||||
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
|
||||
stop:0 #6E757F, stop:1 #96A0A9);
|
||||
border: 2px solid #63535D;
|
||||
border-bottom: none;
|
||||
position: relative;
|
||||
bottom: 0px;
|
||||
}
|
||||
|
||||
QTabBar::tab:selected {
|
||||
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
|
||||
stop:0 #95B2D4, stop:1 #F0F0F0);
|
||||
border: none;
|
||||
position: relative;
|
||||
bottom: 0px;
|
||||
}
|
||||
|
||||
QTabWidget::pane {
|
||||
border: none;
|
||||
background-color: #f0f0f0;
|
||||
top: -12px;
|
||||
}
|
||||
|
||||
QWidget#buttonWidget {
|
||||
background-color: #95989D;
|
||||
}
|
||||
|
||||
QPushButton#confirmBtn, QPushButton#cancelBtn {
|
||||
background-color: #E6F7FF;
|
||||
border: 1px solid #87CEEB;
|
||||
border-radius: 4px;
|
||||
font-size: 24px;
|
||||
color: #228B22;
|
||||
}
|
||||
|
||||
QPushButton#confirmBtn:hover, QPushButton#cancelBtn:hover {
|
||||
background-color: #D1E9FF;
|
||||
}
|
||||
|
||||
QPushButton#confirmBtn:pressed, QPushButton#cancelBtn:pressed {
|
||||
background-color: #BAE7FF;
|
||||
}
|
||||
|
||||
QLabel {
|
||||
font-size: 18px;
|
||||
color: #000000;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
QLineEdit {
|
||||
border: 1px solid #96A0A9;
|
||||
border-radius: 0px;
|
||||
padding: 4px 6px;
|
||||
background-color: #ffffff;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
QLineEdit:focus {
|
||||
border-color: #95B2D4;
|
||||
}
|
||||
|
||||
QComboBox {
|
||||
border: 1px solid #96A0A9;
|
||||
border-radius: 3px;
|
||||
padding: 5px;
|
||||
background-color: #ffffff;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
QComboBox::drop-down {
|
||||
border: none;
|
||||
}
|
||||
|
||||
QComboBox::down-arrow {
|
||||
image: url(:/Demo/image/down.png);
|
||||
width: 25px;
|
||||
height: 35px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
QCheckBox {
|
||||
font-size: 18px;
|
||||
color: #000000;
|
||||
font-weight:500;
|
||||
}
|
||||
|
||||
QCheckBox::indicator {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 1px solid #96A0A9;
|
||||
border-radius: 10px;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
QCheckBox::indicator:checked {
|
||||
background-color: #95B2D4;
|
||||
border-color: #95B2D4;
|
||||
image: url(:/Demo/image/select.png);
|
||||
}
|
||||
|
||||
QPushButton {
|
||||
background-color: #5396C1;
|
||||
color: #ffffff;
|
||||
border: 1px solid #000000;
|
||||
border-radius: 3px;
|
||||
font-size: 24px;
|
||||
font-weight:500;
|
||||
}
|
||||
|
||||
QPushButton:hover {
|
||||
background-color: #5396C1;
|
||||
}
|
||||
|
||||
QPushButton:disabled {
|
||||
background-color: #7C828E;
|
||||
color: #606060;
|
||||
border-color: #808080;
|
||||
}
|
||||
)";
|
||||
|
||||
|
||||
this->setStyleSheet(styleSheet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FontSetWidget::on_comboBoxFont_currentIndexChanged(int index)
|
||||
{
|
||||
getValueFont();
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user