kpresenter

KPrRotationDialogImpl.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Thomas Zander <zander@kde.org>
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; version 2.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17*/
18#include <tqtoolbutton.h>
19#include <tqslider.h>
20#include <tqgroupbox.h>
21#include <tqlayout.h>
22#include <tqbuttongroup.h>
23#include <tqobject.h>
24#include <tqevent.h>
25
26#include <kiconloader.h>
27#include <kdebug.h>
28#include <tdelocale.h>
29#include <knuminput.h>
30
31#include "KPrRotationDialogImpl.h"
32#include "rotationpropertyui.h"
33#include "KPrTextPreview.h"
34
35KPrRotationDialogImpl::KPrRotationDialogImpl( TQWidget *parent, const char* name )
36: KDialogBase( parent, name, true, i18n( "Rotation"), Ok|Cancel|Apply, Ok, true )
37, m_dialog( new RotationPropertyUI( this, name ) )
38{
39 noSignals = false;
40 m_preview = new KPrTextPreview( m_dialog->previewPanel );
41 TQHBoxLayout *lay = new TQHBoxLayout( m_dialog->previewPanel, m_dialog->previewPanel->lineWidth(), 0 );
42 lay->addWidget( m_preview );
43
44 TQHBoxLayout *hbox = new TQHBoxLayout(m_dialog->angleFrame);
45 m_angleGroup = new KPrCircleGroup(m_dialog->angleFrame);
46 hbox->addWidget(m_angleGroup);
47
48 // Draw the circle of checkboxes.
49 TQGridLayout *circleLayout = new TQGridLayout(m_angleGroup, 4, 5);
50 circleLayout->addItem(new TQSpacerItem ( 1, 1 , TQSizePolicy::MinimumExpanding ), 0, 0);
51 circleLayout->addItem(new TQSpacerItem ( 1, 1 , TQSizePolicy::MinimumExpanding ), 0, 5);
52 KPrCircleToggle *r0 = new KPrCircleToggle(m_angleGroup, "tm", 0);
53 KPrCircleToggle *r45 = new KPrCircleToggle(m_angleGroup, "tr", 45);
54 KPrCircleToggle *r90 = new KPrCircleToggle(m_angleGroup, "mr", 90);
55 KPrCircleToggle *r135 = new KPrCircleToggle(m_angleGroup, "br", 135);
56 KPrCircleToggle *r180 = new KPrCircleToggle(m_angleGroup, "bm", 180);
57 KPrCircleToggle *r225 = new KPrCircleToggle(m_angleGroup, "bl", -135);
58 KPrCircleToggle *r270 = new KPrCircleToggle(m_angleGroup, "ml", -90);
59 KPrCircleToggle *r315 = new KPrCircleToggle(m_angleGroup, "tl", -45);
60 circleLayout->addWidget(r0, 0, 2);
61 circleLayout->addWidget(r180, 2, 2);
62 circleLayout->addWidget(r45, 0, 3);
63 circleLayout->addWidget(r135, 2, 3);
64 circleLayout->addWidget(r315, 0, 1);
65 circleLayout->addWidget(r225, 2, 1);
66 circleLayout->addWidget(r90, 1, 3);
67 circleLayout->addWidget(r270, 1, 1);
68
69 connect( m_angleGroup, TQ_SIGNAL (clicked (int)),
70 this, TQ_SLOT( angleMode( int ) ) );
71 connect (m_dialog->angleSlider, TQ_SIGNAL( valueChanged (int ) ),
72 this, TQ_SLOT( angleMode( int ) ) );
73 connect (m_dialog->angleSpinbox, TQ_SIGNAL (valueChanged (double) ),
74 this, TQ_SLOT( angleChanged( double ) ) );
75 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
76
77 setMainWidget( m_dialog );
78}
79
80void KPrRotationDialogImpl::slotOk()
81{
82 emit apply();
83 accept();
84}
85
86void KPrRotationDialogImpl::setAngle( double angle )
87{
88 if(noSignals) return;
89 noSignals = true;
90 int roundedAngle = (int) (angle + (angle >=0 ? 0.5:-0.5));
91 m_dialog->angleSlider->setValue( roundedAngle );
92 if(roundedAngle == -180)
93 roundedAngle = 180;
94 m_angleGroup->setAngle(roundedAngle);
95 m_dialog->angleSpinbox->setValue( angle );
96 m_preview->setAngle( angle );
97 noSignals = false;
98}
99
100double KPrRotationDialogImpl::angle()
101{
102 return m_dialog->angleSpinbox->value();
103}
104
105void KPrRotationDialogImpl::angleChanged( double angle )
106{
107 setAngle( angle );
108}
109
110void KPrRotationDialogImpl::angleMode( int angle )
111{
112 setAngle( angle );
113}
114
115
116KPrCircleToggle::KPrCircleToggle( TQWidget *parent, const TQString &image, int id )
117 : TQLabel( parent )
118{
119 TDEIconLoader il("kpresenter");
120 m_off = il.loadIcon("rotate/" + image, TDEIcon::NoGroup, 28);
121 m_on = il.loadIcon("rotate/" + image + "dn", TDEIcon::NoGroup, 28);
122
123 m_selected = false;
124 m_id = id;
125 setMouseTracking(true);
126 setPixmap( m_off );
127 KPrCircleGroup *cg = dynamic_cast<KPrCircleGroup*> (parent);
128 if(cg != 0)
129 cg->add(this);
130}
131
132void KPrCircleToggle::mousePressEvent ( TQMouseEvent * e ) {
133 if(e->button() != TQt:: LeftButton)
134 return;
135 setChecked(!m_selected);
136}
137
139 if(on == m_selected) return;
140 m_selected = on;
141 setPixmap( m_selected?m_on:m_off );
142 emit clicked(m_id);
143}
144
146 : TQFrame(parent), m_buttons()
147{
148 noSignals=false;
149}
150
152 noSignals = true;
153 KPrCircleToggle *button;
154 for ( button = m_buttons.first(); button; button = m_buttons.next() )
155 button->setChecked(angle == button->id());
156 noSignals = false;
157}
158
160 connect (button, TQ_SIGNAL(clicked (int)), this, TQ_SLOT (selectionChanged (int)) );
161 m_buttons.append(button);
162}
163
164void KPrCircleGroup::selectionChanged(int buttonId) {
165 if(noSignals)
166 return;
167 KPrCircleToggle *button;
168 for ( button = m_buttons.first(); button; button = m_buttons.next() )
169 button->setChecked(buttonId == button->id());
170 emit clicked(buttonId);
171}
172
173#include "KPrRotationDialogImpl.moc"
A button-group equivalent for a set of KPrCircleToggle classes.
void add(KPrCircleToggle *button)
Add a KPrCircleToggle button as one of the representers of this circle.
void setAngle(int angle)
Set the angle the group is currently representing.
KPrCircleGroup(TQWidget *parent)
Constructor.
void clicked(int id)
clicked will be emitted when one of the child buttons is clicked.
A toggle-button like widget that shows one pixmap when it is checked, and another when it is unselect...
KPrCircleToggle(TQWidget *parent, const TQString &image, int id)
Constructor.
void setChecked(bool on)
Check or uncheck the button.
void mousePressEvent(TQMouseEvent *e)
overwritten method from TQWidget.
int id()
return the id which is passed in the constructor
void clicked(int id)
this signal will be emitted whenever the button becomes checked