kpresenter

KPrRotationDialogImpl.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Thomas Zander <zander@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; version 2.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 #include <qtoolbutton.h>
00020 #include <qslider.h>
00021 #include <qgroupbox.h>
00022 #include <qlayout.h>
00023 #include <qbuttongroup.h>
00024 #include <qobject.h>
00025 #include <qevent.h>
00026 
00027 #include <kiconloader.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <knuminput.h>
00031 
00032 #include "KPrRotationDialogImpl.h"
00033 #include "rotationpropertyui.h"
00034 #include "KPrTextPreview.h"
00035 
00036 KPrRotationDialogImpl::KPrRotationDialogImpl( QWidget *parent, const char* name )
00037 : KDialogBase( parent, name, true, i18n( "Rotation"), Ok|Cancel|Apply, Ok, true )
00038 , m_dialog( new RotationPropertyUI( this, name ) )
00039 {
00040     noSignals = false;
00041     m_preview = new KPrTextPreview( m_dialog->previewPanel );
00042     QHBoxLayout *lay = new QHBoxLayout( m_dialog->previewPanel, m_dialog->previewPanel->lineWidth(), 0 );
00043     lay->addWidget( m_preview );
00044 
00045     QHBoxLayout *hbox = new QHBoxLayout(m_dialog->angleFrame);
00046     m_angleGroup = new KPrCircleGroup(m_dialog->angleFrame);
00047     hbox->addWidget(m_angleGroup);
00048 
00049     // Draw the circle of checkboxes.
00050     QGridLayout *circleLayout = new QGridLayout(m_angleGroup, 4, 5);
00051     circleLayout->addItem(new QSpacerItem ( 1, 1 , QSizePolicy::MinimumExpanding ), 0, 0);
00052     circleLayout->addItem(new QSpacerItem ( 1, 1 , QSizePolicy::MinimumExpanding ), 0, 5);
00053     KPrCircleToggle *r0 = new KPrCircleToggle(m_angleGroup, "tm", 0);
00054     KPrCircleToggle *r45 = new KPrCircleToggle(m_angleGroup, "tr", 45);
00055     KPrCircleToggle *r90 = new KPrCircleToggle(m_angleGroup, "mr", 90);
00056     KPrCircleToggle *r135 = new KPrCircleToggle(m_angleGroup, "br", 135);
00057     KPrCircleToggle *r180 = new KPrCircleToggle(m_angleGroup, "bm", 180);
00058     KPrCircleToggle *r225 = new KPrCircleToggle(m_angleGroup, "bl", -135);
00059     KPrCircleToggle *r270 = new KPrCircleToggle(m_angleGroup, "ml", -90);
00060     KPrCircleToggle *r315 = new KPrCircleToggle(m_angleGroup, "tl", -45);
00061     circleLayout->addWidget(r0, 0, 2);
00062     circleLayout->addWidget(r180, 2, 2);
00063     circleLayout->addWidget(r45, 0, 3);
00064     circleLayout->addWidget(r135, 2, 3);
00065     circleLayout->addWidget(r315, 0, 1);
00066     circleLayout->addWidget(r225, 2, 1);
00067     circleLayout->addWidget(r90, 1, 3);
00068     circleLayout->addWidget(r270, 1, 1);
00069 
00070     connect( m_angleGroup, SIGNAL (clicked (int)),
00071              this, SLOT( angleMode( int ) ) );
00072     connect (m_dialog->angleSlider, SIGNAL( valueChanged (int ) ),
00073              this, SLOT( angleMode( int ) ) );
00074     connect (m_dialog->angleSpinbox, SIGNAL (valueChanged (double) ),
00075              this, SLOT( angleChanged( double ) ) );
00076     connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00077 
00078     setMainWidget( m_dialog );
00079 }
00080 
00081 void KPrRotationDialogImpl::slotOk()
00082 {
00083     emit apply();
00084     accept();
00085 }
00086 
00087 void KPrRotationDialogImpl::setAngle( double angle )
00088 {
00089     if(noSignals) return;
00090     noSignals = true;
00091     int roundedAngle = (int) (angle + (angle >=0 ? 0.5:-0.5));
00092     m_dialog->angleSlider->setValue( roundedAngle );
00093     if(roundedAngle == -180)
00094         roundedAngle = 180;
00095     m_angleGroup->setAngle(roundedAngle);
00096     m_dialog->angleSpinbox->setValue( angle );
00097     m_preview->setAngle( angle );
00098     noSignals = false;
00099 }
00100 
00101 double KPrRotationDialogImpl::angle()
00102 {
00103     return m_dialog->angleSpinbox->value();
00104 }
00105 
00106 void KPrRotationDialogImpl::angleChanged( double angle )
00107 {
00108     setAngle( angle );
00109 }
00110 
00111 void KPrRotationDialogImpl::angleMode( int angle )
00112 {
00113     setAngle( angle );
00114 }
00115 
00116 
00117 KPrCircleToggle::KPrCircleToggle( QWidget *parent, const QString &image, int id )
00118     : QLabel( parent )
00119 {
00120     KIconLoader il("kpresenter");
00121     m_off = il.loadIcon("rotate/" + image, KIcon::NoGroup, 28);
00122     m_on = il.loadIcon("rotate/" + image + "dn", KIcon::NoGroup, 28);
00123 
00124     m_selected = false;
00125     m_id = id;
00126     setMouseTracking(true);
00127     setPixmap( m_off );
00128     KPrCircleGroup *cg = dynamic_cast<KPrCircleGroup*> (parent);
00129     if(cg != 0)
00130         cg->add(this);
00131 }
00132 
00133 void KPrCircleToggle::mousePressEvent ( QMouseEvent * e ) {
00134     if(e->button() != Qt:: LeftButton)
00135         return;
00136     setChecked(!m_selected);
00137 }
00138 
00139 void KPrCircleToggle::setChecked(bool on) {
00140     if(on == m_selected) return;
00141     m_selected = on;
00142     setPixmap( m_selected?m_on:m_off );
00143     emit clicked(m_id);
00144 }
00145 
00146 KPrCircleGroup::KPrCircleGroup(QWidget *parent)
00147     : QFrame(parent), m_buttons()
00148 {
00149     noSignals=false;
00150 }
00151 
00152 void KPrCircleGroup::setAngle(int angle) {
00153     noSignals = true;
00154     KPrCircleToggle *button;
00155     for ( button = m_buttons.first(); button; button = m_buttons.next() )
00156         button->setChecked(angle == button->id());
00157     noSignals = false;
00158 }
00159 
00160 void KPrCircleGroup::add(KPrCircleToggle *button) {
00161     connect (button, SIGNAL(clicked (int)), this, SLOT (selectionChanged (int)) );
00162     m_buttons.append(button);
00163 }
00164 
00165 void KPrCircleGroup::selectionChanged(int buttonId) {
00166     if(noSignals)
00167         return;
00168     KPrCircleToggle *button;
00169     for ( button = m_buttons.first(); button; button = m_buttons.next() )
00170         button->setChecked(buttonId == button->id());
00171     emit clicked(buttonId);
00172 }
00173 
00174 #include "KPrRotationDialogImpl.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys