mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Reader: Add 'Line spacing' and 'Margins' options
This commit is contained in:
parent
922ecb0ab5
commit
b5fb886141
4 changed files with 814 additions and 740 deletions
|
@ -44,6 +44,12 @@ namespace global {
|
||||||
inline bool globalReadingSettings;
|
inline bool globalReadingSettings;
|
||||||
inline int pdfOrientation;
|
inline int pdfOrientation;
|
||||||
inline bool highlightAlreadyDone;
|
inline bool highlightAlreadyDone;
|
||||||
|
inline int textAlignment;
|
||||||
|
inline int lineSpacing;
|
||||||
|
inline QString font;
|
||||||
|
static inline int initialFontSize = 6;
|
||||||
|
inline int fontSize;
|
||||||
|
inline int margins;
|
||||||
}
|
}
|
||||||
namespace kobox {
|
namespace kobox {
|
||||||
inline bool showKoboxSplash;
|
inline bool showKoboxSplash;
|
||||||
|
|
|
@ -39,12 +39,21 @@ reader::reader(QWidget *parent) :
|
||||||
textDialogLock = false;
|
textDialogLock = false;
|
||||||
goToSavedPageDone = false;
|
goToSavedPageDone = false;
|
||||||
initialPdfRotationDone = false;
|
initialPdfRotationDone = false;
|
||||||
|
global::reader::textAlignment = 0;
|
||||||
|
global::reader::lineSpacing = 0;
|
||||||
|
global::reader::font = "Source Serif Pro";
|
||||||
|
global::reader::fontSize = 10;
|
||||||
|
global::reader::margins = 1;
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->brightnessStatus->setFont(QFont("u001"));
|
ui->brightnessStatus->setFont(QFont("u001"));
|
||||||
ui->fontLabel->setFont(QFont("u001"));
|
ui->fontLabel->setFont(QFont("u001"));
|
||||||
ui->sizeLabel->setFont(QFont("u001"));
|
ui->sizeLabel->setFont(QFont("u001"));
|
||||||
ui->sizeValueLabel->setFont(QFont("Inter"));
|
ui->sizeValueLabel->setFont(QFont("Inter"));
|
||||||
|
ui->lineSpacingLabel->setFont(QFont("u001"));
|
||||||
|
ui->lineSpacingValueLabel->setFont(QFont("Inter"));
|
||||||
|
ui->marginsLabel->setFont(QFont("u001"));
|
||||||
|
ui->marginsValueLabel->setFont(QFont("Inter"));
|
||||||
ui->alignmentLabel->setFont(QFont("u001"));
|
ui->alignmentLabel->setFont(QFont("u001"));
|
||||||
ui->fontChooser->setFont(QFont("u001"));
|
ui->fontChooser->setFont(QFont("u001"));
|
||||||
ui->definitionStatusLabel->setFont(QFont("u001"));
|
ui->definitionStatusLabel->setFont(QFont("u001"));
|
||||||
|
@ -248,31 +257,12 @@ reader::reader(QWidget *parent) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Font
|
// Font
|
||||||
string_checkconfig(".config/04-book/font");
|
global::reader::font = readFile(".config/04-book/font");
|
||||||
if(checkconfig_str_val == "") {
|
if(global::reader::font == "u001") {
|
||||||
ui->fontChooser->setCurrentText("Source Serif Pro");
|
ui->fontChooser->setCurrentText("Univers (u001)");
|
||||||
ui->text->setFont(QFont("Source Serif Pro"));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log("Setting font to '" + checkconfig_str_val + "'", className);
|
ui->fontChooser->setCurrentText(global::reader::font);
|
||||||
if(checkconfig_str_val == "Crimson Pro") {
|
|
||||||
setCrimsonProFont();
|
|
||||||
}
|
|
||||||
else if(checkconfig_str_val == "Bitter") {
|
|
||||||
setBitterFont();
|
|
||||||
}
|
|
||||||
else if(checkconfig_str_val == "Ibarra Real Nova") {
|
|
||||||
setIbarraFont();
|
|
||||||
}
|
|
||||||
else if(checkconfig_str_val == "u001") {
|
|
||||||
ui->text->setFont(QFont("u001"));
|
|
||||||
ui->fontChooser->setCurrentText("Univers (u001)");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QFont config_font(checkconfig_str_val);
|
|
||||||
ui->text->setFont(config_font);
|
|
||||||
ui->fontChooser->setCurrentText(checkconfig_str_val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Night mode
|
// Night mode
|
||||||
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n437\n" or global::deviceID == "n306\n") {
|
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n437\n" or global::deviceID == "n306\n") {
|
||||||
|
@ -315,6 +305,8 @@ reader::reader(QWidget *parent) :
|
||||||
ui->optionsBtn->setStyleSheet("padding: 10px");
|
ui->optionsBtn->setStyleSheet("padding: 10px");
|
||||||
}
|
}
|
||||||
ui->sizeValueLabel->setStyleSheet("font-size: 9pt; font-weight: bold");
|
ui->sizeValueLabel->setStyleSheet("font-size: 9pt; font-weight: bold");
|
||||||
|
ui->lineSpacingValueLabel->setStyleSheet("font-size: 9pt; font-weight: bold");
|
||||||
|
ui->marginsValueLabel->setStyleSheet("font-size: 9pt; font-weight: bold");
|
||||||
ui->homeBtn->setStyleSheet("font-size: 9pt; padding: 5px");
|
ui->homeBtn->setStyleSheet("font-size: 9pt; padding: 5px");
|
||||||
ui->aboutBtn->setStyleSheet("font-size: 9pt; padding: 5px");
|
ui->aboutBtn->setStyleSheet("font-size: 9pt; padding: 5px");
|
||||||
ui->fontChooser->setStyleSheet("font-size: 9pt");
|
ui->fontChooser->setStyleSheet("font-size: 9pt");
|
||||||
|
@ -488,33 +480,38 @@ reader::reader(QWidget *parent) :
|
||||||
ui->text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
ui->text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Text alignment
|
// Line spacing, margins and text alignment
|
||||||
string_checkconfig(".config/04-book/alignment");
|
QString lineSpacingString = readFile(".config/04-book/line_spacing");
|
||||||
if(checkconfig_str_val == "Left") {
|
if(!lineSpacingString.isEmpty()) {
|
||||||
textAlignment = 0;
|
global::reader::lineSpacing = lineSpacingString.toInt();
|
||||||
alignAndHighlightText(0);
|
|
||||||
}
|
}
|
||||||
else if(checkconfig_str_val == "Center") {
|
|
||||||
textAlignment = 1;
|
QString marginsString = readFile(".config/04-book/margins");
|
||||||
alignAndHighlightText(1);
|
if(!marginsString.isEmpty()) {
|
||||||
|
global::reader::margins = marginsString.toInt();
|
||||||
}
|
}
|
||||||
else if(checkconfig_str_val == "Right") {
|
|
||||||
textAlignment = 2;
|
QString alignment = readFile(".config/04-book/alignment");
|
||||||
alignAndHighlightText(2);
|
if(alignment == "Left") {
|
||||||
|
global::reader::textAlignment = 0;
|
||||||
}
|
}
|
||||||
else if(checkconfig_str_val == "Justify") {
|
else if(alignment == "Center") {
|
||||||
textAlignment = 3;
|
global::reader::textAlignment = 1;
|
||||||
alignAndHighlightText(3);
|
}
|
||||||
|
else if(alignment == "Right") {
|
||||||
|
global::reader::textAlignment = 2;
|
||||||
|
}
|
||||||
|
else if(alignment == "Justify") {
|
||||||
|
global::reader::textAlignment = 3;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
checkconfig_str_val = "Left";
|
alignment = "Left";
|
||||||
textAlignment = 0;
|
global::reader::textAlignment = 0;
|
||||||
alignAndHighlightText(0);
|
|
||||||
}
|
}
|
||||||
log("Setting text alignment to '" + checkconfig_str_val + "'", className);
|
log("Setting text alignment to '" + alignment + "'", className);
|
||||||
|
|
||||||
// Don't ask me why it doesn't work without that QTimer
|
// Don't ask me why it doesn't work without that QTimer
|
||||||
QTimer::singleShot(0, this, SLOT(setFontSizeSlot()));
|
QTimer::singleShot(0, this, SLOT(setInitialTextProperties()));
|
||||||
|
|
||||||
// Wheeee!
|
// Wheeee!
|
||||||
if(is_epub == true) {
|
if(is_epub == true) {
|
||||||
|
@ -1020,7 +1017,7 @@ void reader::on_nextBtn_clicked()
|
||||||
|
|
||||||
pagesTurned = pagesTurned + 1;
|
pagesTurned = pagesTurned + 1;
|
||||||
writeconfig_pagenumber(false);
|
writeconfig_pagenumber(false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(is_epub == true) {
|
else if(is_epub == true) {
|
||||||
|
@ -1036,7 +1033,7 @@ void reader::on_nextBtn_clicked()
|
||||||
|
|
||||||
pagesTurned = pagesTurned + 1;
|
pagesTurned = pagesTurned + 1;
|
||||||
writeconfig_pagenumber(false);
|
writeconfig_pagenumber(false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(is_pdf == true) {
|
else if(is_pdf == true) {
|
||||||
|
@ -1080,7 +1077,7 @@ void reader::on_previousBtn_clicked()
|
||||||
// We always increment pagesTurned regardless whether we press the Previous or Next button or not
|
// We always increment pagesTurned regardless whether we press the Previous or Next button or not
|
||||||
pagesTurned = pagesTurned + 1;
|
pagesTurned = pagesTurned + 1;
|
||||||
writeconfig_pagenumber(false);
|
writeconfig_pagenumber(false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (is_pdf == true) {
|
else if (is_pdf == true) {
|
||||||
|
@ -1112,10 +1109,10 @@ void reader::on_previousBtn_clicked()
|
||||||
ui->text->setText("");
|
ui->text->setText("");
|
||||||
ui->text->setText(epubPageContent);
|
ui->text->setText(epubPageContent);
|
||||||
|
|
||||||
// We always increment pagesTurned regardless whether we press the Previous or Next button not
|
// We always increment pagesTurned regardless whether we press the Previous or Next button or not
|
||||||
pagesTurned = pagesTurned + 1;
|
pagesTurned = pagesTurned + 1;
|
||||||
writeconfig_pagenumber(false);
|
writeconfig_pagenumber(false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setupPageWidget();
|
setupPageWidget();
|
||||||
|
@ -1256,109 +1253,43 @@ void reader::on_homeBtn_clicked()
|
||||||
void reader::on_fontChooser_currentIndexChanged(const QString &arg1)
|
void reader::on_fontChooser_currentIndexChanged(const QString &arg1)
|
||||||
{
|
{
|
||||||
log("Setting font to '" + arg1 + "'", className);
|
log("Setting font to '" + arg1 + "'", className);
|
||||||
if(arg1 == "Roboto") {
|
global::reader::font = arg1;
|
||||||
QFont roboto("Roboto");
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
ui->text->setFont(roboto);
|
|
||||||
string_writeconfig(".config/04-book/font", "Roboto");
|
|
||||||
}
|
|
||||||
if(arg1 == "Inter") {
|
|
||||||
QFont inter("Inter");
|
|
||||||
ui->text->setFont(inter);
|
|
||||||
string_writeconfig(".config/04-book/font", "Inter");
|
|
||||||
}
|
|
||||||
if(arg1 == "Source Serif Pro") {
|
|
||||||
QFont sourceserif("Source Serif Pro");
|
|
||||||
ui->text->setFont(sourceserif);
|
|
||||||
string_writeconfig(".config/04-book/font", "Source Serif Pro");
|
|
||||||
}
|
|
||||||
if(arg1 == "Libre Baskerville") {
|
|
||||||
QFont librebaskerville("Libre Baskerville");
|
|
||||||
ui->text->setFont(librebaskerville);
|
|
||||||
string_writeconfig(".config/04-book/font", "Libre Baskerville");
|
|
||||||
}
|
|
||||||
if(arg1 == "Noto Mono") {
|
|
||||||
QFont notomono("Noto Mono");
|
|
||||||
ui->text->setFont(notomono);
|
|
||||||
string_writeconfig(".config/04-book/font", "Noto Mono");
|
|
||||||
}
|
|
||||||
if(arg1 == "Roboto Mono") {
|
|
||||||
ui->text->setFont(QFont("Roboto Mono"));
|
|
||||||
writeFile(".config/04-book/font", "Roboto Mono");
|
|
||||||
}
|
|
||||||
if(arg1 == "Libertinus Serif") {
|
|
||||||
QFont libertinus("Libertinus Serif");
|
|
||||||
ui->text->setFont(libertinus);
|
|
||||||
string_writeconfig(".config/04-book/font", "Libertinus Serif");
|
|
||||||
}
|
|
||||||
if(arg1 == "Crimson Pro") {
|
|
||||||
// As adding Crimson Pro to the default fonts bundled along with the Qt libs breaks the general u001/Inter homogeneity, it is incorporated on-demand here.
|
|
||||||
setCrimsonProFont();
|
|
||||||
string_writeconfig(".config/04-book/font", "Crimson Pro");
|
|
||||||
}
|
|
||||||
if(arg1 == "Bitter") {
|
|
||||||
setBitterFont();
|
|
||||||
string_writeconfig(".config/04-book/font", "Bitter");
|
|
||||||
}
|
|
||||||
if(arg1 == "Ibarra Real Nova") {
|
|
||||||
setIbarraFont();
|
|
||||||
string_writeconfig(".config/04-book/font", "Ibarra Real Nova");
|
|
||||||
}
|
|
||||||
if(arg1 == "Univers (u001)") {
|
|
||||||
ui->text->setFont(QFont("u001"));
|
|
||||||
string_writeconfig(".config/04-book/font", "u001");
|
|
||||||
}
|
|
||||||
alignAndHighlightText(textAlignment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_alignLeftBtn_clicked()
|
void reader::on_alignLeftBtn_clicked()
|
||||||
{
|
{
|
||||||
log("Setting text alignment to 'Left'", className);
|
log("Setting text alignment to 'Left'", className);
|
||||||
if(is_epub != true) {
|
global::reader::textAlignment = 0;
|
||||||
ui->text->setAlignment(Qt::AlignLeft);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
|
||||||
else {
|
|
||||||
alignAndHighlightText(0);
|
|
||||||
}
|
|
||||||
string_writeconfig(".config/04-book/alignment", "Left");
|
string_writeconfig(".config/04-book/alignment", "Left");
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_alignCenterBtn_clicked()
|
void reader::on_alignCenterBtn_clicked()
|
||||||
{
|
{
|
||||||
log("Setting text alignment to 'Center'", className);
|
log("Setting text alignment to 'Center'", className);
|
||||||
if(is_epub != true) {
|
global::reader::textAlignment = 1;
|
||||||
ui->text->setAlignment(Qt::AlignHCenter);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
|
||||||
else {
|
|
||||||
alignAndHighlightText(1);
|
|
||||||
}
|
|
||||||
string_writeconfig(".config/04-book/alignment", "Center");
|
string_writeconfig(".config/04-book/alignment", "Center");
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_alignRightBtn_clicked()
|
void reader::on_alignRightBtn_clicked()
|
||||||
{
|
{
|
||||||
log("Setting text alignment to 'Right'", className);
|
log("Setting text alignment to 'Right'", className);
|
||||||
if(is_epub != true) {
|
global::reader::textAlignment = 2;
|
||||||
ui->text->setAlignment(Qt::AlignRight);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
|
||||||
else {
|
|
||||||
alignAndHighlightText(2);
|
|
||||||
}
|
|
||||||
string_writeconfig(".config/04-book/alignment", "Right");
|
string_writeconfig(".config/04-book/alignment", "Right");
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_alignJustifyBtn_clicked()
|
void reader::on_alignJustifyBtn_clicked()
|
||||||
{
|
{
|
||||||
log("Setting text alignment to 'Justify'", className);
|
log("Setting text alignment to 'Justify'", className);
|
||||||
if(is_epub != true) {
|
global::reader::textAlignment = 3;
|
||||||
ui->text->setAlignment(Qt::AlignJustify);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
|
||||||
else {
|
|
||||||
alignAndHighlightText(3);
|
|
||||||
}
|
|
||||||
string_writeconfig(".config/04-book/alignment", "Justify");
|
string_writeconfig(".config/04-book/alignment", "Justify");
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::alignAndHighlightText(int alignment) {
|
void reader::setTextProperties(int alignment, int lineSpacing, int margins, QString font, int fontSize) {
|
||||||
// Alignment
|
// Alignment
|
||||||
/*
|
/*
|
||||||
* 0 - Left
|
* 0 - Left
|
||||||
|
@ -1366,50 +1297,118 @@ void reader::alignAndHighlightText(int alignment) {
|
||||||
* 2 - Right
|
* 2 - Right
|
||||||
* 3 - Justify
|
* 3 - Justify
|
||||||
*/
|
*/
|
||||||
textAlignment = alignment;
|
|
||||||
QString modifiedPageContent;
|
|
||||||
|
|
||||||
if(is_epub == true) {
|
// Don't try to improve this
|
||||||
modifiedPageContent = epubPageContent;
|
// I have spent more time on it than I would care to admit
|
||||||
if(alignment == 0) {
|
|
||||||
modifiedPageContent.prepend("<div align='left'>");
|
setLineSpacing(lineSpacing, false);
|
||||||
modifiedPageContent.append("</div>");
|
ui->lineSpacingSlider->setValue(lineSpacing);
|
||||||
|
setMargins(margins, false);
|
||||||
|
ui->marginsSlider->setValue(margins);
|
||||||
|
|
||||||
|
QTextCursor cursor = ui->text->textCursor();
|
||||||
|
textDialogLock = true;
|
||||||
|
// Kudos to Qt for not implementing the opposite of the following function /)_-)
|
||||||
|
ui->text->selectAll();
|
||||||
|
if(alignment == 0) {
|
||||||
|
ui->text->setAlignment(Qt::AlignLeft);
|
||||||
|
}
|
||||||
|
else if(alignment == 1) {
|
||||||
|
ui->text->setAlignment(Qt::AlignHCenter);
|
||||||
|
}
|
||||||
|
else if(alignment == 2) {
|
||||||
|
ui->text->setAlignment(Qt::AlignRight);
|
||||||
|
}
|
||||||
|
else if(alignment == 3) {
|
||||||
|
ui->text->setAlignment(Qt::AlignJustify);
|
||||||
|
}
|
||||||
|
// Font
|
||||||
|
{
|
||||||
|
if(font == "Crimson Pro") {
|
||||||
|
// As adding Crimson Pro to the default fonts bundled along with the Qt libs breaks the general u001/Inter homogeneity, it is incorporated on-demand here.
|
||||||
|
{
|
||||||
|
QString family;
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Italic.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Bold.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-BoldItalic.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
ui->text->setFont(QFont(family));
|
||||||
|
}
|
||||||
|
writeFile(".config/04-book/font", "Crimson Pro");
|
||||||
}
|
}
|
||||||
if(alignment == 1) {
|
else if(font == "Bitter") {
|
||||||
modifiedPageContent.prepend("<div align='center'>");
|
{
|
||||||
modifiedPageContent.append("</div>");
|
QString family;
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-Medium.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-MediumItalic.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-Bold.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-BoldItalic.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
ui->text->setFont(QFont(family));
|
||||||
|
}
|
||||||
|
writeFile(".config/04-book/font", "Bitter");
|
||||||
}
|
}
|
||||||
if(alignment == 2) {
|
else if(font == "Ibarra Real Nova") {
|
||||||
modifiedPageContent.prepend("<div align='right'>");
|
{
|
||||||
modifiedPageContent.append("</div>");
|
QString family;
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-Medium.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-MediumItalic.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-Bold.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-BoldItalic.ttf");
|
||||||
|
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
}
|
||||||
|
ui->text->setFont(QFont(family));
|
||||||
|
}
|
||||||
|
writeFile(".config/04-book/font", "Ibarra Real Nova");
|
||||||
}
|
}
|
||||||
if(alignment == 3) {
|
else if(font == "Univers (u001)" or font == "u001") {
|
||||||
modifiedPageContent.prepend("<div align='justify'>");
|
ui->text->setFont(QFont("u001"));
|
||||||
modifiedPageContent.append("</div>");
|
writeFile(".config/04-book/font", "Univers (u001)");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->text->setFont(QFont(font));
|
||||||
|
writeFile(".config/04-book/font", font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
// Font size
|
||||||
modifiedPageContent = ittext;
|
ui->text->setFontPointSize(fontSize);
|
||||||
if(alignment == 0) {
|
ui->text->setTextCursor(cursor);
|
||||||
modifiedPageContent.prepend("<div align='left'>");
|
textDialogLock = false;
|
||||||
modifiedPageContent.append("</div>");
|
|
||||||
}
|
|
||||||
if(alignment == 1) {
|
|
||||||
modifiedPageContent.prepend("<div align='center'>");
|
|
||||||
modifiedPageContent.append("</div>");
|
|
||||||
}
|
|
||||||
if(alignment == 2) {
|
|
||||||
modifiedPageContent.prepend("<div align='right'>");
|
|
||||||
modifiedPageContent.append("</div>");
|
|
||||||
}
|
|
||||||
if(alignment == 3) {
|
|
||||||
modifiedPageContent.prepend("<div align='justify'>");
|
|
||||||
modifiedPageContent.append("</div>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui->text->setText(modifiedPageContent);
|
|
||||||
|
|
||||||
// Highlight
|
// Highlighting
|
||||||
QString htmlText = ui->text->toHtml();
|
QString htmlText = ui->text->toHtml();
|
||||||
QJsonObject jsonObject = getHighlightsForBook(book_file);
|
QJsonObject jsonObject = getHighlightsForBook(book_file);
|
||||||
int keyCount = 1;
|
int keyCount = 1;
|
||||||
|
@ -1428,7 +1427,8 @@ void reader::alignAndHighlightText(int alignment) {
|
||||||
}
|
}
|
||||||
keyCount++;
|
keyCount++;
|
||||||
}
|
}
|
||||||
ui->text->setText(htmlText);
|
htmlText.replace(QRegExp("font-family:'.*';"), "");
|
||||||
|
ui->text->setHtml(htmlText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::menubar_show() {
|
void reader::menubar_show() {
|
||||||
|
@ -1602,17 +1602,13 @@ void reader::on_saveWordBtn_clicked()
|
||||||
void reader::on_sizeSlider_valueChanged(int value)
|
void reader::on_sizeSlider_valueChanged(int value)
|
||||||
{
|
{
|
||||||
// Font size
|
// Font size
|
||||||
int initialValue = 6;
|
log("Setting font size to " + QString::number(value + global::reader::initialFontSize + 1) + " points", className);
|
||||||
log("Setting font size to " + QString::number(value + initialValue + 1) + " points", className);
|
|
||||||
|
|
||||||
string value_str = to_string(value);
|
|
||||||
string_writeconfig(".config/04-book/size", value_str);
|
|
||||||
|
|
||||||
QString styleSheet = "font-size: " + QString::number(initialValue + value + 1) + "pt;";
|
|
||||||
ui->text->setStyleSheet(styleSheet);
|
|
||||||
ui->sizeValueLabel->setText(QString::number(value + 1));
|
ui->sizeValueLabel->setText(QString::number(value + 1));
|
||||||
|
|
||||||
alignAndHighlightText(textAlignment);
|
global::reader::fontSize = global::reader::initialFontSize + value + 1;
|
||||||
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
|
|
||||||
|
writeFile(".config/04-book/size", QString::number(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::writeconfig_pagenumber(bool persistent) {
|
void reader::writeconfig_pagenumber(bool persistent) {
|
||||||
|
@ -1826,7 +1822,8 @@ void reader::on_text_selectionChanged() {
|
||||||
global::reader::highlightAlreadyDone = false;
|
global::reader::highlightAlreadyDone = false;
|
||||||
QJsonObject jsonObject = getHighlightsForBook(book_file);
|
QJsonObject jsonObject = getHighlightsForBook(book_file);
|
||||||
QString htmlText = ui->text->toHtml();
|
QString htmlText = ui->text->toHtml();
|
||||||
if(htmlText.contains("<span style=\" background-color:#bbbbbb;\">" + selected_text + "</span>")) {
|
qDebug() << htmlText << QString::number(global::reader::initialFontSize + global::reader::fontSize);
|
||||||
|
if(htmlText.contains("<span style=\" font-size:" + QString::number(global::reader::fontSize) + "pt; background-color:#bbbbbb;\">" + selected_text + "</span>") or htmlText.contains("<span style=\" background-color:#bbbbbb;\">" + selected_text + "</span>")) {
|
||||||
log("Highlight already done", className);
|
log("Highlight already done", className);
|
||||||
global::reader::highlightAlreadyDone = true;
|
global::reader::highlightAlreadyDone = true;
|
||||||
}
|
}
|
||||||
|
@ -1960,7 +1957,7 @@ void reader::gotoPage(int pageNumber) {
|
||||||
|
|
||||||
pagesTurned = 0;
|
pagesTurned = 0;
|
||||||
writeconfig_pagenumber(false);
|
writeconfig_pagenumber(false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(is_pdf == true) {
|
else if(is_pdf == true) {
|
||||||
|
@ -1989,7 +1986,7 @@ void reader::gotoPage(int pageNumber) {
|
||||||
|
|
||||||
pagesTurned = 0;
|
pagesTurned = 0;
|
||||||
writeconfig_pagenumber(false);
|
writeconfig_pagenumber(false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setupPageWidget();
|
setupPageWidget();
|
||||||
|
@ -2022,75 +2019,6 @@ void reader::setupSearchDialog() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::setBitterFont() {
|
|
||||||
QString family;
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-Medium.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-MediumItalic.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-Bold.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/Bitter-BoldItalic.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
QFont bitter(family);
|
|
||||||
ui->text->setFont(bitter);
|
|
||||||
ui->fontChooser->setCurrentText("Bitter");
|
|
||||||
}
|
|
||||||
|
|
||||||
void reader::setCrimsonProFont() {
|
|
||||||
QString family;
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Italic.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Bold.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-BoldItalic.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
QFont crimson(family);
|
|
||||||
ui->text->setFont(crimson);
|
|
||||||
ui->fontChooser->setCurrentText("Crimson Pro");
|
|
||||||
}
|
|
||||||
|
|
||||||
void reader::setIbarraFont() {
|
|
||||||
QString family;
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-Medium.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-MediumItalic.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-Bold.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/IbarraRealNova-BoldItalic.ttf");
|
|
||||||
family = QFontDatabase::applicationFontFamilies(id).at(0);
|
|
||||||
}
|
|
||||||
QFont ibarra(family);
|
|
||||||
ui->text->setFont(ibarra);
|
|
||||||
ui->fontChooser->setCurrentText("Ibarra Real Nova");
|
|
||||||
}
|
|
||||||
|
|
||||||
void reader::searchRefreshScreen() {
|
void reader::searchRefreshScreen() {
|
||||||
this->repaint();
|
this->repaint();
|
||||||
}
|
}
|
||||||
|
@ -2316,13 +2244,13 @@ void reader::unsetTextDialogLock() {
|
||||||
void reader::highlightText() {
|
void reader::highlightText() {
|
||||||
log("Highlighting text '" + selected_text + "'", className);
|
log("Highlighting text '" + selected_text + "'", className);
|
||||||
highlightBookText(selected_text, book_file, false);
|
highlightBookText(selected_text, book_file, false);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::unhighlightText() {
|
void reader::unhighlightText() {
|
||||||
log("Removing highlighted text '" + selected_text + "'", className);
|
log("Removing highlighted text '" + selected_text + "'", className);
|
||||||
highlightBookText(selected_text, book_file, true);
|
highlightBookText(selected_text, book_file, true);
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_viewHighlightsBtn_clicked()
|
void reader::on_viewHighlightsBtn_clicked()
|
||||||
|
@ -2336,18 +2264,84 @@ void reader::on_viewHighlightsBtn_clicked()
|
||||||
else {
|
else {
|
||||||
global::highlightsListDialog::bookPath = book_file;
|
global::highlightsListDialog::bookPath = book_file;
|
||||||
highlightsListDialog * highlightsListDialogWindow = new highlightsListDialog(this);
|
highlightsListDialog * highlightsListDialogWindow = new highlightsListDialog(this);
|
||||||
QObject::connect(highlightsListDialogWindow, &highlightsListDialog::destroyed, this, &reader::alignAndHighlightTextSlot);
|
QObject::connect(highlightsListDialogWindow, &highlightsListDialog::destroyed, this, &reader::setTextPropertiesSlot);
|
||||||
QObject::connect(highlightsListDialogWindow, &highlightsListDialog::showToast, this, &reader::showToast);
|
QObject::connect(highlightsListDialogWindow, &highlightsListDialog::showToast, this, &reader::showToast);
|
||||||
highlightsListDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
highlightsListDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::alignAndHighlightTextSlot() {
|
void reader::setTextPropertiesSlot() {
|
||||||
alignAndHighlightText(textAlignment);
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::setFontSizeSlot() {
|
void reader::setInitialTextProperties() {
|
||||||
// Checking saved font size if any, and if there is, set it
|
// Checking saved font size if any, and if there is, set it
|
||||||
string_checkconfig(".config/04-book/size");
|
QString fontSizeString = readFile(".config/04-book/size");
|
||||||
ui->sizeSlider->setValue(checkconfig_str_val.toInt());
|
if(!fontSizeString.isEmpty()) {
|
||||||
|
global::reader::fontSize = fontSizeString.toInt();
|
||||||
|
ui->sizeSlider->setValue(global::reader::fontSize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
global::reader::fontSize = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reader::setLineSpacing(int spacing, bool write) {
|
||||||
|
global::reader::lineSpacing = spacing;
|
||||||
|
if(write == true and readFile(".config/04-book/line_spacing") != QString::number(global::reader::lineSpacing)) {
|
||||||
|
writeFile(".config/04-book/line_spacing", QString::number(global::reader::lineSpacing));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(write == false) {
|
||||||
|
log("Setting line spacing to " + QString::number(global::reader::lineSpacing + 1), className);
|
||||||
|
QTextCursor textCursor = ui->text->textCursor();
|
||||||
|
|
||||||
|
QTextBlockFormat * newFormat = new QTextBlockFormat();
|
||||||
|
textCursor.clearSelection();
|
||||||
|
textCursor.select(QTextCursor::Document);
|
||||||
|
newFormat->setLineHeight((global::reader::lineSpacing * 10 + 100), QTextBlockFormat::ProportionalHeight);
|
||||||
|
newFormat->setLeftMargin(global::reader::margins * 10);
|
||||||
|
newFormat->setRightMargin(global::reader::margins * 10);
|
||||||
|
textCursor.setBlockFormat(*newFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reader::setMargins(int margins, bool write) {
|
||||||
|
global::reader::margins = margins;
|
||||||
|
if(write == true and readFile(".config/04-book/margins") != QString::number(global::reader::margins)) {
|
||||||
|
writeFile(".config/04-book/margins", QString::number(global::reader::margins));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(write == false) {
|
||||||
|
log("Setting margins to " + QString::number(global::reader::margins), className);
|
||||||
|
QTextCursor textCursor = ui->text->textCursor();
|
||||||
|
|
||||||
|
QTextBlockFormat * newFormat = new QTextBlockFormat();
|
||||||
|
textCursor.clearSelection();
|
||||||
|
textCursor.select(QTextCursor::Document);
|
||||||
|
newFormat->setLineHeight((global::reader::lineSpacing * 10 + 100), QTextBlockFormat::ProportionalHeight);
|
||||||
|
newFormat->setLeftMargin(global::reader::margins * 10);
|
||||||
|
newFormat->setRightMargin(global::reader::margins * 10);
|
||||||
|
textCursor.setBlockFormat(*newFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reader::on_lineSpacingSlider_valueChanged(int value)
|
||||||
|
{
|
||||||
|
global::reader::lineSpacing = value;
|
||||||
|
// Write setting once
|
||||||
|
setLineSpacing(global::reader::lineSpacing, true);
|
||||||
|
// Be consistent with other settings
|
||||||
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
|
ui->lineSpacingValueLabel->setText(QString::number(value + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void reader::on_marginsSlider_valueChanged(int value)
|
||||||
|
{
|
||||||
|
global::reader::margins = value;
|
||||||
|
// Write setting once
|
||||||
|
setMargins(global::reader::margins, true);
|
||||||
|
// Be consistent with other settings
|
||||||
|
setTextProperties(global::reader::textAlignment, global::reader::lineSpacing, global::reader::margins, global::reader::font, global::reader::fontSize);
|
||||||
|
ui->marginsValueLabel->setText(QString::number(value + 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ public:
|
||||||
int page_number;
|
int page_number;
|
||||||
int dictionary_position = 1;
|
int dictionary_position = 1;
|
||||||
int pagesTurned = 0;
|
int pagesTurned = 0;
|
||||||
int textAlignment;
|
|
||||||
|
|
||||||
// -1 : Never refresh | 0 : Refresh every page | 1 : Refresh every 1 page. And so on...
|
// -1 : Never refresh | 0 : Refresh every page | 1 : Refresh every 1 page. And so on...
|
||||||
// Refresh every 3 pages is the default
|
// Refresh every 3 pages is the default
|
||||||
|
@ -113,16 +112,13 @@ public:
|
||||||
void convertMuPdfVars(int fileType, bool convertAll);
|
void convertMuPdfVars(int fileType, bool convertAll);
|
||||||
void refreshScreen();
|
void refreshScreen();
|
||||||
void setPageStyle(int fileType);
|
void setPageStyle(int fileType);
|
||||||
void alignAndHighlightText(int alignment);
|
void setTextProperties(int alignment, int lineSpacing, int margins, QString font, int fontSize);
|
||||||
void delay(int seconds);
|
void delay(int seconds);
|
||||||
void openUsbmsDialog();
|
void openUsbmsDialog();
|
||||||
QString setPageNumberLabelContent();
|
QString setPageNumberLabelContent();
|
||||||
void setupPageWidget();
|
void setupPageWidget();
|
||||||
void getTotalEpubPagesNumber();
|
void getTotalEpubPagesNumber();
|
||||||
void getTotalPdfPagesNumber();
|
void getTotalPdfPagesNumber();
|
||||||
void setBitterFont();
|
|
||||||
void setCrimsonProFont();
|
|
||||||
void setIbarraFont();
|
|
||||||
bool pdf_file_match(QString file);
|
bool pdf_file_match(QString file);
|
||||||
bool image_file_match(QString file);
|
bool image_file_match(QString file);
|
||||||
|
|
||||||
|
@ -168,8 +164,12 @@ private slots:
|
||||||
void highlightText();
|
void highlightText();
|
||||||
void unhighlightText();
|
void unhighlightText();
|
||||||
void on_viewHighlightsBtn_clicked();
|
void on_viewHighlightsBtn_clicked();
|
||||||
void alignAndHighlightTextSlot();
|
void setTextPropertiesSlot();
|
||||||
void setFontSizeSlot();
|
void setInitialTextProperties();
|
||||||
|
void setLineSpacing(int spacing, bool write = true);
|
||||||
|
void setMargins(int margins, bool write = true);
|
||||||
|
void on_lineSpacingSlider_valueChanged(int value);
|
||||||
|
void on_marginsSlider_valueChanged(int value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void openBookFile(QString book, bool relativePath);
|
void openBookFile(QString book, bool relativePath);
|
||||||
|
|
1038
src/reader/reader.ui
1038
src/reader/reader.ui
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue