summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dialogs/searchtextdialog.cpp
blob: 578a253aceb7edc813a93b62e985055a12d6edb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "searchtextdialog.h"
#include "ui_searchtextdialog.h"
#include "searchtextlocator.h"
#include "common/unused.h"

SearchTextDialog::SearchTextDialog(SearchTextLocator* textLocator, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SearchTextDialog), textLocator(textLocator)
{
    ui->setupUi(this);
    connect(textLocator, SIGNAL(replaceAvailable(bool)), this, SLOT(setReplaceAvailable(bool)));
    connect(ui->findEdit, SIGNAL(textChanged(QString)), this, SLOT(markModifiedState()));
    connect(ui->caseSensitiveCheck, SIGNAL(toggled(bool)), this, SLOT(markModifiedState()));
    connect(ui->backwardsCheck, SIGNAL(toggled(bool)), this, SLOT(markModifiedState()));
    connect(ui->regExpCheck, SIGNAL(toggled(bool)), this, SLOT(markModifiedState()));
}

SearchTextDialog::~SearchTextDialog()
{
    delete ui;
}

void SearchTextDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
        case QEvent::LanguageChange:
            ui->retranslateUi(this);
            break;
        default:
            break;
    }
}

void SearchTextDialog::showEvent(QShowEvent* e)
{
    UNUSED(e);
    ui->findEdit->setFocus();
    ui->findEdit->selectAll();
    configModifiedState = true;
    setReplaceAvailable(false);
}

void SearchTextDialog::applyConfigToLocator()
{
    if (!configModifiedState)
        return;

    textLocator->setCaseSensitive(ui->caseSensitiveCheck->isChecked());
    textLocator->setSearchBackwards(ui->backwardsCheck->isChecked());
    textLocator->setRegularExpression(ui->regExpCheck->isChecked());
    textLocator->setLookupString(ui->findEdit->text());
    configModifiedState = false;
}

void SearchTextDialog::setReplaceAvailable(bool available)
{
    ui->replaceButton->setEnabled(available);
}

void SearchTextDialog::on_findButton_clicked()
{
    applyConfigToLocator();
    textLocator->find();
}

void SearchTextDialog::on_replaceButton_clicked()
{
    applyConfigToLocator();
    textLocator->setReplaceString(ui->replaceEdit->text());
    textLocator->replaceAndFind();
}

void SearchTextDialog::on_replaceAllButton_clicked()
{
    applyConfigToLocator();
    textLocator->setReplaceString(ui->replaceEdit->text());
    textLocator->replaceAll();
}

void SearchTextDialog::markModifiedState()
{
    configModifiedState = true;
}