Changeset 52 in tspsg-svn for trunk/src/mainwindow.cpp


Ignore:
Timestamp:
Aug 4, 2009, 6:18:14 PM (15 years ago)
Author:
laleppa
Message:

Implemented printing of solution results (not supported under wince).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mainwindow.cpp

    r51 r52  
    4040#endif
    4141#ifndef Q_OS_WINCE
    42         printer = new QPrinter();
     42        printer = new QPrinter(QPrinter::HighResolution);
    4343#endif // Q_OS_WINCE
    4444        groupSettingsLanguageList = new QActionGroup(this);
     
    5959        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered()));
    6060#ifndef Q_OS_WINCE
    61         connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(actionFilePrintSetupTriggered()));
     61        connect(actionFilePrintPreview,SIGNAL(triggered()),this,SLOT(actionFilePrintPreviewTriggered()));
     62        connect(actionFilePrint,SIGNAL(triggered()),this,SLOT(actionFilePrintTriggered()));
    6263#endif // Q_OS_WINCE
    6364        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
     
    8485        qsrand(QDateTime().currentDateTime().toTime_t());
    8586        tspmodel = new CTSPModel();
     87        taskView->setModel(tspmodel);
    8688        connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
    8789        connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged()));
     
    9294                setFileName();
    9395                spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
    94                 tspmodel->setNumCities(spinCities->value());
    95         }
    96         taskView->setModel(tspmodel);
     96                spinCitiesValueChanged(spinCities->value());
     97        }
    9798        setWindowModified(false);
    98         taskView->resizeColumnsToContents();
    99         taskView->resizeRowsToContents();
    10099}
    101100
     
    107106        if (!enable)
    108107                output.clear();
     108#ifndef Q_OS_WINCE
     109        actionFilePrint->setEnabled(enable);
     110        actionFilePrintPreview->setEnabled(enable);
     111#endif // Q_OS_WINCE
    109112}
    110113
     
    117120                lang = settings->value("Language",QLocale::system().name()).toString();
    118121        }
    119 static QTranslator *qtTranslator;
     122static QTranslator *qtTranslator; // Qt library translator
    120123        if (qtTranslator) {
    121124                qApp->removeTranslator(qtTranslator);
     
    124127        }
    125128        qtTranslator = new QTranslator();
    126 static QTranslator *translator;
     129static QTranslator *translator; // Application translator
    127130        if (translator) {
    128131                qApp->removeTranslator(translator);
     
    139142                                qApp->installTranslator(qtTranslator);
    140143                        else {
     144                                // Qt library translation unavailable
    141145                                delete qtTranslator;
    142146                                qtTranslator = NULL;
     
    147151                else {
    148152                        if (!ad)
    149                                 QMessageBox(QMessageBox::Warning,trUtf8("Language change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();
     153                                QMessageBox(QMessageBox::Warning,trUtf8("Language Change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();
    150154                        delete translator;
    151155                        translator = NULL;
     
    346350
    347351#ifndef Q_OS_WINCE
    348 void MainWindow::actionFilePrintSetupTriggered()
     352void MainWindow::printPreview(QPrinter *printer)
     353{
     354        solutionText->print(printer);
     355}
     356
     357void MainWindow::actionFilePrintPreviewTriggered()
     358{
     359QPrintPreviewDialog ppd(printer, this);
     360    connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
     361    ppd.exec();
     362}
     363
     364void MainWindow::actionFilePrintTriggered()
    349365{
    350366QPrintDialog pd(printer,this);
     
    354370        pd.setOption(QAbstractPrintDialog::PrintPageRange,false);
    355371#endif
    356         pd.exec();
     372        if (pd.exec() != QDialog::Accepted)
     373                return;
     374        solutionText->document()->print(printer);
    357375}
    358376#endif // Q_OS_WINCE
Note: See TracChangeset for help on using the changeset viewer.