File: StarDelegate.pm

package info (click to toggle)
qt4-perl 4.8.4-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,636 kB
  • ctags: 8,100
  • sloc: perl: 42,963; cpp: 28,039; makefile: 160; xml: 98; sh: 4
file content (108 lines) | stat: -rw-r--r-- 2,343 bytes parent folder | download | duplicates (4)
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
package StarDelegate;

use strict;
use warnings;
use QtCore4;
use QtGui4;

# [0]
use QtCore4::isa qw( Qt::StyledItemDelegate );
use QtCore4::slots
    commitAndCloseEditor => [];
# [0]

use StarDelegate;
use StarEditor;
use StarRating;

sub NEW {
    my ($class, $parent) = @_;
    $class->SUPER::NEW($parent);
}

# [0]
sub paint
{
    my ($painter, $option, $index) = @_;
    my $starRating = $index->data()->value();
    if ( ref $starRating eq 'StarRating') {

        if (${$option->state() & Qt::Style::State_Selected()}) {
            $painter->fillRect($option->rect(), $option->palette()->highlight());
        }

        $starRating->paint($painter, $option->rect(), $option->palette(),
                         StarRating::ReadOnly);
    } else {
        this->SUPER::paint($painter, $option, $index);
    }
# [0]
}

# [1]
sub sizeHint
{
    my ($option, $index) = @_;
    my $starRating = $index->data()->value();
    if ( ref $starRating eq 'StarRating') {
        return $starRating->sizeHint();
    } else {
        return this->SUPER::sizeHint($option, $index);
    }
}
# [1]

# [2]
sub createEditor
{
    my ($parent, $option, $index) = @_;
    my $starRating = $index->data()->value();
    if ( ref $starRating eq 'StarRating') {
        my $editor = StarEditor($parent);
        this->connect($editor, SIGNAL 'editingFinished()',
                this, SLOT 'commitAndCloseEditor()');
        return $editor;
    } else {
        return this->SUPER::createEditor($parent, $option, $index);
    }
}
# [2]

# [3]
sub setEditorData
{
    my ($editor, $index) = @_;
    my $starRating = $index->data()->value();
    if ( ref $starRating eq 'StarRating') {
        my $starEditor = $editor;
        $starEditor->setStarRating($starRating);
    } else {
        this->SUPER::setEditorData($editor, $index);
    }
}
# [3]

# [4]
sub setModelData
{
    my ($editor, $model, $index) = @_;
    my $starRating = $index->data()->value();
    if ( ref $starRating eq 'StarRating') {
        my $starEditor = $editor;
        $model->setData($index, Qt::qVariantFromValue($starEditor->starRating()));
    } else {
        this->SUPER::setModelData($editor, $model, $index);
    }
}
# [4]

# [5]
sub commitAndCloseEditor
{
    my $editor = this->sender();
    emit this->commitData($editor);
    emit this->closeEditor($editor);
}
# [5]

1;