summaryrefslogtreecommitdiffstatshomepage
path: root/configfile.h
blob: 04235e547c87201249b8fab47f3eff7be843bcd7 (plain)
1
2
3
4
5
6
7
8
#ifndef CONFIGFILE_H
#define CONFIGFILE_H

typedef void (*configfile_value_fn)(const char *name, const char *value);

extern int parse_configfile(const char *filename, configfile_value_fn fn);

#endif /* CONFIGFILE_H */
color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "finddialog.h"
#include "./ui_finddialog.h"

#include <QTimer>
#include <QDebug>

FindDialog::FindDialog(QWidget* parent)
    : QDialog(parent, Qt::Tool), ui(new Ui::FindDialog)
{
    ui->setupUi(this);
}

FindDialog::~FindDialog() {
    delete last_search;
    delete ui;
}

void FindDialog::on_buttonSearchPrev_clicked() {
    if (--selected_match < 0) {
        selected_match = total_matches - 1;
        ui->statusLabel->setText(tr("Reached top, continued from bottom."));
    } else update_status();
    select_match();
}

void FindDialog::on_buttonSearchNext_clicked() {
    if (++selected_match >= total_matches) {
        selected_match = 0;
        ui->statusLabel->setText(tr("Reached bottom, continued from top."));
    } else update_status();
    select_match();
}

// Update the textbox in the main window and search after 400 ms of no typing
void FindDialog::on_textInputSearch_textEdited(const QString &text) {
    emit search_text_changed(text);
    static QTimer* differed_search = new QTimer(this);
    if (static bool timer_init_done = false; not timer_init_done) {
        differed_search->setTimerType(Qt::CoarseTimer);
        differed_search->setSingleShot(true);
        differed_search->setInterval(400);
        connect(differed_search, &QTimer::timeout, this, &FindDialog::run_search);
        timer_init_done = true;
    }
    differed_search->start();
}

void FindDialog::set_search_text(const QString &text, bool search_immediately) {
    ui->textInputSearch->setText(text);
    if (search_immediately) init_search();
    else on_textInputSearch_textEdited(text);
}

inline void FindDialog::run_search() {
    init_search();
}

void FindDialog::on_hSlider_valueChanged(int value) {
    selected_match = value;
    update_status();
    select_match();
}

void FindDialog::on_spinBox_valueChanged(int value) {
    // Avoids repeatedly changing the selected_match as the valueChanged signal is a notifier for the spin box's value
    if (not value_changed_processed) {
        selected_match = value - 1;
        update_status();
        select_match();
    }
    value_changed_processed = false;
}

void FindDialog::set_qlist_widget(QListWidget* widget) {
    list_widget = widget;
}

// Start a new search only if the search text input has changed
void FindDialog::init_search() {
    QString current_search = ui->textInputSearch->text();
    if (*last_search == current_search or not list_widget) return;

    matches = list_widget->findItems(current_search, Qt::MatchContains);

    *last_search = current_search;
    selected_match = 0;
    total_matches = matches.size();

    if (total_matches > 0) {
        ui->hSlider->setEnabled(true);
        ui->spinBox->setEnabled(true);
        ui->buttonSearchPrev->setEnabled(true);
        ui->buttonSearchNext->setEnabled(true);
    } else {
        ui->spinBox->setEnabled(false);
        ui->hSlider->setEnabled(false);
        ui->buttonSearchPrev->setEnabled(false);
        ui->buttonSearchNext->setEnabled(false);
    }

    // Set the minimum as when there are no matches, the widget would return out of range index values to having an out of range minimum.
    ui->hSlider->setMinimum(0);
    ui->spinBox->setMinimum(1);
    ui->hSlider->setMaximum(total_matches - 1);
    ui->spinBox->setMaximum(total_matches);

    select_match();
    update_status();
}

// Activate the match requested by the user
void FindDialog::select_match() {
    if (list_widget and total_matches != 0 and selected_match >= 0) {
        list_widget->scrollToItem(matches[selected_match], QAbstractItemView::EnsureVisible);
        list_widget->setCurrentItem(matches[selected_match]);
        emit item_selected(matches[selected_match]);
    }

    // Best place to update these sliders as select_match is always called by each input
    ui->hSlider->setValue(selected_match);
    ui->spinBox->setValue(selected_match + 1);
    value_changed_processed = true;
}

// Update the status line with current search information
void FindDialog::update_status() {
    if (total_matches > 0) {
        ui->statusLabel->setText(tr("Search result %1 out of %2.")
                                    .arg(selected_match+1)
                                    .arg(total_matches));
    } else ui->statusLabel->setText(tr("No search results."));
}