Improve font size range

The font size slider now has 16 levels of different font sizes.
This commit is contained in:
Nicolas Mailloux 2022-09-05 14:18:27 -04:00
parent 087cfbe837
commit 922ecb0ab5
3 changed files with 143 additions and 230 deletions

View file

@ -478,44 +478,6 @@ reader::reader(QWidget *parent) :
} }
// Display text // Display text
// Checking saved font size if any
string_checkconfig(".config/04-book/size");
if(checkconfig_str_val == "0") {
checkconfig_str_val = "6";
ui->sizeSlider->setValue(0);
ui->sizeValueLabel->setText("1");
}
if(checkconfig_str_val == "1") {
checkconfig_str_val = "10";
ui->sizeSlider->setValue(1);
ui->sizeValueLabel->setText("2");
}
if(checkconfig_str_val == "2") {
checkconfig_str_val = "14";
ui->sizeSlider->setValue(2);
ui->sizeValueLabel->setText("3");
}
if(checkconfig_str_val == "3") {
checkconfig_str_val = "18";
ui->sizeSlider->setValue(3);
ui->sizeValueLabel->setText("4");
}
if(checkconfig_str_val == "4") {
checkconfig_str_val = "22";
ui->sizeSlider->setValue(4);
ui->sizeValueLabel->setText("5");
}
if(checkconfig_str_val == "") {
checkconfig_str_val = "10";
ui->sizeSlider->setValue(1);
ui->sizeValueLabel->setText("2");
}
QString font_size = "font-size: ";
font_size = font_size.append(checkconfig_str_val);
font_size = font_size.append("pt");
log("Setting font size to " + checkconfig_str_val + " points", className);
ui->text->setStyleSheet(font_size);
// If needed, show scroll bar when rendering engine isn't doing its job properly // If needed, show scroll bar when rendering engine isn't doing its job properly
if(checkconfig(".config/14-reader_scrollbar/config") == true) { if(checkconfig(".config/14-reader_scrollbar/config") == true) {
ui->text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui->text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -526,6 +488,34 @@ reader::reader(QWidget *parent) :
ui->text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui->text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
} }
// Text alignment
string_checkconfig(".config/04-book/alignment");
if(checkconfig_str_val == "Left") {
textAlignment = 0;
alignAndHighlightText(0);
}
else if(checkconfig_str_val == "Center") {
textAlignment = 1;
alignAndHighlightText(1);
}
else if(checkconfig_str_val == "Right") {
textAlignment = 2;
alignAndHighlightText(2);
}
else if(checkconfig_str_val == "Justify") {
textAlignment = 3;
alignAndHighlightText(3);
}
else {
checkconfig_str_val = "Left";
textAlignment = 0;
alignAndHighlightText(0);
}
log("Setting text alignment to '" + checkconfig_str_val + "'", className);
// Don't ask me why it doesn't work without that QTimer
QTimer::singleShot(0, this, SLOT(setFontSizeSlot()));
// Wheeee! // Wheeee!
if(is_epub == true) { if(is_epub == true) {
ui->graphicsView->hide(); ui->graphicsView->hide();
@ -556,31 +546,6 @@ reader::reader(QWidget *parent) :
ui->text->setText(ittext); ui->text->setText(ittext);
} }
// Alignment
string_checkconfig(".config/04-book/alignment");
if (checkconfig_str_val == "") {
;
}
else {
if(checkconfig_str_val == "Left") {
textAlignment = 0;
alignAndHighlightText(0);
}
if(checkconfig_str_val == "Center") {
textAlignment = 1;
alignAndHighlightText(1);
}
if(checkconfig_str_val == "Right") {
textAlignment = 2;
alignAndHighlightText(2);
}
if(checkconfig_str_val == "Justify") {
textAlignment = 3;
alignAndHighlightText(3);
}
log("Setting text alignment to '" + checkconfig_str_val + "'", className);
}
// Topbar info widget // Topbar info widget
if(is_epub == true) { if(is_epub == true) {
QString bookCreator = findEpubMetadata(book_file, "creator"); QString bookCreator = findEpubMetadata(book_file, "creator");
@ -1637,75 +1602,16 @@ 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 + initialValue + 1) + " points", className);
string value_str = to_string(value); string value_str = to_string(value);
string_writeconfig(".config/04-book/size", value_str); string_writeconfig(".config/04-book/size", value_str);
if(global::deviceID == "n705\n") { QString styleSheet = "font-size: " + QString::number(initialValue + value + 1) + "pt;";
if(value == 0) { ui->text->setStyleSheet(styleSheet);
ui->text->setStyleSheet("font-size: 6pt"); ui->sizeValueLabel->setText(QString::number(value + 1));
ui->sizeValueLabel->setText("1");
}
if(value == 1) {
ui->text->setStyleSheet("font-size: 10pt");
ui->sizeValueLabel->setText("2");
}
if(value == 2) {
ui->text->setStyleSheet("font-size: 14pt");
ui->sizeValueLabel->setText("3");
}
if(value == 3) {
ui->text->setStyleSheet("font-size: 18pt");
ui->sizeValueLabel->setText("4");
}
if(value == 4) {
ui->text->setStyleSheet("font-size: 22pt");
ui->sizeValueLabel->setText("5");
}
}
if(global::deviceID == "n905\n" or global::deviceID == "kt\n") {
if(value == 0) {
ui->text->setStyleSheet("font-size: 6pt");
ui->sizeValueLabel->setText("1");
}
if(value == 1) {
ui->text->setStyleSheet("font-size: 10pt");
ui->sizeValueLabel->setText("2");
}
if(value == 2) {
ui->text->setStyleSheet("font-size: 14pt");
ui->sizeValueLabel->setText("3");
}
if(value == 3) {
ui->text->setStyleSheet("font-size: 18pt");
ui->sizeValueLabel->setText("4");
}
if(value == 4) {
ui->text->setStyleSheet("font-size: 22pt");
ui->sizeValueLabel->setText("5");
}
}
else {
if(value == 0) {
ui->text->setStyleSheet("font-size: 6pt");
ui->sizeValueLabel->setText("1");
}
if(value == 1) {
ui->text->setStyleSheet("font-size: 10pt");
ui->sizeValueLabel->setText("2");
}
if(value == 2) {
ui->text->setStyleSheet("font-size: 14pt");
ui->sizeValueLabel->setText("3");
}
if(value == 3) {
ui->text->setStyleSheet("font-size: 18pt");
ui->sizeValueLabel->setText("4");
}
if(value == 4) {
ui->text->setStyleSheet("font-size: 22pt");
ui->sizeValueLabel->setText("5");
}
}
alignAndHighlightText(textAlignment); alignAndHighlightText(textAlignment);
} }
@ -2439,3 +2345,9 @@ void reader::on_viewHighlightsBtn_clicked()
void reader::alignAndHighlightTextSlot() { void reader::alignAndHighlightTextSlot() {
alignAndHighlightText(textAlignment); alignAndHighlightText(textAlignment);
} }
void reader::setFontSizeSlot() {
// Checking saved font size if any, and if there is, set it
string_checkconfig(".config/04-book/size");
ui->sizeSlider->setValue(checkconfig_str_val.toInt());
}

View file

@ -169,6 +169,7 @@ private slots:
void unhighlightText(); void unhighlightText();
void on_viewHighlightsBtn_clicked(); void on_viewHighlightsBtn_clicked();
void alignAndHighlightTextSlot(); void alignAndHighlightTextSlot();
void setFontSizeSlot();
signals: signals:
void openBookFile(QString book, bool relativePath); void openBookFile(QString book, bool relativePath);

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>644</width> <width>644</width>
<height>851</height> <height>931</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -591,33 +591,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<widget class="QSlider" name="sizeSlider">
<property name="maximum">
<number>4</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="sizeValueLabel">
<property name="text">
<string>Value</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="fontLabel"> <widget class="QLabel" name="fontLabel">
<property name="text"> <property name="text">
@ -625,79 +598,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QComboBox" name="fontChooser">
<item>
<property name="text">
<string>Univers (u001)</string>
</property>
</item>
<item>
<property name="text">
<string>Inter</string>
</property>
</item>
<item>
<property name="text">
<string>Source Serif Pro</string>
</property>
</item>
<item>
<property name="text">
<string>Bitter</string>
</property>
</item>
<item>
<property name="text">
<string>Crimson Pro</string>
</property>
</item>
<item>
<property name="text">
<string>Libre Baskerville</string>
</property>
</item>
<item>
<property name="text">
<string>Libertinus Serif</string>
</property>
</item>
<item>
<property name="text">
<string>Ibarra Real Nova</string>
</property>
</item>
<item>
<property name="text">
<string>Noto Mono</string>
</property>
</item>
<item>
<property name="text">
<string>Roboto Mono</string>
</property>
</item>
<item>
<property name="text">
<string>Roboto</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="alignmentLabel">
<property name="text">
<string>Alignment:</string>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="4"> <item row="0" column="4">
@ -778,6 +678,106 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="fontChooser">
<item>
<property name="text">
<string>Univers (u001)</string>
</property>
</item>
<item>
<property name="text">
<string>Inter</string>
</property>
</item>
<item>
<property name="text">
<string>Source Serif Pro</string>
</property>
</item>
<item>
<property name="text">
<string>Bitter</string>
</property>
</item>
<item>
<property name="text">
<string>Crimson Pro</string>
</property>
</item>
<item>
<property name="text">
<string>Libre Baskerville</string>
</property>
</item>
<item>
<property name="text">
<string>Libertinus Serif</string>
</property>
</item>
<item>
<property name="text">
<string>Ibarra Real Nova</string>
</property>
</item>
<item>
<property name="text">
<string>Noto Mono</string>
</property>
</item>
<item>
<property name="text">
<string>Roboto Mono</string>
</property>
</item>
<item>
<property name="text">
<string>Roboto</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="alignmentLabel">
<property name="text">
<string>Alignment:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<widget class="QSlider" name="sizeSlider">
<property name="maximum">
<number>15</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="sizeValueLabel">
<property name="text">
<string>Value</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>