File: MainWindow.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 (177 lines) | stat: -rw-r--r-- 5,372 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package MainWindow;

use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
    openFile => ['const QString &'],
    openFileNoArg => [''],
    setRenderer => ['QAction *'];
use SvgView;

sub m_nativeAction() {
    return this->{m_nativeAction};
}

sub m_glAction() {
    return this->{m_glAction};
}

sub m_imageAction() {
    return this->{m_imageAction};
}

sub m_highQualityAntialiasingAction() {
    return this->{m_highQualityAntialiasingAction};
}

sub m_backgroundAction() {
    return this->{m_backgroundAction};
}

sub m_outlineAction() {
    return this->{m_outlineAction};
}

sub m_view() {
    return this->{m_view};
}

sub m_currentPath() {
    return this->{m_currentPath};
}

sub NEW
{
    my ($class) = @_;
    $class->SUPER::NEW();
    my $m_view = this->{m_view} = SvgView();

    my $fileMenu = Qt::Menu(this->tr('&File'), this);
    my $openAction = $fileMenu->addAction(this->tr('&Open...'));
    $openAction->setShortcut(Qt::KeySequence(this->tr('Ctrl+O')));
    my $quitAction = $fileMenu->addAction(this->tr('E&xit'));
    $quitAction->setShortcut(Qt::KeySequence(this->tr('Ctrl+Q')));

    this->menuBar()->addMenu($fileMenu);

    my $viewMenu = Qt::Menu(this->tr('&View'), this);
    my $m_backgroundAction = this->{m_backgroundAction} = $viewMenu->addAction(this->tr('&Background'));
    $m_backgroundAction->setEnabled(0);
    $m_backgroundAction->setCheckable(1);
    $m_backgroundAction->setChecked(0);
    this->connect($m_backgroundAction, SIGNAL 'toggled(bool)', $m_view, SLOT 'setViewBackground(bool)');

    my $m_outlineAction = this->{m_outlineAction} = $viewMenu->addAction(this->tr('&Outline'));
    $m_outlineAction->setEnabled(0);
    $m_outlineAction->setCheckable(1);
    $m_outlineAction->setChecked(1);
    this->connect($m_outlineAction, SIGNAL 'toggled(bool)', $m_view, SLOT 'setViewOutline(bool)');

    this->menuBar()->addMenu($viewMenu);

    my $rendererMenu = Qt::Menu(this->tr('&Renderer'), this);
    my $m_nativeAction = this->{m_nativeAction} = $rendererMenu->addAction(this->tr('&Native'));
    $m_nativeAction->setCheckable(1);
    $m_nativeAction->setChecked(1);
#ifndef QT_NO_OPENGL
    my $m_glAction = this->{m_glAction} = $rendererMenu->addAction(this->tr('&OpenGL'));
    $m_glAction->setCheckable(1);
#endif
    my $m_imageAction = this->{m_imageAction} = $rendererMenu->addAction(this->tr('&Image'));
    $m_imageAction->setCheckable(1);

#ifndef QT_NO_OPENGL
    $rendererMenu->addSeparator();
    my $m_highQualityAntialiasingAction = this->{m_highQualityAntialiasingAction} =
        $rendererMenu->addAction(this->tr('&High Quality Antialiasing'));
    $m_highQualityAntialiasingAction->setEnabled(0);
    $m_highQualityAntialiasingAction->setCheckable(1);
    $m_highQualityAntialiasingAction->setChecked(0);
    this->connect($m_highQualityAntialiasingAction, SIGNAL 'toggled(bool)', $m_view, SLOT 'setHighQualityAntialiasing(bool)');
#endif

    my $rendererGroup = Qt::ActionGroup(this);
    $rendererGroup->addAction($m_nativeAction);
#ifndef QT_NO_OPENGL
    $rendererGroup->addAction($m_glAction);
#endif
    $rendererGroup->addAction($m_imageAction);

    this->menuBar()->addMenu($rendererMenu);

    this->connect($openAction, SIGNAL 'triggered()', this, SLOT 'openFileNoArg()');
    this->connect($quitAction, SIGNAL 'triggered()', qApp, SLOT 'quit()');
    this->connect($rendererGroup, SIGNAL 'triggered(QAction *)',
            this, SLOT 'setRenderer(QAction *)');

    this->setCentralWidget($m_view);
    this->setWindowTitle(this->tr('SVG Viewer'));
}

sub openFileNoArg {
    this->openFile();
}

sub openFile
{
    my ($path) = @_;
    my $fileName;
    if (!$path) {
        $fileName = Qt::FileDialog::getOpenFileName(this, this->tr('Open SVG File'),
                this->m_currentPath, 'SVG files (*.svg *.svgz *.svg.gz)');
    }
    else {
        $fileName = $path;
    }

    if ($fileName) {
        my $file = Qt::File($fileName);
        if (!$file->exists()) {
            Qt::MessageBox::critical(this, this->tr('Open SVG File'),
                           "Could not open file '$fileName'.");

            this->m_outlineAction->setEnabled(0);
            this->m_backgroundAction->setEnabled(0);
            return;
        }

        this->m_view->openFile($file);

        #if (!fileName.startsWith(':/')) {
            this->{m_currentPath} = $fileName;
            this->setWindowTitle(sprintf this->tr('%s - SVGViewer'), this->m_currentPath);
        #}

        this->m_outlineAction->setEnabled(1);
        this->m_backgroundAction->setEnabled(1);

        this->resize(this->m_view->sizeHint() + Qt::Size(80, 80 + this->menuBar()->height()));
    }
}

sub setRenderer
{
    my ($action) = @_;
#ifndef QT_NO_OPENGL
    this->m_highQualityAntialiasingAction->setEnabled(0);
#endif

    # FIXME Why doesn't adding an operator overload to call op_ref_equal work?
    if ($action->op_ref_equal( this->m_nativeAction ) ) {
        this->m_view->setRenderer(SvgView::Native);
    }
#ifndef QT_NO_OPENGL
    elsif ($action->op_ref_equal( this->m_glAction ) ) {
        this->m_highQualityAntialiasingAction->setEnabled(1);
        this->m_view->setRenderer(SvgView::OpenGL);
    }
#endif
    elsif ($action->op_ref_equal( this->m_imageAction ) ) {
        this->m_view->setRenderer(SvgView::Image);
    }
}

1;