-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqcocoapreferencesdialog.cpp
120 lines (88 loc) · 3.27 KB
/
qcocoapreferencesdialog.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
#include "pch.h"
#include "qcocoapreferencesdialog.h"
QCocoaPreferencesDialog::QCocoaPreferencesDialog(QWidget *parent, Qt::WindowFlags f) :
QDialog(parent, f), _currentPage(0)
{
setAttribute(Qt::WA_QuitOnClose, false);
_toolbar = new QCocoaToolbarImpl(this);
QObject::connect(_toolbar, &QCocoaToolbarImpl::buttonActivated, this, &QCocoaPreferencesDialog::toolbarButtonActivated);
}
void QCocoaPreferencesDialog::addPage(QPreferencesPage *page, bool bLast)
{
if (!page)
return;
_toolbar->addButton(page, bLast);
_pages.push_back(page);
page->setParent(this);
QObject::connect(page, &QPreferencesPage::preferencesChanged, this, &QCocoaPreferencesDialog::preferencesChanged);
QObject::connect(page, &QPreferencesPage::needRecalculateLayout, this, &QCocoaPreferencesDialog::layoutChanged);
if (bLast)
setCurrentPage(0, false); // activate the first
}
void QCocoaPreferencesDialog::toolbarButtonActivated(int nButton)
{
setCurrentPage(nButton, true);
}
void QCocoaPreferencesDialog::setCurrentPage(int nButton, bool bAnimate)
{
for (auto w: _pages)
w->setVisible(false);
Q_ASSERT(nButton < _pages.size());
if (nButton < _pages.size())
{
_currentPage = nButton;
_toolbar->setSelectedButton(nButton);
QPreferencesPage *page = _pages[_currentPage];
page->updateLayout();
page->setVisible(true);
QSize pageSize = page->size();
int nToolbarHeight = _toolbar->getHeight();
int nContentPaddingY = _toolbar->getContentPaddingY();
int nContentPaddingLeft = 40;
int nContentPaddingRight = 20;
int nDialogMinimumWidth = _toolbar->getMinimumWidth();
int nContentWidth = nContentPaddingLeft + pageSize.width() + nContentPaddingRight;
int nDialogWidth = qMax(nDialogMinimumWidth, nContentWidth);
// no need to add toolbar height mac
int nDialogHeight = nContentPaddingY * 2 + pageSize.height() + (nToolbarHeight ? nToolbarHeight : 0);
QSize targetSize = QSize(nDialogWidth, nDialogHeight);
if (targetSize != size())
{
if (bAnimate && isVisible())
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "size");
animation->setDuration(150);
animation->setStartValue(size());
animation->setEndValue(targetSize);
animation->start();
}
else {
QWidget::resize(targetSize);
}
}
page->move(nContentPaddingLeft, nToolbarHeight + nContentPaddingY);
QString dialogTitle;
if (_prependingTitle.size())
dialogTitle = _prependingTitle + QString(": ") + page->getTitle();
else
dialogTitle = page->getTitle();
QWidget::setWindowTitle(dialogTitle);
emit currentPageChanged(_currentPage);
}
}
int QCocoaPreferencesDialog::getCurrentPage() const
{
return _currentPage;
}
void QCocoaPreferencesDialog::layoutChanged()
{
for (int i=0; i<_pages.size(); i++)
{
QPreferencesPage *page = _pages[i];
_toolbar->setButtonTitle(i, page->getTitle());
}
setCurrentPage(getCurrentPage(), true);
}
QCocoaPreferencesDialog::~QCocoaPreferencesDialog()
{
}