📄 qtoolbutton.cpp
字号:
}/*! Shows (pops up) the associated popup menu. If there is no such menu, this function does nothing. This function does not return until the popup menu has been closed by the user.*/void QToolButton::showMenu(){ Q_D(QToolButton); if (!d->hasMenu()) { d->menuButtonDown = false; return; // no menu to show } d->menuButtonDown = true; repaint(); d->popupTimer.stop(); d->popupTimerDone();}void QToolButtonPrivate::_q_buttonPressed(){ Q_Q(QToolButton); if (!hasMenu()) return; // no menu to show if (delay > 0 && popupMode == QToolButton::DelayedPopup) popupTimer.start(delay, q); else if (popupMode == QToolButton::InstantPopup) q->showMenu();}void QToolButtonPrivate::popupTimerDone(){ Q_Q(QToolButton); popupTimer.stop(); if (!menuButtonDown && !down) return; menuButtonDown = true; QPointer<QMenu> actualMenu; bool mustDeleteActualMenu = false; if(menuAction) { actualMenu = menuAction->menu(); if (q->actions().size() > 1) qWarning("QToolButton: Menu in setMenu() overriding actions set in addAction!"); } else if (defaultAction && defaultAction->menu()) { actualMenu = defaultAction->menu(); } else { actualMenu = new QMenu(q); mustDeleteActualMenu = true; QList<QAction*> actions = q->actions(); for(int i = 0; i < actions.size(); i++) actualMenu->addAction(actions.at(i)); } repeat = q->autoRepeat(); q->setAutoRepeat(false); bool horizontal = true;#if !defined(QT_NO_TOOLBAR) QToolBar *tb = qobject_cast<QToolBar*>(q->parentWidget()); if (tb && tb->orientation() == Qt::Vertical) horizontal = false;#endif QPoint p; QRect screen = qApp->desktop()->availableGeometry(q); QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); QRect rect = q->rect(); if (horizontal) { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) { p = q->mapToGlobal(rect.bottomRight()); } else { p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height())); } p.rx() -= sh.width(); } else { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) { p = q->mapToGlobal(rect.bottomLeft()); } else { p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height())); } } } else { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) { p = q->mapToGlobal(rect.topRight()); } else { p = q->mapToGlobal(rect.topLeft()); p.rx() -= sh.width(); } } else { if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) { p = q->mapToGlobal(rect.topRight()); } else { p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0)); } } } p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); p.ry() += 1; QPointer<QToolButton> that = q; actualMenu->setNoReplayFor(q); QObject::connect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown())); actualMenu->d_func()->causedPopup.widget = q; actualMenu->d_func()->causedPopup.action = defaultAction; actualMenu->exec(p); QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown())); if (mustDeleteActualMenu) delete actualMenu; if (!that) return; if (repeat) q->setAutoRepeat(true);}void QToolButtonPrivate::_q_updateButtonDown(){ Q_Q(QToolButton); menuButtonDown = false; if (q->isDown()) q->setDown(false); else q->repaint();}#endif // QT_NO_MENU#ifdef QT3_SUPPORT/*! \fn void QToolButton::setPopupDelay(int delay) Use the style hint QStyle::SH_ToolButton_PopupDelay instead.*/void QToolButton::setPopupDelay(int delay){ Q_D(QToolButton); d->userDefinedPopupDelay = true; d->delay = delay; update();}/*! Use the style hint QStyle::SH_ToolButton_PopupDelay instead.*/int QToolButton::popupDelay() const{ Q_D(const QToolButton); return d->delay;}#endif#ifndef QT_NO_MENU/*! \enum QToolButton::ToolButtonPopupMode Describes how a menu should be popped up for tool buttons that has a menu set or contains a list of actions. \value DelayedPopup After pressing and holding the tool button down for a certain amount of time (the timeout is style dependant, see QStyle::SH_ToolButton_PopupDelay), the menu is displayed. A typical application example is the "back" button in some web browsers's tool bars. If the user clicks it, the browser simply browses back to the previous page. If the user presses and holds the button down for a while, the tool button shows a menu containing the current history list \value MenuButtonPopup In this mode the tool button displays a special arrow to indicate that a menu is present. The menu is displayed when the arrow part of the button is pressed. \value InstantPopup The menu is displayed, without delay, when the tool button is pressed. In this mode, the button's own action is not triggered.*//*! \property QToolButton::popupMode \brief describes the way that popup menus are used with tool buttons*/void QToolButton::setPopupMode(ToolButtonPopupMode mode){ Q_D(QToolButton); d->popupMode = mode;}QToolButton::ToolButtonPopupMode QToolButton::popupMode() const{ Q_D(const QToolButton); return d->popupMode;}#endif/*! \property QToolButton::autoRaise \brief whether auto-raising is enabled or not. The default is disabled (i.e. false). This property is currently ignored on Mac OS X when using QMacStyle.*/void QToolButton::setAutoRaise(bool enable){ Q_D(QToolButton); d->autoRaise = enable; update();}bool QToolButton::autoRaise() const{ Q_D(const QToolButton); return d->autoRaise;}/*! Sets the default action to \a action. If a tool button has a default action, the action defines the button's properties like text, icon, tool tip, etc. */void QToolButton::setDefaultAction(QAction *action){ Q_D(QToolButton);#ifndef QT_NO_MENU bool hadMenu = false; hadMenu = d->hasMenu();#endif d->defaultAction = action; if (!action) return; if (!actions().contains(action)) addAction(action); setText(action->iconText()); setIcon(action->icon());#ifndef QT_NO_TOOLTIP setToolTip(action->toolTip());#endif#ifndef QT_NO_STATUSTIP setStatusTip(action->statusTip());#endif#ifndef QT_NO_WHATSTHIS setWhatsThis(action->whatsThis());#endif#ifndef QT_NO_MENU if (action->menu() && !hadMenu) { // new 'default' popup mode defined introduced by tool bar. We // should have changed QToolButton's default instead. Do that // in 4.2. setPopupMode(QToolButton::MenuButtonPopup); }#endif setCheckable(action->isCheckable()); setChecked(action->isChecked()); setEnabled(action->isEnabled()); if (action->d_func()->fontSet) setFont(action->font());}/*! Returns the default action. \sa setDefaultAction() */QAction *QToolButton::defaultAction() const{ Q_D(const QToolButton); return d->defaultAction;}/*! \reimp */void QToolButton::nextCheckState(){ Q_D(QToolButton); if (!d->defaultAction) QAbstractButton::nextCheckState(); else d->defaultAction->trigger();}/*! \reimp */bool QToolButton::event(QEvent *e){ return QAbstractButton::event(e);}/*! \internal */QToolButton::QToolButton(QToolButtonPrivate &dd, QWidget *parent) :QAbstractButton(dd, parent){ Q_D(QToolButton); d->init();}/*! \fn void QToolButton::setPixmap(const QPixmap &pixmap) Use setIcon(QIcon(pixmap)) instead.*//*! \fn void QToolButton::setIconSet(const QIcon &icon) Use setIcon() instead.*//*! \fn void QToolButton::setTextLabel(const QString &text, bool tooltip) Use setText() and setToolTip() instead.*//*! \fn QString QToolButton::textLabel() const Use text() instead.*//*! \fn QIcon QToolButton::iconSet() const Use icon() instead.*//*! \fn void QToolButton::openPopup() Use showMenu() instead.*//*! \fn void QToolButton::setPopup(QMenu* popup) Use setMenu() instead.*//*! \fn QMenu* QToolButton::popup() const Use menu() instead.*//*! \fn TextPosition QToolButton::textPosition() const Use toolButtonStyle() instead.*//*! \fn void QToolButton::setTextPosition(QToolButton::TextPosition pos) Use setToolButtonStyle() instead.*//*! \fn bool QToolButton::usesBigPixmap() const Use iconSize() instead.*//*! \fn void QToolButton::setUsesBigPixmap(bool enable) Use setIconSize() instead.*//*! \fn bool QToolButton::usesTextLabel() const Use toolButtonStyle() instead.*//*! \fn void QToolButton::setUsesTextLabel(bool enable) Use setToolButtonStyle() instead.*/#include "moc_qtoolbutton.cpp"#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -