Subversion Repositories Scribus

Rev

Rev 22600 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20424 jghali 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 <QModelIndex>
8
 
9
#include "ui/scrspinbox.h"
10
#include "scribusdoc.h"
11
#include "guidesdelegate.h"
12
#include "units.h"
13
 
14
 
15
GuidesDelegate::GuidesDelegate(QObject *parent)
23210 craig 16
        : QItemDelegate(parent)
20424 jghali 17
{
18
}
19
 
20
// QWidget * GuidesDelegate::createEditor(QWidget *parent,
21
//                                                                         const QStyleOptionViewItem &/* option */,
22
//                                                                         const QModelIndex &/* index */) const
23
// {
24
//      Q_ASSERT_X(m_doc != 0, "GuidesDelegate::createEditor",
25
//                         "No reference to the doc");
26
//      ScrSpinBox *editor = new ScrSpinBox(0, m_doc->currentPage()->height(),
27
//                                                                              parent, m_doc->unitIndex());
28
//      return editor;
29
// }
30
 
22600 craig 31
void GuidesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
20424 jghali 32
{
33
        double value = index.model()->data(index, Qt::EditRole).toDouble();
34
        ScrSpinBox *w = static_cast<ScrSpinBox*>(editor);
35
        w->setValue(value);
36
}
37
 
22600 craig 38
void GuidesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
20424 jghali 39
{
40
        ScrSpinBox *w = static_cast<ScrSpinBox*>(editor);
21026 craig 41
        // When user exit widget, editor value may not be committed at this point
20424 jghali 42
        // so we have to get value from widget text
43
        double value = w->valueFromText(w->text());
44
        model->setData(index, value, Qt::EditRole);
45
}
46
 
22600 craig 47
void GuidesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
20424 jghali 48
{
49
        editor->setGeometry(option.rect);
50
}
51
 
52
void GuidesDelegate::setDoc(ScribusDoc * doc)
53
{
54
        m_doc = doc;
55
}
56
 
57
 
58
// horizontals
59
 
60
GuidesHDelegate::GuidesHDelegate(QObject *parent)
61
        : GuidesDelegate(parent)
62
{
63
}
64
 
22600 craig 65
QWidget * GuidesHDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
20424 jghali 66
{
22600 craig 67
        Q_ASSERT_X(m_doc != nullptr, "GuidesHDelegate::createEditor", "No reference to the doc");
20424 jghali 68
        double uix = unitGetRatioFromIndex(m_doc->unitIndex());
69
        double min = 0.0 - (m_doc->bleeds()->top() * uix);
22600 craig 70
        double max = (m_doc->currentPage()->height() * uix) + (m_doc->bleeds()->bottom() * uix);
71
        ScrSpinBox *editor = new ScrSpinBox(min, max, parent, m_doc->unitIndex());
20424 jghali 72
        return editor;
73
}
74
 
75
// verticals
76
 
77
GuidesVDelegate::GuidesVDelegate(QObject *parent)
78
        : GuidesDelegate(parent)
79
{
80
}
81
 
22600 craig 82
QWidget * GuidesVDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
20424 jghali 83
{
22600 craig 84
        Q_ASSERT_X(m_doc != nullptr, "GuidesVDelegate::createEditor", "No reference to the doc");
20424 jghali 85
        double uix = unitGetRatioFromIndex(m_doc->unitIndex());
86
        double min = 0.0 - (m_doc->bleeds()->left() * uix);
22600 craig 87
        double max = (m_doc->currentPage()->width() * uix) + (m_doc->bleeds()->right() * uix);
88
        ScrSpinBox *editor = new ScrSpinBox(min, max, parent, m_doc->unitIndex());
20424 jghali 89
        return editor;
90
}