~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/kfontinst/viewpart/PreviewSelectAction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KFontInst - KDE Font Installer
 
3
 *
 
4
 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
 
5
 *
 
6
 * ----
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; see the file COPYING.  If not, write to
 
20
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
 * Boston, MA 02110-1301, USA.
 
22
 */
 
23
 
 
24
#include "PreviewSelectAction.h"
 
25
#include "UnicodeBlocks.h"
 
26
#include "UnicodeScripts.h"
 
27
#include <KDE/KLocale>
 
28
 
 
29
namespace KFI
 
30
{
 
31
 
 
32
CPreviewSelectAction::CPreviewSelectAction(QObject *parent, Mode mode)
 
33
                    : KSelectAction(KIcon("character-set"), i18n("Preview Type"), parent),
 
34
                      itsNumUnicodeBlocks(0)
 
35
{
 
36
    setMode(mode);
 
37
 
 
38
    connect(this, SIGNAL(triggered(int)), SLOT(selected(int)));
 
39
}
 
40
 
 
41
void CPreviewSelectAction::setStd()
 
42
{
 
43
    setCurrentItem(0);
 
44
    selected(0);
 
45
}
 
46
 
 
47
void CPreviewSelectAction::setMode(Mode mode)
 
48
{
 
49
    QStringList items;
 
50
 
 
51
    items.append(i18n("Standard Preview"));
 
52
    items.append(i18n("All Characters"));
 
53
 
 
54
    switch(mode)
 
55
    {
 
56
        default:
 
57
        case Basic:
 
58
            break;
 
59
        case BlocksAndScripts:
 
60
            for(itsNumUnicodeBlocks=0; constUnicodeBlocks[itsNumUnicodeBlocks].blockName; ++itsNumUnicodeBlocks)
 
61
                items.append(i18n("Unicode Block: %1", i18n(constUnicodeBlocks[itsNumUnicodeBlocks].blockName)));
 
62
 
 
63
            for(int i=0; constUnicodeScriptList[i]; ++i)
 
64
                items.append(i18n("Unicode Script: %1", i18n(constUnicodeScriptList[i])));
 
65
            break;
 
66
        case ScriptsOnly:
 
67
            for(int i=0; constUnicodeScriptList[i]; ++i)
 
68
                items.append(i18n(constUnicodeScriptList[i]));
 
69
    }
 
70
 
 
71
    setItems(items);
 
72
    setStd();
 
73
}
 
74
 
 
75
void CPreviewSelectAction::selected(int index)
 
76
{
 
77
    QList<CFcEngine::TRange> list;
 
78
 
 
79
    if(0==index)
 
80
        ;
 
81
    else if(1==index)
 
82
        list.append(CFcEngine::TRange());
 
83
    else if(index<itsNumUnicodeBlocks+2)
 
84
        list.append(CFcEngine::TRange(constUnicodeBlocks[index-2].start, constUnicodeBlocks[index-2].end));
 
85
    else
 
86
    {
 
87
        int script(index-(2+itsNumUnicodeBlocks));
 
88
 
 
89
        for(int i=0; constUnicodeScripts[i].scriptIndex>=0; ++i)
 
90
            if(constUnicodeScripts[i].scriptIndex==script)
 
91
                list.append(CFcEngine::TRange(constUnicodeScripts[i].start, constUnicodeScripts[i].end));
 
92
    }
 
93
 
 
94
    emit range(list);
 
95
}
 
96
 
 
97
}
 
98
 
 
99
#include "PreviewSelectAction.moc"