Changeset 2044 in vbox for trunk/src/VBox/Frontends/VirtualBox/ui
- Timestamp:
- Apr 12, 2007 1:04:20 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 20346
- Location:
- trunk/src/VBox/Frontends/VirtualBox/ui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui
r2022 r2044 782 782 <cstring>unnamed</cstring> 783 783 </property> 784 <property name="spacing"> 785 <number>10</number> 786 </property> 784 787 <widget class="QListView"> 785 788 <column> … … 791 794 </property> 792 795 <property name="resizable"> 793 <bool> false</bool>796 <bool>true</bool> 794 797 </property> 795 798 </column> … … 799 802 <property name="sizePolicy"> 800 803 <sizepolicy> 801 <hsizetype> 0</hsizetype>804 <hsizetype>4</hsizetype> 802 805 <vsizetype>7</vsizetype> 803 806 <horstretch>0</horstretch> … … 806 809 </property> 807 810 <property name="resizeMode"> 808 <enum> AllColumns</enum>811 <enum>NoColumn</enum> 809 812 </property> 810 813 <property name="whatsThis" stdset="0"> 811 <string>The list of languages available for interface translation.</string> 814 <string> 815 Lists all available user interface languages. The effective language 816 is written in <b>bold</b>. 817 </string> 812 818 </property> 813 819 </widget> … … 834 840 <property name="sizePolicy"> 835 841 <sizepolicy> 836 <hsizetype> 7</hsizetype>837 <vsizetype> 5</vsizetype>842 <hsizetype>1</hsizetype> 843 <vsizetype>1</vsizetype> 838 844 <horstretch>0</horstretch> 839 845 <verstretch>0</verstretch> … … 854 860 <sizepolicy> 855 861 <hsizetype>1</hsizetype> 856 <vsizetype> 5</vsizetype>862 <vsizetype>1</vsizetype> 857 863 <horstretch>0</horstretch> 858 864 <verstretch>0</verstretch> … … 873 879 <sizepolicy> 874 880 <hsizetype>1</hsizetype> 875 <vsizetype> 5</vsizetype>881 <vsizetype>1</vsizetype> 876 882 <horstretch>0</horstretch> 877 883 <verstretch>0</verstretch> … … 891 897 <property name="sizePolicy"> 892 898 <sizepolicy> 893 <hsizetype> 7</hsizetype>894 <vsizetype> 5</vsizetype>899 <hsizetype>1</hsizetype> 900 <vsizetype>1</vsizetype> 895 901 <horstretch>0</horstretch> 896 902 <verstretch>0</verstretch> … … 919 925 <size> 920 926 <width>20</width> 921 <height> 121</height>927 <height>0</height> 922 928 </size> 923 929 </property> … … 925 931 </vbox> 926 932 </widget> 933 <spacer> 934 <property name="name"> 935 <cstring>spacer8</cstring> 936 </property> 937 <property name="orientation"> 938 <enum>Horizontal</enum> 939 </property> 940 <property name="sizeType"> 941 <enum>Expanding</enum> 942 </property> 943 <property name="sizeHint"> 944 <size> 945 <width>0</width> 946 <height>20</height> 947 </size> 948 </property> 949 </spacer> 927 950 </hbox> 928 951 </widget> … … 1214 1237 <include location="global" impldecl="in implementation">qmessagebox.h</include> 1215 1238 <include location="global" impldecl="in implementation">qfont.h</include> 1239 <include location="global" impldecl="in implementation">qpainter.h</include> 1216 1240 <include location="global" impldecl="in implementation">qobjectlist.h</include> 1217 1241 <include location="global" impldecl="in implementation">qfiledialog.h</include> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h
r2022 r2044 31 31 32 32 33 extern const QString transFileName; 34 extern const QString langIdRegExp; 35 extern const QString builtInName; 33 /* defined in VBoxGlobal.cpp */ 34 extern const char *gVBoxLangSubDir; 35 extern const char *gVBoxLangFileBase; 36 extern const char *gVBoxLangFileExt; 37 extern const char *gVBoxLangIDRegExp; 38 extern const char *gVBoxBuiltInLangName; 36 39 37 40 /** … … 83 86 enum { TypeId = 1001 }; 84 87 85 LanguageItem (QListView *aParent, const QString &aName)86 : QListViewItem (aParent, aName)87 {88 /* making separator field */89 if (aName == "-")90 {91 QString sepLine;92 while (listView()->fontMetrics().width (sepLine) < listView()->width())93 sepLine += "-";94 setText (0, sepLine);95 setSelectable (false);96 }97 }98 99 88 LanguageItem (QListView *aParent, const QTranslator &aTranslator, 100 89 const QString &aId, bool aBuiltIn = false) 101 : QListViewItem (aParent) 90 : QListViewItem (aParent), mBuiltIn (aBuiltIn), mInvalid (false) 102 91 { 103 92 QTranslatorMessage transMes; 104 93 105 QString nativeLanguage = translate (aTranslator, 106 "@@@", "English", "Native language name", aBuiltIn); 107 QString nativeCountry = translate (aTranslator, 108 "@@@", "built-in", "Native language country name " 109 "(empty if this language is for all countries)", aBuiltIn); 110 111 QString englishLanguage = translate (aTranslator, 112 "@@@", "English", "Language name, in English", aBuiltIn); 113 QString englishCountry = translate (aTranslator, 114 "@@@", "built-in", "Language country name, in English " 115 "(empty if native country name is empty)", aBuiltIn); 116 117 QString translatorsName = translate (aTranslator, 118 "@@@", "InnoTek", "Comma-separated list of translators", aBuiltIn); 119 if (translatorsName.isNull()) 120 translatorsName = QListView::tr ("--", "no info"); 94 /* Note: context/source/comment arguments below must match strings 95 * used in VBoxGlobal::languageName() and friends (the latter are the 96 * source of information for the lupdate tool that generates 97 * translation files) */ 98 99 QString nativeLanguage = tratra (aTranslator, 100 "@@@", "English", "Native language name"); 101 QString nativeCountry = tratra (aTranslator, 102 "@@@", "--", "Native language country name " 103 "(empty if this language is for all countries)"); 104 105 QString englishLanguage = tratra (aTranslator, 106 "@@@", "English", "Language name, in English"); 107 QString englishCountry = tratra (aTranslator, 108 "@@@", "--", "Language country name, in English " 109 "(empty if native country name is empty)"); 110 111 QString translatorsName = tratra (aTranslator, 112 "@@@", "InnoTek", "Comma-separated list of translators"); 121 113 122 114 QString itemName = nativeLanguage; 123 if (!nativeCountry.isNull())124 itemName += " (" + nativeCountry + ")";125 126 115 QString langName = englishLanguage; 127 if (!englishCountry.isNull()) 128 langName += " (" + englishCountry + ")"; 116 129 117 if (!aBuiltIn) 130 langName = itemName + " / " + langName; 118 { 119 if (nativeCountry != "--") 120 itemName += " (" + nativeCountry + ")"; 121 122 if (englishCountry != "--") 123 langName += " (" + englishCountry + ")"; 124 125 if (itemName != langName) 126 langName = itemName + " / " + langName; 127 } 128 else 129 { 130 itemName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language"); 131 langName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language"); 132 } 131 133 132 134 setText (0, itemName); … … 136 138 } 137 139 140 /* Constructs an item for an invalid language ID (i.e. when a language 141 * file is missing or corrupt). */ 142 LanguageItem (QListView *aParent, const QString &aId) 143 : QListViewItem (aParent), mBuiltIn (false), mInvalid (true) 144 { 145 setText (0, QString ("<%1>").arg (aId)); 146 setText (1, aId); 147 setText (2, VBoxGlobalSettingsDlg::tr ("<unavailabie>", "Language")); 148 setText (3, VBoxGlobalSettingsDlg::tr ("<unknown>", "Author(s)")); 149 } 150 138 151 int rtti() const { return TypeId; } 139 152 … … 142 155 QString thisValue = text (1); 143 156 QString thatValue = aItem->text (1); 144 if (thisValue == builtInName)157 if (thisValue == gVBoxBuiltInLangName) 145 158 return -1; 146 else if (thatValue == builtInName)159 else if (thatValue == gVBoxBuiltInLangName) 147 160 return 1; 148 161 else … … 151 164 152 165 void paintCell (QPainter *aPainter, const QColorGroup &aGroup, 153 int aColumn, int aWidth, int aSlign) 154 { 155 /* adjusting list-view width */ 156 int fullwidth = width (listView()->fontMetrics(), listView(), 0) + 4; 157 if (listView()->width() < fullwidth) 158 listView()->setFixedWidth (fullwidth); 159 /* standard paint procedure */ 160 QListViewItem::paintCell (aPainter, aGroup, aColumn, aWidth, aSlign); 166 int aColumn, int aWidth, int aAlign) 167 { 168 QFont font = aPainter->font(); 169 170 if (mInvalid) 171 font.setItalic (true); 172 /* mark the effectively active language */ 173 if (text (1) == VBoxGlobal::languageId()) 174 font.setBold (true); 175 176 if (aPainter->font() != font) 177 aPainter->setFont (font); 178 179 QListViewItem::paintCell (aPainter, aGroup, aColumn, aWidth, aAlign); 180 181 if (mBuiltIn) 182 { 183 int y = height() - 1; 184 aPainter->setPen (aGroup.mid()); 185 aPainter->drawLine (0, y, aWidth - 1, y); 186 } 187 } 188 189 int width (const QFontMetrics &aFM, const QListView *aLV, int aC) const 190 { 191 QFont font = aLV->font(); 192 193 if (mInvalid) 194 font.setItalic (true); 195 /* mark the effectively active language */ 196 if (text (1) == VBoxGlobal::languageId()) 197 font.setBold (true); 198 199 QFontMetrics fm = aFM; 200 if (aLV->font() != font) 201 fm = QFontMetrics (font); 202 203 return QListViewItem::width (fm, aLV, aC); 204 } 205 206 void setup () 207 { 208 QListViewItem::setup(); 209 if (mBuiltIn) 210 setHeight (height() + 1); 161 211 } 162 212 163 213 private: 164 214 165 QString translate (const QTranslator &aTranslator, const char *aCtxt, 166 const char *aSrc, const char *aCmnt, bool aBuiltIn) 167 { 168 QTranslatorMessage msg = aTranslator.findMessage (aCtxt, aSrc, aCmnt); 169 return msg.translation().isNull() && aBuiltIn ? QString (aSrc) : msg.translation(); 170 } 215 QString tratra (const QTranslator &aTranslator, const char *aCtxt, 216 const char *aSrc, const char *aCmnt) 217 { 218 QString msg = aTranslator.findMessage (aCtxt, aSrc, aCmnt).translation(); 219 /* return the source text if no translation is found */ 220 if (msg.isEmpty()) 221 msg = QString (aSrc); 222 return msg; 223 } 224 225 bool mBuiltIn : 1; 226 bool mInvalid : 1; 171 227 }; 172 228 … … 300 356 lvLanguages->header()->hide(); 301 357 lvLanguages->setSorting (0); 302 QString nlsPath = qApp->applicationDirPath() + "/nls";358 QString nlsPath = qApp->applicationDirPath() + gVBoxLangSubDir; 303 359 QDir nlsDir (nlsPath); 304 QStringList files = nlsDir.entryList (transFileName + "*", QDir::Files); 360 QStringList files = nlsDir.entryList (QString ("%1*%2") 361 .arg (gVBoxLangFileBase, gVBoxLangFileExt), 362 QDir::Files); 305 363 QTranslator translator; 306 new LanguageItem (lvLanguages, translator, builtInName, true /* built-in */); 307 new LanguageItem (lvLanguages, tr ("-")); 308 for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) 309 { 310 const QString &fileName = *it; 311 bool status = translator.load (fileName, nlsPath); 312 if (!status) continue; 313 314 QRegExp regExp (transFileName + langIdRegExp); 364 /* add the built-in language */ 365 new LanguageItem (lvLanguages, translator, gVBoxBuiltInLangName, true /* built-in */); 366 /* add all existing languages */ 367 for (QStringList::Iterator it = files.begin(); it != files.end(); ++ it) 368 { 369 QString fileName = *it; 370 QRegExp regExp (QString (gVBoxLangFileBase) + gVBoxLangIDRegExp); 315 371 int pos = regExp.search (fileName); 316 if (pos == -1) continue; 372 if (pos == -1) 373 continue; 374 375 bool loadOk = translator.load (fileName, nlsPath); 376 if (!loadOk) 377 continue; 317 378 318 379 new LanguageItem (lvLanguages, translator, regExp.cap (1)); 319 380 } 381 lvLanguages->adjustColumn (0); 320 382 321 383 /* … … 502 564 /* language properties */ 503 565 504 QListViewItem *item = lvLanguages->findItem (VBoxGlobal::languageID(), 1); 566 QString langId = gs.languageId(); 567 QListViewItem *item = lvLanguages->findItem (langId, 1); 568 if (!item) 569 { 570 /* add an item for an invalid language to represent it in the list */ 571 item = new LanguageItem (lvLanguages, langId); 572 lvLanguages->adjustColumn (0); 573 } 574 Assert (item); 505 575 if (item) 506 576 { … … 573 643 if (mLanguageChanged && selItem) 574 644 { 575 gs.setLanguageId (selItem->text (1) == VBoxGlobal::systemLanguageI D() ?645 gs.setLanguageId (selItem->text (1) == VBoxGlobal::systemLanguageId() ? 576 646 QString::null : selItem->text (1)); 577 647 VBoxGlobal::loadLanguage (selItem->text (1)); … … 846 916 tlLangData->setText (aItem->text (2)); 847 917 tlAuthorData->setText (aItem->text (3)); 848 if (!mLanguageChanged) 849 mLanguageChanged = true; 850 } 918 mLanguageChanged = true; 919 }
Note:
See TracChangeset
for help on using the changeset viewer.