summaryrefslogtreecommitdiffstats
path: root/kbarcode/rectsettingsdlg.cpp
blob: 10e6958e0b6f6e776008a81c37b6efedaab526d6 (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
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
178
179
180
181
182
183
/***************************************************************************
                          rectsettingsdlg.cpp  -  description
                             -------------------
    begin                : Mit Jun 18 2003
    copyright            : (C) 2003 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "rectsettingsdlg.h"

// TQt includes
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpainter.h>
#include <tqpen.h>

// KDE includes
#include <kcolorbutton.h>
#include <kcombobox.h>
#include <tdelocale.h>
#include <knuminput.h>

void fillLineCombo( KComboBox* box )
{
    /* A small helper function to fill
     * a combobox with all by TQt
     * supported pen styles.
     */

    TQPainter p;
    for( int i = 1; i < 6; i++ ) {
        TQPixmap pixmap( 60, 20 );
        pixmap.fill( TQt::white );
        p.begin( &pixmap );
        p.setPen( TQPen( TQt::black, 3, (TQt::PenStyle)i ) );
        p.drawLine( 5, 10, 55, 10 );
        p.end();

        box->insertItem( pixmap );
    }
}

RectSettingsDlg::RectSettingsDlg(TQWidget *parent, const char *name )
    : KDialogBase( KDialogBase::Plain, i18n("Settings"),
      KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent,name)
{
    TQFrame* frame = plainPage();
    TQGridLayout* grid = new TQGridLayout( frame, 6, 6 );
    TQSpacerItem* spacer = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );

    
    buttonBorder = new KColorButton( frame );
    buttonFill = new KColorButton( frame );

    spinWidth = new KIntNumInput( frame );
    spinWidth->setRange( 1, 100, 1, false );

    comboLine = new KComboBox( false, frame );
    fillLineCombo( comboLine );
    
    checkBorder = new TQCheckBox( i18n("&Enable Border"), frame );
    
    grid->addWidget( new TQLabel( i18n("Fill Color:"), frame ), 0, 0 );
    grid->addWidget( buttonFill, 0, 1 );
    grid->addItem( spacer, 1, 0 );
    grid->addWidget( checkBorder, 2, 0 );            
    grid->addWidget( new TQLabel( i18n("Border Color:"), frame ), 3, 0 );
    grid->addWidget( buttonBorder, 3, 1 );
    grid->addWidget( new TQLabel( i18n("Border Width:"), frame ), 4, 0 );
    grid->addWidget( spinWidth, 4, 1 );
    grid->addWidget( new TQLabel( i18n("Line Style:"), frame ), 5, 0 );
    grid->addWidget( comboLine, 5, 1 );

    connect( checkBorder, TQ_SIGNAL( clicked() ), this, TQ_SLOT( enableControls() ) );
}

RectSettingsDlg::~RectSettingsDlg()
{
}

void RectSettingsDlg::enableControls()
{
    buttonBorder->setEnabled( checkBorder->isChecked() );
    spinWidth->setEnabled( checkBorder->isChecked() );
    comboLine->setEnabled( checkBorder->isChecked() );
}

void RectSettingsDlg::setBorderColor( const TQColor & c )
{
    buttonBorder->setColor( c );
}

void RectSettingsDlg::setFillColor( const TQColor & c )
{
    buttonFill->setColor( c );
}

void RectSettingsDlg::setBorderWidth( int w )
{
    spinWidth->setValue( w );
}

void RectSettingsDlg::setPenStyle( int s )
{
    if( s ) {
        comboLine->setCurrentItem( s - 1 );
        checkBorder->setChecked( true );
    } else
        checkBorder->setChecked( false );

    enableControls();    
}

const TQColor RectSettingsDlg::borderColor() const
{
    return buttonBorder->color();
}

const TQColor RectSettingsDlg::fillColor() const
{
    return buttonFill->color();
}

int RectSettingsDlg::borderWidth() const
{
    return spinWidth->value();
}

int RectSettingsDlg::penStyle() const
{
    return checkBorder->isChecked() ? comboLine->currentItem() + 1 : 0;
}

LineSettingsDlg::LineSettingsDlg(TQWidget *parent, const char *name )
    : KDialogBase( KDialogBase::Plain, i18n("Settings"),
      KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent,name)
{
    TQFrame* frame = plainPage();
    TQGridLayout* grid = new TQGridLayout( frame, 6, 6 );

    buttonColor = new KColorButton( frame );

    spinWidth = new KIntNumInput( frame );
    spinWidth->setRange( 1, 100, 1, false );

    comboLine = new KComboBox( false, frame );
    fillLineCombo( comboLine );    

    grid->addWidget( new TQLabel( i18n("Color:"), frame ), 0, 0 );
    grid->addWidget( buttonColor, 0, 1 );
    grid->addWidget( new TQLabel( i18n("Line Width:"), frame ), 1, 0 );
    grid->addWidget( spinWidth, 1, 1 );
    grid->addWidget( new TQLabel( i18n("Line Style:"), frame ), 2, 0 );
    grid->addWidget( comboLine, 2, 1 );
}

LineSettingsDlg::~LineSettingsDlg()
{
}

TQPen LineSettingsDlg::pen() const
{
    return TQPen( buttonColor->color(), spinWidth->value(), (TQt::PenStyle)(comboLine->currentItem() + 1) );
}

void LineSettingsDlg::setPen( const TQPen p )
{
    buttonColor->setColor( p.color() );
    spinWidth->setValue( p.width() );
    comboLine->setCurrentItem( p.style() - 1 );
}

#include "rectsettingsdlg.moc"