Ejemplo n.º 1
0
QDesignerActions::QDesignerActions(QDesignerWorkbench *workbench)
    : QObject(workbench),
      m_workbench(workbench), m_assistantClient(0), m_openDirectory(QString())
{
    Q_ASSERT(m_workbench != 0);

    m_core = m_workbench->core();
    Q_ASSERT(m_core != 0);

    QDesignerFormWindowManagerInterface *formWindowManager = m_core->formWindowManager();
    Q_ASSERT(formWindowManager != 0);

    QDesignerSettings settings;
    m_fileActions = new QActionGroup(this);
    m_fileActions->setExclusive(false);

    m_recentFilesActions = new QActionGroup(this);
    m_recentFilesActions->setExclusive(false);

    m_editActions = new QActionGroup(this);
    m_editActions->setExclusive(false);

    m_formActions = new QActionGroup(this);
    m_formActions->setExclusive(false);

    m_windowActions = new QActionGroup(this);
    m_windowActions->setExclusive(false);

    m_toolActions = new QActionGroup(this);
    m_toolActions->setExclusive(true);

    m_helpActions = new QActionGroup(this);
    m_helpActions->setExclusive(false);


//
// file actions
//
    m_newFormAction = new QAction(tr("&New Form..."), this);
    m_newFormAction->setShortcut(tr("CTRL+N"));
    connect(m_newFormAction, SIGNAL(triggered()), this, SLOT(createForm()));
    m_fileActions->addAction(m_newFormAction);

    m_openFormAction = new QAction(tr("&Open Form..."), this);
    m_openFormAction->setShortcut(tr("CTRL+O"));
    connect(m_openFormAction, SIGNAL(triggered()), this, SLOT(openForm()));
    m_fileActions->addAction(m_openFormAction);

    QAction *act;
    // Need to insert this into the QAction.
    for (int i = 0; i < MaxRecentFiles; ++i) {
        act = new QAction(this);
        act->setVisible(false);
        connect(act, SIGNAL(triggered()), this, SLOT(openRecentForm()));
        m_recentFilesActions->addAction(act);
    }
    updateRecentFileActions();

    act = new QAction(this);
    act->setSeparator(true);
    m_recentFilesActions->addAction(act);

    act = new QAction(tr("Clear &Menu"), this);
    connect(act, SIGNAL(triggered()), this, SLOT(clearRecentFiles()));
    m_recentFilesActions->addAction(act);

    QAction *sep = new QAction(this);
    sep->setSeparator(true);
    m_fileActions->addAction(sep);

    m_saveFormAction = new QAction(tr("&Save Form"), this);
    m_saveFormAction->setShortcut(tr("CTRL+S"));
    connect(m_saveFormAction, SIGNAL(triggered()), this, SLOT(saveForm()));
    m_fileActions->addAction(m_saveFormAction);

    m_saveFormAsAction = new QAction(tr("Save Form &As..."), this);
    connect(m_saveFormAsAction, SIGNAL(triggered()), this, SLOT(saveFormAs()));
    m_fileActions->addAction(m_saveFormAsAction);

    m_saveFormAsTemplateAction = new QAction(tr("Save Form As &Template..."), this);
    connect(m_saveFormAsTemplateAction, SIGNAL(triggered()), this, SLOT(saveFormAsTemplate()));
    m_fileActions->addAction(m_saveFormAsTemplateAction);

    sep = new QAction(this);
    sep->setSeparator(true);
    m_fileActions->addAction(sep);

    m_closeFormAction = new QAction(tr("&Close Form"), this);
    m_closeFormAction->setShortcut(tr("CTRL+W"));
    connect(m_closeFormAction, SIGNAL(triggered()), this, SLOT(closeForm()));
    m_fileActions->addAction(m_closeFormAction);

    sep = new QAction(this);
    sep->setSeparator(true);
    m_fileActions->addAction(sep);

    m_quitAction = new QAction(tr("&Quit"), this);
    m_quitAction->setShortcut(tr("CTRL+Q"));
    connect(m_quitAction, SIGNAL(triggered()),
            this, SLOT(shutdown()));
    m_fileActions->addAction(m_quitAction);

//
// edit actions
//
    m_undoAction = formWindowManager->actionUndo();
    m_undoAction->setShortcut(tr("CTRL+Z"));
    m_editActions->addAction(m_undoAction);

    m_redoAction = formWindowManager->actionRedo();
    m_redoAction->setShortcut(tr("CTRL+SHIFT+Z"));
    m_editActions->addAction(m_redoAction);

    sep = new QAction(this);
    sep->setSeparator(true);
    m_editActions->addAction(sep);

    m_cutAction = formWindowManager->actionCut();
    m_editActions->addAction(m_cutAction);

    m_copyAction = formWindowManager->actionCopy();
    m_editActions->addAction(m_copyAction);

    m_pasteAction = formWindowManager->actionPaste();
    m_editActions->addAction(m_pasteAction);

    m_deleteAction = formWindowManager->actionDelete();
    m_editActions->addAction(m_deleteAction);

    m_selectAllAction = formWindowManager->actionSelectAll();
    m_editActions->addAction(m_selectAllAction);

    sep = new QAction(this);
    sep->setSeparator(true);
    m_editActions->addAction(sep);

    m_sendToBackAction = formWindowManager->actionLower();
    m_editActions->addAction(m_sendToBackAction);

    m_bringToFrontAction = formWindowManager->actionRaise();
    m_editActions->addAction(m_bringToFrontAction);

//
// edit mode actions
//

    m_editWidgetsAction = new QAction(tr("Edit Widgets"), this);
    m_editWidgetsAction->setCheckable(true);
    m_editWidgetsAction->setShortcut(tr("F3"));
    m_editWidgetsAction->setIcon(QIcon(m_core->resourceLocation() + QLatin1String("/widgettool.png")));
    connect(formWindowManager, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
                this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface*)));
    connect(m_editWidgetsAction, SIGNAL(triggered()), this, SLOT(editWidgetsSlot()));
    m_toolActions->addAction(m_editWidgetsAction);
    m_editWidgetsAction->setChecked(true);
    m_editWidgetsAction->setEnabled(false);
    QList<QObject*> builtinPlugins = QPluginLoader::staticInstances();
    builtinPlugins += m_core->pluginManager()->instances();
    foreach (QObject *plugin, builtinPlugins) {
        if (QDesignerFormEditorPluginInterface *formEditorPlugin = qobject_cast<QDesignerFormEditorPluginInterface*>(plugin)) {
            m_toolActions->addAction(formEditorPlugin->action());
            formEditorPlugin->action()->setCheckable(true);
        }
    }

    m_uiMode = new QActionGroup(this);
    m_uiMode->setExclusive(true);

    m_sdiAction = m_uiMode->addAction(tr("Multiple Top-Level Windows"));
    m_sdiAction->setCheckable(true);

    m_dockedMdiAction = m_uiMode->addAction(tr("Docked Window"));
    m_dockedMdiAction->setCheckable(true);

    switch (settings.uiMode()) {
        default: Q_ASSERT(0); break;

        case QDesignerWorkbench::TopLevelMode:
            m_sdiAction->setChecked(true);
            break;
        case QDesignerWorkbench::DockedMode:
            m_dockedMdiAction->setChecked(true);
            break;
    }

    connect(m_uiMode, SIGNAL(triggered(QAction*)), this, SLOT(updateUIMode(QAction*)));

//
// form actions
//
    m_layoutHorizontallyAction = formWindowManager->actionHorizontalLayout();
    m_formActions->addAction(m_layoutHorizontallyAction);

    m_layoutVerticallyAction = formWindowManager->actionVerticalLayout();
    m_formActions->addAction(m_layoutVerticallyAction);

    m_layoutHorizontallyInSplitterAction = formWindowManager->actionSplitHorizontal();
    m_formActions->addAction(m_layoutHorizontallyInSplitterAction);

    m_layoutVerticallyInSplitterAction = formWindowManager->actionSplitVertical();
    m_formActions->addAction(m_layoutVerticallyInSplitterAction);

    m_layoutGridAction = formWindowManager->actionGridLayout();
    m_formActions->addAction(m_layoutGridAction);

    m_breakLayoutAction = formWindowManager->actionBreakLayout();
    m_formActions->addAction(m_breakLayoutAction);

    m_adjustSizeAction = formWindowManager->actionAdjustSize();
    m_formActions->addAction(m_adjustSizeAction);

    sep = new QAction(this);
    sep->setSeparator(true);

    m_formActions->addAction(sep);

    m_previewFormAction = new QAction(tr("&Preview"), this);
    m_previewFormAction->setShortcut(tr("CTRL+R"));
    connect(m_previewFormAction, SIGNAL(triggered()), this, SLOT(previewFormLater()));
    m_formActions->addAction(m_previewFormAction);

    m_styleActions = new QActionGroup(this);
    m_styleActions->setExclusive(true);
    connect(m_styleActions, SIGNAL(triggered(QAction*)), this, SLOT(previewForm(QAction*)));

    QAction *sep2 = new QAction(this);
    sep2->setSeparator(true);
    m_formActions->addAction(sep2);

    m_formSettings = new QAction(tr("Form &Settings..."), this);
    m_formSettings->setEnabled(false);
    connect(m_formSettings, SIGNAL(triggered()), this, SLOT(showFormSettings()));
    m_formActions->addAction(m_formSettings);

    QStringList availableStyleList = QStyleFactory::keys();
    foreach (QString style, availableStyleList) {
        QAction *a = new QAction(this);
        a->setText(tr("%1 Style").arg(style));
        a->setObjectName(QLatin1String("__qt_action_style_") + style);

        m_styleActions->addAction(a);
    }
Ejemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);

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

	form = new Form(this);
	view = new GraphicsView(form, this);
	setCentralWidget(view);

	itemWidget = new ItemWidget(ui->propertyWidget);
	itemWidget->setHidden(true);
	connect(view, SIGNAL(mouseDoubleClick()), itemWidget, SLOT(selectPicture()));

	formWidget = new FormWidget(ui->propertyWidget);
	formWidget->connectForm(form);
	formWidget->update(form);
	ui->propertyWidget->setWidget(formWidget);

	fontCombo = new QFontComboBox(this);
	ui->formatToolBar->insertWidget(ui->actionBold, fontCombo);

	insertGroup = new QActionGroup(this);
	insertGroup->addAction(ui->actionSelect);
	insertGroup->addAction(ui->actionPaint);
	connect(insertGroup, SIGNAL(triggered(QAction*)), this, SLOT(insertObject(QAction*)));

	ui->actionLeft->setData(Qt::AlignLeft);
	ui->actionCenter->setData(Qt::AlignHCenter);
	ui->actionRight->setData(Qt::AlignRight);

	zoomGroup = new QActionGroup(this);
	zoomGroup->addAction(ui->actionActualSize);
	zoomGroup->addAction(ui->actionFitWidth);
	zoomGroup->addAction(ui->actionFitHeight);
	connect(zoomGroup, SIGNAL(triggered(QAction*)), this, SLOT(zoom(QAction*)));

	ui->actionActualSize->setData(GraphicsView::ActualSize);
	ui->actionFitWidth->setData(GraphicsView::FitWidth);
	ui->actionFitHeight->setData(GraphicsView::FitHeight);

	horzAlignGroup = new QActionGroup(this);
	horzAlignGroup->addAction(ui->actionLeft);
	horzAlignGroup->addAction(ui->actionCenter);
	horzAlignGroup->addAction(ui->actionRight);
	connect(horzAlignGroup, SIGNAL(triggered(QAction*)), this, SLOT(horzAlign(QAction*)));

	sizeGroup = new QActionGroup(this);
	sizeGroup->addAction(ui->actionShrinkWidth);
	sizeGroup->addAction(ui->actionGrowWidth);
	sizeGroup->addAction(ui->actionPageWidth);
	sizeGroup->addAction(ui->actionShrinkHeight);
	sizeGroup->addAction(ui->actionGrowHeight);
	sizeGroup->addAction(ui->actionPageHeight);
	sizeGroup->addAction(ui->actionShrinkBoth);
	sizeGroup->addAction(ui->actionGrowBoth);
	sizeGroup->addAction(ui->actionPageBoth);

	ui->actionShrinkWidth->setData(Form::ShrinkWidth);
	ui->actionGrowWidth->setData(Form::GrowWidth);
	ui->actionPageWidth->setData(Form::PageWidth);
	ui->actionShrinkHeight->setData(Form::ShrinkHeight);
	ui->actionGrowHeight->setData(Form::GrowHeight);
	ui->actionPageHeight->setData(Form::PageHeight);
	ui->actionShrinkBoth->setData(Form::ShrinkBoth);
	ui->actionGrowBoth->setData(Form::GrowBoth);
	ui->actionPageBoth->setData(Form::PageBoth);

	connect(sizeGroup, SIGNAL(triggered(QAction*)), this, SLOT(size(QAction*)));

	connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newForm()));
	connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openForm()));
	connect(ui->actionReload, SIGNAL(triggered()), this, SLOT(reload()));
	connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveForm()));
	connect(ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(saveFormAs()));
	connect(ui->actionSaveAsPDF, SIGNAL(triggered()), this, SLOT(saveFormAsPdf()));
	connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
	connect(ui->actionOpenPrintData, SIGNAL(triggered()), this, SLOT(openPrintData()));
	connect(ui->actionPageSetup, SIGNAL(triggered()), form, SLOT(pageSetup()));
	connect(ui->actionPagePreview, SIGNAL(triggered()), this, SLOT(preview()));
	connect(ui->actionSend, SIGNAL(triggered()), this, SLOT(email()));
	connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print()));
	connect(ui->actionFullScreen, SIGNAL(triggered()), this, SLOT(fullScreen()));
	connect(ui->actionMargins, SIGNAL(toggled(bool)), form, SLOT(showMargins(bool)));
	connect(ui->actionGrid, SIGNAL(toggled(bool)), form, SLOT(showGrid(bool)));
	connect(ui->actionPrintData, SIGNAL(toggled(bool)), form, SLOT(showData(bool)));
	connect(ui->actionSelectAll, SIGNAL(triggered()), form, SLOT(selectAll()));
	connect(ui->actionDelete, SIGNAL(triggered()), form, SLOT(deleteSelected()));
	connect(ui->actionProperties, SIGNAL(toggled(bool)), ui->propertyWidget, SLOT(setVisible(bool)));
	connect(ui->actionMoveForwards, SIGNAL(triggered()), form, SLOT(moveForwards()));
	connect(ui->actionMoveBackwards, SIGNAL(triggered()), form, SLOT(moveBackwards()));
	connect(ui->actionAlignLeft, SIGNAL(triggered()), form, SLOT(alignLeft()));
	connect(ui->actionAlignRight, SIGNAL(triggered()), form, SLOT(alignRight()));
	connect(ui->actionAlignTop, SIGNAL(triggered()), form, SLOT(alignTop()));
	connect(ui->actionAlignBottom, SIGNAL(triggered()), form, SLOT(alignBottom()));
	connect(ui->actionCut, SIGNAL(triggered()), form, SLOT(cut()));
	connect(ui->actionCopy, SIGNAL(triggered()), form, SLOT(copy()));
	connect(ui->actionPaste, SIGNAL(triggered()), this, SLOT(paste()));
	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->menuView, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu()));
	connect(form, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
	connect(form, SIGNAL(changed()), this, SLOT(formChanged()));
	connect(view, SIGNAL(doneRubberBanding(QRectF)), this, SLOT(doneRubberBanding(QRectF)));

	connectForm();
	loadSettings();
	QTimer::singleShot(0, this, SLOT(init()));
}