Changeset 20e8115cee in tspsg


Ignore:
Timestamp:
Apr 14, 2011, 1:09:20 AM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
8f2427aaf0
Parents:
144fbe6b96
git-author:
Oleksii Serdiuk <contacts@…> (04/14/11 01:09:20)
git-committer:
Oleksii Serdiuk <contacts@…> (06/29/12 19:45:58)
Message:

+ Added the ability to setup page-related options for printing (closed ticket #5).

  • Fixed bug #3 (Solution graph font size should be fixed) - font size now depends on the graph size.
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/defaults.h

    r144fbe6b96 r20e8115cee  
    4949//! Default for "Save main window state and position"
    5050#define DEF_SAVEPOS true
    51 //! Default for "Use translucency effects in Vista/7"
    52 #define DEF_USE_TRANSLUCENCY true
     51/*!
     52 * \def DEF_USE_TRANSLUCENCY
     53 * \brief Default for "Use translucency effects"
     54 */
     55#ifdef Q_WS_WIN
     56#   define DEF_USE_TRANSLUCENCY true
     57#else
     58#   define DEF_USE_TRANSLUCENCY false
     59#endif
    5360//! Default for "Check for updates"
    5461#define DEF_CHECK_FOR_UPDATES false
  • src/mainwindow.cpp

    r144fbe6b96 r20e8115cee  
    6262    printer = new QPrinter(QPrinter::HighResolution);
    6363    settings->beginGroup("Printer");
    64     printer->setPaperSize(qvariant_cast<QPrinter::PaperSize>(settings->value("PaperSize", DEF_PAGE_SIZE)));
     64QPrinter::PaperSize size = qvariant_cast<QPrinter::PaperSize>(settings->value("PaperSize", DEF_PAGE_SIZE));
     65    if (size != QPrinter::Custom) {
     66        printer->setPaperSize(size);
     67    } else {
     68        printer->setPaperSize(QSizeF(settings->value("PaperWidth").toReal(), settings->value("PaperHeight").toReal()),
     69                              QPrinter::Millimeter);
     70    }
     71
    6572    printer->setOrientation(qvariant_cast<QPrinter::Orientation>(settings->value("PageOrientation", DEF_PAGE_ORIENTATION)));
    6673    printer->setPageMargins(
    67         settings->value("MarginLeft", DEF_MARGIN_LEFT).toDouble(),
    68         settings->value("MarginTop", DEF_MARGIN_TOP).toDouble(),
    69         settings->value("MarginRight", DEF_MARGIN_RIGHT).toDouble(),
    70         settings->value("MarginBottom", DEF_MARGIN_BOTTOM).toDouble(),
     74        settings->value("MarginLeft", DEF_MARGIN_LEFT).toReal(),
     75        settings->value("MarginTop", DEF_MARGIN_TOP).toReal(),
     76        settings->value("MarginRight", DEF_MARGIN_RIGHT).toReal(),
     77        settings->value("MarginBottom", DEF_MARGIN_BOTTOM).toReal(),
    7178        QPrinter::Millimeter);
    7279    settings->endGroup();
     
    8592#ifndef QT_NO_PRINTER
    8693    connect(actionFilePrintPreview, SIGNAL(triggered()), SLOT(actionFilePrintPreviewTriggered()));
     94    connect(actionFilePageSetup, SIGNAL(triggered()), SLOT(actionFilePageSetupTriggered()));
    8795    connect(actionFilePrint, SIGNAL(triggered()), SLOT(actionFilePrintTriggered()));
    8896#endif // QT_NO_PRINTER
     
    363371    settings->beginGroup("Printer");
    364372    settings->setValue("PaperSize", printer->paperSize());
     373    if (printer->paperSize() == QPrinter::Custom) {
     374QSizeF size(printer->paperSize(QPrinter::Millimeter));
     375        settings->setValue("PaperWidth", size.width());
     376        settings->setValue("PaperHeight", size.height());
     377    }
     378    settings->setValue("PageOrientation", printer->orientation());
     379    settings->setValue("MarginLeft", l);
     380    settings->setValue("MarginTop", t);
     381    settings->setValue("MarginRight", r);
     382    settings->setValue("MarginBottom", b);
     383    settings->endGroup();
     384}
     385
     386void MainWindow::actionFilePageSetupTriggered()
     387{
     388QPageSetupDialog psd(printer, this);
     389    if (psd.exec() != QDialog::Accepted)
     390        return;
     391
     392qreal l, t, r ,b;
     393    printer->getPageMargins(&l, &t, &r, &b, QPrinter::Millimeter);
     394
     395    settings->beginGroup("Printer");
     396    settings->setValue("PaperSize", printer->paperSize());
     397    if (printer->paperSize() == QPrinter::Custom) {
     398QSizeF size(printer->paperSize(QPrinter::Millimeter));
     399        settings->setValue("PaperWidth", size.width());
     400        settings->setValue("PaperHeight", size.height());
     401    }
    365402    settings->setValue("PageOrientation", printer->orientation());
    366403    settings->setValue("MarginLeft", l);
     
    784821        pic.begin(&graph);
    785822        pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    786 QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE, 9)));
     823QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE)));
     824        //! \todo FIXME: Get rid of the "magic number" in the code.
     825        font.setPixelSize(logicalDpiX() / 7);
    787826        if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) {
    788827            font.setWeight(QFont::DemiBold);
    789             font.setPointSizeF(font.pointSizeF() * 2);
     828            font.setPixelSize(font.pixelSize() * 2);
    790829        }
    791830        pic.setFont(font);
     
    11291168{
    11301169qreal r;
     1170    //! \todo FIXME: Get rid of the "magic numbers" in the code.
    11311171    if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool())
    11321172        r = logicalDpiX() / 1.27;
     
    14781518#ifndef QT_NO_STATUSTIP
    14791519    actionFilePrintPreview->setStatusTip(tr("Preview current solution results before printing"));
    1480     actionFileExit->setStatusTip(tr("Exit %1").arg(QCoreApplication::applicationName()));
     1520#endif // QT_NO_STATUSTIP
     1521
     1522    actionFilePageSetup->setText(tr("Pa&ge Setup..."));
     1523#ifndef QT_NO_TOOLTIP
     1524    actionFilePageSetup->setToolTip(tr("Setup print options"));
     1525#endif // QT_NO_TOOLTIP
     1526#ifndef QT_NO_STATUSTIP
     1527    actionFilePageSetup->setStatusTip(tr("Setup page-related options for printing"));
    14811528#endif // QT_NO_STATUSTIP
    14821529
     
    14901537    actionFilePrint->setShortcut(tr("Ctrl+P"));
    14911538#endif // QT_NO_PRINTER
     1539
     1540#ifndef QT_NO_STATUSTIP
     1541    actionFileExit->setStatusTip(tr("Exit %1").arg(QCoreApplication::applicationName()));
     1542#endif // QT_NO_STATUSTIP
    14921543
    14931544#ifndef HANDHELD
     
    16401691    actionFilePrintPreview->setIcon(GET_ICON("document-print-preview"));
    16411692
     1693    actionFilePageSetup = new QAction(this);
     1694    actionFilePageSetup->setObjectName("actionFilePrintSetup");
     1695//    actionFilePageSetup->setEnabled(false);
     1696#if QT_VERSION >= 0x040600
     1697    actionFilePageSetup->setIcon(QIcon::fromTheme("document-page-setup", QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/page-setup-32.png")));
     1698#else
     1699    actionFilePageSetup->setIcon(QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/page-setup-32.png"));
     1700#endif
     1701
    16421702    actionFilePrint = new QAction(this);
    16431703    actionFilePrint->setObjectName("actionFilePrint");
     
    16451705    actionFilePrint->setIcon(GET_ICON("document-print"));
    16461706
    1647     menuFile->insertAction(actionFileExit,actionFilePrintPreview);
    1648     menuFile->insertAction(actionFileExit,actionFilePrint);
     1707    menuFile->insertAction(actionFileExit, actionFilePrintPreview);
     1708    menuFile->insertAction(actionFileExit, actionFilePageSetup);
     1709    menuFile->insertAction(actionFileExit, actionFilePrint);
    16491710    menuFile->insertSeparator(actionFileExit);
    16501711
     
    16841745
    16851746#ifndef HANDHELD
    1686     toolBarManager = new QtToolBarManager;
     1747    toolBarManager = new QtToolBarManager(this);
    16871748    toolBarManager->setMainWindow(this);
    16881749QString cat = toolBarMain->windowTitle();
     
    16901751#ifndef QT_NO_PRINTER
    16911752    toolBarManager->addAction(actionFilePrintPreview, cat);
     1753    toolBarManager->addAction(actionFilePageSetup, cat);
    16921754#endif // QT_NO_PRINTER
    16931755    toolBarManager->addAction(actionHelpContents, cat);
    16941756    toolBarManager->addAction(actionHelpContextual, cat);
    1695 //      toolBarManager->addAction(action, cat);
    16961757    toolBarManager->restoreState(settings->value("MainWindow/Toolbars").toByteArray());
    16971758#else
  • src/mainwindow.h

    r144fbe6b96 r20e8115cee  
    6464#ifndef QT_NO_PRINTER
    6565    void actionFilePrintPreviewTriggered();
     66    void actionFilePageSetupTriggered();
    6667    void actionFilePrintTriggered();
    6768#endif // QT_NO_PRINTER
     
    109110    QPrinter *printer;
    110111    QAction *actionFilePrintPreview;
     112    QAction *actionFilePageSetup;
    111113    QAction *actionFilePrint;
    112114#endif // QT_NO_PRINTER
Note: See TracChangeset for help on using the changeset viewer.