34
33
#include <kiconloader.h>
35
34
#include <kstandarddirs.h>
40
KPrinter::PageSize kprinter;
41
const char* shortName; // Short name
42
const char* descriptiveName; // Full name, which will be translated
43
double width; // in mm
44
double height; // in mm
48
// - the width and height of non-ISO formats are rounded
49
// - the comments "should be..." indicates the exact values if the inch sizes would be multiplied by 25.4 mm/inch
51
const PageFormatInfo pageFormatInfo[]=
53
{ PG_DIN_A3, KPrinter::A3, "A3", I18N_NOOP("ISO A3"), 297.0, 420.0 },
54
{ PG_DIN_A4, KPrinter::A4, "A4", I18N_NOOP("ISO A4"), 210.0, 297.0 },
55
{ PG_DIN_A5, KPrinter::A5, "A5", I18N_NOOP("ISO A5"), 148.0, 210.0 },
56
{ PG_US_LETTER, KPrinter::Letter, "Letter", I18N_NOOP("US Letter"), 216.0, 279.0 }, // should be 215.9 mm x 279.4 mm
57
{ PG_US_LEGAL, KPrinter::Legal, "Legal", I18N_NOOP("US Legal"), 216.0, 356.0 }, // should be 215.9 mm x 335.6 mm
58
{ PG_SCREEN, KPrinter::A4, "Screen", I18N_NOOP("Screen"), PG_A4_HEIGHT, PG_A4_WIDTH }, // Custom, so fall back to A4
59
{ PG_CUSTOM, KPrinter::A4, "Custom", I18N_NOOP("Custom"), PG_A4_WIDTH, PG_A4_HEIGHT }, // Custom, so fall back to A4
60
{ PG_DIN_B5, KPrinter::B5, "B5", I18N_NOOP("ISO B5"), 182.0, 257.0 },
61
{ PG_US_EXECUTIVE, KPrinter::Executive, "Executive", I18N_NOOP("US Executive"), 191.0, 254.0 }, // should be 190.5 mm x 254.0 mm
62
{ PG_DIN_A0, KPrinter::A0, "A0", I18N_NOOP("ISO A0"), 841.0, 1189.0 },
63
{ PG_DIN_A1, KPrinter::A1, "A1", I18N_NOOP("ISO A1"), 594.0, 841.0 },
64
{ PG_DIN_A2, KPrinter::A2, "A2", I18N_NOOP("ISO A2"), 420.0, 594.0 },
65
{ PG_DIN_A6, KPrinter::A6, "A6", I18N_NOOP("ISO A6"), 105.0, 148.0 },
66
{ PG_DIN_A7, KPrinter::A7, "A7", I18N_NOOP("ISO A7"), 74.0, 105.0 },
67
{ PG_DIN_A8, KPrinter::A8, "A8", I18N_NOOP("ISO A8"), 52.0, 74.0 },
68
{ PG_DIN_A9, KPrinter::A9, "A9", I18N_NOOP("ISO A9"), 37.0, 52.0 },
69
{ PG_DIN_B0, KPrinter::B0, "B0", I18N_NOOP("ISO B0"), 1030.0, 1456.0 },
70
{ PG_DIN_B1, KPrinter::B1, "B1", I18N_NOOP("ISO B1"), 728.0, 1030.0 },
71
{ PG_DIN_B10, KPrinter::B10, "B10", I18N_NOOP("ISO B10"), 32.0, 45.0 },
72
{ PG_DIN_B2, KPrinter::B2, "B2", I18N_NOOP("ISO B2"), 515.0, 728.0 },
73
{ PG_DIN_B3, KPrinter::B3, "B3", I18N_NOOP("ISO B3"), 364.0, 515.0 },
74
{ PG_DIN_B4, KPrinter::B4, "B4", I18N_NOOP("ISO B4"), 257.0, 364.0 },
75
{ PG_DIN_B6, KPrinter::B6, "B6", I18N_NOOP("ISO B6"), 128.0, 182.0 },
76
{ PG_ISO_C5, KPrinter::C5E, "C5", I18N_NOOP("ISO C5"), 163.0, 229.0 }, // Some sources tells: 162 mm x 228 mm
77
{ PG_US_COMM10, KPrinter::Comm10E, "Comm10", I18N_NOOP("US Common 10"), 105.0, 241.0 }, // should be 104.775 mm x 241.3 mm
78
{ PG_ISO_DL, KPrinter::DLE, "DL", I18N_NOOP("ISO DL"), 110.0, 220.0 },
79
{ PG_US_FOLIO, KPrinter::Folio, "Folio", I18N_NOOP("US Folio"), 210.0, 330.0 }, // should be 209.54 mm x 330.2 mm
80
{ PG_US_LEDGER, KPrinter::Ledger, "Ledger", I18N_NOOP("US Ledger"), 432.0, 279.0 }, // should be 431.8 mm x 297.4 mm
81
{ PG_US_TABLOID, KPrinter::Tabloid, "Tabloid", I18N_NOOP("US Tabloid"), 279.0, 432.0 } // should be 297.4 mm x 431.8 mm
84
int KoPageFormat::printerPageSize( KoFormat format )
86
if ( format == PG_SCREEN )
88
kdWarning() << "You use the page layout SCREEN. Printing in DIN A4 LANDSCAPE." << endl;
91
else if ( format == PG_CUSTOM )
93
kdWarning() << "The used page layout (CUSTOM) is not supported by KPrinter. Printing in A4." << endl;
96
else if ( format <= PG_LAST_FORMAT )
97
return pageFormatInfo[ format ].kprinter;
102
double KoPageFormat::width( KoFormat format, KoOrientation orientation )
104
if ( orientation == PG_LANDSCAPE )
105
return height( format, PG_PORTRAIT );
106
if ( format <= PG_LAST_FORMAT )
107
return pageFormatInfo[ format ].width;
108
return PG_A4_WIDTH; // should never happen
111
double KoPageFormat::height( KoFormat format, KoOrientation orientation )
113
if ( orientation == PG_LANDSCAPE )
114
return width( format, PG_PORTRAIT );
115
if ( format <= PG_LAST_FORMAT )
116
return pageFormatInfo[ format ].height;
120
KoFormat KoPageFormat::guessFormat( double width, double height )
122
for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
124
// We have some tolerance. 1pt is a third of a mm, this is
125
// barely noticeable for a page size.
127
&& kAbs( width - pageFormatInfo[i].width ) < 1.0
128
&& kAbs( height - pageFormatInfo[i].height ) < 1.0 )
129
return static_cast<KoFormat>(i);
134
QString KoPageFormat::formatString( KoFormat format )
136
if ( format <= PG_LAST_FORMAT )
137
return QString::fromLatin1( pageFormatInfo[ format ].shortName );
138
return QString::fromLatin1( "A4" );
141
KoFormat KoPageFormat::formatFromString( const QString & string )
143
for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
145
if (string == QString::fromLatin1( pageFormatInfo[ i ].shortName ))
146
return pageFormatInfo[ i ].format;
148
// We do not know the format name, so we have a custom format
152
QString KoPageFormat::name( KoFormat format )
154
if ( format <= PG_LAST_FORMAT )
155
return i18n( pageFormatInfo[ format ].descriptiveName );
156
return i18n( pageFormatInfo[ PG_DIN_A4 ].descriptiveName );
159
QStringList KoPageFormat::allFormats()
162
for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
164
lst << i18n( pageFormatInfo[ i ].descriptiveName );
169
37
KoGlobal* KoGlobal::s_global = 0L;
170
38
static KStaticDeleter<KoGlobal> sdg;
216
QStringList KoGlobal::_listTagOfLanguages()
95
QStringList KoGlobal::_listOfLanguageTags()
218
if ( m_languageTag.isEmpty() )
97
if ( m_langMap.isEmpty() )
219
98
createListOfLanguages();
220
return m_languageTag;
99
return m_langMap.values();
223
102
QStringList KoGlobal::_listOfLanguages()
225
if ( m_languageList.empty() )
104
if ( m_langMap.empty() )
226
105
createListOfLanguages();
227
return m_languageList;
106
return m_langMap.keys();
230
109
void KoGlobal::createListOfLanguages()
232
QStringList alllang = KGlobal::dirs()->findAllResources("locale",
111
KConfig config( "all_languages", true, false, "locale" );
112
// Note that we could also use KLocale::allLanguagesTwoAlpha
114
QMap<QString, bool> seenLanguages;
115
const QStringList langlist = config.groupList();
116
for ( QStringList::ConstIterator itall = langlist.begin();
117
itall != langlist.end(); ++itall )
119
const QString tag = *itall;
120
config.setGroup( tag );
121
const QString name = config.readEntry("Name", tag);
122
// e.g. name is "French" and tag is "fr"
124
// The QMap does the sorting on the display-name, so that
125
// comboboxes are sorted.
126
m_langMap.insert( name, tag );
128
seenLanguages.insert( tag, true );
131
// Also take a look at the installed translations.
132
// Many of them are already in all_languages but all_languages doesn't
133
// currently have en_GB or en_US etc.
135
const QStringList translationList = KGlobal::dirs()->findAllResources("locale",
233
136
QString::fromLatin1("*/entry.desktop"));
234
QStringList langlist=alllang;
235
for ( QStringList::ConstIterator it = langlist.begin();
236
it != langlist.end(); ++it )
137
for ( QStringList::ConstIterator it = translationList.begin();
138
it != translationList.end(); ++it )
238
KSimpleConfig entry(*it);
239
entry.setGroup("KCM Locale");
240
QString name = entry.readEntry("Name",
241
KGlobal::locale()->translate("without name"));
140
// Extract the language tag from the directory name
243
141
QString tag = *it;
244
142
int index = tag.findRev('/');
245
143
tag = tag.left(index);
246
144
index = tag.findRev('/');
247
145
tag = tag.mid(index+1);
248
m_languageList.append(name);
249
m_languageTag.append(tag);
147
if ( seenLanguages.find( tag ) == seenLanguages.end() ) {
148
KSimpleConfig entry(*it);
149
entry.setGroup("KCM Locale");
151
const QString name = entry.readEntry("Name", tag);
152
// e.g. name is "US English" and tag is "en_US"
153
m_langMap.insert( name, tag );
155
// enable this if writing a third way of finding languages below
156
//seenLanguages.insert( tag, true );
161
// #### We also might not have an entry for a language where spellchecking is supported,
162
// but no KDE translation is available, like fr_CA.
254
166
QString KoGlobal::tagOfLanguage( const QString & _lang)
256
// Should use iterator...
257
int pos = self()->m_languageList.findIndex( _lang );
260
return self()->m_languageTag[ pos ];
168
const LanguageMap& map = self()->m_langMap;
169
QMap<QString,QString>::ConstIterator it = map.find( _lang );
170
if ( it != map.end() )
262
172
return QString::null;
265
int KoGlobal::languageIndexFromTag( const QString &_lang )
175
QString KoGlobal::languageFromTag( const QString &langTag )
267
return self()->m_languageTag.findIndex( _lang );
177
const LanguageMap& map = self()->m_langMap;
178
QMap<QString,QString>::ConstIterator it = map.begin();
179
const QMap<QString,QString>::ConstIterator end = map.end();
180
for ( ; it != end; ++it )
181
if ( it.data() == langTag )
270
QString KoGlobal::languageFromTag( const QString &_lang )
272
// should use iterator
273
int pos = self()->m_languageTag.findIndex( _lang );
275
return self()->m_languageList[ pos ];
277
return QString::null;
184
// Language code not found. Better return the code (tag) than nothing.
280
188
KConfig* KoGlobal::_kofficeConfig()