summaryrefslogtreecommitdiff
path: root/src/frontend/display/bthtmlfindtext.cpp
blob: 9e0feff5680f861143a94669828bd996f0e19890 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2009 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "bthtmlfindtext.h"
#include "bthtmlreaddisplay.h"
#include "creaddisplay.h"
#include "frontend/cmdiarea.h"
#include "frontend/displaywindow/cdisplaywindow.h"
#include <QMdiSubWindow>

static BtHtmlFindText* dialog = 0;

void showBtHtmlFindText(CMDIArea* mdiArea) {
    if (dialog == 0)
        dialog = new BtHtmlFindText(mdiArea, mdiArea);
    dialog->show();
}

BtHtmlFindText::BtHtmlFindText(CMDIArea* mdiArea, QWidget *parent, Qt::WindowFlags f)
        : QDialog(parent, f), m_mdiArea(mdiArea) {
    ui.setupUi(this);
    bool ok;
    ok = connect(ui.nextButton, SIGNAL(clicked()), this, SLOT(findNext()));
    Q_ASSERT(ok);
    ok = connect(ui.previousButton, SIGNAL(clicked()), this, SLOT(findPrevious()));
    Q_ASSERT(ok);
}

BtHtmlFindText::~BtHtmlFindText() {
}

void BtHtmlFindText::findNext() {
    QWebView* webView = getActiveWindowWebView();
    if (webView != 0) {
        QWebPage::FindFlags options = 0;
        if (ui.caseBox->checkState() == Qt::Checked)
            options |= QWebPage::FindCaseSensitively;
        QString searchText = ui.findTextComboBox->currentText();
        if (!searchText.isEmpty())
            webView->findText(searchText, options);
    }
}

void BtHtmlFindText::doHide() {
    hide();
}

void BtHtmlFindText::findPrevious() {
    QWebView* webView = getActiveWindowWebView();
    if (webView != 0) {
        QWebPage::FindFlags options = QWebPage::FindBackward;
        if (ui.caseBox->checkState() == Qt::Checked)
            options |= QWebPage::FindCaseSensitively;
        QString searchText = ui.findTextComboBox->currentText();
        if (!searchText.isEmpty())
            webView->findText(searchText, options);
    }
}


QWebView* BtHtmlFindText::getActiveWindowWebView() {
    QMdiSubWindow* activeSubWindow = m_mdiArea->activeSubWindow();
    if (activeSubWindow == 0)
        return 0;

    QWidget* activeWindowWidget = activeSubWindow->widget();
    if (activeWindowWidget == 0)
        return 0;

    CDisplayWindow* cDisplayWindow = qobject_cast<CDisplayWindow*>(activeWindowWidget);
    if (cDisplayWindow == 0)
        return 0;

    CDisplay* cDisplay = cDisplayWindow->displayWidget();
    if (cDisplay == 0)
        return 0;

    QWidget* textView = cDisplay->view();
    if (textView == 0)
        return 0;

    QWebView* webView = qobject_cast<QWebView*>(textView);
    return webView;
}