Linux.com

Author Message
Joined: May 06, 2008
Posts: 5
Other Topics
Posted Jun 23, 2008 at 2:29:21 AM
Subject: source code for drawing sqaures

hi to all pros..

i'm a noob using KDE C/C++ (Fedora 7). and i had no programming experience in C++. I am required to do a project using this for a floorplan and now i cant even start drawing squares for the rooms using the source codes?

does any kind souls out there pls direct me? ^^
*(like any recommended web sites that i can find relevant sources)*

thx

Back to top Profile Email Website
Johannes Truschnigg

Joined Jun 15, 2008
Posts: 24

Other Topics
Posted: Jun 23, 2008 9:49:50 PM
Subject: source code for drawing sqaures

Use kdevelop or Trolltech's Qt Designer; both provide RAD-interfaces which allow for a graphical GUi design process in conjunction with Qt. Both are free software.

Free software. Free society. Better lives.

Back to top Profile Email Website
0605195G
Joined May 06, 2008
Posts: 5

Other Topics
Posted: Jun 26, 2008 9:37:02 AM
Subject: source code for drawing sqaures

hi Johannes Truschnigg,

We have already found the source code for drawing the sample already.

And now we cannot qmake using the terminal? any suggestion on how should this problem be solved?

THX!


#
# PerlQt Example Application: drawdemo
#
# Demonstrates the painter and the printer.
#

use QColor;
use QFont;
use QPainter;
use QPrinter;
use QPushButton;
use QRadioButton;
use POSIX 'math_h'; # No atan() in Perl.

#
# This function draws a color wheel.
# The coordinate system x=(0..500), y=(0..500) spans the paint device.
#

sub drawColorWheel {
my $p = shift;
my $f = new QFont('Times', 18, $Weight{Bold});
$p->setFont($f);
$p->setPen($black);
$p->setWindow(0, 0, 500, 500);

for(my $i = 0; $i < 36; $i++) {
my $matrix = new QWMatrix;
$matrix->translate(250.0, 250.0);
$matrix->shear(0.0, 0.3);
$matrix->rotate($i*10);
$p->setWorldMatrix($matrix);

$c = new QColor;
$c->setHsv($i*10, 255, 255);
$p->setBrush($c);
$p->drawRect(70, -10, 80, 10);

$p->drawText(80+70+5, 0, "H=" . $i*10);
}
}

#
# This function draws a few lines of text using different fonts.
#

{
my @fonts = ('Helvetica', 'Courier', 'Times');
my @sizes = (10, 12, 18, 24);

sub drawFonts {
my $p = shift;
my($y) = (0, 0, 0);
for my $f (@fonts) {
for my $s (@sizes) {
my $font = new QFont($f, $s);
$p->setFont($font);
my $fm = $p->fontMetrics();
$y += $fm->ascent();
$p->drawText(10, $y, "Quartz Glyph Job Vex'd Cwm Finks");
$y += $fm->descent();
}
}
}
}

#
# This function draws some shapes
#

sub drawShapes {
my $p = shift;
my $b1 = new QBrush($blue);
my $b2 = new QBrush($green, $BrushStyle{Dense6});
my $b3 = new QBrush($BrushStyle{NoBrush});
my $b4 = new QBrush($BrushStyle{Cross});

$p->setPen($red);
$p->setBrush($b1);
$p->drawRect(10, 10, 200, 100);
$p->setBrush($b2);
$p->drawRoundRect(10, 150, 200, 100, 20, 20);
$p->setBrush($b3);
$p->drawEllipse(250, 10, 200, 100);
$p->setBrush($b4);
$p->drawPie(250, 150, 200, 100, 45*16, 90*16);
}

#
# This function draws a text that follows a (Bezier) curve.
# Notice that this function does not support the general case.
# It should be rewritten to calculate the real dx/dy.
#

sub drawPathText {
my $p = new QPainter;
my $a = new QPointArray(4);
$a->setPoint(0, 100,200);
$a->setPoint(1, 150,75);
$a->setPoint(2, 250,75);
$a->setPoint(3, 300,200);
$a = $a->quadBezier();

$p->setPen($lightGray);
$p->drawPolyline($a);

$p->setFont(new QFont('Times', 24));
$p->setPen($black);

my $text = "PerlQt rocks!";

my $len = length($text);
return unless $len;
my $ipos = $a->size()/$len;
my $cpos = $ipos;

for(my $i = 0; $i < $len; $i++) {
my $p1 = $a->point($cpos-1);
my $p2 = $a->point($cpos+1);
my $pt = $a->point($cpos);
my $dx = $p2->x() - $p1->x();
my $dy = $p2->y() - $p1->y();
my $angle = atan($dy/$dx);
$angle *= 180.0/3.14;
my $m = new QWMatrix;
$m->translate($pt->x(), $pt->y());
$m->rotate($angle);
$p->setWorldMatrix($m);
$p->drawText(0, 0, substr($text, $i, 1), 1);
$cpos += $ipos;
}
}

package DrawView;

use slots 'updateIt(int)', 'printIt()';

@ourDrawFunctions = (
{ f => \&drawColorWheel, name => 'Draw color wheel' },
{ f => \&drawFonts, name => 'Draw fonts' },
{ f => \&drawShapes, name => 'Draw shapes' },
{ f => \&drawPathText, name => 'Draw path text' }
);

sub new {}

Back to top Profile Email Website
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya