1 | /**********************************************************************
|
---|
2 | ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
|
---|
3 | **
|
---|
4 | ** This file is part of Qt Linguist.
|
---|
5 | **
|
---|
6 | ** This file may be distributed and/or modified under the terms of the
|
---|
7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
9 | ** packaging of this file.
|
---|
10 | **
|
---|
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
13 | ** Agreement provided with the Software.
|
---|
14 | **
|
---|
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | **
|
---|
18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
20 | ** information about Qt Commercial License Agreements.
|
---|
21 | **
|
---|
22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
23 | ** not clear to you.
|
---|
24 | **
|
---|
25 | **********************************************************************/
|
---|
26 |
|
---|
27 | /* TRANSLATOR PhraseLV
|
---|
28 |
|
---|
29 | The phrase list in the right panel of the main window (with Source phrase,
|
---|
30 | Target phrase, and Definition in its header) is a PhraseLV object.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "phraselv.h"
|
---|
34 |
|
---|
35 | #include <qregexp.h>
|
---|
36 | #include <qwhatsthis.h>
|
---|
37 | #include <qheader.h>
|
---|
38 |
|
---|
39 | class WhatPhrase : public QWhatsThis
|
---|
40 | {
|
---|
41 | public:
|
---|
42 | WhatPhrase( PhraseLV *w );
|
---|
43 |
|
---|
44 | virtual QString text( const QPoint& p );
|
---|
45 |
|
---|
46 | private:
|
---|
47 | PhraseLV *parent;
|
---|
48 | };
|
---|
49 |
|
---|
50 | WhatPhrase::WhatPhrase( PhraseLV *w )
|
---|
51 | : QWhatsThis( w )
|
---|
52 | {
|
---|
53 | parent = w;
|
---|
54 | }
|
---|
55 |
|
---|
56 | QString WhatPhrase::text( const QPoint& p )
|
---|
57 | {
|
---|
58 | QListViewItem *item = parent->itemAt( p );
|
---|
59 | if ( item == 0 )
|
---|
60 | return PhraseLV::tr( "This is a list of phrase entries relevant to the"
|
---|
61 | " source text. Each phrase is supplemented with a suggested"
|
---|
62 | " translation and a definition." );
|
---|
63 | else
|
---|
64 | return QString( PhraseLV::tr("<p><u>%1:</u> %2</p>"
|
---|
65 | "<p><u>%3:</u> %4</p>"
|
---|
66 | "<p><u>%5:</u> %6</p>") )
|
---|
67 | .arg( parent->columnText(PhraseLVI::SourceTextShown) )
|
---|
68 | .arg( item->text(PhraseLVI::SourceTextShown) )
|
---|
69 | .arg( parent->columnText(PhraseLVI::TargetTextShown) )
|
---|
70 | .arg( item->text(PhraseLVI::TargetTextShown) )
|
---|
71 | .arg( parent->columnText(PhraseLVI::DefinitionText) )
|
---|
72 | .arg( item->text(PhraseLVI::DefinitionText) );
|
---|
73 | }
|
---|
74 |
|
---|
75 | PhraseLVI::PhraseLVI( PhraseLV *parent, const Phrase& phrase, int accelKey )
|
---|
76 | : QListViewItem( parent ),
|
---|
77 | akey( accelKey )
|
---|
78 | {
|
---|
79 | setPhrase( phrase );
|
---|
80 | }
|
---|
81 |
|
---|
82 | QString PhraseLVI::key( int column, bool ascending ) const
|
---|
83 | {
|
---|
84 | if ( column == SourceTextShown ) {
|
---|
85 | if ( sourceTextKey.isEmpty() ) {
|
---|
86 | if ( ascending ) {
|
---|
87 | return "";
|
---|
88 | } else {
|
---|
89 | return QString::null;
|
---|
90 | }
|
---|
91 | } else {
|
---|
92 | return sourceTextKey;
|
---|
93 | }
|
---|
94 | } else if ( column == TargetTextShown ) {
|
---|
95 | return targetTextKey;
|
---|
96 | } else {
|
---|
97 | return QChar( '0' + akey ) + text( column );
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | void PhraseLVI::setText( int column, const QString& text )
|
---|
102 | {
|
---|
103 | if ( column == SourceTextShown ) {
|
---|
104 | sourceTextKey = makeKey( text );
|
---|
105 | } else if ( column == TargetTextShown ) {
|
---|
106 | targetTextKey = makeKey( text );
|
---|
107 | }
|
---|
108 | QListViewItem::setText( column, text );
|
---|
109 | }
|
---|
110 |
|
---|
111 | void PhraseLVI::setPhrase( const Phrase& phrase )
|
---|
112 | {
|
---|
113 | setText( SourceTextShown, phrase.source().simplifyWhiteSpace() );
|
---|
114 | setText( TargetTextShown, phrase.target().simplifyWhiteSpace() );
|
---|
115 | setText( DefinitionText, phrase.definition() );
|
---|
116 | setText( SourceTextOriginal, phrase.source() );
|
---|
117 | setText( TargetTextOriginal, phrase.target() );
|
---|
118 | }
|
---|
119 |
|
---|
120 | Phrase PhraseLVI::phrase() const
|
---|
121 | {
|
---|
122 | return Phrase( text(SourceTextOriginal), text(TargetTextOriginal),
|
---|
123 | text(DefinitionText) );
|
---|
124 | }
|
---|
125 |
|
---|
126 | QString PhraseLVI::makeKey( const QString& text ) const
|
---|
127 | {
|
---|
128 | if ( text == NewPhrase )
|
---|
129 | return QString::null;
|
---|
130 |
|
---|
131 | QString key;
|
---|
132 | for ( int i = 0; i < (int) text.length(); i++ ) {
|
---|
133 | if ( text[i] != QChar('&') )
|
---|
134 | key += text[i].lower();
|
---|
135 | }
|
---|
136 | // see Section 5, Exercise 4 of The Art of Computer Programming
|
---|
137 | key += QChar::null;
|
---|
138 | key += text;
|
---|
139 | return key;
|
---|
140 | }
|
---|
141 |
|
---|
142 | PhraseLV::PhraseLV( QWidget *parent, const char *name )
|
---|
143 | : QListView( parent, name )
|
---|
144 | {
|
---|
145 | setAllColumnsShowFocus( TRUE );
|
---|
146 | setShowSortIndicator( TRUE );
|
---|
147 | for ( int i = 0; i < 3; i++ )
|
---|
148 | addColumn( QString::null, 120 );
|
---|
149 | setColumnText( PhraseLVI::SourceTextShown, tr("Source phrase") );
|
---|
150 | setColumnText( PhraseLVI::TargetTextShown, tr("Translation") );
|
---|
151 | setColumnText( PhraseLVI::DefinitionText, tr("Definition") );
|
---|
152 | header()->setStretchEnabled( TRUE, -1 );
|
---|
153 | what = new WhatPhrase( this );
|
---|
154 | }
|
---|
155 |
|
---|
156 | PhraseLV::~PhraseLV()
|
---|
157 | {
|
---|
158 | // delete what;
|
---|
159 | }
|
---|
160 |
|
---|
161 | QSize PhraseLV::sizeHint() const
|
---|
162 | {
|
---|
163 | return QSize( QListView::sizeHint().width(), 50 );
|
---|
164 | }
|
---|