Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/linguist/linguist/mainwindow.cpp

    r511 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the Qt Linguist of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5151#include "finddialog.h"
    5252#include "formpreviewview.h"
     53#include "globals.h"
    5354#include "messageeditor.h"
    5455#include "messagemodel.h"
     
    8283#include <QMessageBox>
    8384#include <QPrintDialog>
     85#include <QPrinter>
    8486#include <QProcess>
    8587#include <QRegExp>
     
    9799static const int MessageMS = 2500;
    98100
    99 const QString &settingsPrefix()
    100 {
    101     static QString prefix = QString(QLatin1String("%1.%2/"))
    102         .arg((QT_VERSION >> 16) & 0xff)
    103         .arg((QT_VERSION >> 8) & 0xff);
    104     return prefix;
    105 }
    106 
    107101enum Ending {
    108102    End_None,
     
    122116{
    123117    str = str.simplified();
    124     int ch = 0;
    125     if (!str.isEmpty())
    126         ch = str.right(1)[0].unicode();
    127 
    128     switch (ch) {
     118    if (str.isEmpty())
     119        return End_None;
     120
     121    switch (str.at(str.length() - 1).unicode()) {
    129122    case 0x002e: // full stop
    130         if (str.endsWith(QString(QLatin1String("..."))))
     123        if (str.endsWith(QLatin1String("...")))
    131124            return End_Ellipsis;
    132125        else
     
    266259    : QMainWindow(0, Qt::Window),
    267260      m_assistantProcess(0),
     261      m_printer(0),
    268262      m_findMatchCase(Qt::CaseInsensitive),
    269263      m_findIgnoreAccelerators(true),
     
    276270      m_statistics(0)
    277271{
     272    setUnifiedTitleAndToolBarOnMac(true);
    278273    m_ui.setupUi(this);
    279274
     
    311306    m_contextView->header()->setMovable(false);
    312307    m_contextView->setColumnHidden(0, true);
    313     m_contextView->header()->setResizeMode(1, QHeaderView::Stretch);
    314     m_contextView->header()->setResizeMode(2, QHeaderView::ResizeToContents);
    315308    m_contextView->header()->setStretchLastSection(false);
    316309
     
    341334    m_messageView->header()->setMovable(false);
    342335    m_messageView->setColumnHidden(0, true);
    343     m_messageView->setColumnHidden(2, true);
    344     // last visible column auto-stretches
    345336
    346337    m_messagesDock->setWidget(m_messageView);
     
    449440
    450441    modelCountChanged();
     442    initViewHeaders();
    451443    resetSorting();
    452444
     
    479471    connect(m_findDialog, SIGNAL(findNext(QString,DataModel::FindLocation,bool,bool)),
    480472            this, SLOT(findNext(QString,DataModel::FindLocation,bool,bool)));
    481     connect(m_translateDialog, SIGNAL(requestMatchUpdate(bool &)), SLOT(updateTranslateHit(bool &)));
     473    connect(m_translateDialog, SIGNAL(requestMatchUpdate(bool&)), SLOT(updateTranslateHit(bool&)));
    482474    connect(m_translateDialog, SIGNAL(activated(int)), SLOT(translate(int)));
    483475
     
    488480    readConfig();
    489481    m_statistics = 0;
     482
     483    connect(m_ui.actionLengthVariants, SIGNAL(toggled(bool)),
     484            m_messageEditor, SLOT(setLengthVariants(bool)));
     485    m_messageEditor->setLengthVariants(m_ui.actionLengthVariants->isChecked());
    490486
    491487    m_focusWatcher = new FocusWatcher(m_messageEditor, this);
     
    508504    delete m_dataModel;
    509505    delete m_statistics;
     506    delete m_printer;
     507}
     508
     509void MainWindow::initViewHeaders()
     510{
     511    m_contextView->header()->setResizeMode(1, QHeaderView::Stretch);
     512    m_contextView->header()->setResizeMode(2, QHeaderView::ResizeToContents);
     513    m_messageView->setColumnHidden(2, true);
     514    // last visible column auto-stretches
    510515}
    511516
     
    741746        m_dataModel->closeAll();
    742747        modelCountChanged();
     748        initViewHeaders();
    743749        recentFiles().closeGroup();
    744750        return true;
     
    875881}
    876882
     883QPrinter *MainWindow::printer()
     884{
     885    if (!m_printer)
     886        m_printer = new QPrinter;
     887    return m_printer;
     888}
     889
    877890void MainWindow::print()
    878891{
    879892#ifndef QT_NO_PRINTER
    880893    int pageNum = 0;
    881     QPrintDialog dlg(&m_printer, this);
     894    QPrintDialog dlg(printer(), this);
    882895    if (dlg.exec()) {
    883896        QApplication::setOverrideCursor(Qt::WaitCursor);
    884         m_printer.setDocName(m_dataModel->condensedSrcFileNames(true));
     897        printer()->setDocName(m_dataModel->condensedSrcFileNames(true));
    885898        statusBar()->showMessage(tr("Printing..."));
    886         PrintOut pout(&m_printer);
     899        PrintOut pout(printer());
    887900
    888901        for (int i = 0; i < m_dataModel->contextCount(); ++i) {
     
    12371250    int pageNum = 0;
    12381251
    1239     QPrintDialog dlg(&m_printer, this);
     1252    QPrintDialog dlg(printer(), this);
    12401253    if (dlg.exec()) {
    1241         m_printer.setDocName(phraseBook->fileName());
     1254        printer()->setDocName(phraseBook->fileName());
    12421255        statusBar()->showMessage(tr("Printing..."));
    1243         PrintOut pout(&m_printer);
     1256        PrintOut pout(printer());
    12441257        pout.setRule(PrintOut::ThinRule);
    12451258        foreach (const Phrase *p, phraseBook->phrases()) {
     
    13471360    version = version.arg(QLatin1String(QT_VERSION_STR));
    13481361
    1349     // TODO: Remove this variable for 4.6.0.  Must keep this way for 4.5.x due to string freeze.
    1350     QString edition;
    1351 
    13521362    box.setText(tr("<center><img src=\":/images/splash.png\"/></img><p>%1</p></center>"
    13531363                    "<p>Qt Linguist is a tool for adding translations to Qt "
    13541364                    "applications.</p>"
    1355                     "<p>%2</p>"
    13561365                    "<p>Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)."
    1357                     "</p><p>The program is provided AS IS with NO WARRANTY OF ANY KIND,"
    1358                     " INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A"
    1359                     " PARTICULAR PURPOSE.</p>").arg(version).arg(edition));
     1366                   ).arg(version));
    13601367
    13611368    box.setWindowTitle(QApplication::translate("AboutDialog", "Qt Linguist"));
     
    23522359}
    23532360
     2361static bool haveMnemonic(const QString &str)
     2362{
     2363    QString mnemonic = QKeySequence::mnemonic(str);
     2364    if (mnemonic == QLatin1String("Alt+Space")) {
     2365        // "Nobody" ever really uses these, and they are highly annoying
     2366        // because we get a lot of false positives.
     2367        return false;
     2368    }
     2369    return !mnemonic.isEmpty();
     2370}
     2371
    23542372void MainWindow::updateDanger(const MultiDataIndex &index, bool verbose)
    23552373{
     
    23752393            QStringList translations = m->translations();
    23762394
     2395            // Truncated variants are permitted to be "denormalized"
     2396            for (int i = 0; i < translations.count(); ++i) {
     2397                int sep = translations.at(i).indexOf(QChar(Translator::BinaryVariantSeparator));
     2398                if (sep >= 0)
     2399                    translations[i].truncate(sep);
     2400            }
     2401
    23772402            if (m_ui.actionAccelerators->isChecked()) {
    2378                 bool sk = !QKeySequence::mnemonic(source).isEmpty();
     2403                bool sk = haveMnemonic(source);
    23792404                bool tk = true;
    23802405                for (int i = 0; i < translations.count() && tk; ++i) {
    2381                     tk &= !QKeySequence::mnemonic(translations[i]).isEmpty();
     2406                    tk &= haveMnemonic(translations[i]);
    23822407                }
    23832408
     
    25032528void MainWindow::readConfig()
    25042529{
    2505     QString keybase = settingsPrefix();
    25062530    QSettings config;
    25072531
    25082532    QRect r(pos(), size());
    2509     restoreGeometry(config.value(keybase + QLatin1String("Geometry/WindowGeometry")).toByteArray());
    2510     restoreState(config.value(keybase + QLatin1String("MainWindowState")).toByteArray());
     2533    restoreGeometry(config.value(settingPath("Geometry/WindowGeometry")).toByteArray());
     2534    restoreState(config.value(settingPath("MainWindowState")).toByteArray());
    25112535
    25122536    m_ui.actionAccelerators->setChecked(
    2513         config.value(keybase + QLatin1String("Validators/Accelerator"), true).toBool());
     2537        config.value(settingPath("Validators/Accelerator"), true).toBool());
    25142538    m_ui.actionEndingPunctuation->setChecked(
    2515         config.value(keybase + QLatin1String("Validators/EndingPunctuation"), true).toBool());
     2539        config.value(settingPath("Validators/EndingPunctuation"), true).toBool());
    25162540    m_ui.actionPhraseMatches->setChecked(
    2517         config.value(keybase + QLatin1String("Validators/PhraseMatch"), true).toBool());
     2541        config.value(settingPath("Validators/PhraseMatch"), true).toBool());
    25182542    m_ui.actionPlaceMarkerMatches->setChecked(
    2519         config.value(keybase + QLatin1String("Validators/PlaceMarkers"), true).toBool());
     2543        config.value(settingPath("Validators/PlaceMarkers"), true).toBool());
     2544    m_ui.actionLengthVariants->setChecked(
     2545        config.value(settingPath("Options/LengthVariants"), false).toBool());
    25202546
    25212547    recentFiles().readConfig();
    25222548
    2523     int size = config.beginReadArray(keybase + QLatin1String("OpenedPhraseBooks"));
     2549    int size = config.beginReadArray(settingPath("OpenedPhraseBooks"));
    25242550    for (int i = 0; i < size; ++i) {
    25252551        config.setArrayIndex(i);
     
    25312557void MainWindow::writeConfig()
    25322558{
    2533     QString keybase = settingsPrefix();
    25342559    QSettings config;
    2535     config.setValue(keybase + QLatin1String("Geometry/WindowGeometry"),
     2560    config.setValue(settingPath("Geometry/WindowGeometry"),
    25362561        saveGeometry());
    2537     config.setValue(keybase + QLatin1String("Validators/Accelerator"),
     2562    config.setValue(settingPath("Validators/Accelerator"),
    25382563        m_ui.actionAccelerators->isChecked());
    2539     config.setValue(keybase + QLatin1String("Validators/EndingPunctuation"),
     2564    config.setValue(settingPath("Validators/EndingPunctuation"),
    25402565        m_ui.actionEndingPunctuation->isChecked());
    2541     config.setValue(keybase + QLatin1String("Validators/PhraseMatch"),
     2566    config.setValue(settingPath("Validators/PhraseMatch"),
    25422567        m_ui.actionPhraseMatches->isChecked());
    2543     config.setValue(keybase + QLatin1String("Validators/PlaceMarkers"),
     2568    config.setValue(settingPath("Validators/PlaceMarkers"),
    25442569        m_ui.actionPlaceMarkerMatches->isChecked());
    2545     config.setValue(keybase + QLatin1String("MainWindowState"),
     2570    config.setValue(settingPath("Options/LengthVariants"),
     2571        m_ui.actionLengthVariants->isChecked());
     2572    config.setValue(settingPath("MainWindowState"),
    25462573        saveState());
    25472574    recentFiles().writeConfig();
    25482575
    2549     config.beginWriteArray(keybase + QLatin1String("OpenedPhraseBooks"),
     2576    config.beginWriteArray(settingPath("OpenedPhraseBooks"),
    25502577        m_phraseBooks.size());
    25512578    for (int i = 0; i < m_phraseBooks.size(); ++i) {
Note: See TracChangeset for help on using the changeset viewer.