lib Library API Documentation

koToolBox.cpp

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 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., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include "koToolBox.h" 00021 #include "koDocumentChild.h" 00022 00023 #include <kwin.h> 00024 00025 #include <qlayout.h> 00026 #include <qspinbox.h> 00027 #include <qobjectlist.h> 00028 00029 KoToolBox::KoToolBox( QWidget* parent, const char* name ) 00030 : QFrame( parent, name, WType_TopLevel | WStyle_Tool ) 00031 { 00032 KWin::setType( winId(), NET::Tool ); 00033 00034 setFrameShape( Panel ); 00035 setFrameShadow( Raised ); 00036 00037 m_layout = new QVBoxLayout( this, 2, 2 ); 00038 // m_layout->addSpacing( 12 ); 00039 } 00040 00041 void KoToolBox::setEnabled( bool enable ) 00042 { 00043 if ( enable ) 00044 { 00045 if ( children() ) 00046 { 00047 QObjectListIt it( *children() ); 00048 QWidget *w; 00049 while( (w=(QWidget *)it.current()) != 0 ) 00050 { 00051 ++it; 00052 if ( w->isWidgetType() ) 00053 w->setEnabled( TRUE ); 00054 } 00055 } 00056 } 00057 else 00058 { 00059 if ( focusWidget() == this ) 00060 focusNextPrevChild( TRUE ); 00061 if ( children() ) 00062 { 00063 QObjectListIt it( *children() ); 00064 QWidget *w; 00065 while( (w=(QWidget *)it.current()) != 0 ) 00066 { 00067 ++it; 00068 if ( w->isWidgetType() ) 00069 { 00070 w->setEnabled( FALSE ); 00071 // w->clearWState( WState_ForceDisabled ); 00072 } 00073 } 00074 } 00075 } 00076 } 00077 00078 /* 00079 void KoToolBox::paintEvent( QPaintEvent* ev ) 00080 { 00081 QPainter painter; 00082 painter.begin( this ); 00083 00084 painter.fillRect( 0, 0, width(), 12, darkBlue ); 00085 00086 painter.end(); 00087 00088 QFrame::paintEvent( ev ); 00089 } 00090 */ 00091 00092 void KoToolBox::childEvent( QChildEvent* ev ) 00093 { 00094 if ( ev->inserted() && ev->child()->isWidgetType() ) 00095 m_layout->addWidget( (QWidget*)ev->child() ); 00096 resize( sizeHint() ); 00097 } 00098 00099 void KoToolBox::mousePressEvent( QMouseEvent* ev ) 00100 { 00101 m_startPos = geometry().topLeft(); 00102 m_mousePos = ev->globalPos(); 00103 } 00104 00105 void KoToolBox::mouseMoveEvent( QMouseEvent* ev ) 00106 { 00107 setGeometry( m_startPos.x() - m_mousePos.x() + ev->globalPos().x(), 00108 m_startPos.y() - m_mousePos.y() + ev->globalPos().y(), 00109 width(), height() ); 00110 } 00111 00112 // --------------------------------------------- 00113 00114 KoTransformToolBox::KoTransformToolBox( KoDocumentChild* ch, QWidget* parent, const char* name ) 00115 : KoToolBox( parent, name ) 00116 { 00117 m_child = 0; 00118 00119 m_rotation = new QSpinBox( 0, 360, 5, this ); 00120 m_rotation->setSuffix( " deg" ); 00121 m_scale = new QSpinBox( 10, 400, 10, this ); 00122 m_scale->setSuffix( "%" ); 00123 m_shearX = new QSpinBox( -100, 100, 1, this ); 00124 m_shearX->setSuffix( " px" ); 00125 m_shearY = new QSpinBox( -100, 100, 1, this ); 00126 m_shearY->setSuffix( " px" ); 00127 00128 setDocumentChild( ch ); 00129 00130 connect( m_rotation, SIGNAL( valueChanged( int ) ), 00131 this, SLOT( slotRotationChanged( int ) ) ); 00132 connect( m_scale, SIGNAL( valueChanged( int ) ), 00133 this, SLOT( slotScalingChanged( int ) ) ); 00134 connect( m_shearX, SIGNAL( valueChanged( int ) ), 00135 this, SLOT( slotXShearingChanged( int ) ) ); 00136 connect( m_shearY, SIGNAL( valueChanged( int ) ), 00137 this, SLOT( slotYShearingChanged( int ) ) ); 00138 } 00139 00140 void KoTransformToolBox::setDocumentChild( KoDocumentChild* ch ) 00141 { 00142 if ( m_child == ch ) 00143 return; 00144 00145 m_child = ch; 00146 00147 if ( m_child ) 00148 { 00149 setRotation( m_child->rotation() ); 00150 setScaling( m_child->xScaling() ); 00151 setXShearing( m_child->xShearing() ); 00152 setYShearing( m_child->yShearing() ); 00153 } 00154 } 00155 00156 double KoTransformToolBox::rotation() const 00157 { 00158 return m_rotation->text().toDouble(); 00159 } 00160 00161 double KoTransformToolBox::scaling() const 00162 { 00163 return m_scale->text().toDouble() / 100.0; 00164 } 00165 00166 double KoTransformToolBox::xShearing() const 00167 { 00168 return m_shearX->text().toDouble() / 10.0; 00169 } 00170 00171 double KoTransformToolBox::yShearing() const 00172 { 00173 return m_shearY->text().toDouble() / 10.0; 00174 } 00175 00176 void KoTransformToolBox::slotRotationChanged( int v ) 00177 { 00178 if ( m_child ) 00179 m_child->setRotation( double( v ) ); 00180 00181 emit rotationChanged( double( v ) ); 00182 } 00183 00184 void KoTransformToolBox::slotScalingChanged( int v ) 00185 { 00186 if ( m_child ) 00187 m_child->setScaling( double( v ) / 100.0, double( v ) / 100.0 ); 00188 00189 emit scalingChanged( double( v ) / 100.0 ); 00190 } 00191 00192 void KoTransformToolBox::slotXShearingChanged( int v ) 00193 { 00194 if ( m_child ) 00195 m_child->setShearing( double( v ) / 10.0, m_child->yShearing() ); 00196 00197 emit xShearingChanged( double( v ) / 10.0 ); 00198 } 00199 00200 void KoTransformToolBox::slotYShearingChanged( int v ) 00201 { 00202 if ( m_child ) 00203 m_child->setShearing( m_child->xShearing(), double( v ) / 10.0 ); 00204 00205 emit yShearingChanged( double( v ) / 10.0 ); 00206 } 00207 00208 void KoTransformToolBox::setRotation( double v ) 00209 { 00210 m_rotation->setValue( int( v ) ); 00211 } 00212 00213 void KoTransformToolBox::setScaling( double v ) 00214 { 00215 m_scale->setValue( int( v * 100.0 ) ); 00216 } 00217 00218 void KoTransformToolBox::setXShearing( double v ) 00219 { 00220 m_shearX->setValue( int( v * 10.0 ) ); 00221 } 00222 00223 void KoTransformToolBox::setYShearing( double v ) 00224 { 00225 m_shearY->setValue( int( v * 10.0 ) ); 00226 } 00227 00228 #include "koToolBox.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 06:54:19 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003