-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaskdlg.cpp
123 lines (106 loc) · 2.28 KB
/
askdlg.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "askdlg.h"
#include "parser.h"
#include <qapplication.h>
#include <qwidget.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <stdio.h>
enum { ADM_NONE, ADM_JUMP, ADM_SEARCH };
AskDialog::AskDialog( QWidget* parent, const char* name, WFlags fl )
: AskForm( parent, name, fl )
{
setFocusPolicy(QWidget::StrongFocus);
m_mode = ADM_NONE;
connect(m_wInput, SIGNAL(returnPressed()), this, SLOT(inputEnter()));
}
AskDialog::~AskDialog()
{
// no need to delete child widgets, Qt does it all for us
}
bool
AskDialog::jumpParagraph(int current, int max)
{
if (m_mode!=ADM_NONE) return false;
m_wTitle->setText(tr("Go to paragraph"));
QString mine;
mine = tr("Range : 0 - %1").arg(max-1);
m_wMsg->setText(mine);
mine.sprintf("%d", current);
m_wInput->setText(mine);
m_max = max;
m_mode = ADM_JUMP;
showDialog();
return true;
}
bool
AskDialog::searchParagraph(const QString &str)
{
if (m_mode!=ADM_NONE) return false;
m_wTitle->setText(tr("Search"));
m_wMsg->setText("search text in document");
m_wInput->setText("");
m_mode = ADM_SEARCH;
showDialog();
return true;
}
void
AskDialog::showDialog()
{
QWidget *w = (QWidget*)parent();
move((w->width()-this->width())/2,
(w->height()-this->height())/2);
show();
qApp->processEvents();
m_wInput->selectAll();
m_wInput->setFocus();
}
void
AskDialog::inputEnter()
{
if (m_mode==ADM_NONE) return;
switch (m_mode) {
case ADM_JUMP:
{
bool ok;
int dst = m_wInput->text().toUInt(&ok);
if (ok && dst>=0 && dst<m_max) {
emit jumpTo(dst);
endDialog();
} else {
m_wInput->selectAll();
m_wInput->setFocus();
}
}
break;
case ADM_SEARCH:
emit search(m_wInput->text(), SK_KEYWORD);
break;
}
}
void
AskDialog::endDialog()
{
if (m_mode!=ADM_NONE) {
QWidget *w = (QWidget*)parent();
m_mode = ADM_NONE;
hide();
w->setFocus();
}
}
void
AskDialog::keyPressEvent(QKeyEvent *ev)
{
//printf("AskDialog::keyPressEvent(0x%04x)\n", ev->key());
switch (ev->key()) {
case Qt::Key_Escape:
endDialog();
break;
}
ev->accept();
}
void
AskDialog::keyReleaseEvent(QKeyEvent *ev)
{
//printf("AskDialog::keyReleaseEvent(0x%04x)\n", ev->key());
ev->accept();
}