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

📄 qstatusbar.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** 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.******************************************************************************/#include "qstatusbar.h"#ifndef QT_NO_STATUSBAR#include "qlist.h"#include "qevent.h"#include "qlayout.h"#include "qpainter.h"#include "qtimer.h"#include "qstyle.h"#include "qstyleoption.h"#include "qsizegrip.h"#include <private/qlayoutengine_p.h>#include <private/qwidget_p.h>class QStatusBarPrivate : public QWidgetPrivate{    Q_DECLARE_PUBLIC(QStatusBar)public:    QStatusBarPrivate() {}    struct SBItem {        SBItem(QWidget* widget, int stretch, bool permanent)            : s(stretch), w(widget), p(permanent) {}        int s;        QWidget * w;        bool p;    };    QList<SBItem *> items;    QString tempItem;    QBoxLayout * box;    QTimer * timer;#ifndef QT_NO_SIZEGRIP    QSizeGrip * resizer;#endif    int savedStrut;    int indexToLastNonPermanentWidget() const    {        int i = items.size() - 1;        for (; i >= 0; --i) {            SBItem *item = items.at(i);            if (!(item && item->p))                break;        }        return i;    }};/*!    \class QStatusBar    \brief The QStatusBar class provides a horizontal bar suitable for    presenting status information.    \ingroup application    \ingroup helpsystem    \mainclass    Each status indicator falls into one of three categories:    \list    \o \e Temporary - briefly occupies most of the status bar. Used        to explain tool tip texts or menu entries, for example.    \o \e Normal - occupies part of the status bar and may be hidden        by temporary messages. Used to display the page and line        number in a word processor, for example.    \o \e Permanent - is never hidden. Used for important mode        indications, for example, some applications put a Caps Lock        indicator in the status bar.    \endlist    QStatusBar lets you display all three types of indicators.    Typically, a request for the status bar functionality occurs in    relation to a QMainWindow object. QMainWindow provides a main    application window, with a menu bar, tool bars, dock widgets \e    and a status bar around a large central widget. The status bar can    be retrieved using the QMainWindow::statusBar() function, and    replaced using the QMainWindow::setStatusBar() function.    Use the showMessage() slot to display a \e temporary message:    \quotefromfile mainwindows/dockwidgets/mainwindow.cpp    \skipto MainWindow::createStatusBar()    \printuntil /^\}/    To remove a temporary message, use the clearMessage() slot, or set    a time limit when calling showMessage(). For example:    \quotefromfile mainwindows/dockwidgets/mainwindow.cpp    \skipto void MainWindow::print()    \printuntil /^\}/    Use the currentMessage() function to retrieve the temporary    message currently shown. The QStatusBar class also provide the    messageChanged() signal which is emitted whenever the temporary    status message changes.    \e Normal and \e Permanent messages are displayed by creating a    small widget (QLabel, QProgressBar or even QToolButton) and then    adding it to the status bar using the addWidget() or the    addPermanentWidget() function. Use the removeWidget() function to    remove such messages from the status bar.    \code        statusBar()->addWidget(new MyReadWriteIndication);    \endcode    By default QStatusBar provides a QSizeGrip in the lower-right    corner. You can disable it using the setSizeGripEnabled()    function. Use the isSizeGripEnabled() function to determine the    current status of the size grip.    \image plastique-statusbar.png A status bar shown in the Plastique widget style    \sa QMainWindow, QStatusTipEvent, {fowler}{GUI Design Handbook:    Status Bar}, {Application Example}*/#ifdef QT3_SUPPORT/*!    Constructs a status bar with a size grip and the given \a parent    and object \a name.    Use the QStatusBar() constructor and the QObject::setObjectName()    function instead.    \oldcode        QStatusBar *myStatusBar = new QStatusBar(parent, name);    \newcode        QStatusBar *myStatusBar = new QStatusBar(parent);        myStatusBar->setObjectName(name);    \endcode*/QStatusBar::QStatusBar(QWidget * parent, const char *name)    : QWidget(*new QStatusBarPrivate, parent, 0){    Q_D(QStatusBar);    setObjectName(QString::fromAscii(name));    d->box = 0;    d->timer = 0;#ifndef QT_NO_SIZEGRIP    d->resizer = 0;    setSizeGripEnabled(true); // causes reformat()#else    reformat();#endif}/*!    \fn void QStatusBar::addWidget(QWidget * widget, int stretch, bool permanent)   Use addWidget() or addPermanentWidget() instead, depending on the   value of the \a permanent parameter.    \oldcode        QStatusBar *myStatusBar;        myStatusBar->addWidget(widget, stretch, permanent);  // permanent == true    \newcode        QStatusBar *myStatusBar;        myStatusBar->addPermanentWidget(widget, stretch);    \endcode */#endif/*!    Constructs a status bar with a size grip and the given \a parent.    \sa setSizeGripEnabled()*/QStatusBar::QStatusBar(QWidget * parent)    : QWidget(*new QStatusBarPrivate, parent, 0){    Q_D(QStatusBar);    d->box = 0;    d->timer = 0;#ifndef QT_NO_SIZEGRIP    d->resizer = 0;    setSizeGripEnabled(true); // causes reformat()#else    reformat();#endif}/*!    Destroys this status bar and frees any allocated resources and    child widgets.*/QStatusBar::~QStatusBar(){    Q_D(QStatusBar);    while (!d->items.isEmpty())        delete d->items.takeFirst();}/*!    Adds the given \a widget to this status bar, reparenting the    widget if it isn't already a child of this QStatusBar object. The    \a stretch parameter is used to compute a suitable size for the    given \a widget as the status bar grows and shrinks. The default    stretch factor is 0, i.e giving the widget a minimum of space.    The widget is located to the far left of the first permanent    widget (see addPermanentWidget()) and may be obscured by temporary    messages.    \sa insertWidget(), removeWidget(), addPermanentWidget()*/void QStatusBar::addWidget(QWidget * widget, int stretch){    if (!widget)        return;    insertWidget(d_func()->indexToLastNonPermanentWidget() + 1, widget, stretch);}/*!    \since 4.2    Inserts the given \a widget at the given \a index to this status bar,    reparenting the widget if it isn't already a child of this    QStatusBar object. If \a index is out of range, the widget is appended    (in which case it is the actual index of the widget that is returned).    The \a stretch parameter is used to compute a suitable size for    the given \a widget as the status bar grows and shrinks. The    default stretch factor is 0, i.e giving the widget a minimum of    space.    The widget is located to the far left of the first permanent    widget (see addPermanentWidget()) and may be obscured by temporary    messages.    \sa addWidget(), removeWidget(), addPermanentWidget()*/int QStatusBar::insertWidget(int index, QWidget *widget, int stretch){    if (!widget)        return -1;    Q_D(QStatusBar);    QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, false);    int idx = d->indexToLastNonPermanentWidget();    if (index < 0 || index > d->items.size() || (idx >= 0 && index > idx + 1)) {        qWarning("QStatusBar::insertWidget: Index out of range (%d), appending widget", index);        index = idx + 1;    }    d->items.insert(index, item);    if (!d->tempItem.isEmpty())        widget->hide();    reformat();    if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))        widget->show();    return index;}/*!    Adds the given \a widget permanently to this status bar,    reparenting the widget if it isn't already a child of this    QStatusBar object. The \a stretch parameter is used to compute a    suitable size for the given \a widget as the status bar grows and    shrinks. The default stretch factor is 0, i.e giving the widget a    minimum of space.    Permanently means that the widget may not be obscured by temporary    messages. It is is located at the far right of the status bar.    \sa insertPermanentWidget(), removeWidget(), addWidget()*/void QStatusBar::addPermanentWidget(QWidget * widget, int stretch){    if (!widget)        return;    insertPermanentWidget(d_func()->items.size(), widget, stretch);}/*!    \since 4.2    Inserts the given \a widget at the given \a index permanently to this status bar,    reparenting the widget if it isn't already a child of this    QStatusBar object. If \a index is out of range, the widget is appended    (in which case it is the actual index of the widget that is returned).    The \a stretch parameter is used to compute a    suitable size for the given \a widget as the status bar grows and    shrinks. The default stretch factor is 0, i.e giving the widget a    minimum of space.    Permanently means that the widget may not be obscured by temporary    messages. It is is located at the far right of the status bar.    \sa addPermanentWidget(), removeWidget(), addWidget()*/int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch){    if (!widget)        return -1;    Q_D(QStatusBar);    QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, true);    int idx = d->indexToLastNonPermanentWidget();    if (index < 0 || index > d->items.size() || (idx >= 0 && index <= idx)) {        qWarning("QStatusBar::insertPermanentWidget: Index out of range (%d), appending widget", index);        index = d->items.size();    }    d->items.insert(index, item);    reformat();    if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))        widget->show();    return index;}/*!    Removes the specified \a widget from the status bar.    

⌨️ 快捷键说明

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