summaryrefslogtreecommitdiffstats
path: root/kugar/lib/mlineobject.cpp
blob: 2a4a0bc92470ebb8a28ac9d66688c3bd1487d710 (plain)
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
/***************************************************************************
             mlineobject.cpp  -  Kugar report line object
             -------------------
   begin     : Wed Feb 23 2000
   copyright : (C) 2000 by Mutiny Bay Software
   email     : info@mutinybaysoftware.com
***************************************************************************/

#include "mlineobject.h"

namespace Kugar
{

/** Constructor */
MLineObject::MLineObject() : TQObject()
{
    // Set the object's default tqgeometry
    xpos1 = 0;
    ypos1 = 0;
    xpos2 = 0;
    ypos2 = 0;

    // Set the object's default attributes
    penWidth = 1;
    penColor.setRgb( 0, 0, 0 );
    penStyle = MLineObject::SolidLine;
}

/** Copy constructor */
MLineObject::MLineObject( const MLineObject& mLineObject )  /*: TQObject((TQObject &) mLineObject)*/
{
    copy( &mLineObject );
}

/** Assignment operator */
MLineObject MLineObject::operator=( const MLineObject& mLineObject )
{
    if ( &mLineObject == this )
        return * this;

    // Copy the derived class's data
    copy( &mLineObject );

    // Copy the base class's data
    //((TQObject &) *this) = mLineObject;

    return *this;
}

/** Destructor */
MLineObject::~MLineObject()
{}

/** Sets the start and end points for the line */
void MLineObject::setLine( int xStart, int yStart, int xEnd, int yEnd )
{
    xpos1 = xStart;
    ypos1 = yStart;
    xpos2 = xEnd;
    ypos2 = yEnd;
}

/** Sets the object's color */
void MLineObject::setColor( int r, int g, int b )
{
    penColor.setRgb( r, g, b );
}

/** Sets the object's style */
void MLineObject::setStyle( int style )
{
    penStyle = style;
}

/** Sets the object's width */
void MLineObject::setWidth( int width )
{
    penWidth = width;
}

/** Draws the object to the specified painter & x/y offsets */
void MLineObject::draw( TQPainter* p, int xoffset, int yoffset )
{
    drawBase( p, xoffset, yoffset );
}

/** Draws the base object to the specified painter & x/y offsets */
void MLineObject::drawBase( TQPainter* p, int xoffset, int yoffset )
{
    TQPen linePen( penColor, penWidth, ( TQPen::PenStyle ) penStyle );

    // Set the offsets
    int xcalc1 = xpos1 + xoffset;
    int ycalc1 = ypos1 + yoffset;
    int xcalc2 = xpos2 + xoffset;
    int ycalc2 = ypos2 + yoffset;

    // Draw the line
    p->setPen( linePen );
    p->drawLine( xcalc1, ycalc1, xcalc2, ycalc2 );
}

/** Copies member data from one object to another.
    Used by the copy constructor and assignment operator */
void MLineObject::copy( const MLineObject* mLineObject )
{
    // Copy the object's tqgeometry
    xpos1 = mLineObject->xpos1;
    ypos1 = mLineObject->ypos1;
    xpos2 = mLineObject->xpos2;
    ypos2 = mLineObject->ypos2;

    // copy the object's attributes
    penWidth = mLineObject->penWidth;
    penColor = mLineObject->penColor;
    penStyle = mLineObject->penStyle;
}

}