~pkgcrosswire/bibletime/main

« back to all changes in this revision

Viewing changes to src/frontend/bookshelfmanager/btconfigdialog.cpp

  • Committer: Jonathan Marsden
  • Date: 2011-12-23 20:32:12 UTC
  • Revision ID: jmarsden@fastmail.fm-20111223203212-1g3e35rlhbys07iu
New upstream version 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <QLabel>
18
18
#include <QListWidget>
19
19
#include <QListView>
20
 
#include <QListWidgetItem>
21
20
#include <QStackedWidget>
22
21
#include <QVBoxLayout>
23
22
 
24
23
 
25
 
BtConfigDialog::BtConfigDialog(QWidget* parent)
26
 
        : QDialog(parent),
27
 
        m_maxItemWidth(0),
28
 
        m_previousPageIndex(-2) {
29
 
    setWindowFlags(Qt::Window);
 
24
BtConfigDialog::BtConfigDialog(QWidget* parent, Qt::WindowFlags flags)
 
25
        : QDialog(parent, flags)
 
26
        , m_buttonBoxRuler(0)
 
27
        , m_buttonBox(0)
 
28
        , m_maxItemWidth(0)
 
29
        , m_previousPageIndex(-2)
 
30
{
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);
36
37
 
37
 
    QHBoxLayout *mainLayout = new QHBoxLayout;
38
 
    setLayout(mainLayout);
 
38
    m_pageLayout = new QVBoxLayout;
 
39
    m_pageLayout->addWidget(m_pageWidget);
 
40
 
 
41
    QHBoxLayout *mainLayout = new QHBoxLayout(this);
39
42
    mainLayout->addWidget(m_contentsList);
40
 
    m_pageLayout = new QVBoxLayout;
41
43
    mainLayout->addLayout(m_pageLayout);
42
44
 
43
 
    m_pageLayout->addWidget(m_pageWidget);
44
 
 
45
 
    connect(m_contentsList,
46
 
            SIGNAL(currentRowChanged(int)),
47
 
            this, SLOT(slotChangePage(int))
48
 
           );
49
 
 
 
45
    connect(m_contentsList, SIGNAL(currentRowChanged(int)),
 
46
            this,           SLOT(slotChangePage(int)));
50
47
}
51
48
 
52
 
BtConfigDialog::~BtConfigDialog() {}
53
 
 
54
 
void BtConfigDialog::addPage(BtConfigPage* pageWidget) {
55
 
    // this is a friend
56
 
    pageWidget->m_parentDialog = this;
 
49
void BtConfigDialog::addPage(Page* pageWidget) {
57
50
 
58
51
    m_pageWidget->addWidget(pageWidget);
59
52
 
60
 
 
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);
66
59
 
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()) );
75
68
    }
76
69
 
77
 
    slotChangePage(m_contentsList->row(item));
 
70
    setCurrentPage(m_contentsList->row(item));
78
71
}
79
72
 
80
 
void BtConfigDialog::addButtonBox(QDialogButtonBox* box) {
 
73
void BtConfigDialog::setButtonBox(QDialogButtonBox *box) {
 
74
    Q_ASSERT(box != 0);
 
75
    Q_ASSERT(m_buttonBox == 0);
 
76
    Q_ASSERT(m_buttonBoxRuler == 0);
 
77
 
 
78
    m_buttonBox = box;
 
79
 
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);
88
87
 
89
88
    // Add button box:
90
89
    m_pageLayout->addWidget(box);
91
90
}
92
91
 
 
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);
 
97
    }
 
98
}
 
99
 
93
100
void BtConfigDialog::slotChangePage(int newIndex) {
 
101
    /*
 
102
      This check is in place here because this slot is indirectly called by the
 
103
      setCurrentPage method.
 
104
    */
94
105
    if (m_previousPageIndex != newIndex) {
95
106
        m_previousPageIndex = newIndex;
96
 
        m_contentsList->setCurrentRow(newIndex);
97
107
        m_pageWidget->setCurrentIndex(newIndex);
98
108
    }
99
109
}
100
 
 
101
 
 
102
 
 
103
 
BtConfigPage::BtConfigPage(QWidget *parent)
104
 
    : QWidget(parent)
105
 
    , m_parentDialog(0)
106
 
{
107
 
    setLayout(new QVBoxLayout);
108
 
}
109
 
 
110
 
BtConfigPage::~BtConfigPage() {
111
 
    // Intentionally empty
112
 
}