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

📄 q3dockwindow.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    \value InDock  Inside a Q3DockArea.    \value OutsideDock  Floating as a top level window on the desktop.*//*!    \enum Q3DockWindow::CloseMode    This enum type specifies when (if ever) a dock window has a close    button.    \value Never  The dock window never has a close button and cannot    be closed by the user.    \value Docked  The dock window has a close button only when    docked.    \value Undocked  The dock window has a close button only when    floating.    \value Always The dock window always has a close button.    \omit    Note that dock windows can always be minimized if the user clicks    their dock window handle when they are docked.    \endomit*//*!    \fn void Q3DockWindow::setHorizontalStretchable(bool b)    If \a b is true the dock window is set to be horizontally    stretchable.*//*!    \fn void Q3DockWindow::setVerticalStretchable(bool b)    If \a b is true the dock window is set to be vertically    stretchable.*//*!    \fn bool Q3DockWindow::isHorizontalStretchable() const    Returns true if the dock window can be stretched horizontally;    otherwise returns false.*//*!    \fn bool Q3DockWindow::isVerticalStretchable() const    Returns true if the dock window can be stretched vertically;    otherwise returns false.*//*!    \fn void Q3DockWindow::orientationChanged(Qt::Orientation o)    This signal is emitted when the orientation of the dock window is    changed. The new orientation is \a o.*//*!    \fn void Q3DockWindow::placeChanged(Q3DockWindow::Place p)    This signal is emitted when the dock window is docked (\a p is \c    InDock), undocked (\a p is \c OutsideDock) or moved inside the    the dock area.    \sa Q3DockArea::moveDockWindow(), Q3DockArea::removeDockWindow(),    Q3MainWindow::moveDockWindow(), Q3MainWindow::removeDockWindow()*//*!    \fn void Q3DockWindow::visibilityChanged(bool visible)    This signal is emitted when the visibility of the dock window    relatively to its dock area is changed. If \a visible is true, the    Q3DockWindow is now visible to the dock area, otherwise it has been    hidden.    A dock window can be hidden if it has a close button which the    user has clicked. In the case of a Q3MainWindow a dock window can    have its visibility changed (hidden or shown) by clicking its name    in the dock window menu that lists the Q3MainWindow's dock windows.*//*!    \fn Q3DockArea *Q3DockWindow::area() const    Returns the dock area in which this dock window is docked, or 0 if    the dock window is floating.*//*!    \property Q3DockWindow::place    \brief the location where the dock window is placed    This is either \c InDock or \c OutsideDock.    \sa Q3DockArea::moveDockWindow(), Q3DockArea::removeDockWindow(),        Q3MainWindow::moveDockWindow(), Q3MainWindow::removeDockWindow()*//*!    Constructs a Q3DockWindow with parent \a parent, called \a name and    with widget flags \a f.*/Q3DockWindow::Q3DockWindow(QWidget* parent, const char* name, Qt::WindowFlags f)    : Q3Frame(parent, name, f | Qt::WType_Dialog | Qt::WStyle_Customize | Qt::WStyle_NoBorder){    curPlace = InDock;    isToolbar = false;    init();}/*!    Constructs a Q3DockWindow with parent \a parent, called \a name and    with widget flags \a f.    If \a p is \c InDock, the dock window is docked into a dock area    and \a parent \e must be a Q3DockArea or a Q3MainWindow. If the \a    parent is a Q3MainWindow the dock window will be docked in the main    window's \c Top dock area.    If \a p is \c OutsideDock, the dock window is created as a floating    window.    We recommend creating the dock area \c InDock with a Q3MainWindow    as parent then calling Q3MainWindow::moveDockWindow() to move the    dock window where you want it.*/Q3DockWindow::Q3DockWindow(Place p, QWidget *parent, const char *name, Qt::WindowFlags f)    : Q3Frame(parent, name, f | Qt::WType_Dialog | Qt::WStyle_Customize | Qt::WStyle_NoBorder){    curPlace = p;    isToolbar = false;    init();}/*! \internal*/Q3DockWindow::Q3DockWindow(Place p, QWidget *parent, const char *name, Qt::WindowFlags f, bool toolbar)    : Q3Frame(parent, name, f | Qt::WType_Dialog | Qt::WStyle_Customize | Qt::WStyle_NoBorder){    curPlace = p;    isToolbar = toolbar;    init();}class Q3DockWindowGridLayout : public QGridLayout{public:    Q3DockWindowGridLayout(QWidget *parent, int nRows, int nCols)        : QGridLayout(parent, nRows, nCols) {};    Qt::Orientations expandingDirections() const    {        return 0;    }};void Q3DockWindow::init(){    wid = 0;    rubberBand = 0;    dockArea = 0;    tmpDockArea = 0;    resizeEnabled = false;    moveEnabled = true;    nl = false;    opaque = default_opaque;    cMode = Never;    offs = 0;    fExtent = QSize(-1, -1);    dockWindowData = 0;    lastPos = QPoint(-1, -1);    lastSize = QSize(-1, -1);    stretchable[Qt::Horizontal] = false;    stretchable[Qt::Vertical] = false;    widgetResizeHandler = new QWidgetResizeHandler(this);    widgetResizeHandler->setMovingEnabled(false);    titleBar      = new Q3DockWindowTitleBar(this);    verHandle     = new Q3DockWindowHandle(this);    verHandle->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));    horHandle     = new Q3DockWindowHandle(this);    horHandle->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));    vHandleLeft   = new Q3DockWindowResizeHandle(Qt::Vertical, this, this, "vert. handle");    vHandleRight  = new Q3DockWindowResizeHandle(Qt::Vertical, this, this, "vert. handle");    hHandleTop    = new Q3DockWindowResizeHandle(Qt::Horizontal, this, this, "horz. handle");    hHandleBottom = new Q3DockWindowResizeHandle(Qt::Horizontal, this, this, "horz. handle");    // Creating inner layout    hbox          = new QVBoxLayout();    vbox          = new QHBoxLayout();    childBox          = new QBoxLayout(QBoxLayout::LeftToRight);    vbox->addSpacing(2);    vbox->addWidget(verHandle);    vbox->addStretch(0);    vbox->addLayout(childBox, 1);    vbox->addStretch(0);    hbox->setResizeMode(QLayout::FreeResize);    hbox->setMargin(isResizeEnabled() || curPlace == OutsideDock ? 2 : 0);    hbox->setSpacing(1);    hbox->addWidget(titleBar);    hbox->addWidget(horHandle);    hbox->addLayout(vbox);    // Set up the initial handle layout for Qt::Vertical    // Handle layout will change on calls to setOrienation()    QGridLayout *glayout = new Q3DockWindowGridLayout(this, 3, 3);    glayout->setResizeMode(QLayout::Minimum);    glayout->addMultiCellWidget(hHandleTop,    0, 0, 1, 1);    glayout->addMultiCellWidget(hHandleBottom, 2, 2, 1, 1);    glayout->addMultiCellWidget(vHandleLeft,   0, 2, 0, 0);    glayout->addMultiCellWidget(vHandleRight,  0, 2, 2, 2);    glayout->addLayout(hbox, 1, 1);    glayout->setRowStretch(1, 1);    glayout->setColStretch(1, 1);    hHandleBottom->hide();    vHandleRight->hide();    hHandleTop->hide();    vHandleLeft->hide();    setFrameStyle(Q3Frame::StyledPanel | Q3Frame::Raised);    setLineWidth(2);    if (parentWidget())        parentWidget()->installEventFilter(this);    QWidget *mw = parentWidget();    Q3DockArea *da = qobject_cast<Q3DockArea*>(parentWidget());    if (da) {        if (curPlace == InDock)            da->moveDockWindow(this);        mw = da->parentWidget();    }    if (qobject_cast<Q3MainWindow*>(mw)) {        if (place() == InDock) {            Qt::Dock myDock = Qt::DockTop;            // make sure we put the window in the correct dock.            if (dockArea) {                Q3MainWindow *mainw = (Q3MainWindow*)mw;                // I'm not checking if it matches the top because I've                // done the assignment to it above.                if (dockArea == mainw->leftDock())                    myDock = Qt::DockLeft;                else if (dockArea == mainw->rightDock())                    myDock = Qt::DockRight;                else if (dockArea == mainw->bottomDock())                    myDock = Qt::DockBottom;            }            ((Q3MainWindow*)mw)->addDockWindow(this, myDock);        }        moveEnabled = ((Q3MainWindow*)mw)->dockWindowsMovable();        opaque = ((Q3MainWindow*)mw)->opaqueMoving();    }    updateGui();    connect(titleBar, SIGNAL(doubleClicked()), this, SLOT(dock()));    connect(verHandle, SIGNAL(doubleClicked()), this, SLOT(undock()));    connect(horHandle, SIGNAL(doubleClicked()), this, SLOT(undock()));    connect(this, SIGNAL(orientationChanged(Qt::Orientation)),             this, SLOT(setOrientation(Qt::Orientation)));}/*!    Sets the orientation of the dock window to \a o. The orientation    is propagated to the layout boxLayout().    \warning All undocked Q3ToolBars will always have a horizontal orientation.*/void Q3DockWindow::setOrientation(Qt::Orientation o){    QGridLayout *glayout = (QGridLayout*)layout();    glayout->removeWidget(hHandleTop);    glayout->removeWidget(hHandleBottom);    glayout->removeWidget(vHandleLeft);    glayout->removeWidget(vHandleRight);    if (o == Qt::Horizontal) {        // Set up the new layout as        //   3 3 3      1 = vHandleLeft   4 = hHandleBottom        //   1 X 2      2 = vHandleRight  X = Inner Layout        //   4 4 4      3 = hHandleTop        glayout->addMultiCellWidget(hHandleTop,    0, 0, 0, 2);        glayout->addMultiCellWidget(hHandleBottom, 2, 2, 0, 2);        glayout->addMultiCellWidget(vHandleLeft,   1, 1, 0, 0);        glayout->addMultiCellWidget(vHandleRight,  1, 1, 2, 2);    } else {        // Set up the new layout as        //   1 3 2      1 = vHandleLeft   4 = hHandleBottom        //   1 X 2      2 = vHandleRight  X = Inner Layout        //   1 4 2      3 = hHandleTop        glayout->addMultiCellWidget(hHandleTop,    0, 0, 1, 1);        glayout->addMultiCellWidget(hHandleBottom, 2, 2, 1, 1);        glayout->addMultiCellWidget(vHandleLeft,   0, 2, 0, 0);        glayout->addMultiCellWidget(vHandleRight,  0, 2, 2, 2);    }    boxLayout()->setDirection(o == Qt::Horizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);    QApplication::sendPostedEvents(this, QEvent::LayoutHint);    QEvent *e = new QEvent(QEvent::LayoutHint);    QApplication::postEvent(this, e);}/*!    Destroys the dock window and its child widgets.*/Q3DockWindow::~Q3DockWindow(){    qApp->removeEventFilter(this);    if (area())        area()->removeDockWindow(this, false, false);    Q3DockArea *a = area();    if (!a && dockWindowData)        a = ((Q3DockArea::DockWindowData*)dockWindowData)->area;    Q3MainWindow *mw = a ? qobject_cast<Q3MainWindow*>(a->parentWidget()) : 0;    if (mw)        mw->removeDockWindow(this);    delete (Q3DockArea::DockWindowData*)dockWindowData;}/*!  \reimp*/void Q3DockWindow::resizeEvent(QResizeEvent *e){    Q3Frame::resizeEvent(e);    updateGui();}void Q3DockWindow::swapRect(QRect &r, Qt::Orientation o, const QPoint &offset, Q3DockArea *){    r.setSize(QSize(r.height(), r.width()));    bool reverse = QApplication::reverseLayout();    if (o == Qt::Horizontal)        r.moveBy(-r.width()/2, 0);    else        r.moveBy(reverse ? - r.width() : 0, -r.height() / 2 );    r.moveBy(offset.x(), offset.y());}QWidget *Q3DockWindow::areaAt(const QPoint &gp){    QWidget *w = qApp->widgetAt(gp);    if (w && (w == this || w == titleBar) && parentWidget())        w = parentWidget()->childAt(parentWidget()->mapFromGlobal(gp));    while (w) {        if (qobject_cast<Q3DockArea*>(w)) {            Q3DockArea *a = (Q3DockArea*)w;            if (a->isDockWindowAccepted(this))                return w;        }        if (qobject_cast<Q3MainWindow*>(w)) {            Q3MainWindow *mw = (Q3MainWindow*)w;            Q3DockArea *a = mw->dockingArea(mw->mapFromGlobal(gp));            if (a && a->isDockWindowAccepted(this))                return a;        }        w = w->isWindow() ? 0 : (QWidget *)w->parent();    }    return 0;}void Q3DockWindow::handleMove(const QPoint &pos, const QPoint &gp, bool drawRect){    if (!rubberBand)        return;    currRect = QRect(realWidgetPos(this), size());    QWidget *w = areaAt(gp);    if (titleBar->ctrlDown || horHandle->ctrlDown || verHandle->ctrlDown)        w = 0;    currRect.moveBy(pos.x(), pos.y());    if (!qobject_cast<Q3DockArea*>(w)) {        if (startOrientation != Qt::Horizontal && qobject_cast<Q3ToolBar*>(this))            swapRect(currRect, Qt::Horizontal, startOffset, (Q3DockArea*)w);        if (drawRect) {            rubberBand->setGeometry(currRect);        } else {            QPoint mp(mapToGlobal(pos));            if(place() == InDock) {                undock();                if(titleBar) {                    mp = QPoint(titleBar->width() / 2, titleBar->height() / 2);                    QMouseEvent me(QEvent::MouseButtonPress, mp, Qt::LeftButton, 0);                    QApplication::sendEvent(titleBar, &me);                    mp = titleBar->mapToGlobal(mp);                }            }            move(mp);        }        state = OutsideDock;        return;    }    Q3DockArea *area = (Q3DockArea*)w;    if(area->isVisible()) {        state = InDock;        Qt::Orientation o = (area ? area->orientation() :                          (boxLayout()->direction() == QBoxLayout::LeftToRight ||                            boxLayout()->direction() == QBoxLayout::RightToLeft ?                            Qt::Horizontal : Qt::Vertical));        if (startOrientation != o)            swapRect(currRect, o, startOffset, area);        if (drawRect) {            rubberBand->setGeometry(currRect);        }        tmpDockArea = area;    }}void Q3DockWindow::updateGui(){    if (curPlace == OutsideDock) {        hbox->setMargin(2);

⌨️ 快捷键说明

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