⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formwindow.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    }    blockSignals(blocked);    emitSelectionChanged();}void FormWindow::layoutHorizontal(){    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), selectedWidgets(), LayoutInfo::HBox);    clearSelection(false);    commandHistory()->push(cmd);}void FormWindow::layoutVertical(){    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), selectedWidgets(), LayoutInfo::VBox);    clearSelection(false);    commandHistory()->push(cmd);}void FormWindow::layoutGrid(){    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), selectedWidgets(), LayoutInfo::Grid);    clearSelection(false);    commandHistory()->push(cmd);}void FormWindow::deleteWidgets(const QList<QWidget*> &widget_list){    if (widget_list.isEmpty())        return;    beginCommand(tr("Delete"));    foreach (QWidget *w, widget_list) {        emit widgetRemoved(w);        DeleteWidgetCommand *cmd = new DeleteWidgetCommand(this);        cmd->init(w);        m_commandHistory->push(cmd);    }    endCommand();}void FormWindow::deleteWidgets(){    QList<QWidget*> selection = selectedWidgets();    simplifySelection(&selection);    deleteWidgets(selection);}QString FormWindow::fileName() const{    return m_fileName;}void FormWindow::setFileName(const QString &fileName){    if (m_fileName == fileName)        return;    m_fileName = fileName;    emit fileNameChanged(fileName);}QString FormWindow::contents() const{    QBuffer b;    if (!b.open(QIODevice::WriteOnly))        return QString();    QDesignerResource resource(const_cast<FormWindow*>(this));    resource.save(&b, mainContainer());    return QString::fromUtf8(b.buffer());}void FormWindow::copy(){    QBuffer b;    if (!b.open(QIODevice::WriteOnly))        return;    QDesignerResource resource(this);    QList<QWidget*> sel = selectedWidgets();    simplifySelection(&sel);    resource.copy(&b, sel);    qApp->clipboard()->setText(QString::fromUtf8(b.buffer()), QClipboard::Clipboard);}void FormWindow::cut(){    copy();    deleteWidgets();}void FormWindow::paste(){    QWidget *w = mainContainer();    QList<QWidget*> l(selectedWidgets());    if (l.count() == 1) {        w = l.first();        if (LayoutInfo::layoutType(m_core, w) != LayoutInfo::NoLayout ||             (!core()->widgetDataBase()->isContainer(w) &&               w != mainContainer()))            w = mainContainer();    }    if (w && LayoutInfo::layoutType(m_core, w) == LayoutInfo::NoLayout) {        clearSelection(true);        QByteArray code = qApp->clipboard()->text().toUtf8();        QBuffer b(&code);        b.open(QIODevice::ReadOnly);        QDesignerResource resource(this);        QWidget *widget = core()->widgetFactory()->containerOfWidget(w);        QList<QWidget*> widgets = resource.paste(&b, widget);        beginCommand(tr("Paste"));        foreach (QWidget *w, widgets) {            InsertWidgetCommand *cmd = new InsertWidgetCommand(this);            cmd->init(w);            m_commandHistory->push(cmd);            selectWidget(w);        }        endCommand();        /* This will put the freshly pasted widgets into the clipboard, replacing the original.           The point here is that the copied widgets are shifted a little with respect to the original.           If the user presses paste again, the pasted widgets will be shifted again, rather than           appearing on top of the previously pasted widgets. */        copy();    } else {        QMessageBox::information(this, tr("Paste error"),                                  tr("Can't paste widgets. Designer couldn't find a container\n"                                      "to paste into which does not contain a layout. Break the layout\n"                                      "of the container you want to paste into and select this container\n"                                      "and then paste again."));    }}void FormWindow::manageWidget(QWidget *w){    if (isManaged(w))        return;    Q_ASSERT(qobject_cast<QMenu*>(w) == 0);    if (w->hasFocus())        setFocus();    core()->metaDataBase()->add(w);    m_insertedWidgets.insert(w);    m_widgets.append(w);    setCursorToAll(Qt::ArrowCursor, w);    if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(w))        manageWidget(promoted->child());    emit changed();    emit widgetManaged(w);}void FormWindow::unmanageWidget(QWidget *w){    if (!isManaged(w))        return;    if (usedSelections.contains(w))        usedSelections.value(w)->setWidget(0);    emit aboutToUnmanageWidget(w);    core()->metaDataBase()->remove(w);    m_insertedWidgets.remove(w);    m_widgets.removeAt(m_widgets.indexOf(w));    emit changed();    emit widgetUnmanaged(w);}bool FormWindow::isManaged(QWidget *w) const{    return m_insertedWidgets.contains(w);}void FormWindow::breakLayout(QWidget *w){    if (w == this)        w = mainContainer();    w = core()->widgetFactory()->containerOfWidget(w);    beginCommand(tr("Break layout"));    for (;;) {        if (!w || w == this)            break;        if (LayoutInfo::layoutType(m_core, core()->widgetFactory()->containerOfWidget(w)) != LayoutInfo::NoLayout                && core()->widgetDataBase()->isContainer(w, false)) {            if (BreakLayoutCommand *cmd = breakLayoutCommand(w)) {                commandHistory()->push(cmd);            }            if (!qobject_cast<QLayoutWidget*>(w) && !qobject_cast<QSplitter*>(w))                break;        }        w = w->parentWidget();    }    clearSelection(false);    endCommand();}BreakLayoutCommand *FormWindow::breakLayoutCommand(QWidget *w){    QList<QWidget*> widgets;    QListIterator<QObject*> it(w->children());    while (it.hasNext()) {        QObject *obj = it.next();        if (!obj->isWidgetType()                || !core()->metaDataBase()->item(obj))            continue;        widgets.append(static_cast<QWidget*>(obj));    }    Q_ASSERT(widgets.isEmpty() == false);    BreakLayoutCommand *cmd = new BreakLayoutCommand(this);    cmd->init(widgets, core()->widgetFactory()->widgetOfContainer(w));    return cmd;}void FormWindow::breakLayout(){    QWidget *w = currentWidget() ? currentWidget() : mainContainer();    if (LayoutInfo::layoutType(m_core, w) != LayoutInfo::NoLayout ||         w->parentWidget() && LayoutInfo::layoutType(m_core, w->parentWidget()) != LayoutInfo::NoLayout) {        breakLayout(w);        return;    } else {        QList<QWidget*> widgets = selectedWidgets();        QListIterator<QWidget*> it(widgets);        while (it.hasNext()) {            QWidget *w = it.next();            if (LayoutInfo::layoutType(m_core, w) != LayoutInfo::NoLayout ||                 w->parentWidget() && LayoutInfo::layoutType(m_core, w->parentWidget()) != LayoutInfo::NoLayout)                break;        }        if (w) {            breakLayout(w);            return;        }    }    w = mainContainer();    if (LayoutInfo::layoutType(m_core, w) != LayoutInfo::NoLayout ||         w->parentWidget() && LayoutInfo::layoutType(m_core, w->parentWidget()) != LayoutInfo::NoLayout)        breakLayout(w);}void FormWindow::beginCommand(const QString &description){    m_commandHistory->push(new QtCommand(QtCommand::MacroBegin, description));}void FormWindow::endCommand(){    m_commandHistory->push(new QtCommand(QtCommand::MacroEnd, QString()));}void FormWindow::raiseWidgets(){    QList<QWidget*> widgets = selectedWidgets();    simplifySelection(&widgets);    foreach (QWidget *widget, widgets) {        widget->raise();    }}void FormWindow::lowerWidgets(){    QList<QWidget*> widgets = selectedWidgets();    simplifySelection(&widgets);    foreach (QWidget *widget, widgets) {        widget->lower();    }}bool FormWindow::handleMouseButtonDblClickEvent(QWidget *, QWidget *managedWidget, QMouseEvent *e){    e->accept();    clearSelection(false);    selectWidget(managedWidget);    emit activated(managedWidget);    return true;}void FormWindow::finishContextMenu(QWidget *w, QWidget *, QContextMenuEvent *e){    e->accept();    QDesignerTaskMenuExtension *taskMenu = qt_extension<QDesignerTaskMenuExtension*>(core()->extensionManager(), w);    QMenu *menu = createPopupMenu(w);    if (menu && taskMenu) {        QList<QAction *> acts = taskMenu->taskActions();        QAction *sep = new QAction(menu);        sep->setSeparator(true);        acts.append(sep);        menu->insertActions(menu->actions().at(0), acts);    }    if (menu) {        emit contextMenuRequested(menu, w);        menu->exec(e->globalPos());        delete menu;    }}bool FormWindow::handleContextMenu(QWidget *, QWidget *managedWidget, QContextMenuEvent *e){    e->accept();    bool selected = isWidgetSelected(managedWidget);    if (selected == false) {        clearSelection(false);        selectWidget(managedWidget);        raiseChildSelections(managedWidget); // raise selections and select widget        QMetaObject::invokeMethod(core()->formWindowManager(), "slotUpdateActions");    }    if (!isMainContainer(managedWidget)) { // press on a child widget        // if widget is laid out, find the first non-laid out super-widget        QWidget *realWidget = managedWidget; // but store the original one        QMainWindow *mw = qobject_cast<QMainWindow*>(mainContainer());        if (mw && mw->centralWidget() == realWidget) {            finishContextMenu(managedWidget, this, e);        } else {            finishContextMenu(realWidget, realWidget, e);        }    } else {        finishContextMenu(mainContainer(), mainContainer(), e);    }    return true;}void FormWindow::setContents(QIODevice *dev){    bool saved = updatesEnabled();    setUpdatesEnabled(false);    clearSelection();    if (mainContainer()) {        core()->metaDataBase()->remove(mainContainer());        delete mainContainer();        m_mainContainer = 0;    }    m_insertedWidgets.clear();    m_widgets.clear();    emit changed();    QDesignerResource r(this);    QWidget *w = r.load(dev, this);    if (w == 0) {        setFileName(QString());        w = core()->widgetFactory()->createWidget(QLatin1String("QWidget"), this);        w->resize(400, 300);    }    setMainContainer(w);    setUpdatesEnabled(saved);}void FormWindow::setContents(const QString &contents){    QByteArray data = contents.toUtf8();    QBuffer b(&data);    if (b.open(QIODevice::ReadOnly))        setContents(&b);}void FormWindow::layoutHorizontalContainer(QWidget *w){    if (w == this)        w = mainContainer();    w = core()->widgetFactory()->containerOfWidget(w);    QList<QObject*> l = w->children();    if (l.isEmpty())        return;    QList<QWidget*> widgets;    QListIterator<QObject*> it(l);    while (it.hasNext()) {        QObject* o = it.next();        if (!o->isWidgetType())            continue;        QWidget *widget = static_cast<QWidget*>(o);        if (widget->isVisibleTo(this) && isManaged(widget))            widgets.append(widget);    }    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), widgets, LayoutInfo::HBox, w);    clearSelection(false);    commandHistory()->push(cmd);}void FormWindow::layoutVerticalContainer(QWidget *w){    if (w == this)        w = mainContainer();    w = core()->widgetFactory()->containerOfWidget(w);    QList<QObject*> l = w->children();    if (l.isEmpty())        return;    QListIterator<QObject*> it(l);    QList<QWidget*> widgets;    while (it.hasNext()) {        QObject* o = it.next();        if (!o->isWidgetType())            continue;        QWidget *widget = static_cast<QWidget*>(o);        if (widget->isVisibleTo(this) && isManaged(widget))            widgets.append(widget);    }    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), widgets, LayoutInfo::VBox, w);    clearSelection(false);    commandHistory()->push(cmd);}void FormWindow::layoutGridContainer(QWidget *w){    if (w == this)        w = mainContainer();    w = core()->widgetFactory()->containerOfWidget(w);    QList<QObject*> l = w->children();    if (l.isEmpty())        return;    QList<QWidget*> widgets;    QListIterator<QObject*> it(l);    while (it.hasNext()) {        QObject* o = it.next();        if (!o->isWidgetType())            continue;        QWidget *widget = static_cast<QWidget*>(o);        if (widget->isVisibleTo(this) && isManaged(widget))            widgets.append(widget);    }    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), widgets, LayoutInfo::Grid, w);    clearSelection(false);    commandHistory()->push(cmd);}bool FormWindow::hasInsertedChildren(QWidget *widget) const // ### move{    if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), widget)) {        widget = container->widget(container->currentIndex());    }    QList<QWidget*> l = widgets(widget);    foreach (QWidget *child, l) {        if (isManaged(child) && !LayoutInfo::isWidgetLaidout(core(), child) && child->isVisibleTo(const_cast<FormWindow*>(this)))            return true;    }    return false;}void FormWindow::layoutHorizontalSplit(){    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), selectedWidgets(), LayoutInfo::HBox, /*layoutBase=*/ 0, /*splitter=*/ true);    clearSelection(false);    commandHistory()->push(cmd);}void FormWindow::layoutVerticalSplit(){    LayoutCommand *cmd = new LayoutCommand(this);    cmd->init(mainContainer(), selectedWidgets(), LayoutInfo::VBox, /*layoutBase=*/ 0, /*splitter=*/ true);    clearSelection(false);    commandHistory()->push(cmd);}QMenu *FormWindow::createPopupMenu(QWidget *w){    QDesignerFormWindowManagerInterface *manager = core()->formWindowManager();    bool isFormWindow = qobject_cast<FormWindow*>(w);    QMenu *popup = new QMenu(this);    if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(w))        w = promoted->child();    if (qobject_cast<QDesignerTabWidget*>(w)) {        QDesignerTabWidget *tabWidget = static_cast<QDesignerTabWidget*>(w);        if (tabWidget->count()) {            popup->addAction(tabWidget->actionDeletePage());        }        QMenu *insertPageMenu = popup->addMenu(tr("Insert Page"));        insertPageMenu->addAction(tabWidget->actionInsertPageAfter());        insertPageMenu->addAction(tabWidget->actionInsertPage());        popup->addSeparator();    } else if (qobject_cast<QDesignerStackedWidget*>(w)) {        QDesignerStackedWidget *stackedWidget = static_cast<QDesignerStackedWidget*>(w);        if (stackedWidget->count()) {            popup->addAction(stackedWidget->actionDeletePage());        }        QMenu *insertPageMenu = popup->addMenu(tr("Insert Page"));        insertPageMenu->addAction(stackedWidget->actionInsertPageAfter());        insertPageMenu->addAction(stackedWidget->actionInsertPage());

⌨️ 快捷键说明

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