formwindowmanager.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 773 行 · 第 1/2 页

CPP
773
字号
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//*TRANSLATOR qdesigner_internal::FormWindowManager*/#include "formwindowmanager.h"#include "formwindow_dnditem.h"#include "formwindow.h"#include "formeditor.h"#include "widgetdatabase_p.h"#include "iconloader_p.h"#include "widgetselection.h"#include "connectionedit_p.h"#include <qdesigner_dnditem_p.h>#include <qdesigner_command_p.h>#include <layoutinfo_p.h>#include <qlayout_widget_p.h>#include <qdesigner_objectinspector_p.h>#include <actioneditor_p.h>#include <QtDesigner/QDesignerWidgetFactoryInterface>#include <QtDesigner/QExtensionManager>#include <QtDesigner/QDesignerContainerExtension>#include <QtDesigner/QDesignerWidgetBoxInterface>#include <QtGui/QUndoGroup>#include <QtGui/QAction>#include <QtGui/QSplitter>#include <QtGui/QMouseEvent>#include <QtGui/QApplication>#include <QtGui/QSizeGrip>#include <QtGui/QClipboard>#include <QtGui/QMdiArea>#include <QtGui/QMdiSubWindow>#include <QtGui/QDesktopWidget>#include <QtCore/qdebug.h>namespace {    enum { debugFWM = 0 };}static inline QString whatsThisFrom(const QString &str) { /// ### implement me!    return str;}// find the first child of w in a sequencetemplate <class Iterator>static inline Iterator findFirstChildOf(Iterator it,Iterator end, const QWidget *w){    for  (;it != end; ++it) {        if (w->isAncestorOf(*it))            return  it;    }    return it;}namespace qdesigner_internal {FormWindowManager::FormWindowManager(QDesignerFormEditorInterface *core, QObject *parent) :    QDesignerFormWindowManagerInterface(parent),    m_core(core),    m_activeFormWindow(0),    m_layoutChilds(false){    setupActions();    qApp->installEventFilter(this);}FormWindowManager::~FormWindowManager(){    qDeleteAll(m_formWindows);}QDesignerFormEditorInterface *FormWindowManager::core() const{    return m_core;}QDesignerFormWindowInterface *FormWindowManager::activeFormWindow() const{    return m_activeFormWindow;}int FormWindowManager::formWindowCount() const{    return m_formWindows.size();}QDesignerFormWindowInterface *FormWindowManager::formWindow(int index) const{    return m_formWindows.at(index);}bool FormWindowManager::eventFilter(QObject *o, QEvent *e){    if (!o->isWidgetType())        return false;    QWidget *widget = static_cast<QWidget*>(o);    if (qobject_cast<WidgetHandle*>(widget)) { // ### remove me        return false;    }    FormWindow *fw = FormWindow::findFormWindow(widget);    if (fw == 0) {        return false;    }    if (QWidget *managedWidget = findManagedWidget(fw, widget)) {       switch (e->type()) {        case QEvent::Hide: {            if (widget == managedWidget && fw->isWidgetSelected(managedWidget))                fw->hideSelection(widget);        } break;        case QEvent::WindowActivate: {            if (fw->parentWidget()->isWindow() && fw->isMainContainer(managedWidget) && activeFormWindow() != fw) {                setActiveFormWindow(fw);            }        } break;        case QEvent::WindowDeactivate: {            if (o == fw && o == activeFormWindow())                fw->repaintSelection();        } break;        case QEvent::KeyPress: {            QKeyEvent *ke = static_cast<QKeyEvent*>(e);            if (ke->key() == Qt::Key_Escape) {                ke->accept();                return true;            }        }        // don't break...        default: {            if (fw->handleEvent(widget, managedWidget, e)) {                return true;            }        } break;        } // end switch    }    return false;}void FormWindowManager::addFormWindow(QDesignerFormWindowInterface *w){    FormWindow *formWindow = qobject_cast<FormWindow*>(w);    if (!formWindow || m_formWindows.contains(formWindow))        return;    connect(formWindow, SIGNAL(selectionChanged()), this, SLOT(slotUpdateActions()));    connect(formWindow->commandHistory(), SIGNAL(indexChanged(int)), this, SLOT(slotUpdateActions()));    connect(formWindow, SIGNAL(toolChanged(int)), this, SLOT(slotUpdateActions()));    if (ActionEditor *ae = qobject_cast<ActionEditor *>(m_core->actionEditor()))        connect(w, SIGNAL(mainContainerChanged(QWidget*)), ae, SLOT(mainContainerChanged()));    if (QDesignerObjectInspector *oi = qobject_cast<QDesignerObjectInspector *>(m_core->objectInspector()))        connect(w, SIGNAL(mainContainerChanged(QWidget*)), oi, SLOT(mainContainerChanged()));    m_formWindows.append(formWindow);    emit formWindowAdded(formWindow);}void FormWindowManager::removeFormWindow(QDesignerFormWindowInterface *w){    FormWindow *formWindow = qobject_cast<FormWindow*>(w);    int idx = m_formWindows.indexOf(formWindow);    if (!formWindow || idx == -1)        return;    formWindow->disconnect(this);    m_formWindows.removeAt(idx);    emit formWindowRemoved(formWindow);    if (formWindow == m_activeFormWindow)        setActiveFormWindow(0);}void FormWindowManager::setActiveFormWindow(QDesignerFormWindowInterface *w){    FormWindow *formWindow = qobject_cast<FormWindow*>(w);    if (formWindow == m_activeFormWindow)        return;    FormWindow *old = m_activeFormWindow;    m_activeFormWindow = formWindow;    slotUpdateActions();    if (m_activeFormWindow) {        m_activeFormWindow->repaintSelection();        if (old)            old->repaintSelection();    }    emit activeFormWindowChanged(m_activeFormWindow);    if (m_activeFormWindow) {        m_activeFormWindow->emitSelectionChanged();        m_activeFormWindow->commandHistory()->setActive();        // Trigger setActiveSubWindow on mdi area unless we are in toplevel mode        QMdiSubWindow *mdiSubWindow = 0;        if (QWidget *formwindow = m_activeFormWindow->parentWidget()) {            mdiSubWindow = qobject_cast<QMdiSubWindow *>(formwindow->parentWidget());        }        if (mdiSubWindow) {            for (QWidget *parent = mdiSubWindow->parentWidget(); parent; parent = parent->parentWidget()) {                if (QMdiArea *mdiArea = qobject_cast<QMdiArea*>(parent)) {                    mdiArea->setActiveSubWindow(mdiSubWindow);                    break;                }            }        }    }}QWidget *FormWindowManager::findManagedWidget(FormWindow *fw, QWidget *w){    while (w && w != fw) {        if (fw->isManaged(w))            break;        w = w->parentWidget();    }    return w;}void FormWindowManager::setupActions(){    m_actionCut = new QAction(createIconSet(QLatin1String("editcut.png")), tr("Cu&t"), this);    m_actionCut->setShortcut(Qt::CTRL + Qt::Key_X);    m_actionCut->setStatusTip(tr("Cuts the selected widgets and puts them on the clipboard"));    m_actionCut->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Cut")));    connect(m_actionCut, SIGNAL(triggered()), this, SLOT(slotActionCutActivated()));    m_actionCut->setEnabled(false);    m_actionCopy = new QAction(createIconSet(QLatin1String("editcopy.png")), tr("&Copy"), this);    m_actionCopy->setShortcut(Qt::CTRL + Qt::Key_C);    m_actionCopy->setStatusTip(tr("Copies the selected widgets to the clipboard"));    m_actionCopy->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Copy")));    connect(m_actionCopy, SIGNAL(triggered()), this, SLOT(slotActionCopyActivated()));    m_actionCopy->setEnabled(false);    m_actionPaste = new QAction(createIconSet(QLatin1String("editpaste.png")), tr("&Paste"), this);    m_actionPaste->setShortcut(Qt::CTRL + Qt::Key_V);    m_actionPaste->setStatusTip(tr("Pastes the clipboard's contents"));    m_actionPaste->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Paste")));    connect(m_actionPaste, SIGNAL(triggered()), this, SLOT(slotActionPasteActivated()));    m_actionPaste->setEnabled(false);    m_actionDelete = new QAction(tr("&Delete"), this);    m_actionDelete->setStatusTip(tr("Deletes the selected widgets"));    m_actionDelete->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Delete")));    connect(m_actionDelete, SIGNAL(triggered()), this, SLOT(slotActionDeleteActivated()));    m_actionDelete->setEnabled(false);    m_actionSelectAll = new QAction(tr("Select &All"), this);    m_actionSelectAll->setShortcut(Qt::CTRL + Qt::Key_A);    m_actionSelectAll->setStatusTip(tr("Selects all widgets"));    m_actionSelectAll->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Select All")));    connect(m_actionSelectAll, SIGNAL(triggered()), this, SLOT(slotActionSelectAllActivated()));    m_actionSelectAll->setEnabled(false);    m_actionRaise = new QAction(createIconSet(QLatin1String("editraise.png")), tr("Bring to &Front"), this);    m_actionRaise->setShortcut(Qt::CTRL + Qt::Key_L);    m_actionRaise->setStatusTip(tr("Raises the selected widgets"));    m_actionRaise->setWhatsThis(tr("Raises the selected widgets"));    connect(m_actionRaise, SIGNAL(triggered()), this, SLOT(slotActionRaiseActivated()));    m_actionRaise->setEnabled(false);    m_actionLower = new QAction(createIconSet(QLatin1String("editlower.png")), tr("Send to &Back"), this);    m_actionLower->setShortcut(Qt::CTRL + Qt::Key_K);    m_actionLower->setStatusTip(tr("Lowers the selected widgets"));    m_actionLower->setWhatsThis(tr("Lowers the selected widgets"));    connect(m_actionLower, SIGNAL(triggered()), this, SLOT(slotActionLowerActivated()));    m_actionLower->setEnabled(false);    m_actionAdjustSize = new QAction(createIconSet(QLatin1String("adjustsize.png")), tr("Adjust &Size"), this);    m_actionAdjustSize->setShortcut(Qt::CTRL + Qt::Key_J);    m_actionAdjustSize->setStatusTip(tr("Adjusts the size of the selected widget"));    m_actionAdjustSize->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Adjust Size")));    connect(m_actionAdjustSize, SIGNAL(triggered()), this, SLOT(slotActionAdjustSizeActivated()));    m_actionAdjustSize->setEnabled(false);    m_actionHorizontalLayout = new QAction(createIconSet(QLatin1String("edithlayout.png")), tr("Lay Out &Horizontally"), this);    m_actionHorizontalLayout->setShortcut(Qt::CTRL + Qt::Key_1);    m_actionHorizontalLayout->setStatusTip(tr("Lays out the selected widgets horizontally"));    m_actionHorizontalLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Horizontally")));    connect(m_actionHorizontalLayout, SIGNAL(triggered()), this, SLOT(slotActionHorizontalLayoutActivated()));    m_actionHorizontalLayout->setEnabled(false);    m_actionVerticalLayout = new QAction(createIconSet(QLatin1String("editvlayout.png")), tr("Lay Out &Vertically"), this);    m_actionVerticalLayout->setShortcut(Qt::CTRL + Qt::Key_2);    m_actionVerticalLayout->setStatusTip(tr("Lays out the selected widgets vertically"));    m_actionVerticalLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Vertically")));    connect(m_actionVerticalLayout, SIGNAL(triggered()), this, SLOT(slotActionVerticalLayoutActivated()));    m_actionVerticalLayout->setEnabled(false);    m_actionGridLayout = new QAction(createIconSet(QLatin1String("editgrid.png")), tr("Lay Out in a &Grid"), this);    m_actionGridLayout->setShortcut(Qt::CTRL + Qt::Key_5);    m_actionGridLayout->setStatusTip(tr("Lays out the selected widgets in a grid"));    m_actionGridLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out in a Grid")));    connect(m_actionGridLayout, SIGNAL(triggered()), this, SLOT(slotActionGridLayoutActivated()));    m_actionGridLayout->setEnabled(false);    m_actionSplitHorizontal = new QAction(createIconSet(QLatin1String("editvlayoutsplit.png")),                                          tr("Lay Out Horizontally in S&plitter"), this);    m_actionSplitHorizontal->setShortcut(Qt::CTRL + Qt::Key_3);    m_actionSplitHorizontal->setStatusTip(tr("Lays out the selected widgets horizontally in a splitter"));    m_actionSplitHorizontal->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Horizontally in Splitter")));    connect(m_actionSplitHorizontal, SIGNAL(triggered()), this, SLOT(slotActionSplitHorizontalActivated()));    m_actionSplitHorizontal->setEnabled(false);    m_actionSplitVertical = new QAction(createIconSet(QLatin1String("edithlayoutsplit.png")),                                        tr("Lay Out Vertically in Sp&litter"), this);    m_actionSplitVertical->setShortcut(Qt::CTRL + Qt::Key_4);    m_actionSplitVertical->setStatusTip(tr("Lays out the selected widgets vertically in a splitter"));    m_actionSplitVertical->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Vertically in Splitter")));    connect(m_actionSplitVertical, SIGNAL(triggered()), this, SLOT(slotActionSplitVerticalActivated()));    m_actionSplitVertical->setEnabled(false);    m_actionBreakLayout = new QAction(createIconSet(QLatin1String("editbreaklayout.png")), tr("&Break Layout"), this);    m_actionBreakLayout->setShortcut(Qt::CTRL + Qt::Key_0);    m_actionBreakLayout->setStatusTip(tr("Breaks the selected layout"));    m_actionBreakLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Break Layout")));    connect(m_actionBreakLayout, SIGNAL(triggered()), this, SLOT(slotActionBreakLayoutActivated()));    m_actionBreakLayout->setEnabled(false);    m_undoGroup = new QUndoGroup(this);    m_actionUndo = m_undoGroup->createUndoAction(this);    m_actionUndo->setEnabled(false);    m_actionRedo = m_undoGroup->createRedoAction(this);    m_actionRedo->setEnabled(false);}void FormWindowManager::slotActionCutActivated(){    m_activeFormWindow->cut();}void FormWindowManager::slotActionCopyActivated()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?