blob: 37944a6d8799e450fac6fe6a28f9ae944b36b553 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
******************************************************************************/
#include "qtoolbarextension_p.h"
#include <qevent.h>
#include <qstyle.h>
#include <qstylepainter.h>
#include <qstyleoption.h>
QT_BEGIN_NAMESPACE
QToolBarExtension::QToolBarExtension(QWidget *parent)
: QToolButton(parent)
, m_orientation(Qt::Horizontal)
{
setObjectName(QLatin1String("qt_toolbar_ext_button"));
setAutoRaise(true);
setOrientation(m_orientation);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setCheckable(true);
}
void QToolBarExtension::setOrientation(Qt::Orientation o)
{
QStyleOption opt;
opt.initFrom(this);
if (o == Qt::Horizontal) {
setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, &opt));
} else {
setIcon(style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton, &opt));
}
m_orientation = o;
}
void QToolBarExtension::paintEvent(QPaintEvent *)
{
QStylePainter p(this);
QStyleOptionToolButton opt;
initStyleOption(&opt);
// We do not need to draw both extension arrows
opt.features &= ~QStyleOptionToolButton::HasMenu;
p.drawComplexControl(QStyle::CC_ToolButton, opt);
}
QSize QToolBarExtension::sizeHint() const
{
QStyleOption opt;
opt.initFrom(this);
const int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt);
return QSize(ext, ext);
}
bool QToolBarExtension::event(QEvent *event)
{
switch (event->type()) {
case QEvent::LayoutDirectionChange:
setOrientation(m_orientation);
break;
default:
break;
}
return QToolButton::event(event);
}
QT_END_NAMESPACE
#include "moc_qtoolbarextension_p.cpp"
|