-
Notifications
You must be signed in to change notification settings - Fork 2
/
qcocoapreferencesdialog_generic.cpp
129 lines (97 loc) · 3.05 KB
/
qcocoapreferencesdialog_generic.cpp
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
120
121
122
123
124
125
126
127
128
129
#include "stdafx.h"
#include "qcocoapreferencesdialog.h"
#include <functional>
class QToolBarNoTooltips : public QToolBar
{
public :
explicit QToolBarNoTooltips(QWidget *parent): QToolBar(parent)
{
}
bool eventFilter(QObject *object, QEvent *e) override
{
if (e->type() == QEvent::ToolTip)
return true;
return QToolBar::eventFilter(object, e);
}
protected:
void resizeEvent(QResizeEvent *event) override
{
for (QToolButton* button : findChildren<QToolButton*>())
{
button->setToolTip(QString());
button->installEventFilter(this);
}
QToolBar::resizeEvent(event);
}
};
class QCocoaPreferencesPrivate
{
public:
explicit QCocoaPreferencesPrivate(QCocoaPreferencesDialog *parent)
{
_toolbar = new QToolBarNoTooltips(parent);
_toolbar->setFloatable(false);
_toolbar->setMovable(false);
_toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
_toolbar->setIconSize(QSize(32, 32));
_toolbar->move(_paddingLeft, _paddingTop);
_actionGroup = new QActionGroup(_toolbar);
}
QCocoaPreferencesPrivate(const QCocoaPreferencesPrivate &c) = delete; // non construction-copyable
QCocoaPreferencesPrivate& operator=(const QCocoaPreferencesPrivate&) = delete; // non copyable
QToolBar *toolbar() const { return _toolbar; }
QActionGroup *actionGroup() const { return _actionGroup; }
private:
QToolBar *_toolbar = nullptr;
QActionGroup *_actionGroup = nullptr;
int _paddingLeft = 4;
int _paddingTop = 0;
};
QCocoaToolbarImpl::QCocoaToolbarImpl(QCocoaPreferencesDialog *parent)
: QObject(parent)
{
_private = new QCocoaPreferencesPrivate(parent);
}
void QCocoaToolbarImpl::setButtonTitle(int nButton, const QString &title)
{
}
int QCocoaToolbarImpl::getHeight() const
{
return _private->toolbar()->height();
}
int QCocoaToolbarImpl::getContentPaddingY() const
{
return 0;
}
int QCocoaToolbarImpl::getMinimumWidth() const
{
int nWidth = 0;
for (QToolButton* button : _private->toolbar()->findChildren<QToolButton*>())
{
nWidth += button->width();
}
return nWidth;
}
QCocoaToolbarImpl::~QCocoaToolbarImpl()
{
delete _private;
}
void QCocoaToolbarImpl::addButton(QPreferencesPage *page, bool bLast)
{
QAction *pAction = _private->actionGroup()->addAction(page->getIcon(), page->getTitle());
pAction->setCheckable(true);
QObject::connect(pAction, &QAction::triggered, std::bind(&QCocoaToolbarImpl::buttonActivated, this, _private->actionGroup()->actions().size() - 1));
if (bLast)
{
_private->toolbar()->addActions(_private->actionGroup()->actions());
_private->toolbar()->adjustSize(); // must be here in order to have correct toolbar height
}
}
void QCocoaToolbarImpl::setSelectedButton(int nButton)
{
Q_ASSERT(nButton < _private->toolbar()->actions().size());
if (nButton < _private->toolbar()->actions().size())
{
_private->toolbar()->actions().at(nButton)->setChecked(true);
}
}