summaryrefslogtreecommitdiffstats
path: root/PerlQt/lib
diff options
context:
space:
mode:
Diffstat (limited to 'PerlQt/lib')
-rw-r--r--PerlQt/lib/Qt/GlobalSpace.pm25
-rw-r--r--PerlQt/lib/Qt/attributes.pm51
-rw-r--r--PerlQt/lib/Qt/constants.pm62
-rw-r--r--PerlQt/lib/Qt/debug.pm36
-rw-r--r--PerlQt/lib/Qt/enumerations.pm15
-rw-r--r--PerlQt/lib/Qt/isa.pm81
-rw-r--r--PerlQt/lib/Qt/properties.pm14
-rw-r--r--PerlQt/lib/Qt/signals.pm77
-rw-r--r--PerlQt/lib/Qt/slots.pm84
9 files changed, 445 insertions, 0 deletions
diff --git a/PerlQt/lib/Qt/GlobalSpace.pm b/PerlQt/lib/Qt/GlobalSpace.pm
new file mode 100644
index 0000000..65e481a
--- /dev/null
+++ b/PerlQt/lib/Qt/GlobalSpace.pm
@@ -0,0 +1,25 @@
+package Qt::GlobalSpace;
+use strict;
+require Qt;
+require Exporter;
+
+our @ISA = qw(Exporter);
+our @EXPORT;
+our $allMeth = Qt::_internal::findAllMethods( Qt::_internal::idClass("QGlobalSpace") );
+no strict 'refs';
+
+for my $proto( keys %$allMeth )
+{
+ next if $proto =~ /operator\W/; # skip operators
+ $proto =~ s/[\#\$\?]+$//;
+ *{ $proto } = sub
+ {
+ $Qt::_internal::autoload::AUTOLOAD = "Qt::GlobalSpace\::$proto";
+ goto &Qt::GlobalSpace::AUTOLOAD
+ } unless defined &$proto;
+ push @EXPORT, $proto;
+}
+
+our %EXPORT_TAGS = ( "all" => [@EXPORT] );
+
+1; \ No newline at end of file
diff --git a/PerlQt/lib/Qt/attributes.pm b/PerlQt/lib/Qt/attributes.pm
new file mode 100644
index 0000000..3a25487
--- /dev/null
+++ b/PerlQt/lib/Qt/attributes.pm
@@ -0,0 +1,51 @@
+package Qt::attributes;
+#
+# I plan to support public/protected/private attributes. here goes.
+# Attributes default to protected.
+#
+# package MyBase;
+# use Qt::attributes qw(
+# private:
+# foo
+# protected:
+# bar
+# public:
+# baz
+# );
+#
+# package MyDerived;
+# use Qt::isa qw(MyBase);
+#
+# sub foo {
+# # 1 way to access private attributes from derived class
+# #
+# # this->{$class} contains private attributes for $class
+# # I specify it to always work that way,
+# # so feel free to use it in code.
+# this->{MyBase}{foo} = 10;
+#
+# # 2 ways to access protected attributes
+# bar = 10;
+# this->{bar} = 10;
+#
+# # 3 ways to access public attributes
+# baz = 10;
+# this->{baz} = 10;
+# this->baz = 10;
+# }
+#
+# Attributes override any method with the same name, so you may want
+# to prefix them with _ to prevent conflicts.
+#
+sub import {
+ my $class = shift;
+ my $caller = (caller)[0];
+
+ for my $attribute (@_) {
+ exists ${ ${$caller . '::META'}{'attributes'} }{$attribute} and next;
+ Qt::_internal::installattribute($caller, $attribute);
+ ${ ${$caller . '::META'}{'attributes'} }{$attribute} = 1;
+ }
+}
+
+1;
diff --git a/PerlQt/lib/Qt/constants.pm b/PerlQt/lib/Qt/constants.pm
new file mode 100644
index 0000000..9c7081c
--- /dev/null
+++ b/PerlQt/lib/Qt/constants.pm
@@ -0,0 +1,62 @@
+package Qt::constants;
+
+require Exporter;
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(
+ IO_Direct
+ IO_Sequential
+ IO_Combined
+ IO_TypeMask
+ IO_Raw
+ IO_Async
+ IO_ReadOnly
+ IO_WriteOnly
+ IO_ReadWrite
+ IO_Append
+ IO_Truncate
+ IO_Translate
+ IO_ModeMask
+ IO_Open
+ IO_StateMask
+ IO_Ok
+ IO_ReadError
+ IO_WriteError
+ IO_FatalError
+ IO_ResourceError
+ IO_OpenError
+ IO_ConnectError
+ IO_AbortError
+ IO_TimeOutError
+ IO_UnspecifiedError
+);
+
+our %EXPORT_TAGS = ( 'IO' => [ @EXPORT ] );
+
+sub IO_Direct () { 0x0100 }
+sub IO_Sequential () { 0x0200 }
+sub IO_Combined () { 0x0300 }
+sub IO_TypeMask () { 0x0f00 }
+sub IO_Raw () { 0x0040 }
+sub IO_Async () { 0x0080 }
+sub IO_ReadOnly () { 0x0001 }
+sub IO_WriteOnly () { 0x0002 }
+sub IO_ReadWrite () { 0x0003 }
+sub IO_Append () { 0x0004 }
+sub IO_Truncate () { 0x0008 }
+sub IO_Translate () { 0x0010 }
+sub IO_ModeMask () { 0x00ff }
+sub IO_Open () { 0x1000 }
+sub IO_StateMask () { 0xf000 }
+sub IO_Ok () { 0 }
+sub IO_ReadError () { 1 }
+sub IO_WriteError () { 2 }
+sub IO_FatalError () { 3 }
+sub IO_ResourceError () { 4 }
+sub IO_OpenError () { 5 }
+sub IO_ConnectError () { 5 }
+sub IO_AbortError () { 6 }
+sub IO_TimeOutError () { 7 }
+sub IO_UnspecifiedError() { 8 }
+
+1; \ No newline at end of file
diff --git a/PerlQt/lib/Qt/debug.pm b/PerlQt/lib/Qt/debug.pm
new file mode 100644
index 0000000..28c0a43
--- /dev/null
+++ b/PerlQt/lib/Qt/debug.pm
@@ -0,0 +1,36 @@
+package Qt::debug;
+use Qt;
+
+our %channel = (
+ 'ambiguous' => 0x01,
+ 'autoload' => 0x02,
+ 'calls' => 0x04,
+ 'gc' => 0x08,
+ 'virtual' => 0x10,
+ 'verbose' => 0x20,
+ 'all' => 0xffff
+);
+
+sub import {
+ shift;
+ my $db = (@_)? 0x0000 : (0x01|0x20);
+ my $usage = 0;
+ for my $ch(@_) {
+ if( exists $channel{$ch}) {
+ $db |= $channel{$ch};
+ } else {
+ warn "Unknown debugging channel: $ch\n";
+ $usage++;
+ }
+ }
+ Qt::_internal::setDebug($db);
+ print "Available channels: \n\t".
+ join("\n\t", sort keys %channel).
+ "\n" if $usage;
+}
+
+sub unimport {
+ Qt::_internal::setDebug(0);
+}
+
+1; \ No newline at end of file
diff --git a/PerlQt/lib/Qt/enumerations.pm b/PerlQt/lib/Qt/enumerations.pm
new file mode 100644
index 0000000..003b65b
--- /dev/null
+++ b/PerlQt/lib/Qt/enumerations.pm
@@ -0,0 +1,15 @@
+package Qt::enumerations;
+#
+# Proposed usage:
+#
+# package MyWidget;
+#
+# use Qt::enumerations MyInfo => {
+# Foo => 1,
+# Bar => 10,
+# Baz => 64
+# };
+#
+# use Qt::enumerations MyInfo => [qw(Foo Bar Baz)];
+#
+1;
diff --git a/PerlQt/lib/Qt/isa.pm b/PerlQt/lib/Qt/isa.pm
new file mode 100644
index 0000000..fb4b646
--- /dev/null
+++ b/PerlQt/lib/Qt/isa.pm
@@ -0,0 +1,81 @@
+package Qt::isa;
+use strict;
+
+sub import {
+ no strict 'refs';
+ my $class = shift;
+ my $caller = (caller)[0];
+
+ # Trick 'use' into believing the file for this class has been read
+ my $pm = $caller . ".pm";
+ $pm =~ s!::!/!g;
+ unless(exists $::INC{$pm}) {
+ $::INC{$pm} = $::INC{"Qt/isa.pm"};
+ }
+
+ for my $super (@_) {
+ push @{ $caller . '::ISA' }, $super;
+ push @{ ${$caller . '::META'}{'superClass'} }, $super; # if isa(QObject)?
+ }
+
+ *{ $caller . '::className' } = sub { # closure on $caller
+ return $caller;
+ };
+
+ ${ $caller. '::_INTERNAL_STATIC_'}{'SUPER'} = bless {}, " $caller";
+ Qt::_internal::installsuper($caller) unless defined &{ $caller.'::SUPER' };
+
+ *{ $caller . '::metaObject' } = sub {
+ Qt::_internal::getMetaObject($caller);
+ };
+
+ *{ $caller . '::import' } = sub {
+ my $name = shift; # classname = function-name
+ my $incaller = (caller)[0];
+ $incaller = (caller(1))[0] if $incaller eq 'if'; # work-around bug in package 'if' pre 0.02
+ (my $cname = $name) =~ s/.*::// and do
+ {
+ *{ "$name" } = sub {
+ $name->new(@_);
+ } unless defined &{ "$name" };
+ };
+ my $p = defined $&? $&:'';
+ $p eq ($incaller=~/.*::/?($p?$&:''):'') and
+ *{ "$incaller\::$cname" } = sub {
+ $name->new(@_);
+ };
+
+ if(defined @{ ${$caller.'::META'}{'superClass'} } &&
+ @{ ${$caller.'::META'}{'superClass'} } )
+ {
+ # attributes inheritance
+ for my $attribute( keys %{ ${$caller.'::META'}{'attributes'} } )
+ {
+ if(! defined &{$incaller.'::'.$attribute })
+ {
+ Qt::_internal::installattribute($incaller, $attribute);
+ ${ ${$incaller .'::META'}{'attributes'} }{$attribute} = 1;
+ }
+ }
+ }
+ };
+
+ Qt::_internal::installautoload(" $caller");
+ Qt::_internal::installautoload(" $caller");
+ Qt::_internal::installautoload($caller);
+ {
+ package Qt::AutoLoad;
+ my $autosub = \&{ " $caller\::_UTOLOAD" };
+ *{ " $caller\::AUTOLOAD" } = sub { &$autosub };
+ $autosub = \&{ " $caller\::_UTOLOAD" };
+ *{ " $caller\::AUTOLOAD" } = sub { &$autosub };
+ $autosub = \&{ "$caller\::_UTOLOAD" };
+ *{ "$caller\::AUTOLOAD" } = sub { &$autosub };
+ }
+ Qt::_internal::installthis($caller);
+
+ # operator overloading
+ *{ " $caller\::ISA" } = ["Qt::base::_overload"];
+}
+
+1;
diff --git a/PerlQt/lib/Qt/properties.pm b/PerlQt/lib/Qt/properties.pm
new file mode 100644
index 0000000..5dfcdb7
--- /dev/null
+++ b/PerlQt/lib/Qt/properties.pm
@@ -0,0 +1,14 @@
+package Qt::properties;
+#
+# Proposed usage:
+#
+# use Qt::properties foo => {
+# TYPE => 'bool',
+# READ => 'getFoo',
+# WRITE => 'setFoo',
+# STORED => 0,
+# RESET => 'unsetFoo',
+# DESIGNABLE => 0
+# };
+#
+1;
diff --git a/PerlQt/lib/Qt/signals.pm b/PerlQt/lib/Qt/signals.pm
new file mode 100644
index 0000000..00aa061
--- /dev/null
+++ b/PerlQt/lib/Qt/signals.pm
@@ -0,0 +1,77 @@
+package Qt::signals;
+use Carp;
+#
+# Proposed usage:
+#
+# use Qt::signals fooActivated => ['int'];
+#
+# use Qt::signals fooActivated => {
+# name => 'fooActivated(int)',
+# args => ['int']
+# };
+#
+# sub whatever { emit fooActivated(10); }
+#
+
+sub import {
+ no strict 'refs';
+ my $self = shift;
+ my $caller = $self eq "Qt::signals" ? (caller)[0] : $self;
+ my $parent = ${ $caller . '::ISA' }[0];
+ my $parent_qt_emit = $parent . '::qt_emit';
+
+ Qt::_internal::installqt_invoke($caller . '::qt_emit') unless defined &{ $caller. '::qt_emit' };
+
+# *{ $caller . '::qt_emit' } = sub {
+# my $meta = \%{ $caller . '::META' };
+# die unless $meta->{object};
+# my $offset = $_[0] - $meta->{object}->signalOffset;
+# if($offset >= 0) {
+# Qt::_internal::invoke(Qt::this(), $meta->{signals}[$offset], $_[1]);
+# return 1;
+# } else {
+# Qt::this()->$parent_qt_emit(@_);
+# }
+# } unless defined &{ $caller . '::qt_emit' };
+
+ my $meta = \%{ $caller . '::META' };
+ croak "Odd number of arguments in signal declaration" if @_%2;
+ my(%signals) = @_;
+ for my $signalname (keys %signals) {
+ my $signal = { name => $signalname };
+ my $args = $signals{$signalname};
+ $signal->{arguments} = [map { s/\s(?=[*&])//; { type => $_, name => "" } } @$args];
+ my $arglist = join ',', @$args;
+ $signal->{prototype} = $signalname . "($arglist)";
+ $signal->{returns} = 'void';
+ $signal->{method} = $signalname;
+ push @{$meta->{signals}}, $signal;
+ my $signal_index = $#{ $meta->{signals} };
+
+ my $argcnt = scalar @$args;
+ my $mocargs = Qt::_internal::allocateMocArguments($argcnt);
+ my $i = 0;
+ for my $arg (@$args) {
+ my $a = $arg;
+ $a =~ s/^const\s+//;
+ if($a =~ /^(bool|int|double|char\*|QString)&?$/) {
+ $a = $1;
+ } else {
+ $a = 'ptr';
+ }
+ my $valid = Qt::_internal::setMocType($mocargs, $i, $arg, $a);
+ die "Invalid type for signal argument ($arg)\n" unless $valid;
+ $i++;
+ }
+
+ $meta->{signal}{$signalname} = $signal;
+ $signal->{index} = $signal_index;
+ $signal->{mocargs} = $mocargs;
+ $signal->{argcnt} = $argcnt;
+
+ Qt::_internal::installsignal("$caller\::$signalname");
+ }
+ @_ and $meta->{changed} = 1;
+}
+
+1;
diff --git a/PerlQt/lib/Qt/slots.pm b/PerlQt/lib/Qt/slots.pm
new file mode 100644
index 0000000..5d1daf6
--- /dev/null
+++ b/PerlQt/lib/Qt/slots.pm
@@ -0,0 +1,84 @@
+package Qt::slots;
+use Carp;
+#
+# Proposed usage:
+#
+# use Qt::slots changeSomething => ['int'];
+#
+# use Qt::slots 'changeSomething(int)' => {
+# args => ['int'],
+# call => 'changeSomething'
+# };
+#
+
+sub import {
+ no strict 'refs';
+ my $self = shift;
+ my $caller = $self eq "Qt::slots" ? (caller)[0] : $self;
+ my $parent = ${ $caller . '::ISA' }[0];
+ my $parent_qt_invoke = $parent . '::qt_invoke';
+
+ Qt::_internal::installqt_invoke($caller . '::qt_invoke') unless defined &{ $caller. '::qt_invoke' };
+
+# *{ $caller . '::qt_invoke' } = sub {
+# my $meta = \%{ $caller . '::META' };
+# die unless $meta->{object};
+# my $offset = $_[0] - $meta->{object}->slotOffset;
+# if($offset >= 0) {
+# Qt::_internal::invoke(Qt::this(), $meta->{slots}[$offset], $_[1]);
+# return 1;
+# } else {
+# Qt::this()->$parent_qt_invoke(@_);
+# }
+# } unless defined &{ $caller . '::qt_invoke' };
+
+ my $meta = \%{ $caller . '::META' };
+ croak "Odd number of arguments in slot declaration" if @_%2;
+ my(%slots) = @_;
+ for my $slotname (keys %slots) {
+ my $slot = { name => $slotname };
+ my $args = $slots{$slotname};
+ $slot->{arguments} = [map { s/\s(?=[*&])//; { type => $_, name => "" } } @$args];
+ my $arglist = join ',', @$args;
+
+ $slot->{prototype} = $slotname . "($arglist)";
+ if ( exists $meta->{slot}{$slotname} ) {
+ (my $s1 = $slot->{prototype}) =~ s/\s+//g;
+ (my $s2 = $meta->{slot}{$slotname}{prototype}) =~ s/\s+//g;
+ if( $s1 ne $s2 ) {
+ warn( "Slot declaration:\n\t$slot->{prototype}\nwill override ".
+ "previous declaration:\n\t$meta->{slot}{$slotname}{prototype}");
+ } else {
+ next;
+ }
+ }
+ $slot->{returns} = 'void';
+ $slot->{method} = $slotname;
+ push @{$meta->{slots}}, $slot;
+ my $slot_index = $#{ $meta->{slots} };
+
+ my $argcnt = scalar @$args;
+ my $mocargs = Qt::_internal::allocateMocArguments($argcnt);
+ my $i = 0;
+ for my $arg (@$args) {
+ my $a = $arg;
+ $a =~ s/^const\s+//;
+ if($a =~ /^(bool|int|double|char\*|QString)&?$/) {
+ $a = $1;
+ } else {
+ $a = 'ptr';
+ }
+ my $valid = Qt::_internal::setMocType($mocargs, $i, $arg, $a);
+ die "Invalid type for slot argument ($arg)\n" unless $valid;
+ $i++;
+ }
+
+ $meta->{slot}{$slotname} = $slot;
+ $slot->{index} = $slot_index;
+ $slot->{mocargs} = $mocargs;
+ $slot->{argcnt} = $argcnt;
+ }
+ @_ and $meta->{changed} = 1;
+}
+
+1;