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

📄 q3toolbar.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    \reimp*/void Q3ToolBar::styleChange(QStyle &oldStyle){    Q3DockWindow::styleChange(oldStyle);}/*!    \reimp*/void Q3ToolBar::setVisible(bool visible){    Q3DockWindow::setVisible(visible);    if (mw)        mw->triggerLayout(false);    if (visible)        checkForExtension(size());}/*!    Returns a pointer to the Q3MainWindow which manages this toolbar.*/Q3MainWindow * Q3ToolBar::mainWindow() const{    return mw;}/*!    Sets the widget \a w to be expanded if this toolbar is requested    to stretch.    The request to stretch might occur because Q3MainWindow    right-justifies the dock area the toolbar is in, or because this    toolbar's isVerticalStretchable() or isHorizontalStretchable() is    set to true.    If you call this function and the toolbar is not yet stretchable,    setStretchable() is called.    \sa Q3MainWindow::setRightJustification(), setVerticalStretchable(),    setHorizontalStretchable()*/void Q3ToolBar::setStretchableWidget(QWidget * w){    sw = w;    boxLayout()->setStretchFactor(w, 1);    if (!isHorizontalStretchable() && !isVerticalStretchable()) {        if (orientation() == Qt::Horizontal)            setHorizontalStretchable(true);        else            setVerticalStretchable(true);    }}/*!    \reimp*/bool Q3ToolBar::event(QEvent * e){    bool r =  Q3DockWindow::event(e);    // After the event filters have dealt with it, do our stuff.    if (e->type() == QEvent::ChildInserted) {        QObject * child = ((QChildEvent*)e)->child();        if (child && child->isWidgetType() && !((QWidget*)child)->isWindow()             && child->parent() == this            && QLatin1String("qt_dockwidget_internal") != child->objectName()) {            boxLayout()->addWidget((QWidget*)child);            QLayoutItem *item = boxLayout()->itemAt(boxLayout()->indexOf((QWidget*)child));            if (QToolButton *button = qobject_cast<QToolButton*>(child)) {                item->setAlignment(Qt::AlignHCenter);                button->setFocusPolicy(Qt::NoFocus);                if (mw) {                    QObject::connect(mw, SIGNAL(pixmapSizeChanged(bool)),                                     button, SLOT(setUsesBigPixmap(bool)));                    button->setUsesBigPixmap(mw->usesBigPixmaps());                    QObject::connect(mw, SIGNAL(usesTextLabelChanged(bool)),                                     child, SLOT(setUsesTextLabel(bool)));                    button->setUsesTextLabel(mw->usesTextLabel());                }                button->setAutoRaise(true);            }            if (isVisible()) {                // toolbar compatibility: we auto show widgets that                // are not explicitly hidden                if (((QWidget*)child)->testAttribute(Qt::WA_WState_Hidden)                    && !((QWidget*)child)->testAttribute(Qt::WA_WState_ExplicitShowHide))                    ((QWidget*)child)->show();                checkForExtension(size());            }        }        if (child && child->isWidgetType() && ((QWidget*)child) == sw)            boxLayout()->setStretchFactor((QWidget*)child, 1);    } else if (e->type() == QEvent::Show) {        layout()->activate();    } else if (e->type() == QEvent::LayoutHint && place() == OutsideDock) {        adjustSize();    }    return r;}/*!    \property Q3ToolBar::label    \brief the toolbar's label.    If the toolbar is floated the label becomes the toolbar window's    caption. There is no default label text.*/void Q3ToolBar::setLabel(const QString & label){    l = label;    setWindowTitle(l);}QString Q3ToolBar::label() const{    return l;}/*!    Deletes all the toolbar's child widgets.*/void Q3ToolBar::clear(){    QObjectList childList = children();    d->extension = 0;    d->extensionPopup = 0; //they will both be destroyed by the following code    for (int i = 0; i < childList.size(); ++i) {        QObject *obj = childList.at(i);        if (obj->isWidgetType() && QLatin1String("qt_dockwidget_internal") != obj->objectName())            delete obj;    }}/*!    \internal*/QSize Q3ToolBar::minimumSize() const{    if (orientation() == Qt::Horizontal)        return QSize(0, Q3DockWindow::minimumSize().height());    return QSize(Q3DockWindow::minimumSize().width(), 0);}/*!    \reimp*/QSize Q3ToolBar::minimumSizeHint() const{    if (orientation() == Qt::Horizontal)        return QSize(0, Q3DockWindow::minimumSizeHint().height());    return QSize(Q3DockWindow::minimumSizeHint().width(), 0);}void Q3ToolBar::createPopup(){    if (!d->extensionPopup) {        d->extensionPopup = new Q3PopupMenu(this, "qt_dockwidget_internal");        connect(d->extensionPopup, SIGNAL(aboutToShow()), this, SLOT(createPopup()));    }    if (!d->extension) {        d->extension = new Q3ToolBarExtensionWidget(this);        d->extension->setOrientation(orientation());        d->extension->button()->setPopup(d->extensionPopup);        d->extension->button()->setPopupMode(QToolButton::InstantPopup);    }    d->extensionPopup->clear();    // delete submenus    QObjectList popups = d->extensionPopup->queryList("Q3PopupMenu", 0, false, true);    while (!popups.isEmpty())        delete popups.takeFirst();    QObjectList childlist = queryList("QWidget", 0, false, true);    bool hide = false;    bool doHide = false;    int id;    for (int i = 0; i < childlist.size(); ++i) {        QObject *obj = childlist.at(i);        if (!obj->isWidgetType() || obj == d->extension->button() || obj == d->extensionPopup            || QLatin1String("qt_dockwidget_internal") == obj->objectName()) {            continue;        }        int j = 2;        QWidget *w = (QWidget*)obj;        if (qobject_cast<QComboBox*>(w))            j = 1;        hide = false;        const int padding = 4; // extra pixels added by the layout hierarchy        QPoint p(mapTo(this, w->geometry().bottomRight()));        if (orientation() == Qt::Horizontal) {            if ((p.x() > (doHide ? width() - d->extension->width() / j - padding : width() - padding))                || (p.x() > parentWidget()->width() - d->extension->width()))                hide = true;        } else {            if ((p.y() > (doHide ? height()- d->extension->height() / j - padding : height() - padding))                || (p.y() > parentWidget()->height() - d->extension->height()))                hide = true;        }        if (hide && w->isVisible()) {            doHide = true;            if (qobject_cast<QToolButton*>(w)) {                QToolButton *b = (QToolButton*)w;                QString s = b->textLabel();                if (s.isEmpty())                    s = b->text();                if (b->popup() && b->popupDelay() == 0)                    id = d->extensionPopup->insertItem(b->iconSet(), s, b->popup());                else                    id = d->extensionPopup->insertItem(b->iconSet(), s, b, SLOT(click())) ;                if (b->isToggleButton())                    d->extensionPopup->setItemChecked(id, b->isOn());                if (!b->isEnabled())                    d->extensionPopup->setItemEnabled(id, false);            } else if (qobject_cast<QAbstractButton*>(w)) {                QAbstractButton *b = (QAbstractButton*)w;                QString s = b->text();                if (s.isEmpty())                    s = QLatin1String("");                if (b->pixmap())                    id = d->extensionPopup->insertItem(*b->pixmap(), s, b, SLOT(click()));                else                    id = d->extensionPopup->insertItem(s, b, SLOT(click()));                if (b->isToggleButton())                    d->extensionPopup->setItemChecked(id, b->isOn());                if (!b->isEnabled())                    d->extensionPopup->setItemEnabled(id, false);#ifndef QT_NO_COMBOBOX            } else if (qobject_cast<QComboBox*>(w)) {                QComboBox *c = (QComboBox*)w;                if (c->count() != 0) {                    QString s = c->windowTitle();                    if (s.isEmpty())                        s = c->currentText();                    int maxItems = 0;                    Q3PopupMenu *cp = new Q3PopupMenu(d->extensionPopup);                    cp->setEnabled(c->isEnabled());                    d->extensionPopup->insertItem(s, cp);                    connect(cp, SIGNAL(activated(int)), c, SLOT(internalActivate(int)));                    for (int i = 0; i < c->count(); ++i) {                        QString tmp = c->text(i);                        cp->insertItem(tmp, i);                        if (c->currentText() == tmp)                            cp->setItemChecked(i, true);                        if (!maxItems) {                            if (cp->actions().count() == 10) {                                int h = cp->sizeHint().height();                                maxItems = QApplication::desktop()->height() * 10 / h;                            }                        } else if (cp->actions().count() >= maxItems - 1) {                            Q3PopupMenu* sp = new Q3PopupMenu(d->extensionPopup);                            cp->insertItem(tr("More..."), sp);                            cp = sp;                            connect(cp, SIGNAL(activated(int)), c, SLOT(internalActivate(int)));                        }                    }                }#endif //QT_NO_COMBOBOX            }        }    }}/*!    \reimp*/void Q3ToolBar::resizeEvent(QResizeEvent *e){    Q3DockWindow::resizeEvent(e);    checkForExtension(e->size());}/*!    \internal    This function is called when an action is triggered. The relevant    information is passed in the event \a e.*/void Q3ToolBar::actionEvent(QActionEvent *e){    if (e->type() == QEvent::ActionAdded) {        QAction *a = e->action();        QWidget *w;        if (a->isSeparator()) {            w = new Q3ToolBarSeparator(orientation(), this, "toolbar separator");        } else {            QToolButton* btn = new QToolButton(this);            btn->setDefaultAction(a);            w = btn;        }        d->actions.insert(a, w);    } else if (e->type() == QEvent::ActionRemoved) {        QAction *a = e->action();        delete d->actions.take(a);    }}void Q3ToolBar::checkForExtension(const QSize &sz){    if (!isVisible())        return;    if (d->checkingExtension)        return;    d->checkingExtension = true;    bool tooSmall;    if (orientation() == Qt::Horizontal)        tooSmall = sz.width() < sizeHint().width();    else        tooSmall = sz.height() < sizeHint().height();    if (tooSmall) {        createPopup();        if (d->extensionPopup->actions().count()) {            // parentWidget()->width() used since the Q3ToolBar width            // will never be less than minimumSize()            if (orientation() == Qt::Horizontal)                d->extension->setGeometry((parentWidget() ? parentWidget()->width() : width()) - 20,                                          1, 20, height() - 2);            else                d->extension->setGeometry(1, (parentWidget() ? parentWidget()->height() : height()) - 20,                                          width() - 2, 20);            d->extension->show();            d->extension->raise();        } else {            delete d->extension;            d->extension = 0;            delete d->extensionPopup;            d->extensionPopup = 0;        }    } else {        delete d->extension;        d->extension = 0;        delete d->extensionPopup;        d->extensionPopup = 0;    }    d->checkingExtension = false;}/*!    \internal*/void Q3ToolBar::setMinimumSize(int, int){}/* from chaunsee:1.  Tool Bars should contain only high-frequency functions.  Avoid puttingthings like About and Exit on a tool bar unless they are frequent functions.2.  All tool bar buttons must have some keyboard access method (it can be amenu or shortcut key or a function in a dialog box that can be accessedthrough the keyboard).3.  Make tool bar functions as efficient as possible (the common example is toPrint in Microsoft applications, it doesn't bring up the Print dialog box, itprints immediately to the default printer).4.  Avoid turning tool bars into graphical menu bars.  To me, a tool bar shouldbe efficient. Once you make almost all the items in a tool bar into graphicalpull-down menus, you start to lose efficiency.5.  Make sure that adjacent icons are distinctive. There are some tool barswhere you see a group of 4-5 icons that represent related functions, but theyare so similar that you can't differentiate among them.         These tool bars areoften a poor attempt at a "common visual language".6.  Use any de facto standard icons of your platform (for windows use thecut, copy and paste icons provided in dev kits rather than designing yourown).7.  Avoid putting a highly destructive tool bar button (delete database) by asafe, high-frequency button (Find) -- this will yield 1-0ff errors).8.  Tooltips in many Microsoft products simply reiterate the menu text evenwhen that is not explanatory.  Consider making your tooltips slightly moreverbose and explanatory than the corresponding menu item.9.  Keep the tool bar as stable as possible when you click on differentobjects. Consider disabling tool bar buttons if they are used in most, but notall contexts.10.  If you have multiple tool bars (like the Microsoft MMC snap-ins have),put the most stable tool bar to at the left with less stable ones to theright. This arrangement (stable to less stable) makes the tool bar somewhatmore predictable.11.  Keep a single tool bar to fewer than 20 items divided into 4-7 groups ofitems.*/#endif

⌨️ 快捷键说明

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