-
Notifications
You must be signed in to change notification settings - Fork 2
/
qcocoapreferencesdialog_mac.mm
119 lines (84 loc) · 2.76 KB
/
qcocoapreferencesdialog_mac.mm
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "pch.h"
#include "qcocoapreferencesdialog.h"
#import <AppKit/NSToolbar.h>
#import <AppKit/NSToolbarItem.h>
#include "bigsurtoolbar.h"
class QCocoaPreferencesPrivate
{
public:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
NSToolbar *nativeToolbar() const { return nullptr; }
#else
NSToolbar *nativeToolbar() const { return _macToolbar->nativeToolbar(); }
#endif
QMacToolBarBigSur *_macToolbar;
QCocoaPreferencesDialog *_dialog;
};
QCocoaToolbarImpl::QCocoaToolbarImpl(QCocoaPreferencesDialog *parent)
: QObject(parent)
{
_private = new QCocoaPreferencesPrivate();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#else
_private->_macToolbar = new QMacToolBarBigSur(this);
#endif
_private->_dialog = parent;
NSToolbar *nativeToolbar = _private->nativeToolbar();
nativeToolbar.allowsUserCustomization = NO;
}
void QCocoaToolbarImpl::setButtonTitle(int nButton, const QString &title)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#else
Q_ASSERT(nButton < _private->_macToolbar->items().size());
if (nButton < _private->_macToolbar->items().size())
_private->_macToolbar->items().at(nButton)->setText(title);
#endif
}
QCocoaToolbarImpl::~QCocoaToolbarImpl()
{
delete _private;
}
void QCocoaToolbarImpl::addButton(QPreferencesPage *page, bool bLast)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#else
QMacAutoReleasePool pool;
QMacToolBarItem *toolBarItem = _private->_macToolbar->addItem(page->getIcon(), page->getTitle());
toolBarItem->setSelectable(true);
QObject::connect(toolBarItem, &QMacToolBarItem::activated,
std::bind( &QCocoaToolbarImpl::buttonActivated, this, _private->_macToolbar->items().size() - 1 ) );
if (bLast)
{
_private->_dialog->window()->winId(); // create window->windowhandle()
_private->_macToolbar->attachToWindowWithStyle(_private->_dialog->window()->windowHandle(), QMacToolBarBigSur::StylePreference);
setSelectedButton(0); // now make the first item selected
}
#endif
}
void QCocoaToolbarImpl::setSelectedButton(int nButton)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#else
Q_ASSERT(nButton < _private->_macToolbar->items().size());
if (nButton < _private->_macToolbar->items().size())
{
QMacToolBarItem *toolBarItemFirst = _private->_macToolbar->items()[nButton];
NSToolbarItem *nativeToolBarItem = toolBarItemFirst->nativeToolBarItem();
NSToolbar *nativeToolbar = _private->nativeToolbar();
[nativeToolbar setSelectedItemIdentifier:nativeToolBarItem.itemIdentifier];
}
#endif
}
int QCocoaToolbarImpl::getHeight() const
{
return 0;
}
int QCocoaToolbarImpl::getContentPaddingY() const
{
return 20;
}
int QCocoaToolbarImpl::getMinimumWidth() const
{
return 300;
}