1 /*
2  *  Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 2 or (at your option)
7  *  version 3 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "EditWidget.h"
19 #include "ui_EditWidget.h"
20 
EditWidget(QWidget * parent)21 EditWidget::EditWidget(QWidget* parent)
22     : DialogyWidget(parent)
23     , m_ui(new Ui::EditWidget())
24 {
25     m_ui->setupUi(this);
26     setReadOnly(false);
27 
28     QFont headerLabelFont = m_ui->headerLabel->font();
29     headerLabelFont.setBold(true);
30     headerLabelFont.setPointSize(headerLabelFont.pointSize() + 2);
31     headlineLabel()->setFont(headerLabelFont);
32 
33     connect(m_ui->categoryList, SIGNAL(currentRowChanged(int)),
34             m_ui->stackedWidget, SLOT(setCurrentIndex(int)));
35 
36     connect(m_ui->buttonBox, SIGNAL(accepted()), SIGNAL(accepted()));
37     connect(m_ui->buttonBox, SIGNAL(rejected()), SIGNAL(rejected()));
38 }
39 
~EditWidget()40 EditWidget::~EditWidget()
41 {
42 }
43 
add(const QString & labelText,QWidget * widget)44 void EditWidget::add(const QString& labelText, QWidget* widget)
45 {
46     m_ui->categoryList->addItem(labelText);
47     m_ui->stackedWidget->addWidget(widget);
48 }
49 
setRowHidden(QWidget * widget,bool hide)50 void EditWidget::setRowHidden(QWidget* widget, bool hide)
51 {
52     int row = m_ui->stackedWidget->indexOf(widget);
53     if (row != -1) {
54         m_ui->categoryList->item(row)->setHidden(hide);
55     }
56 }
57 
setCurrentRow(int index)58 void EditWidget::setCurrentRow(int index)
59 {
60     m_ui->categoryList->setCurrentRow(index);
61 }
62 
setHeadline(const QString & text)63 void EditWidget::setHeadline(const QString& text)
64 {
65     m_ui->headerLabel->setText(text);
66 }
67 
headlineLabel()68 QLabel* EditWidget::headlineLabel()
69 {
70     return m_ui->headerLabel;
71 }
72 
setReadOnly(bool readOnly)73 void EditWidget::setReadOnly(bool readOnly)
74 {
75     m_readOnly = readOnly;
76 
77     if (readOnly) {
78         m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Close);
79     }
80     else {
81         m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
82     }
83 }
84 
readOnly() const85 bool EditWidget::readOnly() const
86 {
87     return m_readOnly;
88 }
89