18
18
#include <QListWidget>
19
19
#include <QListView>
20
#include <QListWidgetItem>
21
20
#include <QStackedWidget>
22
21
#include <QVBoxLayout>
25
BtConfigDialog::BtConfigDialog(QWidget* parent)
28
m_previousPageIndex(-2) {
29
setWindowFlags(Qt::Window);
24
BtConfigDialog::BtConfigDialog(QWidget* parent, Qt::WindowFlags flags)
25
: QDialog(parent, flags)
29
, m_previousPageIndex(-2)
30
31
m_contentsList = new QListWidget(this);
31
32
m_contentsList->setViewMode(QListView::IconMode);
32
33
m_contentsList->setMovement(QListView::Static);
34
35
m_pageWidget = new QStackedWidget(this);
35
36
m_pageWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
37
QHBoxLayout *mainLayout = new QHBoxLayout;
38
setLayout(mainLayout);
38
m_pageLayout = new QVBoxLayout;
39
m_pageLayout->addWidget(m_pageWidget);
41
QHBoxLayout *mainLayout = new QHBoxLayout(this);
39
42
mainLayout->addWidget(m_contentsList);
40
m_pageLayout = new QVBoxLayout;
41
43
mainLayout->addLayout(m_pageLayout);
43
m_pageLayout->addWidget(m_pageWidget);
45
connect(m_contentsList,
46
SIGNAL(currentRowChanged(int)),
47
this, SLOT(slotChangePage(int))
45
connect(m_contentsList, SIGNAL(currentRowChanged(int)),
46
this, SLOT(slotChangePage(int)));
52
BtConfigDialog::~BtConfigDialog() {}
54
void BtConfigDialog::addPage(BtConfigPage* pageWidget) {
56
pageWidget->m_parentDialog = this;
49
void BtConfigDialog::addPage(Page* pageWidget) {
58
51
m_pageWidget->addWidget(pageWidget);
61
53
QListWidgetItem* item = new QListWidgetItem(m_contentsList);
62
54
item->setIcon(pageWidget->icon());
63
item->setText(pageWidget->header());
55
item->setText(pageWidget->headerText());
64
56
item->setTextAlignment(Qt::AlignHCenter);
65
57
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
58
pageWidget->setListWidgetItem(item);
67
60
//set the list width - it may bee too wide (if there were no pages) or too narrow
68
61
if (m_maxItemWidth < m_contentsList->visualItemRect(item).width()) {
74
67
m_contentsList->item(i)->setSizeHint(QSize(m_maxItemWidth, m_contentsList->visualItemRect(m_contentsList->item(i)).height()) );
77
slotChangePage(m_contentsList->row(item));
70
setCurrentPage(m_contentsList->row(item));
80
void BtConfigDialog::addButtonBox(QDialogButtonBox* box) {
73
void BtConfigDialog::setButtonBox(QDialogButtonBox *box) {
75
Q_ASSERT(m_buttonBox == 0);
76
Q_ASSERT(m_buttonBoxRuler == 0);
81
80
// First add a horizontal ruler:
82
QFrame *line = new QFrame();
83
line->setGeometry(QRect(1, 1, 1, 3));
84
line->setFrameShape(QFrame::HLine);
85
line->setFrameShadow(QFrame::Sunken);
86
line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
87
m_pageLayout->addWidget(line);
81
m_buttonBoxRuler = new QFrame(this);
82
m_buttonBoxRuler->setGeometry(QRect(1, 1, 1, 3));
83
m_buttonBoxRuler->setFrameShape(QFrame::HLine);
84
m_buttonBoxRuler->setFrameShadow(QFrame::Sunken);
85
m_buttonBoxRuler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
86
m_pageLayout->addWidget(m_buttonBoxRuler);
90
89
m_pageLayout->addWidget(box);
92
void BtConfigDialog::setCurrentPage(int newIndex) {
93
if (m_previousPageIndex != newIndex) {
94
m_previousPageIndex = newIndex;
95
m_contentsList->setCurrentRow(newIndex);
96
m_pageWidget->setCurrentIndex(newIndex);
93
100
void BtConfigDialog::slotChangePage(int newIndex) {
102
This check is in place here because this slot is indirectly called by the
103
setCurrentPage method.
94
105
if (m_previousPageIndex != newIndex) {
95
106
m_previousPageIndex = newIndex;
96
m_contentsList->setCurrentRow(newIndex);
97
107
m_pageWidget->setCurrentIndex(newIndex);
103
BtConfigPage::BtConfigPage(QWidget *parent)
107
setLayout(new QVBoxLayout);
110
BtConfigPage::~BtConfigPage() {
111
// Intentionally empty