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

📄 qmdisubwindow.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module 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.******************************************************************************//*!    \class QMdiSubWindow    \brief The QMdiSubWindow class provides a subwindow class for    QMdiArea.    \since 4.3    \ingroup application    \mainclass    QMdiSubWindow represents a top-level window in a QMdiArea, and consists    of a title bar with window decorations, an internal widget, and    (depending on the current style) a window frame and a size    grip. QMdiSubWindow has its own layout, which consists of the    title bar and a center area for the internal widget.    \image qmdisubwindowlayout.png    The most common way to construct a QMdiSubWindow is to call    QMdiArea::addSubWindow() with the internal widget as the argument.    You can also create a subwindow yourself, and set an internal    widget by calling setWidget().    You use the same API when programming with subwindows as with    regular top-level windows (e.g., you can call functions such as    show(), hide(), showMaximized(), and setWindowTitle()).    \section1 Subwindow Handling    QMdiSubWindow also supports behavior specific to subwindows in    an MDI area.    By default, each QMdiSubWindow is visible inside the MDI area    viewport when moved around, but it is also possible to specify    transparent window movement and resizing behavior, where only    the outline of a subwindow is updated during these operations.    The setOption() function is used to enable this behavior.    The isShaded() function detects whether the subwindow is    currently shaded (i.e., the window is collapsed so that only the    title bar is visible). To enter shaded mode, call showShaded().    QMdiSubWindow emits the windowStateChanged() signal whenever the    window state has changed (e.g., when the window becomes minimized,    or is restored). It also emits aboutToActivate() before it is    activated.    In keyboard-interactive mode, the windows are moved and resized    with the keyboard. You can enter this mode through the system menu    of the window. The keyboardSingleStep and keyboardPageStep    properties control the distance the widget is moved or resized for    each keypress event. When shift is pressed down page step is used;    otherwise single step is used.    \sa QMdiArea*//*!    \enum QMdiSubWindow::SubWindowOption    This enum describes options that customize the behavior    of QMdiSubWindow.    \omitvalue AllowOutsideAreaHorizontally    \omitvalue AllowOutsideAreaVertically    \value RubberBandResize If you enable this option, a rubber band    control is used to represent the subwindow's outline, and the user    resizes this instead of the subwindow itself.    As a result, the subwindow maintains its original position and size    until the resize operation has been completed, at which time it will    receive a single QResizeEvent.    By default, this option is disabled.    \value RubberBandMove If you enable this option, a rubber band    control is used to represent the subwindow's outline, and the user    moves this instead of the subwindow itself.    As a result, the subwindow remains in its original position until    the move operation has completed, at which time a QMoveEvent is    sent to the window. By default, this option is disabled.*//*!    \fn QMdiSubWindow::windowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState)    QMdiSubWindow emits this signal after the window state changes. \a    oldState is the window state before it changed, and \a newState is the    new, current state.*//*!    \fn QMdiSubWindow::aboutToActivate()    QMdiSubWindow emits this signal immediately before it is    activated. After the subwindow has been activated, the QMdiArea that    manages the subwindow will also emit the    \l{QMdiArea::}{subWindowActivated()} signal.    \sa QMdiArea::subWindowActivated()*/#include "qmdisubwindow_p.h"#ifndef QT_NO_MDIAREA#include <QApplication>#include <QStylePainter>#include <QVBoxLayout>#include <QMouseEvent>#include <QWhatsThis>#include <QToolTip>#include <QMainWindow>#include <QStatusBar>#include <QAbstractScrollArea>#include <QScrollBar>#include <QDebug>#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)#include <QMacStyle>#endifstatic const QStyle::SubControl SubControls[] ={    QStyle::SC_TitleBarLabel, // 1    QStyle::SC_TitleBarSysMenu, // 2    QStyle::SC_TitleBarMinButton, // 3    QStyle::SC_TitleBarMaxButton, // 4    QStyle::SC_TitleBarShadeButton, // 5    QStyle::SC_TitleBarCloseButton, // 6    QStyle::SC_TitleBarNormalButton, // 7    QStyle::SC_TitleBarUnshadeButton, // 8    QStyle::SC_TitleBarContextHelpButton // 9};static const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0]);static const QStyle::StandardPixmap ButtonPixmaps[] ={    QStyle::SP_TitleBarMinButton,    QStyle::SP_TitleBarNormalButton,    QStyle::SP_TitleBarCloseButton};static const int NumButtonPixmaps = sizeof(ButtonPixmaps) / sizeof(ButtonPixmaps[0]);static const Qt::WindowFlags CustomizeWindowFlags =      Qt::FramelessWindowHint    | Qt::CustomizeWindowHint    | Qt::WindowTitleHint    | Qt::WindowSystemMenuHint    | Qt::WindowMinimizeButtonHint    | Qt::WindowMaximizeButtonHint    | Qt::WindowMinMaxButtonsHint;static const int BoundaryMargin = 5;static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag,                                        int delta, int maxDelta, int minDelta){    if (cflags & moveFlag) {        if (delta > 0)            return (cflags & resizeFlag) ? qMin(delta, maxDelta) : delta;        return (cflags & resizeFlag) ? qMax(delta, minDelta) : delta;    }    return 0;}static inline int getResizeDeltaComponent(uint cflags, uint resizeFlag,                                          uint resizeReverseFlag, int delta){    if (cflags & resizeFlag) {        if (cflags & resizeReverseFlag)            return -delta;        return delta;    }    return 0;}static inline bool isChildOfQMdiSubWindow(const QWidget *child){    Q_ASSERT(child);    QWidget *parent = child->parentWidget();    while (parent) {        if (qobject_cast<QMdiSubWindow *>(parent))            return true;        parent = parent->parentWidget();    }    return false;}template<typename T>static inline ControlElement<T> *ptr(QWidget *widget){    if (widget && widget->qt_metacast("ControlElement")            && strcmp(widget->metaObject()->className(), T::staticMetaObject.className()) == 0) {        return static_cast<ControlElement<T> *>(widget);    }    return 0;}static inline QString originalWindowTitle(QMdiSubWindow *mdiChild){    Q_ASSERT(mdiChild);    QString originalTitle = mdiChild->window()->windowTitle();    int index = originalTitle.indexOf(QString::fromLatin1(" - ["));    if (index != -1)        return originalTitle.left(index);    if (originalTitle.isEmpty())        return originalTitle;    QList<QMdiSubWindow *> windows = qFindChildren<QMdiSubWindow *>(mdiChild->window());    foreach (QMdiSubWindow *window, windows) {        if (window->windowTitle() == originalTitle)            return QString();    }    return originalTitle;}static inline void setNewWindowTitle(QMdiSubWindow *mdiChild){    Q_ASSERT(mdiChild);    if (!mdiChild)        return;    QString childTitle = mdiChild->windowTitle();    if (childTitle.isEmpty())        return;    QString original = originalWindowTitle(mdiChild);    if (!original.isEmpty()) {        mdiChild->window()->setWindowTitle(QMdiSubWindow::tr("%1 - [%2]")                                           .arg(original, childTitle));    } else {        mdiChild->window()->setWindowTitle(childTitle);    }}static inline bool isHoverControl(QStyle::SubControl control){    return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel;}#if defined(Q_WS_WIN)static inline QRgb colorref2qrgb(COLORREF col){    return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));}#endif/*    \class ControlLabel    \internal*/class ControlLabel : public QWidget{    Q_OBJECTpublic:    ControlLabel(QWidget *parent = 0);    QSize sizeHint() const;signals:    void _q_clicked();    void _q_doubleClicked();protected:    bool event(QEvent *event);    void paintEvent(QPaintEvent *paintEvent);    void mousePressEvent(QMouseEvent *mouseEvent);    void mouseDoubleClickEvent(QMouseEvent *mouseEvent);    void mouseReleaseEvent(QMouseEvent *mouseEvent);private:    QPixmap label;    bool isPressed;    void updateWindowIcon();};ControlLabel::ControlLabel(QWidget *parent)    : QWidget(parent), isPressed(false){    setFocusPolicy(Qt::NoFocus);    updateWindowIcon();    setFixedSize(label.size());}/*    \internal*/QSize ControlLabel::sizeHint() const{    return label.size();}/*    \internal*/bool ControlLabel::event(QEvent *event){    if (event->type() == QEvent::WindowIconChange)        updateWindowIcon();    return QWidget::event(event);}/*    \internal*/void ControlLabel::paintEvent(QPaintEvent * /*paintEvent*/){    QPainter painter(this);    painter.drawPixmap(0, 0, label);}/*    \internal*/void ControlLabel::mousePressEvent(QMouseEvent *mouseEvent){    if (mouseEvent->button() != Qt::LeftButton) {        mouseEvent->ignore();        return;    }    isPressed = true;}/*    \internal*/void ControlLabel::mouseDoubleClickEvent(QMouseEvent *mouseEvent){    if (mouseEvent->button() != Qt::LeftButton) {        mouseEvent->ignore();        return;    }    isPressed = false;    emit _q_doubleClicked();}/*    \internal*/void ControlLabel::mouseReleaseEvent(QMouseEvent *mouseEvent){    if (mouseEvent->button() != Qt::LeftButton) {        mouseEvent->ignore();        return;    }    if (isPressed) {        isPressed = false;        emit _q_clicked();    }}/*    \internal*/void ControlLabel::updateWindowIcon(){    QIcon menuIcon = windowIcon();    if (menuIcon.isNull())        menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton);    label = menuIcon.pixmap(16, 16);    update();}/*    \class ControllerWidget    \internal*/class ControllerWidget : public QWidget{    Q_OBJECTpublic:    ControllerWidget(QWidget *parent = 0);    QSize sizeHint() const;    void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible);    inline bool hasVisibleControls() const    {        return (visibleControls & QStyle::SC_MdiMinButton)               || (visibleControls & QStyle::SC_MdiNormalButton)               || (visibleControls & QStyle::SC_MdiCloseButton);    }signals:    void _q_minimize();    void _q_restore();    void _q_close();protected:

⌨️ 快捷键说明

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