Parent: [5854ec] (diff)

Child: [5ebcb0] (diff)

Download this file

preview.ui.h    180 lines (156 with data), 4.7 kB

  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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include "debuglog.h"
void Preview::init()
{
connect(pvTab, SIGNAL(currentChanged(QWidget *)),
this, SLOT(currentChanged(QWidget *)));
searchTextLine->installEventFilter(this);
dynSearchActive = false;
canBeep = true;
}
void Preview::closeEvent(QCloseEvent *e)
{
emit previewClosed(this);
QWidget::closeEvent(e);
}
extern int recollNeedsExit;
bool Preview::eventFilter(QObject *target, QEvent *event)
{
if (event->type() != QEvent::KeyPress)
return QWidget::eventFilter(target, event);
LOGDEB1(("Preview::eventFilter: keyEvent\n"));
QKeyEvent *keyEvent = (QKeyEvent *)event;
if (keyEvent->key() == Key_Q && (keyEvent->state() & ControlButton)) {
recollNeedsExit = 1;
return true;
} else if (keyEvent->key() ==Key_W &&(keyEvent->state() & ControlButton)) {
// LOGDEB(("Preview::eventFilter: got ^W\n"));
closeCurrentTab();
return true;
} else if (dynSearchActive) {
if (keyEvent->key() == Key_F3) {
doSearch(true, false);
return true;
}
if (target != searchTextLine)
return QApplication::sendEvent(searchTextLine, event);
} else {
QWidget *tw = pvTab->currentPage();
QWidget *e = 0;
if (tw)
e = (QTextEdit *)tw->child("pvEdit");
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
if (e && target == tw && keyEvent->key() == Key_Slash) {
dynSearchActive = true;
return true;
}
}
return QWidget::eventFilter(target, event);
}
void Preview::searchTextLine_textChanged(const QString & text)
{
LOGDEB1(("search line text changed. text: '%s'\n", text.ascii()));
if (text.isEmpty()) {
dynSearchActive = false;
} else {
dynSearchActive = true;
doSearch(false, false);
}
}
// Perform text search. If next is true, we look for the next match of the
// current search, trying to advance and possibly wrapping around. If next is
// false, the search string has been modified, we search for the new string,
// starting from the current position
void Preview::doSearch(bool next, bool reverse)
{
LOGDEB1(("Preview::doSearch: next %d rev %d\n", int(next), int(reverse)));
QWidget *tw = pvTab->currentPage();
QTextEdit *edit = 0;
if (tw) {
if ((edit = (QTextEdit*)tw->child("pvEdit")) == 0) {
// ??
return;
}
}
bool matchCase = matchCheck->isChecked();
int mspara, msindex, mepara, meindex;
edit->getSelection(&mspara, &msindex, &mepara, &meindex);
if (mspara == -1)
mspara = msindex = mepara = meindex = 0;
if (next) {
// We search again, starting from the current match
if (reverse) {
// when searching backwards, have to move back one char
if (msindex > 0)
msindex --;
else if (mspara > 0) {
mspara --;
msindex = edit->paragraphLength(mspara);
}
} else {
// Forward search: start from end of selection
mspara = mepara;
msindex = meindex;
LOGDEB1(("New para: %d index %d\n", mspara, msindex));
}
}
bool found = edit->find(searchTextLine->text(), matchCase, false,
!reverse, &mspara, &msindex);
if (!found && next && true) { // need a 'canwrap' test here
if (reverse) {
mspara = edit->paragraphs();
msindex = edit->paragraphLength(mspara);
} else {
mspara = msindex = 0;
}
found = edit->find(searchTextLine->text(), matchCase, false,
!reverse, &mspara, &msindex);
}
if (found) {
canBeep = true;
} else {
if (canBeep)
QApplication::beep();
canBeep = false;
}
}
void Preview::nextPressed()
{
doSearch(true, false);
}
void Preview::prevPressed()
{
doSearch(true, true);
}
void Preview::currentChanged(QWidget * tw)
{
QObject *o = tw->child("pvEdit");
LOGDEB1(("Preview::currentChanged(). Edit %p\n", o));
if (o == 0) {
LOGERR(("Editor child not found\n"));
} else {
tw->installEventFilter(this);
o->installEventFilter(this);
((QWidget*)o)->setFocus();
}
}
void Preview::closeCurrentTab()
{
if (pvTab->count() > 1) {
QWidget *tw = pvTab->currentPage();
if (tw)
pvTab->removePage(tw);
} else {
close();
}
}