lib

KoLayoutTab.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 "KoLayoutTab.h"
21#include "KoTextFormat.h"
22
23#include <knuminput.h>
24
25#include <tqbuttongroup.h>
26#include <tqcheckbox.h>
27#include <tqspinbox.h>
28
29#include "KoLayoutTab.moc"
30
31KoLayoutTab::KoLayoutTab( bool withSubSuperScript, TQWidget* parent, const char* name, WFlags fl )
32 : KoLayoutTabBase( parent, name, fl )
33{
34 if ( !withSubSuperScript ) positionButtonGroup->hide();
35
36 connect( positionButtonGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotSubSuperScriptChanged( int ) ) );
37 connect( offsetSpinBox, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SIGNAL( offsetChanged( int ) ) );
38 connect( relativeSizeKDoubleSpinBox, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotRelativeSizeChanged( double ) ) );
39 connect( hyphenateCheckBox, TQ_SIGNAL( toggled( bool ) ), this, TQ_SIGNAL( hyphenationChanged( bool ) ) );
40}
41
42KoLayoutTab::~KoLayoutTab()
43{
44}
45
46KoTextFormat::VerticalAlignment KoLayoutTab::getSubSuperScript() const
47{
48 switch ( positionButtonGroup->selectedId() )
49 {
50 case 0:
51 return KoTextFormat::AlignNormal;
52 case 1:
53 return KoTextFormat::AlignSubScript;
54 case 2:
55 return KoTextFormat::AlignSuperScript;
56 case 3:
57 return KoTextFormat::AlignCustom;
58 default:
59 return KoTextFormat::AlignNormal;
60 }
61}
62
63int KoLayoutTab::getOffsetFromBaseline() const
64{
65 switch ( positionButtonGroup->selectedId() )
66 {
67 case 0:
68 return 0;
69 case 1:
70 return 0; // subscript has a default
71 case 2:
72 return 0; // superscript has got a default
73 case 3:
74 return offsetSpinBox->value();
75 default:
76 return 0;
77 }
78}
79
80double KoLayoutTab::getRelativeTextSize() const
81{
82 switch ( positionButtonGroup->selectedId() )
83 {
84 case 0:
85 return 1.0;
86 case 1:
87 return relativeSizeKDoubleSpinBox->value() / 100;
88 case 2:
89 return relativeSizeKDoubleSpinBox->value() / 100;
90 case 3:
91 return relativeSizeKDoubleSpinBox->value() / 100;
92 default:
93 return 1.0;
94 }
95}
96
97bool KoLayoutTab::getAutoHyphenation() const
98{
99 return hyphenateCheckBox->isOn();
100}
101
102void KoLayoutTab::setSubSuperScript( KoTextFormat::VerticalAlignment subSuperScript, int offset, double relativeSize )
103{
104 switch ( static_cast< int >( subSuperScript ) )
105 {
106 case 0:
107 positionButtonGroup->setButton( 0 );
108 break;
109 case 1:
110 positionButtonGroup->setButton( 1 );
111 relativeSizeKDoubleSpinBox->setValue( relativeSize * 100 );
112 break;
113 case 2:
114 positionButtonGroup->setButton( 2 );
115 relativeSizeKDoubleSpinBox->setValue( relativeSize * 100 );
116 break;
117 case 3:
118 positionButtonGroup->setButton( 3 );
119 offsetSpinBox->setValue( offset );
120 relativeSizeKDoubleSpinBox->setValue( relativeSize * 100 );
121 break;
122 default:
123 positionButtonGroup->setButton( 0 );
124 break;
125 }
126 slotSubSuperScriptChanged( static_cast< int >( subSuperScript ) );
127}
128
129void KoLayoutTab::setAutoHyphenation( bool state )
130{
131 hyphenateCheckBox->setChecked( state );
132}
133
134void KoLayoutTab::slotSubSuperScriptChanged( int item )
135{
136 if ( item == 1 || item == 2 ) offsetSpinBox->setValue( 0 );
137 emit subSuperScriptChanged();
138 if ( item ) {
139 emit relativeSizeChanged( relativeSizeKDoubleSpinBox->value() / 100 );
140 emit offsetChanged( offsetSpinBox->value() );
141 }
142}
143
144void KoLayoutTab::slotRelativeSizeChanged( double relativeSize )
145{
146 emit relativeSizeChanged( relativeSize / 100 );
147}
const char * name(StdAction id)