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); }