/
ConfigDialog.cpp
122 lines (105 loc) · 4.29 KB
/
ConfigDialog.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
/****************************************************************************
**
** Copyright (C) 2012 Coode Software
** Contact: http://www.coodesoft.com/
**
** This file is part of Notee.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
****************************************************************************/
#include <QtGui>
#include "Settings.h"
#include "ConfigPages.h"
#include "ConfigDialog.h"
CConfigDialog::CConfigDialog(QWidget *parent, CSettings* pSettings) :
QDialog(parent),
m_pSettings(pSettings),
m_bModified(false)
{
setWindowTitle(tr("Configuration"));
m_pListContentWidget = new QListWidget;
m_pListContentWidget->setViewMode(QListView::IconMode);
m_pListContentWidget->setIconSize(QSize(48,48));
m_pListContentWidget->setMovement(QListView::Static);
m_pListContentWidget->setMaximumWidth(110);
m_pListContentWidget->setSpacing(12);
connect(m_pListContentWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(onChangePage(QListWidgetItem*,QListWidgetItem*)));
// add pages
m_pPagesWidget = new QStackedWidget;
m_pPagesWidget->addWidget(new CConfigurationPage(this, m_pSettings));
m_pPagesWidget->addWidget(new CClassifyPage(this, m_pSettings));
QPushButton* pOkButton = new QPushButton(tr("Ok"));
connect(pOkButton, SIGNAL(clicked()), this, SLOT(onOk()));
QPushButton* pCancelButton = new QPushButton(tr("Cancel"));
connect(pCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout* pHorizontalLayout = new QHBoxLayout;
pHorizontalLayout->addWidget(m_pListContentWidget);
pHorizontalLayout->addSpacing(5);
pHorizontalLayout->addWidget(m_pPagesWidget, 1);
QHBoxLayout* pHButtonsLayout = new QHBoxLayout;
pHButtonsLayout->addStretch(1);
pHButtonsLayout->addWidget(pOkButton);
pHButtonsLayout->addWidget(pCancelButton);
QVBoxLayout* pMainLayout = new QVBoxLayout;
pMainLayout->addLayout(pHorizontalLayout);
pMainLayout->addSpacing(12);
pMainLayout->addLayout(pHButtonsLayout);
setLayout(pMainLayout);
// init pages
createPageItems();
m_pListContentWidget->setCurrentRow(0);
}
void CConfigDialog::onChangePage(QListWidgetItem* pCurrent, QListWidgetItem* pPrevious)
{
if(!pCurrent)
pCurrent = pPrevious;
m_pPagesWidget->setCurrentIndex(m_pListContentWidget->row(pCurrent));
}
void CConfigDialog::createPageItems()
{
QListWidgetItem* pConfigBtn = new QListWidgetItem(m_pListContentWidget);
pConfigBtn->setIcon(QIcon(":/res/config.png"));
pConfigBtn->setText(tr("Configuration"));
pConfigBtn->setTextAlignment(Qt::AlignCenter);
pConfigBtn->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem* pClassifyBtn = new QListWidgetItem(m_pListContentWidget);
pClassifyBtn->setIcon(QIcon(":/res/tb_classify.png"));
pClassifyBtn->setText(tr("Classification"));
pClassifyBtn->setTextAlignment(Qt::AlignCenter);
pClassifyBtn->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
void CConfigDialog::onOk()
{
if(m_pSettings)
{
m_bModified = false;
for(int i = m_pPagesWidget->count() - 1; i >= 0; --i)
{
CSimplePage* pPage = qobject_cast<CSimplePage*>(m_pPagesWidget->widget(i));
if(pPage->isModified())
{
pPage->saveToSettings();
m_bModified = true;
}
}
if(m_bModified)
m_pSettings->save();
}
accept();
}