File indexing completed on 2024-05-12 05:40:38

0001 /*
0002     Cahoots is a crossplatform real-time collaborative text editor.
0003 
0004     Copyright (C) 2010 Chris Dimpfl, Anandi Hira, David Vega
0005 
0006     This program is free software: you can redistribute it and/or modify
0007     it under the terms of the GNU General Public License as published by
0008     the Free Software Foundation, either version 3 of the License, or
0009     (at your option) any later version.
0010 
0011     This program is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014     GNU General Public License for more details.
0015 
0016     You should have received a copy of the GNU General Public License
0017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 #include "findtoolbar.h"
0020 #include "ui_findtoolbar.h"
0021 
0022 FindToolBar::FindToolBar(QWidget* parent) : QWidget(parent), ui(new Ui::FindToolBar)
0023 {
0024     ui->setupUi(this);
0025 
0026     connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(findTriggered(QString)));
0027     connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
0028 }
0029 
0030 FindToolBar::~FindToolBar()
0031 {
0032     delete ui;
0033 }
0034 
0035 void FindToolBar::giveFocus()
0036 {
0037     ui->lineEdit->setFocus();
0038     ui->lineEdit->setText("");
0039 }
0040 
0041 void FindToolBar::findTriggered(QString string)
0042 {
0043     if(string.length() > 2)
0044     {
0045         emit findAll(string);
0046     }
0047 }
0048 
0049 void FindToolBar::findNextTriggered()
0050 {
0051     emit findNext(ui->lineEdit->text());
0052 }
0053 
0054 void FindToolBar::closeButtonClicked()
0055 {
0056     this->hide();
0057 }
0058 
0059 void FindToolBar::keyPressEvent(QKeyEvent* e)
0060 {
0061     if(e->key() == Qt::Key_Escape)
0062     {
0063         closeButtonClicked();
0064     }
0065     else if(ui->lineEdit->hasFocus() && e->key() == Qt::Key_Return && e->modifiers() != Qt::ShiftModifier)
0066     {
0067         emit findNext(ui->lineEdit->text());
0068     }
0069     else if(ui->lineEdit->hasFocus() && e->key() == Qt::Key_Return && e->modifiers() == Qt::ShiftModifier)
0070     {
0071         emit findPrevious(ui->lineEdit->text());
0072     }
0073 }