int QPrintPreviewWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: paintRequested((*reinterpret_cast< QPrinter*(*)>(_a[1]))); break;
        case 1: previewChanged(); break;
        case 2: print(); break;
        case 3: zoomIn((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 4: zoomIn(); break;
        case 5: zoomOut((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 6: zoomOut(); break;
        case 7: setZoomFactor((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 8: setOrientation((*reinterpret_cast< QPrinter::Orientation(*)>(_a[1]))); break;
        case 9: setViewMode((*reinterpret_cast< ViewMode(*)>(_a[1]))); break;
        case 10: setZoomMode((*reinterpret_cast< ZoomMode(*)>(_a[1]))); break;
        case 11: setCurrentPage((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 12: fitToWidth(); break;
        case 13: fitInView(); break;
        case 14: setLandscapeOrientation(); break;
        case 15: setPortraitOrientation(); break;
        case 16: setSinglePageViewMode(); break;
        case 17: setFacingPagesViewMode(); break;
        case 18: setAllPagesViewMode(); break;
        case 19: updatePreview(); break;
        case 20: d_func()->_q_fit(); break;
        case 21: d_func()->_q_updateCurrentPage(); break;
        }
        _id -= 22;
    }
    return _id;
}
Beispiel #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    createStatusBar();

    // Recent files
    for (int i = 0; i < MaxRecentFiles; ++i)
    {
	recentFileActions[i] = new QAction(this);
	recentFileActions[i]->setVisible(false);
	connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
	ui->menuFile->insertAction(ui->actionExit, recentFileActions[i]);
    }
    recentFilesSeparator = ui->menuFile->insertSeparator(ui->actionExit);

    printer = new QPrinter;
    printer->setFullPage(true);
    printer->setPaperSize(QPrinter::Letter);
    printer->setPageMargins(.5, .5, .5, .5, QPrinter::Inch);

    report = new Report(printer, this);
    view = new ReportView(report, this);

    preview = new QPrintPreviewWidget(printer, this);
    setCentralWidget(preview);
    preview->fitToWidth();

    QFontComboBox* fontComboBox = new QFontComboBox;
    fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts | QFontComboBox::ScalableFonts);
    fontComboBox->setCurrentFont(report->font().family());
    ui->fontToolBar->insertWidget(ui->actionBold, fontComboBox);
    connect(fontComboBox, SIGNAL(currentFontChanged(QFont)), report, SLOT(setFont(QFont)));

    pageNumberComboBox = new QComboBox;
    ui->viewToolBar->insertWidget(ui->actionNextPage, pageNumberComboBox);
    connect(pageNumberComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentPageChanged(int)));

    const qreal zoomFactors[] = { 12.5, 25, 50, 100, 125, 150, 200, 400, 800 };
    zoomComboBox = new QComboBox;
    for (unsigned int i = 0; i < sizeof(zoomFactors) / sizeof(*zoomFactors); ++i)
    {
	zoomComboBox->addItem(QString("%1%").arg(zoomFactors[i]));
    }
    zoomComboBox->setCurrentIndex(-1);
    ui->viewToolBar->insertWidget(ui->actionZoomOut, zoomComboBox);
    connect(zoomComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(zoomChanged(QString)));

    QActionGroup* orientationGroup = new QActionGroup(this);
    orientationGroup->addAction(ui->actionPortrait);
    orientationGroup->addAction(ui->actionLandscape);
    orientationChanged(report->orientation());

    QActionGroup* heightGroup = new QActionGroup(this);
    heightGroup->addAction(ui->action6LPI);
    heightGroup->addAction(ui->action8LPI);
    heightGroup->addAction(ui->action9LPI);
    heightGroup->setDisabled(ui->actionStretchFont->isEnabled());
    connect(ui->actionStretchFont, SIGNAL(toggled(bool)), heightGroup, SLOT(setDisabled(bool)));

    QActionGroup* widthGroup = new QActionGroup(this);
    widthGroup->addAction(ui->actionDefaultWidth);
    widthGroup->addAction(ui->action10CPI);
    widthGroup->addAction(ui->action12CPI);
    widthGroup->addAction(ui->action17CPI);
    widthGroup->setDisabled(ui->actionStretchFont->isEnabled());
    connect(ui->actionStretchFont, SIGNAL(toggled(bool)), widthGroup, SLOT(setDisabled(bool)));

    QActionGroup* pageGroup = new QActionGroup(this);
    pageGroup->addAction(ui->actionSinglePage);
    pageGroup->addAction(ui->actionFacingPages);
    pageGroup->addAction(ui->actionAllPages);
    ui->actionSinglePage->setChecked(preview->viewMode() == QPrintPreviewWidget::SinglePageView);
    ui->actionFacingPages->setChecked(preview->viewMode() == QPrintPreviewWidget::FacingPagesView);
    ui->actionAllPages->setChecked(preview->viewMode() == QPrintPreviewWidget::AllPagesView);

    connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
    connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()));
    connect(ui->actionOpenURL, SIGNAL(triggered()), this, SLOT(openUrl()));
    connect(ui->actionReload, SIGNAL(triggered()), this, SLOT(reload()));
    connect(ui->actionSaveAsPDF, SIGNAL(triggered()), this, SLOT(saveAsPdf()));
    connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print()));
    connect(ui->actionPageSetup, SIGNAL(triggered()), this, SLOT(pageSetup()));
    connect(ui->actionEmail, SIGNAL(triggered()), this, SLOT(email()));
    connect(ui->actionCopy, SIGNAL(triggered()), this, SLOT(copy()));
    connect(ui->actionStretchFont, SIGNAL(toggled(bool)), report, SLOT(setStretchFont(bool)));
    connect(report, SIGNAL(stretchFontChanged(bool)), ui->actionStretchFont, SLOT(setChecked(bool)));
    connect(ui->actionBold, SIGNAL(toggled(bool)), report, SLOT(setBold(bool)));
    connect(ui->actionStripes, SIGNAL(toggled(bool)), report, SLOT(setStripes(bool)));
    connect(ui->actionStripeColor, SIGNAL(triggered()), this, SLOT(stripeColor()));
    connect(ui->actionColor, SIGNAL(triggered()), this, SLOT(fontColor()));
    connect(ui->action6LPI, SIGNAL(triggered()), this, SLOT(height6Lpi()));
    connect(ui->action8LPI, SIGNAL(triggered()), this, SLOT(height8Lpi()));
    connect(ui->action9LPI, SIGNAL(triggered()), this, SLOT(height9Lpi()));
    connect(ui->actionDefaultWidth, SIGNAL(toggled(bool)), this, SLOT(widthDefault()));
    connect(ui->action10CPI, SIGNAL(triggered()), this, SLOT(width10Cpi()));
    connect(ui->action12CPI, SIGNAL(triggered()), this, SLOT(width12Cpi()));
    connect(ui->action17CPI, SIGNAL(triggered()), this, SLOT(width17Cpi()));
    connect(ui->actionFirstPage, SIGNAL(triggered()), this, SLOT(firstPage()));
    connect(ui->actionPreviousPage, SIGNAL(triggered()), this, SLOT(previousPage()));
    connect(ui->actionNextPage, SIGNAL(triggered()), this, SLOT(nextPage()));
    connect(ui->actionLastPage, SIGNAL(triggered()), this, SLOT(lastPage()));
    connect(ui->actionFitWidth, SIGNAL(triggered()), preview, SLOT(fitToWidth()));
    connect(ui->actionFitHeight, SIGNAL(triggered()), preview, SLOT(fitInView()));
    connect(ui->actionPortrait, SIGNAL(triggered()), preview, SLOT(setPortraitOrientation()));
    connect(ui->actionLandscape, SIGNAL(triggered()), preview, SLOT(setLandscapeOrientation()));
    connect(ui->actionActualSize, SIGNAL(triggered()), this, SLOT(actualSize()));
    connect(ui->actionZoomIn, SIGNAL(triggered()), preview, SLOT(zoomIn()));
    connect(ui->actionZoomOut, SIGNAL(triggered()), preview, SLOT(zoomOut()));
    connect(ui->actionSinglePage, SIGNAL(triggered()), preview, SLOT(setSinglePageViewMode()));
    connect(ui->actionFacingPages, SIGNAL(triggered()), preview, SLOT(setFacingPagesViewMode()));
    connect(ui->actionAllPages, SIGNAL(triggered()), preview, SLOT(setAllPagesViewMode()));
    connect(ui->actionMainToolbar, SIGNAL(triggered(bool)), this, SLOT(toggleMainToolbar(bool)));
    connect(ui->actionViewToolbar, SIGNAL(triggered(bool)), this, SLOT(toggleViewToolbar(bool)));
    connect(ui->actionFontToolbar, SIGNAL(triggered(bool)), this, SLOT(toggleFontToolbar(bool)));
    connect(ui->actionStatusBar, SIGNAL(triggered(bool)), this, SLOT(toggleStatusBar(bool)));
    connect(ui->menuToolbars, SIGNAL(aboutToShow()), this, SLOT(updateToolbarMenu()));
    connect(ui->menuView, SIGNAL(aboutToShow()), this, SLOT(updateToolbarMenu()));
    connect(preview, SIGNAL(previewChanged()), this, SLOT(previewChanged()));

    connect(preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paint(QPrinter*)));
    connect(report, SIGNAL(loaded()), preview, SLOT(updatePreview()));
    connect(report, SIGNAL(changed()), preview, SLOT(updatePreview()));
    connect(report, SIGNAL(loaded()), this, SLOT(documentLoaded()));
    connect(report, SIGNAL(orientationChanged(QPrinter::Orientation)), this, SLOT(orientationChanged(QPrinter::Orientation)));
    connect(report, SIGNAL(lpiChanged(int)), this, SLOT(lpiChanged(int)));
    connect(report, SIGNAL(cpiChanged(int)), this, SLOT(cpiChanged(int)));
    connect(report, SIGNAL(boldChanged(bool)), ui->actionBold, SLOT(setChecked(bool)));
    connect(report, SIGNAL(fontChanged(QFont)), fontComboBox, SLOT(setCurrentFont(QFont)));

    QSettings settings;
    restoreGeometry(settings.value("geometry").toByteArray());
    restoreState(settings.value("state").toByteArray());
    recentFiles = settings.value("recentFiles").toStringList();
    currentFolder = settings.value("currentFolder").toString();
    ui->statusBar->setVisible(settings.value("statusBar", true).toBool());

    updateRecentFileActions();

    zoomTimer = new QTimer(this);
    connect(zoomTimer, SIGNAL(timeout()), this, SLOT(updateZoom()));
    connect(preview, SIGNAL(previewChanged()), this, SLOT(updateZoom()));
    zoomTimer->start(1000);
}
/**
	Met en place le dialogue
*/
void QETPrintPreviewDialog::build() {
	preview_ = new QPrintPreviewWidget(printer_);
	diagrams_label_       = new QLabel(tr("Sch\351mas \340 imprimer\240:"));
	diagrams_list_        = new DiagramsChooser(project_);
	diagrams_select_all_  = new QPushButton(tr("Tout cocher"));
	diagrams_select_none_ = new QPushButton(tr("Tout d\351cocher"));
	toggle_diagrams_list_ = new QAction(QET::Icons::Diagram,              tr("Cacher la liste des sch\351mas"),            this);
	toggle_print_options_ = new QAction(QET::Icons::Configure,            tr("Cacher les options d'impression"),           this);
	adjust_width_         = new QAction(QET::Icons::ViewFitWidth,         tr("Ajuster la largeur"),                        this);
	adjust_page_          = new QAction(QET::Icons::ViewFitWindow,        tr("Ajuster la page"),                           this);
	zoom_out_             = new QAction(QET::Icons::ZoomOut,              tr("Zoom arri\350re"),                           this);
	zoom_box_             = new QComboBox(this);
	zoom_in_              = new QAction(QET::Icons::ZoomIn,               tr("Zoom avant"),                                this);
	landscape_            = new QAction(QET::Icons::PrintLandscape,       tr("Paysage"),                                   this);
	portrait_             = new QAction(QET::Icons::PrintPortrait,        tr("Portrait"),                                  this);
	first_page_           = new QAction(QET::Icons::ArrowLeftDouble,      tr("Premi\350re page"),                          this);
	previous_page_        = new QAction(QET::Icons::ArrowLeft,            tr("Page pr\351c\351dente"),                     this);
	next_page_            = new QAction(QET::Icons::ArrowRight,           tr("Page suivante"),                             this);
	last_page_            = new QAction(QET::Icons::ArrowRightDouble,     tr("Derni\350re page"),                          this);
	single_page_view_     = new QAction(QET::Icons::SinglePage,           tr("Afficher une seule page"),                   this);
	facing_pages_view_    = new QAction(QET::Icons::PrintTwoPages,        tr("Afficher deux pages"),                       this);
	all_pages_view_       = new QAction(QET::Icons::PrintAllPages,        tr("Afficher un aper\347u de toutes les pages"), this);
	page_setup_           = new QAction(QET::Icons::DocumentPrintFrame,   tr("Mise en page"),                              this);
	
	toggle_diagrams_list_ -> setCheckable(true);
	toggle_diagrams_list_ -> setChecked(true);
	toggle_print_options_ -> setCheckable(true);
	toggle_print_options_ -> setChecked(true);
	
#ifdef Q_OS_WIN32
	/*
		Sous Windows, le QPageSetupDialog utilise le dialogue natif ; ce
		dernier ne peut gerer que les imprimantes physiques ("native
		printers" ).
		cf avertissement : QAbstractPageSetupDialog::QAbstractPageSetupDialog:
		Page setup dialog cannot be used on non-native printers
	*/
	if (!(printer_ -> outputFileName().isEmpty())) {
		page_setup_ -> setEnabled(false);
		page_setup_ -> setText(tr("Mise en page (non disponible sous Windows pour l'impression PDF/PS)"));
	}
#endif
	
	toolbar_ = new QToolBar();
	toolbar_ -> addAction(toggle_diagrams_list_);
	toolbar_ -> addAction(toggle_print_options_);
	toolbar_ -> addSeparator();
	toolbar_ -> addAction(adjust_width_);
	toolbar_ -> addAction(adjust_page_);
	toolbar_ -> addAction(zoom_out_);
	toolbar_ -> addWidget(zoom_box_);
	toolbar_ -> addAction(zoom_in_);
	toolbar_ -> addSeparator();
	toolbar_ -> addAction(landscape_);
	toolbar_ -> addAction(portrait_);
	toolbar_ -> addSeparator();
	toolbar_ -> addAction(first_page_);
	toolbar_ -> addAction(previous_page_);
	toolbar_ -> addAction(next_page_);
	toolbar_ -> addAction(last_page_);
	toolbar_ -> addSeparator();
	toolbar_ -> addAction(single_page_view_);
	toolbar_ -> addAction(facing_pages_view_);
	toolbar_ -> addAction(all_pages_view_);
	toolbar_ -> addSeparator();
	toolbar_ -> addAction(page_setup_);
	
	print_options_box_= new QGroupBox(tr("Options d'impression"));
	use_full_page_ = new QCheckBox(tr("Utiliser toute la feuille"));
	use_full_page_ -> setChecked(printer_ -> fullPage());
	use_full_page_label_ = new QLabel(tr(
		"Si cette option est coch\351e, les marges de la feuille seront "
		"ignor\351es et toute sa surface sera utilis\351e pour l'impression. "
		"Cela peut ne pas \352tre support\351 par votre imprimante."
	));
	use_full_page_label_ -> setWordWrap(true);
	use_full_page_label_ -> setContentsMargins(20, 0, 0, 0);
	fit_diagram_to_page_ = new QCheckBox(tr("Adapter le sch\351ma \340 la page"));
	fit_diagram_to_page_label_ = new QLabel(tr(
		"Si cette option est coch\351e, le sch\351ma sera agrandi ou "
		"r\351tr\351ci de fa\347on \340 remplir toute la surface imprimable "
		"d'une et une seule page."
	));
	fit_diagram_to_page_label_ -> setWordWrap(true);
	fit_diagram_to_page_label_ -> setContentsMargins(20, 0, 0, 0);
	fit_diagram_to_page_ -> setChecked(true);
	
	// recupere les parametres d'export definis dans la configuration de l'application
	ExportProperties default_print_properties = QETDiagramEditor::defaultPrintProperties();
	
	render_properties_ = new ExportPropertiesWidget(default_print_properties);
	render_properties_ -> setPrintingMode(true);
	
	buttons_ = new QDialogButtonBox();
	buttons_ -> addButton(new QPushButton(QET::Icons::DocumentPrint, tr("Imprimer")), QDialogButtonBox::AcceptRole);
	buttons_ -> addButton(QDialogButtonBox::Cancel);
	
	connect(diagrams_select_all_,  SIGNAL(released()),    this,     SLOT(selectAllDiagrams()));
	connect(diagrams_select_none_, SIGNAL(released()),    this,     SLOT(selectNoDiagram()));
	connect(toggle_diagrams_list_, SIGNAL(toggled(bool)), this,     SLOT(setDiagramsListVisible(bool)));
	connect(toggle_print_options_, SIGNAL(toggled(bool)), this,     SLOT(setPrintOptionsVisible(bool)));
	connect(adjust_width_,         SIGNAL(triggered()),   preview_, SLOT(fitToWidth()));
	connect(adjust_page_,          SIGNAL(triggered()),   preview_, SLOT(fitInView()));
	connect(zoom_out_,             SIGNAL(triggered()),   this,     SLOT(zoomOut()));
	connect(zoom_in_,              SIGNAL(triggered()),   this,     SLOT(zoomIn()));
	connect(landscape_,            SIGNAL(triggered()),   preview_, SLOT(setLandscapeOrientation()));
	connect(portrait_,             SIGNAL(triggered()),   preview_, SLOT(setPortraitOrientation()));
	connect(first_page_,           SIGNAL(triggered()),   this,     SLOT(firstPage()));
	connect(previous_page_,        SIGNAL(triggered()),   this,     SLOT(previousPage()));
	connect(next_page_,            SIGNAL(triggered()),   this,     SLOT(nextPage()));
	connect(last_page_,            SIGNAL(triggered()),   this,     SLOT(lastPage()));
	connect(single_page_view_,     SIGNAL(triggered()),   preview_, SLOT(setSinglePageViewMode()));
	connect(facing_pages_view_,    SIGNAL(triggered()),   preview_, SLOT(setFacingPagesViewMode()));
	connect(all_pages_view_,       SIGNAL(triggered()),   preview_, SLOT(setAllPagesViewMode()));
	connect(page_setup_,           SIGNAL(triggered()),   this,     SLOT(pageSetup()));
	
	connect(use_full_page_,        SIGNAL(toggled(bool)), this, SLOT(useFullPage(bool)));
	connect(fit_diagram_to_page_,  SIGNAL(toggled(bool)), this, SLOT(fitDiagramToPage(bool)));
	
	connect(render_properties_,    SIGNAL(optionChanged()), preview_, SLOT(updatePreview()));
	
	connect(preview_,  SIGNAL(previewChanged()),         this, SLOT(updateZoomList()));
	connect(zoom_box_, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreviewZoom()));
	
	connect(buttons_, SIGNAL(accepted()), this, SLOT(accept()));
	connect(buttons_, SIGNAL(rejected()), this, SLOT(reject()));
	
	hlayout0_ = new QHBoxLayout();
	vlayout0_ = new QVBoxLayout();
	vlayout1_ = new QVBoxLayout();
	vlayout2_ = new QVBoxLayout();
	
	vlayout1_ -> addWidget(use_full_page_);
	vlayout1_ -> addWidget(use_full_page_label_);
	vlayout1_ -> addWidget(fit_diagram_to_page_);
	vlayout1_ -> addWidget(fit_diagram_to_page_label_);
	print_options_box_ -> setLayout(vlayout1_);
	
	vlayout2_ -> addWidget(diagrams_label_);
	vlayout2_ -> addWidget(diagrams_list_);
	vlayout2_ -> addWidget(diagrams_select_all_);
	vlayout2_ -> addWidget(diagrams_select_none_);
	
	hlayout0_ -> addLayout(vlayout2_);
	hlayout0_ -> addWidget(preview_);
	
	vlayout0_ -> addWidget(toolbar_);
	vlayout0_ -> addLayout(hlayout0_);
	vlayout0_ -> addWidget(render_properties_);
	vlayout0_ -> addWidget(print_options_box_);
	vlayout0_ -> addWidget(buttons_);
	
	setLayout(vlayout0_);
	updateZoomList();
}