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
|
// $Id: BaseFindDialog.cpp,v 1.29 2014/02/03 10:08:21 hupereir Exp $
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This 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.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* Any WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*******************************************************************************/
#include "BaseIconNames.h"
#include "GridLayout.h"
#include "IconEngine.h"
#include "LineEditor.h"
#include "Debug.h"
#include "BaseFindDialog.h"
#include "BaseFindDialog.moc"
#include <QFrame>
#include <QPushButton>
//________________________________________________________________________
QOrderedSet<QString>& BaseFindDialog::_searchedStrings( void )
{
static QOrderedSet<QString> strings;
return strings;
}
//________________________________________________________________________
BaseFindDialog::BaseFindDialog( QWidget* parent, Qt::WindowFlags flags ):
BaseDialog( parent, flags ),
Counter( "BaseFindDialog" )
{
Debug::Throw( "BaseFindDialog::BaseFindDialog.\n" );
setOptionName( "FIND_DIALOG" );
// set dialog title
setWindowTitle( tr( "Find" ) );
// create vbox layout
setLayout( new QVBoxLayout() );
layout()->setMargin( 10 );
layout()->setSpacing( 5 );
// edition
layout()->addItem( editorLayout_ = new QGridLayout() );
_editorLayout().setMargin( 0 );
_editorLayout().setSpacing( 5 );
// add editor
QLabel *label = new QLabel( tr( "Text to find:" ), this );
label->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
_editorLayout().addWidget( label, 0, 0, 1, 1 );
_editorLayout().addWidget( editor_ = new CustomComboBox( this ), 0, 1, 1, 1 );
label->setBuddy( &editor() );
editor().setEditable( true );
editor().setAutoCompletion( true, Qt::CaseSensitive );
connect( editor().lineEdit(), SIGNAL(returnPressed()), SLOT(_find()) );
connect( editor().lineEdit(), SIGNAL(returnPressed()), SLOT(_updateFindComboBox()) );
connect( editor().lineEdit(), SIGNAL(textChanged(QString)), SLOT(_updateButtons(QString)) );
connect( editor().lineEdit(), SIGNAL(textChanged(QString)), SLOT(_findNoIncrement()) );
// locations
GridLayout* gridLayout( new GridLayout() );
gridLayout->setSpacing( 5 );
gridLayout->setMargin( 0 );
gridLayout->setMaxCount( 2 );
layout()->addItem( gridLayout );
// insert checkboxes
gridLayout->addWidget( backwardCheckbox_ = new QCheckBox( tr( "Search backward" ), this ) );
gridLayout->addWidget( caseSensitiveCheckbox_ = new QCheckBox( tr( "Case sensitive" ), this ) );
gridLayout->addWidget( regexpCheckbox_ = new QCheckBox( tr( "Regular expression" ), this ) );
gridLayout->addWidget( entireWordCheckbox_ = new QCheckBox( tr( "Entire word" ), this ) );
connect( regexpCheckbox_, SIGNAL(toggled(bool)), SLOT(_regExpChecked(bool)) );
// tooltips
backwardCheckbox_->setToolTip( tr( "Perform search backward" ) );
caseSensitiveCheckbox_->setToolTip( tr( "Case sensitive search" ) );
regexpCheckbox_->setToolTip( tr( "Search text using regular expression" ) );
// notification label
layout()->addWidget( label_ = new QLabel( this ) );
label_->setMargin( 2 );
// location layout
layout()->addItem( locationLayout_ = new QHBoxLayout() );
_locationLayout().setMargin(0);
_locationLayout().setSpacing(5);
// horizontal separator
QFrame* frame( new QFrame( this ) );
frame->setFrameStyle( QFrame::HLine | QFrame::Sunken );
layout()->addWidget( frame );
// buttons
layout()->addItem( buttonLayout_ = new QHBoxLayout() );
_buttonLayout().setMargin( 0 );
_buttonLayout().setSpacing( 5 );
_buttonLayout().addStretch(1);
// insert Find button
QPushButton *button;
_buttonLayout().addWidget( button = new QPushButton( IconEngine::get( IconNames::Find ), tr( "Find" ), this ) );
connect( button, SIGNAL(clicked()), SLOT(_find()) );
connect( button, SIGNAL(clicked()), SLOT(_updateFindComboBox()) );
_addDisabledButton( button );
button->setAutoDefault( false );
findButton_ = button;
// insert Cancel button
_buttonLayout().addWidget( button = new QPushButton( IconEngine::get( IconNames::DialogClose ), tr( "Close" ), this ) );
connect( button, SIGNAL(clicked()), SLOT(close()) );
button->setShortcut( Qt::Key_Escape );
button->setAutoDefault( false );
// disable buttons
_updateButtons();
}
//________________________________________________________________________
void BaseFindDialog::synchronize( void )
{
Debug::Throw( "BaseFindDialog::synchronize.\n" );
editor().clear();
for( QOrderedSet<QString>::iterator iter = _searchedStrings().begin(); iter != _searchedStrings().end(); ++iter )
{ editor().addItem( *iter ); }
}
//________________________________________________________________________
void BaseFindDialog::matchFound( void )
{ label_->setText( "" ); }
//________________________________________________________________________
void BaseFindDialog::noMatchFound( void )
{ if( !editor().currentText().isEmpty() ) label_->setText( tr( "Not found" ) ); }
//________________________________________________________________________
void BaseFindDialog::_regExpChecked( bool value )
{
Debug::Throw( "BaseFindDialog::_regExpChecked.\n" );
caseSensitiveCheckbox_->setChecked( value );
if( value )
{
entireWordCheckbox_->setChecked( false );
entireWordCheckbox_->setEnabled( false );
} else { entireWordCheckbox_->setEnabled( true ); }
}
//________________________________________________________________________
void BaseFindDialog::_updateButtons( const QString& text )
{
Debug::Throw( "BaseFindDialog::_updateButtons.\n" );
bool enabled( !( text.isNull() || text.isEmpty() ) );
for( QList< QAbstractButton* >::iterator iter = _disabledButtons().begin(); iter != _disabledButtons().end(); ++iter )
{ (*iter)->setEnabled( enabled ); }
Debug::Throw( "BaseFindDialog::_updateButtons - done.\n" );
}
|