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

📄 widgetselection.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 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://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "widgetselection.h"#include "formwindow.h"#include "formwindowmanager.h"// sdk#include <QtDesigner/QtDesigner>#include <QtDesigner/QExtensionManager>// shared#include <qdesigner_command_p.h>#include <layout_p.h>#include <layoutinfo_p.h>#include <QtGui/QMenu>#include <QtGui/QWidget>#include <QtGui/QApplication>#include <QtGui/QLabel>#include <QtGui/QPainter>#include <QtGui/QMouseEvent>#include <QtGui/QStylePainter>#include <QtGui/QGridLayout>#include <QtCore/QVariant>#include <QtCore/qdebug.h>#define NO_TOPWIDGET#ifndef Q_MOC_RUNusing namespace qdesigner_internal;#endifclass TopWidget: public InvisibleWidget{    Q_OBJECTpublic:    TopWidget(QWidget *parent)        : InvisibleWidget(parent)    {        setAttribute(Qt::WA_TransparentForMouseEvents);    }};WidgetHandle::WidgetHandle(FormWindow *parent, WidgetHandle::Type t, WidgetSelection *s)    : InvisibleWidget(parent){    active = true;    widget = 0;    type = t;    setMouseTracking(false);    formWindow = parent;    sel = s;    setAutoFillBackground(true);    if (type == TaskMenu) {        setBackgroundRole(QPalette::Button);        setFixedSize(12, 12);    } else {        setBackgroundRole(active ? QPalette::Text : QPalette::Dark);        setFixedSize(6, 6);    }    updateCursor();}void WidgetHandle::updateCursor(){    if (!active) {        setCursor(Qt::ArrowCursor);        return;    }    switch (type) {    case LeftTop:        setCursor(Qt::SizeFDiagCursor);        break;    case Top:        setCursor(Qt::SizeVerCursor);        break;    case RightTop:        setCursor(Qt::SizeBDiagCursor);        break;    case Right:        setCursor(Qt::SizeHorCursor);        break;    case RightBottom:        setCursor(Qt::SizeFDiagCursor);        break;    case Bottom:        setCursor(Qt::SizeVerCursor);        break;    case LeftBottom:        setCursor(Qt::SizeBDiagCursor);        break;    case Left:        setCursor(Qt::SizeHorCursor);        break;    case TaskMenu:        setCursor(Qt::ArrowCursor);        break;    default:        Q_ASSERT(0);    }}QDesignerFormEditorInterface *WidgetHandle::core() const{    if (QDesignerFormWindowInterface *fw = formWindow)        return fw->core();    return 0;}void WidgetHandle::setActive(bool a){    active = a;    if (type != TaskMenu) {        setBackgroundRole(active ? QPalette::Text : QPalette::Dark);    }    updateCursor();}void WidgetHandle::setWidget(QWidget *w){    widget = w;}void WidgetHandle::paintEvent(QPaintEvent *){    FormWindow *fw = formWindow;    QDesignerFormWindowManagerInterface *m = fw->core()->formWindowManager();    QStylePainter p(this);    if (type == TaskMenu) {        QStyleOptionToolButton option;        option.init(this);        option.state |= QStyle::State_Raised;        option.arrowType = Qt::RightArrow;        option.toolButtonStyle = Qt::ToolButtonIconOnly;        option.features = QStyleOptionToolButton::Arrow;        option.subControls = QStyle::SC_ToolButton;        p.drawComplexControl(QStyle::CC_ToolButton, option);    } else if (fw->currentWidget() == widget) {        p.setPen(m->activeFormWindow() == fw ? Qt::blue : Qt::red);        p.drawRect(0, 0, width() - 1, height() - 1);    }}void WidgetHandle::mousePressEvent(QMouseEvent *e){    e->accept();    if (!formWindow->hasFeature(FormWindow::EditFeature))        return;    if (!(widget && e->button() == Qt::LeftButton))        return;    if (!(active || type == TaskMenu))        return;    QWidget *container = widget->parentWidget();    oldPressPos = container->mapFromGlobal(e->globalPos());    geom = origGeom = widget->geometry();    if (type == TaskMenu && e->button() == Qt::LeftButton) {        Q_ASSERT(sel->taskMenuExtension());        QMenu m(this);        foreach (QAction *a, sel->taskMenuExtension()->taskActions()) {            m.addAction(a);        }        m.exec(e->globalPos());    }}int WidgetHandle::adjustPoint(int x, int dx){ return (x / dx) * dx + 1; }void WidgetHandle::mouseMoveEvent(QMouseEvent *e){    if (!(widget && active && e->buttons() & Qt::LeftButton))        return;    if (type == TaskMenu)        return;    e->accept();    QWidget *container = widget->parentWidget();    QPoint rp = container->mapFromGlobal(e->globalPos());    QPoint d = rp - oldPressPos;    oldPressPos = rp;    QRect pr = container->rect();    QPoint grid = formWindow->grid();    switch (type) {    case TaskMenu:        break;    case LeftTop: {        if (rp.x() > pr.width() - 2 * width() || rp.y() > pr.height() - 2 * height())            return;        int w = geom.width() - d.x();        geom.setWidth(w);        w = adjustPoint(w, grid.x());        int h = geom.height() - d.y();        geom.setHeight(h);        h = adjustPoint(h, grid.y());        int dx = widget->width() - w;        int dy = widget->height() - h;        trySetGeometry(widget, widget->x() + dx, widget->y() + dy, w, h);    } break;    case Top: {        if (rp.y() > pr.height() - 2 * height())            return;        int h = geom.height() - d.y();        geom.setHeight(h);        h = adjustPoint(h, grid.y());        int dy = widget->height() - h;        trySetGeometry(widget, widget->x(), widget->y() + dy, widget->width(), h);    } break;    case RightTop: {        if (rp.x() < 2 * width() || rp.y() > pr.height() - 2 * height())            return;        int h = geom.height() - d.y();        geom.setHeight(h);        h = adjustPoint(h, grid.y());        int dy = widget->height() - h;        int w = geom.width() + d.x();        geom.setWidth(w);        w = adjustPoint(w, grid.x());        trySetGeometry(widget, widget->x(), widget->y() + dy, w, h);    } break;    case Right: {        if (rp.x() < 2 * width())            return;        int w = geom.width() + d.x();        geom.setWidth(w);        w = adjustPoint(w, grid.x());        tryResize(widget, w, widget->height());    } break;    case RightBottom: {        if (rp.x() < 2 * width() || rp.y() < 2 * height())            return;        int w = geom.width() + d.x();        geom.setWidth(w);        w = adjustPoint(w, grid.x());        int h = geom.height() + d.y();        geom.setHeight(h);        h = adjustPoint(h, grid.y());        tryResize(widget, w, h);    } break;    case Bottom: {        if (rp.y() < 2 * height())            return;        int h = geom.height() + d.y();        geom.setHeight(h);        h = adjustPoint(h, grid.y());        tryResize(widget, widget->width(), h);    } break;    case LeftBottom: {        if (rp.x() > pr.width() - 2 * width() || rp.y() < 2 * height())            return;        int w = geom.width() - d.x();        geom.setWidth(w);        w = adjustPoint(w, grid.x());        int h = geom.height() + d.y();        geom.setHeight(h);        h = adjustPoint(h, grid.y());        int dx = widget->width() - w;        trySetGeometry(widget, widget->x() + dx, widget->y(), w, h);    } break;    case Left: {        if (rp.x() > pr.width() - 2 * width())            return;        int w = geom.width() - d.x();        geom.setWidth(w);        w = adjustPoint(w, grid.x());        int dx = widget->width() - w;        trySetGeometry(widget, widget->x() + dx, widget->y(), w, widget->height());    } break;    default: break;    } // end switch    sel->updateGeometry();    if (LayoutInfo::layoutType(formWindow->core(), widget) != LayoutInfo::NoLayout)        formWindow->updateChildSelections(widget);}void WidgetHandle::mouseReleaseEvent(QMouseEvent *e){    if (e->button() != Qt::LeftButton || !active)        return;    if (type == TaskMenu)        return;    e->accept();    if (!formWindow->hasFeature(FormWindow::EditFeature))        return;

⌨️ 快捷键说明

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