MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); preferencesDialog = new PreferencesDialog(); fontDialog = new FontDialog(); errorMessage = new QErrorMessage(); sheetNumberLabel = new QLabel("<h2>1</h2>"); sheetNumberLabel->setToolTip(tr("Number of Current Sheet")); sheetNumberLabel->setFrameShape(QFrame::Panel); sheetNumberLabel->setFrameShadow(QFrame::Sunken); sheetNumberLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); sheetNumberLabel->setMinimumWidth(ui->toolBar->height()); errorMessage->setMinimumSize(200, 150); //----File---- connect(ui->actionConvert_to_Handwritten, SIGNAL(triggered()), this, SLOT(renderFirstSheet())); connect(ui->actionLoad_Text_from_File, SIGNAL(triggered()), this, SLOT(loadTextFromFile())); connect(ui->actionLoad_Font, SIGNAL(triggered()), this, SLOT(loadFont())); connect(ui->actionFont_Editor, SIGNAL(triggered()), fontDialog, SLOT(exec())); connect(ui->actionSave_Current_Sheet_as, SIGNAL(triggered()), this, SLOT(saveSheet())); connect(ui->actionSave_All_Sheets, SIGNAL(triggered()), this, SLOT(saveAllSheets())); connect(ui->actionPrint_Current_Sheet, SIGNAL(triggered()), this, SLOT(printSheet())); connect(ui->actionPrint_All, SIGNAL(triggered()), this, SLOT(printAllSheets())); //----Edit---- //connect menu action "Show Toolbar" connect(ui->actionShow_ToolBar, SIGNAL(triggered(bool)), ui->toolBar, SLOT(setVisible(bool))); connect(ui->toolBar, SIGNAL(visibilityChanged(bool)), ui->actionShow_ToolBar, SLOT(setChecked(bool))); //preferencesDialog connections connect(ui->actionPreferences, SIGNAL(triggered()), preferencesDialog, SLOT(exec())); connect(preferencesDialog, SIGNAL(settingsChanged()), this, SLOT(loadSettings())); //----Help---- connect(ui->actionAbout_Scribbler, SIGNAL(triggered()), this, SLOT(showAboutBox())); connect(ui->actionLicenses_and_Credits, SIGNAL(triggered()), this, SLOT(showLicensesBox())); connect(ui->actionHowTo, SIGNAL(triggered()), this, SLOT(showHowToBox())); //----ToolBar---- //add actions to tool bar and connect them to slots connect(ui->toolBar->addAction(QPixmap("://render.png"), tr("Convert to Handwritten")), SIGNAL(triggered(bool)), this, SLOT(renderFirstSheet())); connect(ui->toolBar->addAction(QPixmap("://printer.png"), tr("Print Sheets")), SIGNAL(triggered(bool)), this, SLOT(printAllSheets())); connect(ui->toolBar->addAction(QPixmap("://save.png"), tr("Save Sheets")), SIGNAL(triggered(bool)), this, SLOT(saveAllSheets())); ui->toolBar->addSeparator(); connect(ui->toolBar->addAction(QPixmap("://left.png"), tr("Previous Sheet")), SIGNAL(triggered(bool)), this, SLOT(renderPreviousSheet())); ui->toolBar->addWidget(sheetNumberLabel); connect(ui->toolBar->addAction(QPixmap("://right.png"), tr("Next Sheet")), SIGNAL(triggered(bool)), this, SLOT(renderNextSheet())); connect(fontDialog, SIGNAL(fontReady()), this, SLOT(updateCurrentSheet())); errorMessage->setModal(true); ui->toolBar->actions()[ToolButton::Render]->setShortcut(Qt::ControlModifier + Qt::Key_R); ui->toolBar->actions()[ToolButton::Print]->setShortcut(Qt::ControlModifier + Qt::Key_P); ui->toolBar->actions()[ToolButton::Save]->setShortcut(Qt::ControlModifier + Qt::Key_S); ui->toolBar->actions()[ToolButton::Next]->setShortcut(Qt::ControlModifier + Qt::Key_Right); ui->toolBar->actions()[ToolButton::Previous]->setShortcut(Qt::ControlModifier + Qt::Key_Left); ui->textEdit->installEventFilter(this); ui->toolBar->actions()[ToolButton::Next]->setDisabled(true); ui->toolBar->actions()[ToolButton::Previous]->setDisabled(true); //initialize some class members sheetPointers.push_back(0); currentSheetNumber = 0; preferencesDialog->loadSettingsFromFile(); preferencesDialog->loadSettingsToFile(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); preferencesDialog = new PreferencesDialog(); fontDialog = new FontDialog(); //----File---- connect(ui->actionConvert_to_Handwritten, SIGNAL(triggered()), this, SLOT(renderFirstSheet())); connect(ui->actionLoad_Text_from_File, SIGNAL(triggered()), this, SLOT(loadTextFromFile())); connect(ui->actionLoad_Font, SIGNAL(triggered()), this, SLOT(loadFont())); connect(ui->actionFont_Editor, SIGNAL(triggered()), fontDialog, SLOT(exec())); connect(ui->actionSave_Current_Sheet_as, SIGNAL(triggered()), this, SLOT(saveSheet())); connect(ui->actionSave_All_Sheets, SIGNAL(triggered()), this, SLOT(saveAllSheets())); connect(ui->actionPrint_Current_Sheet, SIGNAL(triggered()), this, SLOT(printSheet())); connect(ui->actionPrint_All, SIGNAL(triggered()), this, SLOT(printAllSheets())); //----Edit---- //connect menu action "Show Toolbar" connect(ui->actionShow_ToolBar, SIGNAL(triggered(bool)), ui->toolBar, SLOT(setVisible(bool))); connect(ui->toolBar, SIGNAL(visibilityChanged(bool)), ui->actionShow_ToolBar, SLOT(setChecked(bool))); //preferencesDialog connections connect(ui->actionPreferences, SIGNAL(triggered()), preferencesDialog, SLOT(exec())); connect(preferencesDialog, SIGNAL(settingsChanged()), ui->svgView, SLOT(loadSettingsFromFile())); //----Help---- connect(ui->actionAbout_Scribbler, SIGNAL(triggered()), this, SLOT(showAboutBox())); connect(ui->actionLicenses_and_Credits, SIGNAL(triggered()), this, SLOT(showLicensesBox())); //----ToolBar---- //add actions to tool bar and connect them to slots connect(ui->toolBar->addAction(QPixmap("://render.png"), tr("Convert to Handwritten")), SIGNAL(triggered(bool)), this, SLOT(renderFirstSheet())); connect(ui->toolBar->addAction(QPixmap("://printer.png"), tr("Print Current Sheet")), SIGNAL(triggered(bool)), this, SLOT(printSheet())); connect(ui->toolBar->addAction(QPixmap("://save.png"), tr("Save Current Sheet as Image")), SIGNAL(triggered(bool)), this, SLOT(saveSheet())); ui->toolBar->addSeparator(); connect(ui->toolBar->addAction(QPixmap("://right.png"), tr("Next Sheet")), SIGNAL(triggered(bool)), this, SLOT(renderNextSheet())); connect(ui->toolBar->addAction(QPixmap("://left.png"), tr("Previous Sheet")), SIGNAL(triggered(bool)), this, SLOT(renderPreviousSheet())); connect(fontDialog, SIGNAL(fontReady()), ui->svgView, SLOT(loadFont())); ui->toolBar->actions()[4]->setDisabled(true); ui->toolBar->actions()[5]->setDisabled(true); //initialize some class members sheetPointers.push_back(0); currentSheetNumber = 0; version = "0.4 alpha"; preferencesDialog->loadSettingsFromFile(); /* This is a hack to avoid a bug. When program starts, it needs some time * (at least 1 ms on my configuration, but I set delay to 100 ms just to be sure * that it will work on weaker machines) before it can write settings to file, * otherwise ui->colorButton->palette().background().color() will return * default buttons background color, which will be written to settings * file at once program launches. */ QTime dieTime = QTime::currentTime().addMSecs(100); while (QTime::currentTime() < dieTime) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); preferencesDialog->loadSettingsToFile(); }