VirtualBox

Ignore:
Timestamp:
Apr 12, 2007 1:04:20 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
20346
Message:

FE/Qt: A bunch of corrections and improvements to the Language selectior UI.

Location:
trunk/src/VBox/Frontends/VirtualBox/ui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui

    r2022 r2044  
    782782                                <cstring>unnamed</cstring>
    783783                            </property>
     784                            <property name="spacing">
     785                                <number>10</number>
     786                            </property>
    784787                            <widget class="QListView">
    785788                                <column>
     
    791794                                    </property>
    792795                                    <property name="resizable">
    793                                         <bool>false</bool>
     796                                        <bool>true</bool>
    794797                                    </property>
    795798                                </column>
     
    799802                                <property name="sizePolicy">
    800803                                    <sizepolicy>
    801                                         <hsizetype>0</hsizetype>
     804                                        <hsizetype>4</hsizetype>
    802805                                        <vsizetype>7</vsizetype>
    803806                                        <horstretch>0</horstretch>
     
    806809                                </property>
    807810                                <property name="resizeMode">
    808                                     <enum>AllColumns</enum>
     811                                    <enum>NoColumn</enum>
    809812                                </property>
    810813                                <property name="whatsThis" stdset="0">
    811                                     <string>The list of languages available for interface translation.</string>
     814                                    <string>
     815Lists all available user interface languages. The effective language
     816is written in &lt;b&gt;bold&lt;/b&gt;.
     817                                    </string>
    812818                                </property>
    813819                            </widget>
     
    834840                                                <property name="sizePolicy">
    835841                                                    <sizepolicy>
    836                                                         <hsizetype>7</hsizetype>
    837                                                         <vsizetype>5</vsizetype>
     842                                                        <hsizetype>1</hsizetype>
     843                                                        <vsizetype>1</vsizetype>
    838844                                                        <horstretch>0</horstretch>
    839845                                                        <verstretch>0</verstretch>
     
    854860                                                    <sizepolicy>
    855861                                                        <hsizetype>1</hsizetype>
    856                                                         <vsizetype>5</vsizetype>
     862                                                        <vsizetype>1</vsizetype>
    857863                                                        <horstretch>0</horstretch>
    858864                                                        <verstretch>0</verstretch>
     
    873879                                                    <sizepolicy>
    874880                                                        <hsizetype>1</hsizetype>
    875                                                         <vsizetype>5</vsizetype>
     881                                                        <vsizetype>1</vsizetype>
    876882                                                        <horstretch>0</horstretch>
    877883                                                        <verstretch>0</verstretch>
     
    891897                                                <property name="sizePolicy">
    892898                                                    <sizepolicy>
    893                                                         <hsizetype>7</hsizetype>
    894                                                         <vsizetype>5</vsizetype>
     899                                                        <hsizetype>1</hsizetype>
     900                                                        <vsizetype>1</vsizetype>
    895901                                                        <horstretch>0</horstretch>
    896902                                                        <verstretch>0</verstretch>
     
    919925                                            <size>
    920926                                                <width>20</width>
    921                                                 <height>121</height>
     927                                                <height>0</height>
    922928                                            </size>
    923929                                        </property>
     
    925931                                </vbox>
    926932                            </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>
    927950                        </hbox>
    928951                    </widget>
     
    12141237    <include location="global" impldecl="in implementation">qmessagebox.h</include>
    12151238    <include location="global" impldecl="in implementation">qfont.h</include>
     1239    <include location="global" impldecl="in implementation">qpainter.h</include>
    12161240    <include location="global" impldecl="in implementation">qobjectlist.h</include>
    12171241    <include location="global" impldecl="in implementation">qfiledialog.h</include>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h

    r2022 r2044  
    3131
    3232
    33 extern const QString transFileName;
    34 extern const QString langIdRegExp;
    35 extern const QString builtInName;
     33/* defined in VBoxGlobal.cpp */
     34extern const char *gVBoxLangSubDir;
     35extern const char *gVBoxLangFileBase;
     36extern const char *gVBoxLangFileExt;
     37extern const char *gVBoxLangIDRegExp;
     38extern const char *gVBoxBuiltInLangName;
    3639
    3740/**
     
    8386    enum { TypeId = 1001 };
    8487
    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 
    9988    LanguageItem (QListView *aParent, const QTranslator &aTranslator,
    10089                  const QString &aId, bool aBuiltIn = false)
    101         : QListViewItem (aParent)
     90        : QListViewItem (aParent), mBuiltIn (aBuiltIn), mInvalid (false)
    10291    {
    10392        QTranslatorMessage transMes;
    10493
    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");
    121113
    122114        QString itemName = nativeLanguage;
    123         if (!nativeCountry.isNull())
    124             itemName += " (" + nativeCountry + ")";
    125 
    126115        QString langName = englishLanguage;
    127         if (!englishCountry.isNull())
    128             langName += " (" + englishCountry + ")";
     116
    129117        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        }
    131133
    132134        setText (0, itemName);
     
    136138    }
    137139
     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
    138151    int rtti() const { return TypeId; }
    139152
     
    142155        QString thisValue = text (1);
    143156        QString thatValue = aItem->text (1);
    144         if (thisValue == builtInName)
     157        if (thisValue == gVBoxBuiltInLangName)
    145158            return -1;
    146         else if (thatValue == builtInName)
     159        else if (thatValue == gVBoxBuiltInLangName)
    147160            return 1;
    148161        else
     
    151164
    152165    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);
    161211    }
    162212
    163213private:
    164214
    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;
    171227};
    172228
     
    300356    lvLanguages->header()->hide();
    301357    lvLanguages->setSorting (0);
    302     QString nlsPath = qApp->applicationDirPath() + "/nls";
     358    QString nlsPath = qApp->applicationDirPath() + gVBoxLangSubDir;
    303359    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);
    305363    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);
    315371        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;
    317378
    318379        new LanguageItem (lvLanguages, translator, regExp.cap (1));
    319380    }
     381    lvLanguages->adjustColumn (0);
    320382
    321383    /*
     
    502564    /* language properties */
    503565
    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);
    505575    if (item)
    506576    {
     
    573643    if (mLanguageChanged && selItem)
    574644    {
    575         gs.setLanguageId (selItem->text (1) == VBoxGlobal::systemLanguageID() ?
     645        gs.setLanguageId (selItem->text (1) == VBoxGlobal::systemLanguageId() ?
    576646                          QString::null : selItem->text (1));
    577647        VBoxGlobal::loadLanguage (selItem->text (1));
     
    846916    tlLangData->setText (aItem->text (2));
    847917    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.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette