~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to qt/chardict/chardict-unicodeviewwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
 
4
 
 
5
All rights reserved.
 
6
 
 
7
Redistribution and use in source and binary forms, with or without
 
8
modification, are permitted provided that the following conditions
 
9
are met:
 
10
 
 
11
1. Redistributions of source code must retain the above copyright
 
12
notice, this list of conditions and the following disclaimer.
 
13
2. Redistributions in binary form must reproduce the above copyright
 
14
notice, this list of conditions and the following disclaimer in the
 
15
documentation and/or other materials provided with the distribution.
 
16
3. Neither the name of authors nor the names of its contributors
 
17
may be used to endorse or promote products derived from this software
 
18
without specific prior written permission.
 
19
 
 
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
 
21
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
22
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
23
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
 
24
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
25
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
26
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
27
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
28
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
29
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
30
SUCH DAMAGE.
 
31
 
 
32
*/
 
33
#include "chardict-unicodeviewwidget.h"
 
34
#include "chardict-chargridview.h"
 
35
 
 
36
#include <qlayout.h>
 
37
#include <qvbox.h>
 
38
#include <qlabel.h>
 
39
#include <qheader.h>
 
40
#include <qsettings.h>
 
41
 
 
42
#include "qtgettext.h"
 
43
 
 
44
class UnicodeBlock
 
45
{
 
46
public:
 
47
    UnicodeBlock( const QString &name, uint startHex, uint endHex )
 
48
    {
 
49
        m_name = name;
 
50
        m_startHex = startHex;
 
51
        m_endHex = endHex;
 
52
    }
 
53
 
 
54
    QString getName() const { return m_name; }
 
55
    uint getStartHex() const { return m_startHex; }
 
56
    uint getEndHex() const { return m_endHex; }
 
57
 
 
58
protected:
 
59
    QString m_name;
 
60
    uint m_startHex;
 
61
    uint m_endHex;
 
62
};
 
63
 
 
64
#define UBLOCK_SIZE 125
 
65
static UnicodeBlock uBlocks[ UBLOCK_SIZE ] = {
 
66
            UnicodeBlock( _( "Basic Latin" ), 0x0000, 0x007F ),
 
67
            UnicodeBlock( _( "Latin-1 Supplement" ), 0x0080, 0x00FF ),
 
68
            UnicodeBlock( _( "Latin Extended-A" ), 0x0100, 0x017F ),
 
69
            UnicodeBlock( _( "Latin Extended-B" ), 0x0180, 0x024F ),
 
70
            UnicodeBlock( _( "IPA Extensions" ), 0x0250, 0x02AF ),
 
71
            UnicodeBlock( _( "Spacing Modifier Letters" ), 0x02B0, 0x02FF ),
 
72
            UnicodeBlock( _( "Combining Diacritical Marks" ), 0x0300, 0x036F ),
 
73
            UnicodeBlock( _( "Greek and Coptic" ), 0x0370, 0x03FF ),
 
74
            UnicodeBlock( _( "Cyrillic" ), 0x0400, 0x04FF ),
 
75
            UnicodeBlock( _( "Cyrillic Supplement" ), 0x0500, 0x052F ),
 
76
            UnicodeBlock( _( "Armenian" ), 0x0530, 0x058F ),
 
77
            UnicodeBlock( _( "Hebrew" ), 0x0590, 0x05FF ),
 
78
            UnicodeBlock( _( "Arabic" ), 0x0600, 0x06FF ),
 
79
            UnicodeBlock( _( "Syriac" ), 0x0700, 0x074F ),
 
80
            UnicodeBlock( _( "Thaana" ), 0x0780, 0x07BF ),
 
81
            UnicodeBlock( _( "Devanagari" ), 0x0900, 0x097F ),
 
82
            UnicodeBlock( _( "Bengali" ), 0x0980, 0x09FF ),
 
83
            UnicodeBlock( _( "Gurmukhi" ), 0x0A00, 0x0A7F ),
 
84
            UnicodeBlock( _( "Gujarati" ), 0x0A80, 0x0AFF ),
 
85
            UnicodeBlock( _( "Oriya" ), 0x0B00, 0x0B7F ),
 
86
            UnicodeBlock( _( "Tamil" ), 0x0B80, 0x0BFF ),
 
87
            UnicodeBlock( _( "Telugu" ), 0x0C00, 0x0C7F ),
 
88
            UnicodeBlock( _( "Kannada" ), 0x0C80, 0x0CFF ),
 
89
            UnicodeBlock( _( "Malayalam" ), 0x0D00, 0x0D7F ),
 
90
            UnicodeBlock( _( "Sinhala" ), 0x0D80, 0x0DFF ),
 
91
            UnicodeBlock( _( "Thai" ), 0x0E00, 0x0E7F ),
 
92
            UnicodeBlock( _( "Lao" ), 0x0E80, 0x0EFF ),
 
93
            UnicodeBlock( _( "Tibetan" ), 0x0F00, 0x0FFF ),
 
94
            UnicodeBlock( _( "Myanmar" ), 0x1000, 0x109F ),
 
95
            UnicodeBlock( _( "Georgian" ), 0x10A0, 0x10FF ),
 
96
            UnicodeBlock( _( "Hangul Jamo" ), 0x1100, 0x11FF ),
 
97
            UnicodeBlock( _( "Ethiopic" ), 0x1200, 0x137F ),
 
98
            UnicodeBlock( _( "Cherokee" ), 0x13A0, 0x13FF ),
 
99
            UnicodeBlock( _( "Unified Canadian Aboriginal Syllabics" ), 0x1400, 0x167F ),
 
100
            UnicodeBlock( _( "Ogham" ), 0x1680, 0x169F ),
 
101
            UnicodeBlock( _( "Runic" ), 0x16A0, 0x16FF ),
 
102
            UnicodeBlock( _( "Tagalog" ), 0x1700, 0x171F ),
 
103
            UnicodeBlock( _( "Hanunoo" ), 0x1720, 0x173F ),
 
104
            UnicodeBlock( _( "Buhid" ), 0x1740, 0x175F ),
 
105
            UnicodeBlock( _( "Tagbanwa" ), 0x1760, 0x177F ),
 
106
            UnicodeBlock( _( "Khmer" ), 0x1780, 0x17FF ),
 
107
            UnicodeBlock( _( "Mongolian" ), 0x1800, 0x18AF ),
 
108
            UnicodeBlock( _( "Limbu" ), 0x1900, 0x194F ),
 
109
            UnicodeBlock( _( "Tai Letters" ), 0x1950, 0x197F ),
 
110
            UnicodeBlock( _( "Khmer Symbols" ), 0x19E0, 0x19FF ),
 
111
            UnicodeBlock( _( "Phonetic Extensions" ), 0x1D00, 0x1D7F ),
 
112
            UnicodeBlock( _( "Latin Extended Additional" ), 0x1E00, 0x1EFF ),
 
113
            UnicodeBlock( _( "Greek Extended-B" ), 0x1F00, 0x1FFF ),
 
114
            UnicodeBlock( _( "General Punctuation" ), 0x2000, 0x206F ),
 
115
            UnicodeBlock( _( "Superscripts and Subscripts" ), 0x2070, 0x209F ),
 
116
            UnicodeBlock( _( "Currency Symbols" ), 0x20A0, 0x20CF ),
 
117
            UnicodeBlock( _( "Combining Diacritical Marks for Symbols" ), 0x20D0, 0x20FF ),
 
118
            UnicodeBlock( _( "Letterlike Symbols" ), 0x2100, 0x214F ),
 
119
            UnicodeBlock( _( "Number Forms" ), 0x2150, 0x218F ),
 
120
            UnicodeBlock( _( "Arrows" ), 0x2190, 0x21FF ),
 
121
            UnicodeBlock( _( "Mathematical Operators" ), 0x2200, 0x22FF ),
 
122
            UnicodeBlock( _( "Miscellaneous Technical" ), 0x2300, 0x23FF ),
 
123
            UnicodeBlock( _( "Control Pictures" ), 0x2400, 0x243F ),
 
124
            UnicodeBlock( _( "Optical Character Recognition" ), 0x2440, 0x245F ),
 
125
            UnicodeBlock( _( "Enclosed Alphanumerics" ), 0x2460, 0x24FF ),
 
126
            UnicodeBlock( _( "Box Drawing" ), 0x2500, 0x257F ),
 
127
            UnicodeBlock( _( "Block Elements" ), 0x2580, 0x259F ),
 
128
            UnicodeBlock( _( "Geometric Shapes" ), 0x25A0, 0x25FF ),
 
129
            UnicodeBlock( _( "Miscellaneous Symbols" ), 0x2600, 0x26FF ),
 
130
            UnicodeBlock( _( "Dingbats" ), 0x2700, 0x27BF ),
 
131
            UnicodeBlock( _( "Miscellaneous Mathematical Symbols-A" ), 0x27C0, 0x27EF ),
 
132
            UnicodeBlock( _( "Supplemental Arrows-A" ), 0x27F0, 0x27FF ),
 
133
            UnicodeBlock( _( "Braille Patterns" ), 0x2800, 0x28FF ),
 
134
            UnicodeBlock( _( "Supplemental Arrows-B" ), 0x2900, 0x297F ),
 
135
            UnicodeBlock( _( "Miscellaneous Mathematical Symbols-B" ), 0x2980, 0x29FF ),
 
136
            UnicodeBlock( _( "Supplemental Mathematical Operators" ), 0x2A00, 0x2AFF ),
 
137
            UnicodeBlock( _( "Miscellaneous Symbols and Arrows-B" ), 0x2B00, 0x2BFF ),
 
138
            UnicodeBlock( _( "CJK Radicals Supplemental" ), 0x2E80, 0x2EFF ),
 
139
            UnicodeBlock( _( "Kangxi Radicals" ), 0x2F00, 0x2FDF ),
 
140
            UnicodeBlock( _( "Ideographic Description Characters" ), 0x2FF0, 0x2FFF ),
 
141
            UnicodeBlock( _( "CJK Symbols and Punctuation" ), 0x3000, 0x303F ),
 
142
            UnicodeBlock( _( "Hiragana" ), 0x3040, 0x309F ),
 
143
            UnicodeBlock( _( "Katakana" ), 0x30A0, 0x30FF ),
 
144
            UnicodeBlock( _( "Bopomofo" ), 0x3100, 0x312F ),
 
145
            UnicodeBlock( _( "Hangul Compatibility Jamo" ), 0x3130, 0x318F ),
 
146
            UnicodeBlock( _( "Kanbun" ), 0x3190, 0x319F ),
 
147
            UnicodeBlock( _( "Bopomofo Extended-B 1F00" ), 0x31A0, 0x31BF ),
 
148
            UnicodeBlock( _( "Katakana Phonetic Extensions" ), 0x31F0, 0x31FF ),
 
149
            UnicodeBlock( _( "Enclosed CJK Letters and Months" ), 0x3200, 0x32FF ),
 
150
            UnicodeBlock( _( "CJK Compatibility" ), 0x3300, 0x33FF ),
 
151
            UnicodeBlock( _( "CJK Unified Ideographs Extension and" ), 0x3400, 0x4DBF ),
 
152
            UnicodeBlock( _( "Yijing Hexagram Symbols-B" ), 0x4DC0, 0x4DFF ),
 
153
            UnicodeBlock( _( "CJK Unified Ideographs" ), 0x4E00, 0x9FFF ),
 
154
            UnicodeBlock( _( "Yi Syllables" ), 0xA000, 0xA48F ),
 
155
            UnicodeBlock( _( "Yi Radicals" ), 0xA490, 0xA4CF ),
 
156
            UnicodeBlock( _( "Hangul Syllables" ), 0xAC00, 0xD7AF ),
 
157
            UnicodeBlock( _( "High Surrogates" ), 0xD800, 0xDB7F ),
 
158
            UnicodeBlock( _( "High Private Use Surrogates" ), 0xDB80, 0xDBFF ),
 
159
            UnicodeBlock( _( "Low Surrogates" ), 0xDC00, 0xDFFF ),
 
160
            UnicodeBlock( _( "Private Use Area" ), 0xE000, 0xF8FF ),
 
161
            UnicodeBlock( _( "CJK Compatibility Ideographs" ), 0xF900, 0xFAFF ),
 
162
            UnicodeBlock( _( "Alphabetic Presentation Forms" ), 0xFB00, 0xFB4F ),
 
163
            UnicodeBlock( _( "Arabic Presentation Forms-A" ), 0xFB50, 0xFDFF ),
 
164
            UnicodeBlock( _( "Variation Selectors" ), 0xFE00, 0xFE0F ),
 
165
            UnicodeBlock( _( "Combining Half Marks" ), 0xFE20, 0xFE2F ),
 
166
            UnicodeBlock( _( "CJK Compatibility Forms-A" ), 0xFE30, 0xFE4F ),
 
167
            UnicodeBlock( _( "Small Form Variants" ), 0xFE50, 0xFE6F ),
 
168
            UnicodeBlock( _( "Arabic Presentation Forms-B" ), 0xFE70, 0xFEFF ),
 
169
            UnicodeBlock( _( "Halfwidth and Fullwidth Forms-B" ), 0xFF00, 0xFFEF ),
 
170
            UnicodeBlock( _( "Specials" ), 0xFFF0, 0xFFFF ),
 
171
            UnicodeBlock( _( "Linear B Syllabary" ), 0x10000, 0x1007F ),
 
172
            UnicodeBlock( _( "Linear B Ideograms" ), 0x10080, 0x100FF ),
 
173
            UnicodeBlock( _( "Aegean Numbers" ), 0x10100, 0x1013F ),
 
174
            UnicodeBlock( _( "Old Italic" ), 0x10300, 0x1032F ),
 
175
            UnicodeBlock( _( "Gothic" ), 0x10330, 0x1034F ),
 
176
            UnicodeBlock( _( "Ugaritic" ), 0x10380, 0x1039F ),
 
177
            UnicodeBlock( _( "Deseret" ), 0x10400, 0x1044F ),
 
178
            UnicodeBlock( _( "Shavian" ), 0x10450, 0x1047F ),
 
179
            UnicodeBlock( _( "Osmanya" ), 0x10480, 0x104AF ),
 
180
            UnicodeBlock( _( "Cypriot Syllabary" ), 0x10800, 0x1083F ),
 
181
            UnicodeBlock( _( "Byzantine Musical Symbols-B 4DC0" ), 0x1D000, 0x1D0FF ),
 
182
            UnicodeBlock( _( "Musical Symbols-B 4DC0 1D000" ), 0x1D100, 0x1D1FF ),
 
183
            UnicodeBlock( _( "Tai Xuan Jing Symbols-B 4DC0 1D000 1D100" ), 0x1D300, 0x1D35F ),
 
184
            UnicodeBlock( _( "Mathematical Alphanumeric Symbols-B 4DC0 1D000 1D100 1D300" ), 0x1D400, 0x1D7FF ),
 
185
            UnicodeBlock( _( "CJK Unified Ideographs Extension B 4DC0 1D000 1D100 1D300 1D400" ), 0x20000, 0x2A6DF ),
 
186
            UnicodeBlock( _( "CJK Compatibility Ideographs Supplemental 2E80" ), 0x2F800, 0x2FA1F ),
 
187
            UnicodeBlock( _( "Tags" ), 0xE0000, 0xE007F ),
 
188
            UnicodeBlock( _( "Variation Selectors Supplemental 2E80 2F800" ), 0xE0100, 0xE01EF ),
 
189
            UnicodeBlock( _( "Supplementary Private Use Area-A" ), 0xF0000, 0xFFFFF ),
 
190
            UnicodeBlock( _( "Supplementary Private Use Area-B" ), 0x100000, 0x10FFFF )
 
191
        };
 
192
 
 
193
UnicodeViewWidget::UnicodeViewWidget( QWidget *parent, const char *name )
 
194
        : CharDictViewBase( parent, name )
 
195
{
 
196
    uBlockMap.clear();
 
197
 
 
198
    setupWidgets();
 
199
 
 
200
    readConfig();
 
201
}
 
202
 
 
203
UnicodeViewWidget::~UnicodeViewWidget()
 
204
{
 
205
    writeConfig();
 
206
}
 
207
 
 
208
void UnicodeViewWidget::setupWidgets()
 
209
{
 
210
    m_mainSplitter = new QSplitter( this );
 
211
 
 
212
    QVBox *leftVBox = new QVBox( m_mainSplitter );
 
213
    QLabel *unicodeBlockLabel = new QLabel( leftVBox );
 
214
    unicodeBlockLabel->setText( _( "UnicodeBlock List" ) );
 
215
    unicodeBlockLabel->setAlignment( Qt::AlignHCenter );
 
216
    m_unicodeBlockListView = new QListView( leftVBox );
 
217
    m_unicodeBlockListView->setSorting( -1 );
 
218
    m_unicodeBlockListView->setSelectionMode( QListView::Single );
 
219
    m_unicodeBlockListView->addColumn( "0" );
 
220
    m_unicodeBlockListView->header() ->setStretchEnabled( true, 0 );
 
221
    m_unicodeBlockListView->header() ->hide();
 
222
    m_unicodeBlockListView->setColumnWidthMode( 1, QListView::Maximum );
 
223
    m_unicodeBlockListView->setHScrollBarMode( QScrollView::AlwaysOff );
 
224
    m_unicodeBlockListView->setAllColumnsShowFocus( true );
 
225
    QObject::connect( m_unicodeBlockListView, SIGNAL( selectionChanged( QListViewItem * ) ),
 
226
                      this, SLOT( slotUnicodeBlockSelected( QListViewItem * ) ) );
 
227
    // add Item
 
228
    for ( int i = ( UBLOCK_SIZE - 1 ); i >= 0; i-- )
 
229
    {
 
230
        QListViewItem *item = new QListViewItem( m_unicodeBlockListView, uBlocks[ i ].getName() );
 
231
        uBlockMap[ item ] = &uBlocks[ i ];
 
232
    }
 
233
 
 
234
    m_charGridView = new CharGridView( 10, 0, m_mainSplitter );
 
235
    QObject::connect( m_charGridView, SIGNAL( charSelected( const QString & ) ),
 
236
                      this, SIGNAL( charSelected( const QString & ) ) );
 
237
 
 
238
    // main layout
 
239
    QHBoxLayout* layout = new QHBoxLayout( this );
 
240
    layout->addWidget( m_mainSplitter );
 
241
}
 
242
 
 
243
void UnicodeViewWidget::slotUnicodeBlockSelected( QListViewItem *item )
 
244
{
 
245
    UnicodeBlock * block = uBlockMap[ item ];
 
246
 
 
247
    QStringList charList;
 
248
    for ( uint d = block->getStartHex(); d < block->getEndHex(); d++ )
 
249
    {
 
250
        charList.append( QString( QChar( d ) ) );
 
251
    }
 
252
 
 
253
    m_charGridView->setCharacters( charList );
 
254
}
 
255
 
 
256
void UnicodeViewWidget::writeConfig()
 
257
{
 
258
    QSettings settings;
 
259
 
 
260
    // splitter
 
261
    QString str;
 
262
    QTextOStream out( &str );
 
263
    out << *m_mainSplitter;
 
264
    settings.writeEntry( "/uim-kdehelper/chardict/unicodeview/splitter", str );
 
265
}
 
266
void UnicodeViewWidget::readConfig()
 
267
{
 
268
    QSettings settings;
 
269
    QString str;
 
270
 
 
271
    // splitter
 
272
    str = settings.readEntry( "/uim-kdehelper/chardict/unicodeview/splitter" );
 
273
    if ( !str.isEmpty() )
 
274
    {
 
275
        QTextIStream in( &str );
 
276
        in >> *m_mainSplitter;
 
277
    }
 
278
}
 
279
 
 
280
void UnicodeViewWidget::setFont( const QFont &font )
 
281
{
 
282
    m_charGridView->setFont( font );
 
283
}
 
284
 
 
285
#include "chardict-unicodeviewwidget.moc"