void CtrlrPanelCanvas::handleEditMenu (const int returnCode, const MouseEvent &e) { switch ((EditMenuItems)returnCode) { case Copy: editMenuCopy(&e); break; case Paste: editMenuPaste(e); break; case Cut: editMenuCopy(&e); editMenuDelete(); break; case Delete: editMenuDelete(); break; case AlignToTop: case AlignToLeft: case AlignToBottom: case AlignToRight: alignSelection ((EditMenuItems)returnCode); break; case FitToRect: fitSelection(); break; default: break; } }
MainWindow::MainWindow(Application *app) : QMainWindow(), m_application(app) { app->setMainWindow(this); setUnifiedTitleAndToolBarOnMac(true); setDocumentMode(true); QCoreApplication::setOrganizationName("Dunnart"); QCoreApplication::setOrganizationDomain("dunnart.org"); QCoreApplication::setApplicationName("Dunnart"); // Correct the look of the tab bar on OS X cocoa. app->setStyleSheet( "QGraphicsView {" "border: 0px;" "}" #ifdef Q_WS_MAC "QTabBar::tab:top {" "font-family: \"Lucida Grande\";" "font-size: 11px;" "}" #endif ); // Set the window title. setWindowTitle("Dunnart"); m_tab_widget = new CanvasTabWidget(this); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), this, SLOT(canvasChanged(Canvas*))); connect(m_tab_widget, SIGNAL(currentCanvasFileInfoChanged(QFileInfo)), this, SLOT(canvasFileInfoChanged(QFileInfo))); m_tab_widget->newTab(); setCentralWidget(m_tab_widget); app->setCanvasTabWidget(m_tab_widget); // Inital window size. resize(1020, 743); m_new_action = new QAction("New", this); m_new_action->setShortcut(QKeySequence::New); connect(m_new_action, SIGNAL(triggered()), this, SLOT(documentNew())); m_open_action = new QAction("Open...", this); m_open_action->setShortcut(QKeySequence::Open); connect(m_open_action, SIGNAL(triggered()), this, SLOT(documentOpen())); for (int i = 0; i < MAX_RECENT_FILES; ++i) { m_action_open_recent_file[i] = new QAction(this); m_action_open_recent_file[i]->setVisible(false); connect(m_action_open_recent_file[i], SIGNAL(triggered()), this, SLOT(documentOpenRecent())); } m_close_action = new QAction("Close", this); m_close_action->setShortcut(QKeySequence::Close); connect(m_close_action, SIGNAL(triggered()), m_tab_widget, SLOT(currentCanvasClose())); m_save_action = new QAction("Save", this); m_save_action->setShortcut(QKeySequence::Save); connect(m_save_action, SIGNAL(triggered()), m_tab_widget, SLOT(currentCanvasSave())); m_save_as_action = new QAction("Save As...", this); m_save_as_action->setShortcut(QKeySequence::SaveAs); connect(m_save_as_action, SIGNAL(triggered()), m_tab_widget, SLOT(currentCanvasSaveAs())); m_export_action = new QAction("Export...", this); connect(m_export_action, SIGNAL(triggered()), this, SLOT(documentExport())); m_print_action = new QAction("Print...", this); m_print_action->setShortcut(QKeySequence::Print); connect(m_print_action, SIGNAL(triggered()), this, SLOT(documentPrint())); m_quit_action = new QAction(tr("Quit"), this); m_quit_action->setShortcut(QKeySequence::Quit); connect(m_quit_action, SIGNAL(triggered()), this, SLOT(close())); m_about_action = new QAction(tr("About"), this); connect(m_about_action, SIGNAL(triggered()), this, SLOT(about())); m_homepage_action = new QAction(tr("Dunnart homepage"), this); connect(m_homepage_action, SIGNAL(triggered()), this, SLOT(openHomepage())); m_action_show_zoom_level_dialog = new QAction( tr("Zoom Level"), this); m_action_show_zoom_level_dialog->setCheckable(true); m_action_show_properties_editor_dialog = new QAction( tr("Properties Editor"), this); m_action_show_properties_editor_dialog->setCheckable(true); m_action_show_layout_properties_dialog = new QAction( tr("Layout Properties"), this); m_action_show_layout_properties_dialog->setCheckable(true); m_action_show_connector_properties_dialog = new QAction( tr("Connector Properties"), this); m_action_show_connector_properties_dialog->setCheckable(true); m_action_show_create_alignment_dialog = new QAction( tr("Create Alignments"), this); m_action_show_create_alignment_dialog->setCheckable(true); m_action_show_create_distribution_dialog = new QAction( tr("Create Distributions"), this); m_action_show_create_distribution_dialog->setCheckable(true); m_action_show_create_separation_dialog = new QAction( tr("Create Separations"), this); m_action_show_create_separation_dialog->setCheckable(true); m_action_show_create_template_dialog = new QAction( tr("Create Templates"), this); m_action_show_create_template_dialog->setShortcut(tr("Ctrl+T")); m_action_show_create_template_dialog->setCheckable(true); m_action_show_shape_picker_dialog = new QAction( tr("Shape Picker"), this); m_action_show_shape_picker_dialog->setCheckable(true); m_action_clear_recent_files = new QAction(tr("Clear Menu"), this); connect(m_action_clear_recent_files, SIGNAL(triggered()), this, SLOT(clearRecentFileMenu())); m_action_show_undo_history_dialog = new QAction( tr("Undo History"), this); m_action_show_undo_history_dialog->setCheckable(true); m_action_show_canvas_overview_dialog = new QAction( tr("Canvas Overview"), this); m_action_show_canvas_overview_dialog->setCheckable(true); CanvasView *canvasview = m_tab_widget->currentCanvasView(); Canvas *canvas = m_tab_widget->currentCanvas(); m_action_auto_align_selection = new QAction(tr("Auto-align Selection"), this); connect(m_action_auto_align_selection, SIGNAL(triggered()), m_tab_widget, SLOT(alignSelection())); // Create statusBar, and assign it to the canvas. canvas->setStatusBar(statusBar()); #ifdef Q_WS_MAC // Make the status bar font size slightly smaller. QFont statusBarFont = statusBar()->font(); statusBarFont.setPointSize(statusBarFont.pointSize() - 2); statusBar()->setFont(statusBarFont); #endif m_file_menu = menuBar()->addMenu("File"); m_file_menu->addAction(m_new_action); m_file_menu->addAction(m_open_action); QMenu *recentsMenu = m_file_menu->addMenu(tr("Open Recent")); for (int i = 0; i < MAX_RECENT_FILES; ++i) { recentsMenu->addAction(m_action_open_recent_file[i]); } m_action_recent_file_separator = recentsMenu->addSeparator(); recentsMenu->addAction(m_action_clear_recent_files); updateRecentFileActions(); m_file_menu->addSeparator(); m_file_menu->addAction(m_close_action); m_file_menu->addAction(m_save_action); m_file_menu->addAction(m_save_as_action); m_file_menu->addSeparator(); m_file_menu->addAction(m_export_action); m_file_menu->addSeparator(); m_file_menu->addAction(m_print_action); m_file_menu->addSeparator(); m_file_menu->addAction(m_quit_action); m_edit_menu = menuBar()->addMenu(tr("Edit")); m_tab_widget->addEditMenuActions(m_edit_menu); m_view_menu = menuBar()->addMenu(tr("View")); QMenu *dialogs_menu = m_view_menu->addMenu(tr("Show Dialogs")); dialogs_menu->addAction(m_action_show_canvas_overview_dialog); dialogs_menu->addAction(m_action_show_zoom_level_dialog); dialogs_menu->addSeparator(); dialogs_menu->addAction(m_action_show_shape_picker_dialog); dialogs_menu->addAction(m_action_show_undo_history_dialog); dialogs_menu->addAction(m_action_show_properties_editor_dialog); dialogs_menu->addSeparator(); dialogs_menu->addAction(m_action_show_create_alignment_dialog); dialogs_menu->addAction(m_action_show_create_distribution_dialog); dialogs_menu->addAction(m_action_show_create_separation_dialog); dialogs_menu->addAction(m_action_show_create_template_dialog); dialogs_menu->addSeparator(); dialogs_menu->addAction(m_action_show_layout_properties_dialog); dialogs_menu->addAction(m_action_show_connector_properties_dialog); QMenu *overlays_menu = m_view_menu->addMenu(tr("Canvas Debug Layers")); m_tab_widget->addDebugOverlayMenuActions(overlays_menu); m_layout_menu = menuBar()->addMenu("Layout"); m_tab_widget->addLayoutMenuActions(m_layout_menu); m_layout_menu->addAction(m_action_auto_align_selection); m_edit_toolbar = addToolBar(tr("Edit toolbar")); m_edit_toolbar->setIconSize(QSize(24, 24)); m_edit_toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); m_tab_widget->addEditToolBarActions(m_edit_toolbar); m_dialog_zoomLevel = new ZoomLevel(canvasview); connect(m_tab_widget, SIGNAL(currentCanvasViewChanged(CanvasView*)), m_dialog_zoomLevel, SLOT(changeCanvasView(CanvasView*))); connect(m_action_show_zoom_level_dialog, SIGNAL(triggered(bool)), m_dialog_zoomLevel, SLOT(setVisible(bool))); connect(m_dialog_zoomLevel, SIGNAL(visibilityChanged(bool)), m_action_show_zoom_level_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::RightDockWidgetArea, m_dialog_zoomLevel); m_dialog_zoomLevel->show(); m_dialog_properties_editor = new PropertiesEditorDialog(canvas); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_properties_editor, SLOT(changeCanvas(Canvas*))); connect(m_action_show_properties_editor_dialog, SIGNAL(triggered(bool)), m_dialog_properties_editor, SLOT(setVisible(bool))); connect(m_dialog_properties_editor, SIGNAL(visibilityChanged(bool)), m_action_show_properties_editor_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::BottomDockWidgetArea, m_dialog_properties_editor); m_dialog_properties_editor->hide(); m_dialog_shape_picker = new ShapePickerDialog(canvas); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_shape_picker, SLOT(changeCanvas(Canvas*))); connect(m_action_show_shape_picker_dialog, SIGNAL(triggered(bool)), m_dialog_shape_picker, SLOT(setVisible(bool))); connect(m_dialog_shape_picker, SIGNAL(visibilityChanged(bool)), m_action_show_shape_picker_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::LeftDockWidgetArea, m_dialog_shape_picker); m_dialog_shape_picker->show(); m_dialog_layoutProps = new LayoutPropertiesDialog(canvas); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_layoutProps, SLOT(changeCanvas(Canvas*))); connect(m_action_show_layout_properties_dialog, SIGNAL(triggered(bool)), m_dialog_layoutProps, SLOT(setVisible(bool))); connect(m_dialog_layoutProps, SIGNAL(visibilityChanged(bool)), m_action_show_layout_properties_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::LeftDockWidgetArea, m_dialog_layoutProps); m_dialog_layoutProps->show(); m_dialog_connectorProps = new ConnectorPropertiesDialog(canvas); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_connectorProps, SLOT(changeCanvas(Canvas*))); connect(m_action_show_connector_properties_dialog, SIGNAL(triggered(bool)), m_dialog_connectorProps, SLOT(setVisible(bool))); connect(m_dialog_connectorProps, SIGNAL(visibilityChanged(bool)), m_action_show_connector_properties_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::LeftDockWidgetArea, m_dialog_connectorProps); m_dialog_connectorProps->hide(); m_dialog_alignment = new CreateAlignmentDialog(canvas); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_alignment, SLOT(changeCanvas(Canvas*))); connect(m_action_show_create_alignment_dialog, SIGNAL(triggered(bool)), m_dialog_alignment, SLOT(setVisible(bool))); connect(m_dialog_alignment, SIGNAL(visibilityChanged(bool)), m_action_show_create_alignment_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::RightDockWidgetArea, m_dialog_alignment); m_dialog_alignment->show(); m_dialog_distribution = new CreateDistributionDialog(canvas, this); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_distribution, SLOT(changeCanvas(Canvas*))); connect(m_action_show_create_distribution_dialog, SIGNAL(triggered(bool)), m_dialog_distribution, SLOT(setVisible(bool))); connect(m_dialog_distribution, SIGNAL(visibilityChanged(bool)), m_action_show_create_distribution_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::RightDockWidgetArea, m_dialog_distribution); m_dialog_distribution->show(); m_dialog_separation = new CreateSeparationDialog(canvas, this); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_separation, SLOT(changeCanvas(Canvas*))); connect(m_action_show_create_separation_dialog, SIGNAL(triggered(bool)), m_dialog_separation, SLOT(setVisible(bool))); connect(m_dialog_separation, SIGNAL(visibilityChanged(bool)), m_action_show_create_separation_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::RightDockWidgetArea, m_dialog_separation); m_dialog_separation->show(); m_dialog_template = new CreateTemplateDialog(canvas, this); connect(m_tab_widget, SIGNAL(currentCanvasChanged(Canvas*)), m_dialog_template, SLOT(changeCanvas(Canvas*))); connect(m_action_show_create_template_dialog, SIGNAL(triggered(bool)), m_dialog_template, SLOT(setVisible(bool))); connect(m_dialog_template, SIGNAL(visibilityChanged(bool)), m_action_show_create_template_dialog, SLOT(setChecked(bool))); m_dialog_template->hide(); m_dialog_undo_history = new UndoHistoryDialog( m_tab_widget->undoGroup(), this); connect(m_action_show_undo_history_dialog, SIGNAL(triggered(bool)), m_dialog_undo_history, SLOT(setVisible(bool))); connect(m_dialog_undo_history, SIGNAL(visibilityChanged(bool)), m_action_show_undo_history_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::LeftDockWidgetArea, m_dialog_undo_history); m_dialog_undo_history->hide(); m_dialog_canvas_overview = new CanvasOverviewDialog(canvasview, this); connect(m_tab_widget, SIGNAL(currentCanvasViewChanged(CanvasView*)), m_dialog_canvas_overview, SLOT(changeCanvasView(CanvasView*))); connect(m_action_show_canvas_overview_dialog, SIGNAL(triggered(bool)), m_dialog_canvas_overview, SLOT(setVisible(bool))); connect(m_dialog_canvas_overview, SIGNAL(visibilityChanged(bool)), m_action_show_canvas_overview_dialog, SLOT(setChecked(bool))); addDockWidget(Qt::LeftDockWidgetArea, m_dialog_canvas_overview); m_dialog_canvas_overview->hide(); // Allow plugins to initialise themselves and add things like // menu items and dock widgets to the main window. PluginApplicationManager *appPluginManager = sharedPluginApplicationManager(); appPluginManager->applicationMainWindowInitialised(app); // Add help menu after everything else (if should be rightmost). m_help_menu = menuBar()->addMenu(tr("Help")); m_help_menu->addAction(m_homepage_action); m_help_menu->addSeparator(); m_help_menu->addAction(m_about_action); // Restore window geometry and Dock Widget geometry. QSettings settings; restoreGeometry(settings.value("geometry").toByteArray()); restoreState(settings.value("windowState").toByteArray()); }