43 #ifndef QT_NO_TOOLBUTTON 60 #include <private/qabstractbutton_p.h> 61 #include <private/qaction_p.h> 62 #include <private/qmenu_p.h> 100 bool userDefinedPopupDelay;
225 QObject * receiver,
const char *slot,
234 if (receiver && slot)
236 #ifndef QT_NO_TOOLTIP 240 #ifndef QT_NO_STATUSTIP 279 userDefinedPopupDelay =
false;
282 #ifndef QT_NO_TOOLBAR 283 if (qobject_cast<QToolBar*>(parent))
289 menuButtonDown =
false;
322 bool forceNoText =
false;
325 #ifndef QT_NO_TOOLBAR 328 option->
iconSize = toolBar->iconSize();
340 #endif // QT_NO_TOOLBAR 343 option->
text =
d->text;
344 option->
icon =
d->icon;
352 if (!
d->checked && !
d->down)
366 if (
d->menuButtonDown) {
395 if (
d->icon.isNull() &&
d->arrowType ==
Qt::NoArrow && !forceNoText) {
396 if (!
d->text.isEmpty())
420 if (
d->sizeHint.isValid())
444 h += 4 + textSize.
height();
445 if (textSize.
width() > w)
446 w = textSize.
width();
448 w += 4 + textSize.
width();
449 if (textSize.
height() > h)
452 w = textSize.
width();
522 return d->toolButtonStyle;
535 if (
d->toolButtonStyle == style)
538 d->toolButtonStyle =
style;
549 if (
d->arrowType == type)
579 QAction *action =
event->action();
580 switch (event->
type()) {
582 if (action ==
d->defaultAction)
589 if (
d->defaultAction == action)
590 d->defaultAction = 0;
592 if (action ==
d->menuAction)
607 q->initStyleOption(&opt);
620 QRect lastHoverRect = hoverRect;
623 if (lastHoverControl != newHoverControl(pos) && doesHover) {
624 q->update(lastHoverRect);
625 q->update(hoverRect);
634 if (
QAction *action = qobject_cast<QAction *>(q->sender()))
635 emit q->triggered(action);
646 if (
d->defaultAction)
647 d->defaultAction->hover();
672 if (e->
timerId() ==
d->popupTimer.timerId()) {
686 #ifndef QT_NO_TOOLBAR 697 if (!
d->userDefinedPopupDelay)
755 QIcon QToolButton::onIconSet()
const 763 QIcon QToolButton::offIconSet()
const 777 void QToolButton::setOnIconSet(
const QIcon&
set)
790 void QToolButton::setOffIconSet(
const QIcon&
set)
812 void QToolButton::setIconSet(
const QIcon &
set,
bool )
830 QIcon QToolButton::iconSet(
bool )
const 872 return d->menuAction->menu();
885 d->menuButtonDown =
false;
889 if (
d->menuButtonDown)
892 d->menuButtonDown =
true;
894 d->popupTimer.stop();
906 popupTimer.start(delay, q);
915 if (!menuButtonDown && !
down)
918 menuButtonDown =
true;
920 bool mustDeleteActualMenu =
false;
922 actualMenu = menuAction->menu();
926 actualMenu =
new QMenu(q);
927 mustDeleteActualMenu =
true;
932 q->setAutoRepeat(
false);
933 bool horizontal =
true;
934 #if !defined(QT_NO_TOOLBAR) 944 if (q->isRightToLeft()) {
959 if (q->isRightToLeft()) {
960 if (q->mapToGlobal(
QPoint(rect.
left(), 0)).x() - sh.
width() <= screen.
x()) {
961 p = q->mapToGlobal(rect.
topRight());
963 p = q->mapToGlobal(rect.
topLeft());
968 p = q->mapToGlobal(rect.
topRight());
978 if (!mustDeleteActualMenu)
981 actualMenu->d_func()->causedPopup.widget = q;
983 actionsCopy = q->actions();
986 if (mustDeleteActualMenu)
997 q->setAutoRepeat(
true);
1003 menuButtonDown =
false;
1013 if (action && !actionsCopy.contains(action))
1014 emit q->triggered(action);
1016 #endif // QT_NO_MENU 1027 void QToolButton::setPopupDelay(
int delay)
1030 d->userDefinedPopupDelay =
true;
1039 int QToolButton::popupDelay()
const 1086 d->popupMode = mode;
1092 return d->popupMode;
1110 d->autoRaise = enable;
1118 return d->autoRaise;
1131 bool hadMenu =
false;
1132 hadMenu =
d->hasMenu();
1134 d->defaultAction = action;
1137 if (!
actions().contains(action))
1141 #ifndef QT_NO_TOOLTIP 1144 #ifndef QT_NO_STATUSTIP 1147 #ifndef QT_NO_WHATSTHIS 1151 if (action->
menu() && !hadMenu) {
1161 if (action->d_func()->fontSet)
1174 return d->defaultAction;
1185 if (!
d->defaultAction)
1188 d->defaultAction->trigger();
1194 switch(event->
type()) {
1198 if (
const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
1199 d_func()->updateHoverControl(he->pos());
1338 #include "moc_qtoolbutton.cpp"
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
SubControl
This enum describes the available sub controls.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
The QFontMetrics class provides font metrics information.
#define QT_END_NAMESPACE
This macro expands to.
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
QStyle::State state
the style flags that are used when drawing the control
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
static QSize globalStrut()
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QHoverEvent class contains parameters that describe a mouse event.
CGFloat qt_mac_get_scalefactor()
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int left() const
Returns the x-coordinate of the rectangle's left edge.
int & ry()
Returns a reference to the y coordinate of this point.
The QActionEvent class provides an event that is generated when a QAction is added, removed, or changed.
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
int height() const
Returns the height of the rectangle.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
The QObject class is the base class of all Qt objects.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
void setObjectName(const QString &name)
void setWidth(int w)
Sets the width to the given width.
int width() const
Returns the width.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QPoint bottomRight() const
Returns the position of the rectangle's bottom-right corner.
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=0) const
Returns the size in pixels of text.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void initFrom(const QWidget *w)
const T & at(int i) const
Returns the item at index position i in the list.
QFont font
the action's font
const char * styleHint(const QFontDef &request)
QIcon icon
the action's icon
int & rx()
Returns a reference to the x coordinate of this point.
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
int receivers(const char *signal) const
Returns the number of receivers connected to the signal.
QString toolTip
the action's tooltip
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Qt::MouseButton button() const
Returns the button that caused the event.
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
The QMouseEvent class contains parameters that describe a mouse event.
bool autoRepeat
whether the action can auto repeat
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QPoint topRight() const
Returns the position of the rectangle's top-right corner.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
QMenu * menu() const
Returns the menu contained by this action.
#define Q_DECLARE_PUBLIC(Class)
int right() const
Returns the x-coordinate of the rectangle's right edge.
QPoint bottomLeft() const
Returns the position of the rectangle's bottom-left corner.
The QTimerEvent class contains parameters that describe a timer event.
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
The QPoint class defines a point in the plane using integer precision.
int size() const
Returns the number of items in the list.
QString whatsThis
the action's "What's This?" help text
int height() const
Returns the height.
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
QString iconText
the action's descriptive icon text
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
The QBasicTimer class provides timer events for objects.
The QSize class defines the size of a two-dimensional object using integer point precision.
int x() const
Returns the x coordinate of this point.
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget's style to draw a complex control cc specified by the QStyleOptionComplex option...
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
The QPaintEvent class contains event parameters for paint events.
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QRect rect
the area that should be used for various calculations and painting
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
The QAction class provides an abstract user interface action that can be inserted into widgets...
QString statusTip
the action's status tip
The QList class is a template class that provides lists.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
The QIcon class provides scalable icons in different modes and states.