qdesigner_promotiondialog.cpp

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

CPP
422
字号
/******************************************************************************** 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::QDesignerPromotionDialog*/#include "qdesigner_promotiondialog_p.h"#include "promotionmodel_p.h"#include "iconloader_p.h"#include "widgetdatabase_p.h"#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerFormWindowInterface>#include <QtDesigner/QDesignerPromotionInterface>#include <QtDesigner/QDesignerWidgetDataBaseItemInterface>#include <QtCore/QTimer>#include <QtGui/QVBoxLayout>#include <QtGui/QHBoxLayout>#include <QtGui/QDialogButtonBox>#include <QtGui/QTreeView>#include <QtGui/QHeaderView>#include <QtGui/QPushButton>#include <QtGui/QItemSelectionModel>#include <QtGui/QItemSelection>#include <QtGui/QMessageBox>#include <QtGui/QComboBox>#include <QtGui/QLineEdit>#include <QtGui/QCheckBox>#include <QtGui/QRegExpValidator>#include <QtGui/QLabel>#include <QtGui/QSpacerItem>// Add a row consisting of widget and a description label to a grid.static void addGridRow(const QString &description, QGridLayout *gridLayout, QWidget *w, int &row) {    QLabel *label = new QLabel(description);    gridLayout->addWidget(label, row, 0);    gridLayout->addWidget(w, row, 1);    ++row;}namespace qdesigner_internal {    // PromotionParameters    struct PromotionParameters {        QString m_baseClass;        QString m_className;        QString m_includeFile;    };    //  NewPromotedClassPanel    NewPromotedClassPanel::NewPromotedClassPanel(const QStringList &baseClasses,                                                   int selectedBaseClass,                                                   QWidget *parent) :        QGroupBox(parent),        m_baseClassCombo(new  QComboBox),        m_classNameEdit(new QLineEdit),        m_includeFileEdit(new QLineEdit),        m_globalIncludeCheckBox(new QCheckBox),        m_addButton(new QPushButton(tr("Add")))    {        setTitle(tr("New Promoted Class"));        setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);        QHBoxLayout *hboxLayout = new QHBoxLayout(this);        m_classNameEdit->setValidator(new QRegExpValidator(QRegExp(QLatin1String("[_a-zA-Z:][:_a-zA-Z0-9]*")), m_classNameEdit));        connect(m_classNameEdit,   SIGNAL(textChanged(QString)), this, SLOT(slotNameChanged(QString)));        connect(m_includeFileEdit, SIGNAL(textChanged(QString)), this, SLOT(slotIncludeFileChanged(QString)));        m_baseClassCombo->setEditable(false);        m_baseClassCombo->addItems(baseClasses);        if (selectedBaseClass != -1)            m_baseClassCombo->setCurrentIndex(selectedBaseClass);        // Grid        QGridLayout *gridLayout = new QGridLayout();        int row = 0;        addGridRow(tr("Base class name:"),     gridLayout, m_baseClassCombo, row);        addGridRow(tr("Promoted class name:"), gridLayout, m_classNameEdit, row);        addGridRow(tr("Header file:"),         gridLayout, m_includeFileEdit, row);        addGridRow(tr("Global include"),       gridLayout, m_globalIncludeCheckBox, row);        hboxLayout->addLayout(gridLayout);        hboxLayout->addItem(new QSpacerItem(15, 0, QSizePolicy::Fixed, QSizePolicy::Ignored));        // Button box        QVBoxLayout *buttonLayout = new QVBoxLayout();        m_addButton->setAutoDefault(false);        connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAdd()));        m_addButton->setEnabled(false);        buttonLayout->addWidget(m_addButton);        QPushButton *resetButton = new QPushButton(tr("Reset"));        resetButton->setAutoDefault(false);        connect(resetButton, SIGNAL(clicked()), this, SLOT(slotReset()));        buttonLayout->addWidget(resetButton);        buttonLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::Expanding));        hboxLayout->addLayout(buttonLayout);        enableButtons();    }    void NewPromotedClassPanel::slotAdd() {        bool ok = false;        emit newPromotedClass(promotionParameters(), &ok);        if (ok)            slotReset();    }    void NewPromotedClassPanel::slotReset() {        const QString empty;        m_classNameEdit->setText(empty);        m_includeFileEdit->setText(empty);        m_globalIncludeCheckBox->setCheckState(Qt::Unchecked);    }    void NewPromotedClassPanel::grabFocus() {        m_classNameEdit->setFocus(Qt::OtherFocusReason);    }    void NewPromotedClassPanel::slotNameChanged(const QString &className) {        // Suggest a name        if (!className.isEmpty()) {            QString suggestedHeader = className.toLower().replace(QLatin1String("::"), QString(QLatin1Char('_')));            suggestedHeader += QLatin1String(".h");            const bool blocked = m_includeFileEdit->blockSignals(true);            m_includeFileEdit->setText(suggestedHeader);            m_includeFileEdit->blockSignals(blocked);        }        enableButtons();    }    void NewPromotedClassPanel::slotIncludeFileChanged(const QString &){        enableButtons();    }    void NewPromotedClassPanel::enableButtons() {        const bool enabled = !m_classNameEdit->text().isEmpty() && !m_includeFileEdit->text().isEmpty();        m_addButton->setEnabled(enabled);        m_addButton->setDefault(enabled);    }    PromotionParameters NewPromotedClassPanel::promotionParameters() const {         PromotionParameters rc;         rc.m_baseClass = m_baseClassCombo->currentText();         rc.m_className = m_classNameEdit->text();         rc.m_includeFile = buildIncludeFile(m_includeFileEdit->text(),                                             m_globalIncludeCheckBox->checkState() == Qt::Checked ? IncludeGlobal : IncludeLocal);         return rc;     }    void NewPromotedClassPanel::chooseBaseClass(const QString &baseClass) {        const int index = m_baseClassCombo->findText (baseClass);        if (index != -1)            m_baseClassCombo->setCurrentIndex (index);    }    // QDesignerPromotionDialog    QDesignerPromotionDialog::QDesignerPromotionDialog(QDesignerFormEditorInterface *core,                                                       QWidget *parent,                                                       const QString &promotableWidgetClassName,                                                       QString *promoteTo) :        QDialog(parent),        m_mode(promotableWidgetClassName.isEmpty() || promoteTo == 0 ? ModeEdit : ModeEditChooseClass),        m_promotableWidgetClassName(promotableWidgetClassName),        m_promoteTo(promoteTo),        m_promotion(core->promotion()),        m_model(new PromotionModel(core)),        m_treeView(new QTreeView),        m_buttonBox(0),        m_removeButton(new QPushButton(createIconSet(QString::fromUtf8("minus.png")), QString()))    {        m_buttonBox = createButtonBox();        setModal(true);        setWindowTitle(tr("Promoted Widgets"));        setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

⌨️ 快捷键说明

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