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
|
/***************************************************************************
* copyright : (C) 2003-2012 by Pascal Brachet *
* http://www.xm1math.net/texmaker/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "findwidget.h"
#include <QDebug>
#include <QTextCursor>
#include <QMessageBox>
#include "geticon.h"
FindWidget::FindWidget(QWidget* parent)
: QWidget( parent)
{
ui.setupUi(this);
connect(ui.findButton, SIGNAL( clicked() ), this, SLOT( doFind() ) );
connect(ui.closeButton, SIGNAL( clicked() ), this, SLOT( doHide() ) );
//ui.findButton->setShortcut(Qt::Key_Return);
ui.findButton->setToolTip("Return");
ui.closeButton->setShortcut(Qt::Key_Escape);
ui.closeButton->setToolTip("Escape");
//ui.closeButton->setIcon(getIcon(":/images/fileclose.png"));
ui.moreButton->setCheckable(true);
ui.moreButton->setAutoDefault(false);
connect(ui.moreButton, SIGNAL(toggled(bool)), this, SLOT(expand(bool)));
ui.checkRegExp->setChecked( false );
ui.checkSelection->setChecked( false );
connect(ui.checkSelection, SIGNAL(toggled(bool)), this, SLOT(updateSelection(bool)));
ui.extension->hide();
updateGeometry();
}
FindWidget::~FindWidget()
{
}
void FindWidget::doFind()
{
if ( !editor )
{
startpos=-1;
endpos=-1;
return;
}
if (ui.checkRegExp->isChecked())
{
QRegExp regex(ui.comboFind->currentText());
if (!regex.isValid())
{
QMessageBox::warning( this,tr("Error"), tr("Invalid regular expression."));
return;
}
}
int result=-1;
if (ui.checkSelection->isChecked())
{
if ((startpos>-1) && (endpos>-1))
{
result=editor->searchInSelection( ui.comboFind->currentText(), ui.checkCase->isChecked(),ui.checkWords->isChecked(), ui.checkRegExp->isChecked(),startpos,endpos);
if (result>-1) startpos=result;
else ui.checkSelection->setChecked( false );
}
}
else
{
startpos=-1;
endpos=-1;
if ( !editor->search( ui.comboFind->currentText(), ui.checkCase->isChecked(), ui.checkWords->isChecked(), ui.radioForward->isChecked(), !ui.checkBegin->isChecked(), ui.checkRegExp->isChecked()) )
{
ui.checkBegin->setChecked( true );
}
else ui.checkBegin->setChecked( false );
}
editor->viewport()->repaint();
}
void FindWidget::doHide()
{
emit requestHide();
startpos=-1;
endpos=-1;
if ( editor )
{
editor->viewport()->repaint();
editor->setFocus();
}
}
void FindWidget::SetEditor(LatexEditor *ed)
{
editor=ed;
}
void FindWidget::expand(bool e)
{
ui.extension->setVisible(e);
if (!e)
{
ui.checkRegExp->setChecked( false );
ui.checkSelection->setChecked( false );
}
updateGeometry();
emit requestExtension();
if ( editor ) editor->viewport()->repaint();
}
void FindWidget::updateSelection(bool e)
{
ui.checkBegin->setEnabled(!e);
if (e) ui.radioForward->setChecked(true);
if ( !editor )
{
startpos=-1;
endpos=-1;
}
else if (e)
{
QTextCursor c=editor->textCursor();
if (c.hasSelection())
{
startpos=c.selectionStart();
endpos=c.selectionEnd();
}
else
{
QMessageBox::warning( this,"Texmaker", tr("Text must be selected before checking this option."));
startpos=-1;
endpos=-1;
ui.checkSelection->setChecked( false );
}
}
else
{
startpos=-1;
endpos=-1;
}
}
void FindWidget::keyPressEvent ( QKeyEvent * e )
{
if ((e->key()==Qt::Key_Enter)||(e->key()==Qt::Key_Return)) doFind();
}
|