actioneditor.cpp

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

CPP
593
字号
/******************************************************************************** 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::ActionEditor*/#include "actioneditor_p.h"#include "actionrepository_p.h"#include "iconloader_p.h"#include "newactiondialog_p.h"#include "qdesigner_menu_p.h"#include "qdesigner_command_p.h"#include "qdesigner_propertycommand_p.h"#include "resourcemimedata_p.h"#include "qdesigner_objectinspector_p.h"#include "qdesigner_utils_p.h"#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerPropertyEditorInterface>#include <QtDesigner/QDesignerPropertySheetExtension>#include <QtDesigner/QExtensionManager>#include <QtDesigner/QDesignerMetaDataBaseInterface>#include <QtDesigner/QDesignerFormWindowInterface>#include <QtDesigner/QDesignerIconCacheInterface>#include <QtGui/QMenu>#include <QtGui/QMessageBox>#include <QtGui/QListWidget>#include <QtGui/QToolBar>#include <QtGui/QSplitter>#include <QtGui/QAction>#include <QtGui/QItemDelegate>#include <QtGui/QPainter>#include <QtGui/QVBoxLayout>#include <QtGui/QLineEdit>#include <QtGui/QLabel>#include <QtGui/QPushButton>#include <QtCore/QRegExp>#include <qdebug.h>Q_DECLARE_METATYPE(QAction*)Q_DECLARE_METATYPE(QListWidgetItem*)namespace qdesigner_internal {//-------- ActionFilterWidgetclass ActionFilterWidget: public QWidget{    Q_OBJECTpublic:    ActionFilterWidget(ActionEditor *actionEditor, QToolBar *parent)        : QWidget(parent),          m_button(new QPushButton(this)),          m_editor(new QLineEdit(this)),          m_actionEditor(actionEditor)    {        QHBoxLayout *l = new QHBoxLayout(this);        l->setMargin(0);        l->setSpacing(0);        l->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));        QLabel *label = new QLabel(tr("Filter: "), this);        label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);        l->addWidget(label);        l->addWidget(m_editor);        connect(m_editor, SIGNAL(textChanged(QString)), actionEditor, SLOT(setFilter(QString)));        m_button->setIcon(createIconSet(QLatin1String("resetproperty.png")));        m_button->setIconSize(QSize(16, 16));        m_button->setFlat(true);        l->addWidget(m_button);        connect(m_button, SIGNAL(clicked()), m_editor, SLOT(clear()));        connect(m_editor, SIGNAL(textChanged(QString)), this, SLOT(checkButton(QString)));    }private slots:    void checkButton(const QString &text)    {        m_button->setEnabled(!text.isEmpty());    }private:    QPushButton *m_button;    QLineEdit *m_editor;    ActionEditor *m_actionEditor;};//--------  ActionGroupDelegateclass ActionGroupDelegate: public QItemDelegate{public:    ActionGroupDelegate(QObject *parent)        : QItemDelegate(parent) {}    virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const    {        if (option.state & QStyle::State_Selected)            painter->fillRect(option.rect, option.palette.highlight());        QItemDelegate::paint(painter, option, index);    }    virtual void drawFocus(QPainter * /*painter*/, const QStyleOptionViewItem &/*option*/, const QRect &/*rect*/) const {}};//--------  ActionEditorActionEditor::ActionEditor(QDesignerFormEditorInterface *core, QWidget *parent, Qt::WindowFlags flags)    : QDesignerActionEditorInterface(parent, flags),      m_core(core){    setWindowTitle(tr("Actions"));    QVBoxLayout *l = new QVBoxLayout(this);    l->setMargin(0);    l->setSpacing(0);    QToolBar *toolbar = new QToolBar(this);    toolbar->setIconSize(QSize(24, 24));    toolbar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);    l->addWidget(toolbar);    m_actionNew = toolbar->addAction(tr("New..."));    m_actionNew->setIcon(createIconSet(QLatin1String("filenew.png")));    m_actionNew->setEnabled(false);    connect(m_actionNew, SIGNAL(triggered()), this, SLOT(slotNewAction()));    m_actionDelete = toolbar->addAction(tr("Delete"));    m_actionDelete->setIcon(createIconSet(QLatin1String("editdelete.png")));    m_actionDelete->setEnabled(false);    m_filterWidget = new ActionFilterWidget(this, toolbar);    m_filterWidget->setEnabled(false);    toolbar->addWidget(m_filterWidget);    connect(m_actionDelete, SIGNAL(triggered()), this, SLOT(slotDeleteAction()));    QSplitter *splitter = new QSplitter(Qt::Horizontal, this);    splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);    l->addWidget(splitter);#if 0 // ### implement me    m_actionGroups = new QListWidget(splitter);    splitter->addWidget(m_actionGroups);    m_actionGroups->setItemDelegate(new ActionGroupDelegate(m_actionGroups));    m_actionGroups->setMovement(QListWidget::Static);    m_actionGroups->setResizeMode(QListWidget::Fixed);    m_actionGroups->setIconSize(QSize(48, 48));    m_actionGroups->setFlow(QListWidget::TopToBottom);    m_actionGroups->setViewMode(QListWidget::IconMode);    m_actionGroups->setWrapping(false);#endif    m_actionRepository = new ActionRepository(splitter);    connect(m_actionRepository, SIGNAL(resourceImageDropped(ResourceMimeData,QAction*)),            this, SLOT(resourceImageDropped(ResourceMimeData,QAction*)));    splitter->addWidget(m_actionRepository);    connect(m_actionRepository, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),            this, SLOT(slotItemChanged(QListWidgetItem*)));    // make it possible for vs integration to reimplement edit action dialog    connect(m_actionRepository, SIGNAL(itemActivated(QListWidgetItem*)),            this, SIGNAL(itemActivated(QListWidgetItem*)));    connect(m_actionRepository, SIGNAL(contextMenuRequested(QContextMenuEvent*, QListWidgetItem*)),            this, SIGNAL(contextMenuRequested(QContextMenuEvent*, QListWidgetItem*)));    connect(this, SIGNAL(itemActivated(QListWidgetItem*)),            this, SLOT(editAction(QListWidgetItem*)));}ActionEditor::~ActionEditor(){}QAction *ActionEditor::actionNew() const{    return m_actionNew;}QAction *ActionEditor::actionDelete() const{    return m_actionDelete;}QDesignerFormWindowInterface *ActionEditor::formWindow() const{    return m_formWindow;}void ActionEditor::setFormWindow(QDesignerFormWindowInterface *formWindow){    if (formWindow != 0 && formWindow->mainContainer() == 0)        formWindow = 0;    // we do NOT rely on this function to update the action editor    if (m_formWindow == formWindow)        return;    if (m_formWindow != 0) {        const QList<QAction*> actionList = qFindChildren<QAction*>(m_formWindow->mainContainer());        foreach (QAction *action, actionList)            disconnect(action, SIGNAL(changed()), this, SLOT(slotActionChanged()));    }    m_formWindow = formWindow;    m_actionRepository->clear();    if (!formWindow || !formWindow->mainContainer()) {        m_actionNew->setEnabled(false);        m_actionDelete->setEnabled(false);        m_filterWidget->setEnabled(false);        return;    }    m_actionNew->setEnabled(true);    m_filterWidget->setEnabled(true);    const QList<QAction*> actionList = qFindChildren<QAction*>(formWindow->mainContainer());    foreach (QAction *action, actionList) {        if (!core()->metaDataBase()->item(action)            || action->isSeparator()            // ### || action->menu()            ) {            continue;        }        createListWidgetItem(action);        connect(action, SIGNAL(changed()), this, SLOT(slotActionChanged()));    }    setFilter(m_filter);}static QIcon fixActionIcon(QIcon icon){    if (icon.isNull())        return emptyIcon();    return icon;}// Set up list widget item, icon, tooltipstatic void setListWidgetItem(const QAction *action,  QListWidgetItem *item){    item->setText(action->objectName());    item->setIcon(fixActionIcon(action->icon()));    QString tooltip = action->objectName();    const QString text = action->text();    if (!text.isEmpty()) {        tooltip += QLatin1Char('\n');        tooltip += text;    }    item->setToolTip(tooltip);    item->setWhatsThis(tooltip);}QListWidgetItem *ActionEditor::createListWidgetItem(QAction *action){    if (action->menu())

⌨️ 快捷键说明

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