Rev 10205 | Rev 11836 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10205 | subik | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | #include <QDoubleSpinBox> |
||
8 | #include <QModelIndex> |
||
9 | |||
10 | #include "guidesdelegate.h" |
||
11 | |||
12 | |||
13 | GuidesDelegate::GuidesDelegate(QObject *parent) |
||
10229 | subik | 14 | : QItemDelegate(parent), |
15 | m_docUnitDecimals(0) |
||
10205 | subik | 16 | { |
17 | } |
||
18 | |||
19 | QWidget * GuidesDelegate::createEditor(QWidget *parent, |
||
20 | const QStyleOptionViewItem &/* option */, |
||
21 | const QModelIndex &/* index */) const |
||
22 | { |
||
23 | QDoubleSpinBox *editor = new QDoubleSpinBox(parent); |
||
24 | editor->setRange(0, 1000); |
||
10229 | subik | 25 | editor->setDecimals(m_docUnitDecimals); |
10205 | subik | 26 | return editor; |
27 | } |
||
28 | |||
29 | void GuidesDelegate::setEditorData(QWidget *editor, |
||
30 | const QModelIndex &index) const |
||
31 | { |
||
32 | double value = index.model()->data(index, Qt::DisplayRole).toDouble(); |
||
33 | QDoubleSpinBox *w = static_cast<QDoubleSpinBox*>(editor); |
||
34 | w->setValue(value); |
||
35 | } |
||
36 | |||
37 | void GuidesDelegate::setModelData(QWidget *editor, |
||
38 | QAbstractItemModel *model, |
||
39 | const QModelIndex &index) const |
||
40 | { |
||
41 | QDoubleSpinBox *w = static_cast<QDoubleSpinBox*>(editor); |
||
42 | w->interpretText(); |
||
43 | double value = w->value(); |
||
44 | model->setData(index, value); |
||
45 | } |
||
46 | |||
47 | void GuidesDelegate::updateEditorGeometry(QWidget *editor, |
||
48 | const QStyleOptionViewItem &option, |
||
49 | const QModelIndex &/* index */) const |
||
50 | { |
||
51 | editor->setGeometry(option.rect); |
||
52 | } |
||
10229 | subik | 53 | |
54 | void GuidesDelegate::unitChange(int docUnitDecimals) |
||
55 | { |
||
56 | m_docUnitDecimals = docUnitDecimals; |
||
57 | } |