summaryrefslogtreecommitdiffstats
path: root/tools/linguist/linguist/finddialog.cpp
blob: 979915aa9b6f10c4d39506df39915db93024b874 (plain)
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
180
181
182
183
/**********************************************************************
** Copyright (C) 2000-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of TQt Linguist.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing retquirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** Licensees holding valid TQt Commercial licenses may use this file in
** accordance with the TQt Commercial License Agreement provided with
** the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

/*  TRANSLATOR FindDialog

    Choose Edit|Find from the menu bar or press Ctrl+F to pop up the 
    Find dialog
*/

#include "finddialog.h"

#include <qcheckbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>

FindDialog::FindDialog( bool replace, TQWidget *parent, const char *name,
			bool modal )
    : TQDialog( parent, name, modal )
{
    sourceText = 0;
    
    led = new TQLineEdit( this, "find line edit" );
    TQLabel *findWhat = new TQLabel( led, tr("Fi&nd what:"), this, "find what" );
    TQLabel *replaceWith = 0;
    TQPushButton *findNxt = new TQPushButton( tr("&Find Next"), this,
					    "find next" );
    findNxt->setDefault( TRUE );
    connect( findNxt, SIGNAL(clicked()), this, SLOT(emitFindNext()) );
    TQPushButton *cancel = new TQPushButton( tr("Cancel"), this, "cancel find" );
    connect( cancel, SIGNAL(clicked()), this, SLOT(reject()) );

    TQVBoxLayout *bl = new TQVBoxLayout( 6, "find button layout" );
    bl->addWidget( findNxt );

    matchCase = new TQCheckBox( tr("&Match case"), this, "find match case" );
    matchCase->setChecked( FALSE );

    if ( replace ) {
	TQWhatsThis::add( this, tr("This window allows you to search and replace"
				  " some text in the translations.") );

	red = new TQLineEdit( this, "replace line edit" );
	replaceWith = new TQLabel( red, tr("Replace &with:"), this,
				  "replace with" );
	setTabOrder( led, red );

	TQPushButton *replace = new TQPushButton( tr("&Replace"), this,
						"replace" );
	connect( replace, SIGNAL(clicked()), this, SLOT(emitReplace()) );
	TQPushButton *replaceAll = new TQPushButton( tr("Replace &All"), this,
						   "replace all" );
	connect( replaceAll, SIGNAL(clicked()), this, SLOT(emitReplaceAll()) );
	setTabOrder( findNxt, replace );
	setTabOrder( replace, replaceAll );
	setTabOrder( replaceAll, cancel );

	TQWhatsThis::add( replace, tr("Click here to replace the next occurrence"
				     " of the text you typed in.") );
	TQWhatsThis::add( replaceAll, tr("Click here to replace all occurrences"
					" of the text you typed in.") );

	bl->addWidget( replace );
	bl->addWidget( replaceAll );

	TQGridLayout *gl = new TQGridLayout( this, 4, 3, 11, 11,
					   "find outer layout" );
	gl->addWidget( findWhat, 0, 0 );
	gl->addWidget( led, 0, 1 );
	gl->addWidget( replaceWith, 1, 0 );
	gl->addWidget( red, 1, 1 );
	gl->addMultiCellWidget( matchCase, 2, 2, 0, 1 );
	gl->addMultiCell( bl, 0, 3, 3, 3 );
    } else {
	TQWhatsThis::add( this, tr("This window allows you to search for some"
				  " text in the translation source file.") );

	sourceText = new TQCheckBox( tr("&Source texts"), this,
				    "find in source texts" );
	sourceText->setChecked( TRUE );
	translations = new TQCheckBox( tr("&Translations"), this,
				      "find in translations" );
	translations->setChecked( TRUE );
	comments = new TQCheckBox( tr("&Comments"), this, "find in comments" );
	comments->setChecked( TRUE );

	TQWhatsThis::add( sourceText, tr("Source texts are searched when"
					" checked.") );
	TQWhatsThis::add( translations, tr("Translations are searched when"
					  " checked.") );
	TQWhatsThis::add( comments, tr("Comments and contexts are searched when"
				      " checked.") );

	TQVBoxLayout *cl = new TQVBoxLayout( 6, "find checkbox layout" );

	TQGridLayout *gl = new TQGridLayout( this, 3, 4, 11, 11,
					   "find outer layout" );
	gl->addWidget( findWhat, 0, 0 );
	gl->addMultiCellWidget( led, 0, 0, 1, 2 );
	gl->addWidget( matchCase, 1, 2 );
	gl->addMultiCell( bl, 0, 2, 3, 3 );
	gl->addMultiCell( cl, 1, 2, 0, 1 );
	gl->setColStretch( 0, 0 );
	gl->addColSpacing( 1, 40 );
	gl->setColStretch( 2, 1 );
	gl->setColStretch( 3, 0 );

	cl->addWidget( sourceText );
	cl->addWidget( translations );
	cl->addWidget( comments );
	cl->addStretch( 1 );
    }

    TQWhatsThis::add( led, tr("Type in the text to search for.") );

    TQWhatsThis::add( matchCase, tr("Texts such as 'TeX' and 'tex' are"
				   " considered as different when checked.") );
    TQWhatsThis::add( findNxt, tr("Click here to find the next occurrence of the"
				 " text you typed in.") );
    TQWhatsThis::add( cancel, tr("Click here to close this window.") );

    bl->addWidget( cancel );
    bl->addStretch( 1 );

    resize( 400, 1 );
    setMaximumHeight( height() );

    led->setFocus();
}

void FindDialog::emitFindNext()
{
    int where;
    if ( sourceText != 0 )
	where = ( sourceText->isChecked() ? SourceText : 0 ) |
		( translations->isChecked() ? Translations : 0 ) |
		( comments->isChecked() ? Comments : 0 );
    else
	where = Translations;
    emit findNext( led->text(), where, matchCase->isChecked() );
}

void FindDialog::emitReplace()
{
    emit replace( led->text(), red->text(), matchCase->isChecked(), FALSE );
}

void FindDialog::emitReplaceAll()
{
    emit replace( led->text(), red->text(), matchCase->isChecked(), TRUE );
}