Subversion Repositories Scribus

Rev

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