Skip to content
reader.cpp 39.3 KiB
Newer Older
        dictionary_lookup(selected_text_str, letter, dictionary_position);
        ui->definitionLabel->setText(definition);
        QString dictionary_position_str = QString::number(dictionary_position);
        ui->definitionStatusLabel->setText(dictionary_position_str);
    }
}

void reader::on_nextDefinitionBtn_clicked()
{
    dictionary_position = dictionary_position + 1;
    dictionary_lookup(selected_text_str, letter, dictionary_position);
    if(nextdefinition_lock == true) {
        dictionary_position = dictionary_position - 1;
    }
    else {
        ui->definitionLabel->setText(definition);
        QString dictionary_position_str = QString::number(dictionary_position);
        ui->definitionStatusLabel->setText(dictionary_position_str);
    }
}

void reader::on_saveWordBtn_clicked()
{
    if(checkconfig_match(".config/06-words/config", selected_text_str) == true) {
        checkwords();
        word = word.append("\n");
        words = words.replace(word, "");
        string words_std_string = words.toStdString();
        save_word(words_std_string, true);
        ui->saveWordBtn->setText("");
        ui->saveWordBtn->setIcon(QIcon(":/resources/star.png"));
    }
    else {
        save_word(selected_text_str, false);
        ui->saveWordBtn->setText("");
        ui->saveWordBtn->setIcon(QIcon(":/resources/starred_star.png"));
    }
}

void reader::on_sizeSlider_valueChanged(int value)
{
    // Font size
    string value_str = to_string(value);
    string_writeconfig(".config/04-book/size", value_str);

    // Future improvement?
    if(checkconfig_match("/opt/inkbox_device", "n705\n") == true) {
        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");
        }
    }
    if(checkconfig_match("/opt/inkbox_device", "n905\n") == true) {
        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");
        }
    }
}

void reader::writeconfig_pagenumber() {
    // Saving the page number in tmpfs
    if(is_epub != true) {
        std::string split_total_str = std::to_string(split_total);
        string_writeconfig("/tmp/inkboxPageNumber", split_total_str);
    }
    else {
        std::string epubPageNumber_str = std::to_string(mupdf::epubPageNumber);
        string_writeconfig("/tmp/inkboxPageNumber", epubPageNumber_str);
    }

void reader::quit_restart() {
    // Restarting InkBox
    QProcess process;
    process.startDetached("inkbox", QStringList());
    qApp->quit();
}

void reader::openLowBatteryDialog() {
    global::mainwindow::lowBatteryDialog = true;
    global::battery::batteryAlertLock = true;

    generalDialogWindow = new generalDialog(this);
    generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
    generalDialogWindow->show();
    QApplication::processEvents();
}

void reader::openCriticalBatteryAlertWindow() {
    global::battery::showCriticalBatteryAlert = true;
    global::battery::showLowBatteryDialog = false;

    alertWindow = new alert();
    alertWindow->setAttribute(Qt::WA_DeleteOnClose);
    alertWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
    alertWindow->show();
void reader::convertMuPdfVars() {
    mupdf::fontSize_qstr = QString::number(mupdf::fontSize);
    mupdf::width_qstr = QString::number(mupdf::width);
    mupdf::height_qstr = QString::number(mupdf::height);
    mupdf::epubPageNumber_qstr = QString::number(mupdf::epubPageNumber);
}