⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qprintdialog_unix.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    isc(this, QPrintDialog::tr("B7 (88 x 125 mm)"), QPrinter::B7);    isc(this, QPrintDialog::tr("B8 (62 x 88 mm)"), QPrinter::B8);    isc(this, QPrintDialog::tr("B9 (44 x 62 mm)"), QPrinter::B9);    isc(this, QPrintDialog::tr("B10 (31 x 44 mm)"), QPrinter::B10);    isc(this, QPrintDialog::tr("C5E (163 x 229 mm)"), QPrinter::C5E);    isc(this, QPrintDialog::tr("DLE (110 x 220 mm)"), QPrinter::DLE);    isc(this, QPrintDialog::tr("Executive (7.5 x 10 inches, 191 x 254 mm)"), QPrinter::Executive);    isc(this, QPrintDialog::tr("Folio (210 x 330 mm)"), QPrinter::Folio);    isc(this, QPrintDialog::tr("Ledger (432 x 279 mm)"), QPrinter::Ledger);    isc(this, QPrintDialog::tr("Legal (8.5 x 14 inches, 216 x 356 mm)"), QPrinter::Legal);    isc(this, QPrintDialog::tr("Letter (8.5 x 11 inches, 216 x 279 mm)"), QPrinter::Letter);    isc(this, QPrintDialog::tr("Tabloid (279 x 432 mm)"), QPrinter::Tabloid);    isc(this, QPrintDialog::tr("US Common #10 Envelope (105 x 241 mm)"), QPrinter::Comm10E);    QObject::connect(sizeCombo, SIGNAL(activated(int)),             q, SLOT(_q_paperSizeSelected(int)));    return g;}void QPrintDialogPrivate::_q_printerOrFileSelected(QAbstractButton *b){    outputToFile = (b == printToFileButton);    if (outputToFile) {        ok->setEnabled(true);        _q_fileNameEditChanged(fileName->text());        if (!fileName->isModified() && fileName->text().isEmpty()) {            QString home = QString::fromLocal8Bit(::qgetenv("HOME").constData());            QString cur = QDir::currentPath();            if (home.at(home.length()-1) != '/')                home += '/';            if (cur.at(cur.length()-1) != '/')                cur += '/';            if (cur.left(home.length()) != home)                cur = home;#ifdef Q_WS_X11            cur += "print.ps";#endif            fileName->setText(cur);            fileName->setCursorPosition(cur.length());            fileName->selectAll();            fileName->setModified(true); // confirm overwrite when OK clicked        }        browse->setEnabled(true);        fileName->setEnabled(true);        fileName->setFocus();        view->setEnabled(false);    } else {        ok->setEnabled(printers.count() != 0);        view->setEnabled(true);        if (fileName->hasFocus() || browse->hasFocus())            view->setFocus();        browse->setEnabled(false);        fileName->setEnabled(false);    }}void QPrintDialogPrivate::_q_landscapeSelected(int id){    orientation = (QPrinter::Orientation)id;}void QPrintDialogPrivate::_q_paperSizeSelected(int id){    if (id < QPrinter::NPageSize)        pageSize = QPrinter::PageSize(indexToPageSize[id]);}void QPrintDialogPrivate::_q_orientSelected(int id){    orientation = (QPrinter::Orientation)id;}void QPrintDialogPrivate::_q_pageOrderSelected(QAbstractButton *b){    pageOrder2 = (b == firstPageFirst) ? QPrinter::FirstPageFirst : QPrinter::LastPageFirst;}void QPrintDialogPrivate::_q_setNumCopies(int copies){    numCopies = copies;}void QPrintDialogPrivate::_q_browseClicked(){    Q_Q(QPrintDialog);    QString fn = QFileDialog::getSaveFileName(q, QString(), fileName->text(),                                              QPrintDialog::tr("PostScript Files (*.ps);;All Files (*)"));    if (!fn.isNull()) {        fileName->setText(fn);        fileName->setModified(false); // no need to confirm overwrite when OK clicked    }}void QPrintDialogPrivate::_q_okClicked(){    Q_Q(QPrintDialog);#ifndef QT_NO_MESSAGEBOX    if (outputToFile && fileName->isModified() && QFileInfo(fileName->text()).exists()) {        int confirm = QMessageBox::warning(            q, q->windowTitle(),            q->tr("%1 already exists.\nDo you want to overwrite it?")            .arg(fileName->text()),            QMessageBox::Yes, QMessageBox::No);        if (confirm == QMessageBox::No)            return;    }#endif    lastPage->interpretText();    firstPage->interpretText();    copies->interpretText();    if (outputToFile) {        printer->setOutputFileName(fileName->text());    } else {        printer->setOutputFileName(QString());        QModelIndex current = view->currentIndex();        if (current.isValid())            printer->setPrinterName(printers.at(current.row()).name);    }    printer->setOrientation(orientation);    printer->setPageSize(pageSize);    printer->setPageOrder(pageOrder2);    printer->setColorMode(colorMode2);    printer->setNumCopies(numCopies);    if (printAllButton->isChecked()) {        q->setPrintRange(QPrintDialog::AllPages);        q->setFromTo(0, 0);    } else {        if (printSelectionButton->isChecked()) {            q->setPrintRange(QPrintDialog::Selection);            q->setFromTo(0, 0);        } else {            q->setPrintRange(QPrintDialog::PageRange);            q->setFromTo(firstPage->value(), lastPage->value());        }    }    q->accept();}void QPrintDialogPrivate::_q_printRangeSelected(QAbstractButton *b){    bool enable = (b == printRangeButton);    firstPage->setEnabled(enable);    lastPage->setEnabled(enable);    firstPageLabel->setEnabled(enable);    lastPageLabel->setEnabled(enable);}void QPrintDialogPrivate::_q_setFirstPage(int fp){    Q_Q(QPrintDialog);    if (printer) {        lastPage->setMinimum(fp);        lastPage->setMaximum(qMax(fp, q->maxPage()));    }}void QPrintDialogPrivate::_q_setLastPage(int lp){    Q_Q(QPrintDialog);    if (printer) {        firstPage->setMinimum(qMin(lp, q->minPage()));        firstPage->setMaximum(lp);    }}#ifdef QT3_SUPPORT/*!  Adds the button \a but to the layout of the print dialog. The added  buttons are arranged from the left to the right below the  last groupbox of the printdialog.*/void QPrintDialog::addButton(QPushButton *but){    Q_D(QPrintDialog);    d->customLayout->addWidget(but);}/*!  Returns a pointer to the printer this dialog configures, or 0 if  this dialog does not operate on any printer. */QPrinter *QPrintDialog::printer() const{    Q_D(const QPrintDialog);    return d->printer;}/*!  Sets this dialog to configure printer \a p, or no printer if \a p  is null. If \a pickUpSettings is true, the dialog reads most of  its settings from \a p. If \a pickUpSettings is false (the  default) the dialog keeps its old settings.*/void QPrintDialog::setPrinter(QPrinter *p, bool pickUpSettings){    Q_D(QPrintDialog);    d->setPrinter(p, pickUpSettings);}#endifvoid QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings){    Q_Q(QPrintDialog);    printer = p;    if (p && pickUpSettings) {        // top to botton in the old dialog.        // printer or file        outputToFile = !p->outputFileName().isEmpty() && q->isOptionEnabled(QPrintDialog::PrintToFile);        if (outputToFile)            printToFileButton->setChecked(true);        else            printToPrinterButton->setChecked(true);        browse->setEnabled(outputToFile);        fileName->setEnabled(outputToFile);        view->setEnabled(!outputToFile);        // printer name        if (!p->printerName().isEmpty()) {            for (int i = 0; i < printers.size(); ++i) {                if (printers.at(i).name == p->printerName()) {                    // ###############//                    printers->setSelected(i, true);                    ok->setEnabled(true);                } else if (fileName->text().isEmpty()) {                    ok->setEnabled(model->rowCount() != 0);                }            }        }        // print command does not exist any more        // file name        printToFileButton->setEnabled(q->isOptionEnabled(QPrintDialog::PrintToFile));        fileName->setText(p->outputFileName());        fileName->setModified(!fileName->text().isEmpty());        // orientation        orientationCombo->setCurrentIndex((int)p->orientation());        _q_orientSelected(p->orientation());        // page size        int n = 0;        while (n < QPrinter::NPageSize &&                indexToPageSize[n] != p->pageSize())            n++;        sizeCombo->setCurrentIndex(n);        _q_paperSizeSelected(n);        // New stuff (Options)        // page order        pageOrder2 = p->pageOrder();        if (pageOrder2 == QPrinter::LastPageFirst)            lastPageFirst->setChecked(true);        // color mode        colorMode2 = p->colorMode();        if (colorMode2 == QPrinter::Color) {            printColor->setChecked(true);        } else {            printGray->setChecked(true);        }        // number of copies        copies->setValue(p->numCopies());        _q_setNumCopies(p->numCopies());    }    if(p) {        printAllButton->setEnabled(true);        printSelectionButton->setEnabled(q->isOptionEnabled(QPrintDialog::PrintSelection));        printRangeButton->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange));        switch (q->printRange()) {        case QPrintDialog::AllPages:            printAllButton->click();            break;        case QPrintDialog::Selection:            printSelectionButton->click();            break;        case QPrintDialog::PageRange:            printRangeButton->click();            break;        }    }    if (p && q->maxPage()) {        int from = q->minPage();        int to = q->maxPage();        if (q->printRange() == QPrintDialog::PageRange) {            from = q->fromPage();            to = q->toPage();        }        firstPage->setRange(q->minPage(), to);        lastPage->setRange(from, q->maxPage());        firstPage->setValue(from);        lastPage->setValue(to);    }}void QPrintDialogPrivate::_q_colorModeSelected(QAbstractButton *b){    colorMode2 = (b == printColor) ? QPrinter::Color : QPrinter::GrayScale;}void QPrintDialogPrivate::_q_fileNameEditChanged(const QString &text){    if (fileName->isEnabled())        ok->setEnabled(!text.isEmpty());}int QPrintDialog::exec(){    Q_D(QPrintDialog);    d->setPrinter(d->printer, true);    return QDialog::exec();}void QPrintDialogPrivate::init(){    Q_Q(QPrintDialog);    numCopies = 1;    QBoxLayout *tll = new QBoxLayout(QBoxLayout::Down, q);    // destination    QGroupBox *g;    g = setupDestination();    tll->addWidget(g, 1);    // printer and paper settings    QBoxLayout *lay = new QBoxLayout(QBoxLayout::LeftToRight);    tll->addLayout(lay);    g = setupPrinterSettings();    lay->addWidget(g, 1);    g = setupPaper();    lay->addWidget(g);    // options    g = setupOptions();    tll->addWidget(g);    QBoxLayout *l = new QBoxLayout(QBoxLayout::LeftToRight);    customLayout = new QBoxLayout(QBoxLayout::LeftToRight);    tll->addLayout(l);    l->addLayout(customLayout);    l->addStretch();    // buttons    QBoxLayout *horiz = new QBoxLayout(QBoxLayout::LeftToRight);    tll->addLayout(horiz);    bool rightalign =        bool(q->style()->styleHint(QStyle::SH_PrintDialog_RightAlignButtons, 0, q));    if (rightalign)        horiz->addStretch(1);    ok = new QPushButton(QPrintDialog::tr("OK"), q);    ok->setDefault(true);    ok->setEnabled(printers.count() != 0);    horiz->addWidget(ok);    if (! rightalign)        horiz->addStretch(1);    QPushButton *cancel = new QPushButton(QPrintDialog::tr("Cancel"), q);    horiz->addWidget(cancel);    q->connect(ok, SIGNAL(clicked()), q, SLOT(_q_okClicked()));    q->connect(cancel, SIGNAL(clicked()), q, SLOT(reject()));    QSize ms(q->minimumSize());    QSize ss(QApplication::desktop()->screenGeometry(q->pos()).size());    if (ms.height() < 512 && ss.height() >= 600)        ms.setHeight(512);    else if (ms.height() < 460 && ss.height() >= 480)        ms.setHeight(460);    q->resize(ms);    setPrinter(printer, true);    view->setFocus();}#include "moc_qprintdialog.cpp"#endif // QT_NO_PRINTDIALOG

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -