lib

KoDecorationTab.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002 Montel Laurent <lmontel@mandrakesoft.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KoDecorationTab.h"
21#include <KoGlobal.h>
22
23#include <kcolorbutton.h>
24#include <kpushbutton.h>
25#include <knuminput.h>
26#include <tdelocale.h>
27
28#include <tqbuttongroup.h>
29
30#include "KoDecorationTab.moc"
31
32KoDecorationTab::KoDecorationTab( TQWidget* parent, const char* name, WFlags fl )
33 : KoDecorationTabBase( parent, name, fl )
34{
35 shadowDistanceKDoubleNumInput->setRange(0, 9, 0.5, false);
36
37 connect( textKColorButton, TQ_SIGNAL( changed( const TQColor& ) ), this, TQ_SIGNAL( fontColorChanged( const TQColor& ) ) );
38 connect( backgroundKColorButton, TQ_SIGNAL( changed( const TQColor& ) ), this, TQ_SIGNAL( backgroundColorChanged( const TQColor& ) ) );
39 connect( shadowKColorButton, TQ_SIGNAL( changed( const TQColor& ) ), this, TQ_SIGNAL( shadowColorChanged( const TQColor& ) ) );
40 connect( shadowDistanceKDoubleNumInput, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SIGNAL( shadowDistanceChanged( double ) ) );
41 connect( shadowDirectionButtonGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SIGNAL( shadowDirectionChanged( int ) ) );
42}
43
44KoDecorationTab::~KoDecorationTab()
45{
46}
47
48TQColor KoDecorationTab::getTextColor() const
49{
50 return textKColorButton->color();
51}
52
53TQColor KoDecorationTab::getBackgroundColor() const
54{
55 return backgroundKColorButton->color();
56}
57
58double KoDecorationTab::getShadowDistanceX() const
59{
60 short int sd = shadowDirectionButtonGroup->selectedId();
61 double dist = shadowDistanceKDoubleNumInput->value();
62 return shadowDistanceX( sd, dist );
63}
64
65double KoDecorationTab::getShadowDistanceY() const
66{
67 short int sd = shadowDirectionButtonGroup->selectedId();
68 double dist = shadowDistanceKDoubleNumInput->value();
69 return shadowDistanceY( sd, dist );
70}
71
72TQColor KoDecorationTab::getShadowColor() const
73{
74 return shadowKColorButton->color();
75}
76
77void KoDecorationTab::setTextColor( const TQColor &color )
78{
79 textKColorButton->setColor( color );
80}
81
82void KoDecorationTab::setBackgroundColor( const TQColor &color )
83{
84 backgroundKColorButton->setColor( color );
85}
86
87void KoDecorationTab::setShadow( double shadowDistanceX, double shadowDistanceY, const TQColor& shadowColor )
88{
89 short int sd = SD_RIGHT_UP;
90 double dist = 0.0;
91
92 if ( shadowDistanceX > 0 ) // right
93 if ( shadowDistanceY == 0 )
94 sd = SD_RIGHT;
95 else
96 sd = shadowDistanceY > 0 ? SD_RIGHT_BOTTOM : SD_RIGHT_UP;
97 else if ( shadowDistanceX == 0 ) // top/bottom
98 sd = shadowDistanceY > 0 ? SD_BOTTOM : SD_UP;
99 else // left
100 if ( shadowDistanceY == 0 )
101 sd = SD_LEFT;
102 else
103 sd = shadowDistanceY > 0 ? SD_LEFT_BOTTOM : SD_LEFT_UP;
104
105 shadowDirectionButtonGroup->setButton( sd );
106
107 dist = TQMAX( TQABS(shadowDistanceX), TQABS(shadowDistanceY) );
108 shadowDistanceKDoubleNumInput->setValue( dist );
109
110 shadowKColorButton->setColor( shadowColor.isValid() ? shadowColor: gray );
111
112}
113
114double KoDecorationTab::shadowDistanceX( short int sd, double dist ) const
115{
116 switch ( sd )
117 {
118 case SD_LEFT_BOTTOM:
119 case SD_LEFT:
120 case SD_LEFT_UP:
121 return - dist;
122 case SD_UP:
123 case SD_BOTTOM:
124 return 0;
125 case SD_RIGHT_UP:
126 case SD_RIGHT:
127 case SD_RIGHT_BOTTOM:
128 return dist;
129 }
130 return 0;
131}
132
133double KoDecorationTab::shadowDistanceY( short int sd, double dist ) const
134{
135 switch ( sd )
136 {
137 case SD_LEFT_UP:
138 case SD_UP:
139 case SD_RIGHT_UP:
140 return - dist;
141 case SD_LEFT:
142 case SD_RIGHT:
143 return 0;
144 case SD_LEFT_BOTTOM:
145 case SD_BOTTOM:
146 case SD_RIGHT_BOTTOM:
147 return dist;
148 }
149 return 0;
150}
const char * name(StdAction id)