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

📄 qworkspace.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            default:                break;            }        }    } else {        e->ignore();    }}void QWorkspaceTitleBar::mouseMoveEvent(QMouseEvent *e){    Q_D(QWorkspaceTitleBar);    e->ignore();    if ((e->buttons() & Qt::LeftButton) && style()->styleHint(QStyle::SH_TitleBar_NoBorder, 0, 0)        && !rect().adjusted(5, 5, -5, 0).contains(e->pos()) && !d->pressed) {        // propagate border events to the QWidgetResizeHandler        return;    }    QStyleOptionTitleBar opt = d->getStyleOption();    QStyle::SubControl under_mouse = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,                                                                    e->pos(), this);    if(under_mouse != d->lastControl) {        d->lastControl = under_mouse;        update();    }    switch (d->buttonDown) {    case QStyle::SC_None:        break;    case QStyle::SC_TitleBarSysMenu:        break;    case QStyle::SC_TitleBarLabel:        if (d->buttonDown == QStyle::SC_TitleBarLabel && d->movable && d->pressed) {            if ((d->moveOffset - mapToParent(e->pos())).manhattanLength() >= 4) {                QPoint p = mapFromGlobal(e->globalPos());                QWidget *parent = d->window ? d->window->parentWidget() : 0;                if(parent && parent->inherits("QWorkspaceChild")) {                    QWidget *workspace = parent->parentWidget();                    p = workspace->mapFromGlobal(e->globalPos());                    if (!workspace->rect().contains(p)) {                        if (p.x() < 0)                            p.rx() = 0;                        if (p.y() < 0)                            p.ry() = 0;                        if (p.x() > workspace->width())                            p.rx() = workspace->width();                        if (p.y() > workspace->height())                            p.ry() = workspace->height();                    }                }                QPoint pp = p - d->moveOffset;                if (!parentWidget()->isMaximized())                    parentWidget()->move(pp);            }        }        e->accept();        break;    default:        break;    }}bool QWorkspaceTitleBar::isTool() const{    Q_D(const QWorkspaceTitleBar);    return (d->flags & Qt::WindowType_Mask) == Qt::Tool;}// from qwidget.cppextern QString qt_setWindowTitle_helperHelper(const QString &, QWidget*);void QWorkspaceTitleBar::paintEvent(QPaintEvent *){    Q_D(QWorkspaceTitleBar);    QStyleOptionTitleBar opt = d->getStyleOption();    opt.subControls = QStyle::SC_TitleBarLabel;    opt.activeSubControls = d->buttonDown;    if (d->window) {        QString title = qt_setWindowTitle_helperHelper(opt.text, d->window);        QFontMetrics fm(fontMetrics());        int maxw = style()->subControlRect(QStyle::CC_TitleBar, &opt, QStyle::SC_TitleBarLabel,                                       this).width();        QString cuttitle = title;        if (fm.width(title + "m") > maxw) {            int i = title.length();            int dotlength = fm.width("...");            while (i>0 && fm.width(title.left(i)) + dotlength > maxw)                i--;            if(i != (int)title.length())                cuttitle = title.left(i) + "...";        }        opt.text = cuttitle;    }    if (d->flags & Qt::WindowSystemMenuHint) {        opt.subControls |= QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarCloseButton;        if (d->window && (d->flags & Qt::WindowShadeButtonHint)) {            if (d->window->isMinimized())                opt.subControls |= QStyle::SC_TitleBarUnshadeButton;            else                opt.subControls |= QStyle::SC_TitleBarShadeButton;        }        if (d->window && (d->flags & Qt::WindowMinMaxButtonsHint)) {            if(d->window && d->window->isMinimized())                opt.subControls |= QStyle::SC_TitleBarNormalButton;            else                opt.subControls |= QStyle::SC_TitleBarMinButton;        }        if (d->window && (d->flags & Qt::WindowMaximizeButtonHint) && !d->window->isMaximized())            opt.subControls |= QStyle::SC_TitleBarMaxButton;    }    QStyle::SubControl under_mouse = QStyle::SC_None;    under_mouse = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,                                                     mapFromGlobal(QCursor::pos()), this);    if ((d->buttonDown == under_mouse) && d->pressed) {        opt.state |= QStyle::State_Sunken;    } else if( autoRaise() && under_mouse != QStyle::SC_None && !d->pressed) {        opt.activeSubControls = under_mouse;        opt.state |= QStyle::State_MouseOver;    }    opt.palette.setCurrentColorGroup(usesActiveColor() ? QPalette::Active : QPalette::Inactive);    QPainter p(this);    style()->drawComplexControl(QStyle::CC_TitleBar, &opt, &p, this);}void QWorkspaceTitleBar::mouseDoubleClickEvent(QMouseEvent *e){    Q_D(QWorkspaceTitleBar);    if (e->button() != Qt::LeftButton) {        e->ignore();        return;    }    e->accept();    QStyleOptionTitleBar opt = d->getStyleOption();    switch (style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this)) {    case QStyle::SC_TitleBarLabel:        emit doubleClicked();        break;    case QStyle::SC_TitleBarSysMenu:        if (d->flags & Qt::WindowSystemMenuHint)            emit doClose();        break;    default:        break;    }}void QWorkspaceTitleBar::leaveEvent(QEvent *){    Q_D(QWorkspaceTitleBar);    d->lastControl = QStyle::SC_None;    if(autoRaise() && !d->pressed)        update();}void QWorkspaceTitleBar::enterEvent(QEvent *){    Q_D(QWorkspaceTitleBar);    if(autoRaise() && !d->pressed)        update();    QEvent e(QEvent::Leave);    QApplication::sendEvent(parentWidget(), &e);}void QWorkspaceTitleBar::setActive(bool active){    Q_D(QWorkspaceTitleBar);    if (d->act == active)        return ;    d->act = active;    update();}bool QWorkspaceTitleBar::isActive() const{    Q_D(const QWorkspaceTitleBar);    return d->act;}bool QWorkspaceTitleBar::usesActiveColor() const{    return (isActive() && isActiveWindow()) ||        (!window() && QWidget::window()->isActiveWindow());}QWidget *QWorkspaceTitleBar::window() const{    Q_D(const QWorkspaceTitleBar);    return d->window;}bool QWorkspaceTitleBar::event(QEvent *e){    Q_D(QWorkspaceTitleBar);    if (e->type() == QEvent::ApplicationPaletteChange) {        d->readColors();    } else if (e->type() == QEvent::WindowActivate               || e->type() == QEvent::WindowDeactivate) {        if (d->act)            update();    }    return QWidget::event(e);}void QWorkspaceTitleBar::setMovable(bool b){    Q_D(QWorkspaceTitleBar);    d->movable = b;}bool QWorkspaceTitleBar::isMovable() const{    Q_D(const QWorkspaceTitleBar);    return d->movable;}void QWorkspaceTitleBar::setAutoRaise(bool b){    Q_D(QWorkspaceTitleBar);    d->autoraise = b;}bool QWorkspaceTitleBar::autoRaise() const{    Q_D(const QWorkspaceTitleBar);    return d->autoraise;}QSize QWorkspaceTitleBar::sizeHint() const{    Q_D(const QWorkspaceTitleBar);    ensurePolished();    QStyleOptionTitleBar opt = d->getStyleOption();    QRect menur = style()->subControlRect(QStyle::CC_TitleBar, &opt,                                          QStyle::SC_TitleBarSysMenu, this);    return QSize(menur.width(), style()->pixelMetric(QStyle::PM_TitleBarHeight, &opt, this));}/*!    \class QWorkspace    \brief The QWorkspace widget provides a workspace window that can be    used in an MDI application.    \ingroup application    Multiple Document Interface (MDI) applications are typically    composed of a main window containing a menu bar, a toolbar, and    a central QWorkspace widget. The workspace itself is used to display    a number of child windows, each of which is a widget.    The workspace itself is an ordinary Qt widget. It has a standard    constructor that takes a parent widget.    Workspaces can be placed in any layout, but are typically given    as the central widget in a QMainWindow:    \quotefromfile mainwindows/mdi/mainwindow.cpp    \skipto MainWindow::MainWindow()    \printuntil setCentralWidget(workspace);    \dots    \skipto /^\}/    \printuntil /^\}/    Child windows (MDI windows) are standard Qt widgets that are    inserted into the workspace with addWindow(). As with top-level    widgets, you can call functions such as show(), hide(),    showMaximized(), and setWindowTitle() on a child window to change    its appearance within the workspace. You can also provide widget    flags to determine the layout of the decoration or the behavior of    the widget itself.    To change or retrieve the geometry of a child window, you must    operate on its parentWidget(). The parentWidget() provides    access to the decorated frame that contains the child window    widget. When a child window is maximised, its decorated frame    is hidden. If the top-level widget contains a menu bar, it will display    the maximised window's operations menu to the left of the menu    entries, and the window's controls to the right.    A child window becomes active when it gets the keyboard focus,    or when setFocus() is called. The user can activate a window by moving    focus in the usual ways, for example by clicking a window or by pressing    Tab. The workspace emits a signal windowActivated() when the active    window changes, and the function activeWindow() returns a pointer to the    active child window, or 0 if no window is active.    The convenience function windowList() returns a list of all    child windows. This information could be used in a    popup menu containing a list of windows, for example.    This feature is also available as part of the    \link http://www.trolltech.com/products/solutions/catalog/Widgets/qtwindowlistmenu/    Window Menu \endlink Qt Solution.    QWorkspace provides two built-in layout strategies for child    windows: cascade() and tile(). Both are slots so you can easily    connect menu entries to them.    \img qworkspace-arrange.png    If you want your users to be able to work with child windows    larger than the visible workspace area, set the scrollBarsEnabled    property to true.*/class QWorkspaceChild : public QWidget{    Q_OBJECT    friend class QWorkspacePrivate;    friend class QWorkspace;    friend class QWorkspaceTitleBar;public:    QWorkspaceChild(QWidget* window, QWorkspace* parent=0, Qt::WFlags flags = 0);    ~QWorkspaceChild();    void setActive(bool);    bool isActive() const;    void adjustToFullscreen();    QWidget* windowWidget() const;    QWidget* iconWidget() const;    void doResize();    void doMove();    QSize sizeHint() const;    QSize minimumSizeHint() const;    QSize baseSize() const;    int frameWidth() const;    void show();    bool isWindowOrIconVisible() const;signals:    void showOperationMenu();    void popupOperationMenu(const QPoint&);public slots:    void activate();    void showMinimized();    void showMaximized();    void showNormal();    void showShaded();    void internalRaise();    void titleBarDoubleClicked();protected:    void enterEvent(QEvent *);    void leaveEvent(QEvent *);    void childEvent(QChildEvent*);    void resizeEvent(QResizeEvent *);    void moveEvent(QMoveEvent *);    bool eventFilter(QObject *, QEvent *);    void paintEvent(QPaintEvent *);    void changeEvent(QEvent *);private:    void updateMask();    Q_DISABLE_COPY(QWorkspaceChild)    QWidget *childWidget;    QWidgetResizeHandler *widgetResizeHandler;    QWorkspaceTitleBar *titlebar;    QPointer<QWorkspaceTitleBar> iconw;    QSize windowSize;    QSize shadeRestore;    QSize shadeRestoreMin;    bool act                  :1;    bool shademode            :1;};int QWorkspaceChild::frameWidth() const{    return contentsRect().left();}class QWorkspacePrivate : public QWidgetPrivate {    Q_DECLARE_PUBLIC(QWorkspace)public:    QWorkspaceChild* active;    QList<QWorkspaceChild *> windows;    QList<QWorkspaceChild *> focus;    QList<QWidget *> icons;    QWorkspaceChild* maxWindow;    QRect maxRestore;    QPointer<QFrame> maxcontrols;    QPointer<QMenuBar> maxmenubar;    QHash<int, const char*> shortcutMap;    int px;    int py;    QWidget *becomeActive;    QPointer<QLabel> maxtools;    QString topTitle;    QMenu *popup, *toolPopup;    enum WSActs { RestoreAct, MoveAct, ResizeAct, MinimizeAct, MaximizeAct, CloseAct, StaysOnTopAct, ShadeAct, NCountAct };    QAction *actions[NCountAct];

⌨️ 快捷键说明

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