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
|
package MainWindow;
use strict;
use warnings;
use QtCore4;
use QtGui4;
use XbelTree;
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
open => [],
saveAs => [],
about => [];
sub xbelTree() {
return this->{xbelTree};
}
sub fileMenu() {
return this->{fileMenu};
}
sub helpMenu() {
return this->{helpMenu};
}
sub openAct() {
return this->{openAct};
}
sub saveAsAct() {
return this->{saveAsAct};
}
sub exitAct() {
return this->{exitAct};
}
sub aboutAct() {
return this->{aboutAct};
}
sub aboutQtAct() {
return this->{aboutQtAct};
}
sub NEW
{
my ( $class ) = @_;
$class->SUPER::NEW();
this->{xbelTree} = XbelTree();
setCentralWidget(xbelTree);
createActions();
createMenus();
statusBar()->showMessage(this->tr('Ready'));
setWindowTitle(this->tr('DOM Bookmarks'));
resize(480, 320);
}
sub open
{
my $fileName =
Qt::FileDialog::getOpenFileName(this, this->tr('Open Bookmark File'),
Qt::Dir::currentPath(),
this->tr('XBEL Files (*.xbel *.xml)'));
if (!$fileName) {
return;
}
my $file = Qt::File($fileName);
if (!$file->open(Qt::File::ReadOnly() | Qt::File::Text())) {
Qt::MessageBox::warning(this, this->tr('SAX Bookmarks'),
sprintf this->tr("Cannot read file %s:\n%s."),
$fileName,
$file->errorString());
return;
}
if (xbelTree->read($file)) {
statusBar()->showMessage(this->tr('File loaded'), 2000);
}
}
sub saveAs
{
my $fileName =
Qt::FileDialog::getSaveFileName(this, this->tr('Save Bookmark File'),
Qt::Dir::currentPath(),
this->tr('XBEL Files (*.xbel *.xml)'));
if (!$fileName) {
return;
}
my $file = Qt::File($fileName);
if (!$file->open(Qt::File::WriteOnly() | Qt::File::Text())) {
Qt::MessageBox::warning(this, this->tr('SAX Bookmarks'),
sprintf this->tr("Cannot write file %s:\n%s."),
$fileName,
$file->errorString());
return;
}
if (xbelTree->write($file)) {
statusBar()->showMessage(this->tr('File saved'), 2000);
}
$file->close();
}
sub about
{
Qt::MessageBox::about(this, this->tr('About DOM Bookmarks'),
this->tr('The <b>DOM Bookmarks</b> example demonstrates how to ' .
'use Qt\'s DOM classes to read and write XML ' .
'documents.'));
}
sub createActions
{
this->{openAct} = Qt::Action(this->tr('&Open...'), this);
openAct->setShortcuts(Qt::KeySequence::Open());
this->connect(openAct, SIGNAL 'triggered()', this, SLOT 'open()');
this->{saveAsAct} = Qt::Action(this->tr('&Save As...'), this);
saveAsAct->setShortcuts(Qt::KeySequence::SaveAs());
this->connect(saveAsAct, SIGNAL 'triggered()', this, SLOT 'saveAs()');
this->{exitAct} = Qt::Action(this->tr('E&xit'), this);
exitAct->setShortcuts(Qt::KeySequence::Quit());
this->connect(exitAct, SIGNAL 'triggered()', this, SLOT 'close()');
this->{aboutAct} = Qt::Action(this->tr('&About'), this);
this->connect(aboutAct, SIGNAL 'triggered()', this, SLOT 'about()');
this->{aboutQtAct} = Qt::Action(this->tr('About &Qt'), this);
this->connect(aboutQtAct, SIGNAL 'triggered()', qApp, SLOT 'aboutQt()');
}
sub createMenus
{
this->{fileMenu} = menuBar()->addMenu(this->tr('&File'));
fileMenu->addAction(openAct);
fileMenu->addAction(saveAsAct);
fileMenu->addAction(exitAct);
this->menuBar()->addSeparator();
this->{helpMenu} = menuBar()->addMenu(this->tr('&Help'));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
1;
|