karbon

vtexttool.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 The Karbon Developers
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., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef __VTEXTTOOL_H__
00021 #define __VTEXTTOOL_H__
00022 
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include <kdialogbase.h>
00029 
00030 #include "qframe.h"
00031 #include "qgroupbox.h"
00032 #include "qcombobox.h"
00033 
00034 #include "vcommand.h"
00035 #include "vtext.h"
00036 #include "vtool.h"
00037 
00038 class KFontCombo;
00039 class KIntNumInput;
00040 class QCheckBox;
00041 class QLineEdit;
00042 class QPushButton;
00043 class QTabWidget;
00044 class ShadowWidget;
00045 class VTextTool;
00046 class QCursor;
00047 
00048 class ShadowPreview : public QWidget
00049 {
00050     Q_OBJECT
00051 
00052 public:
00053     ShadowPreview( ShadowWidget* parent );
00054     ~ShadowPreview();
00055 
00056 signals:
00057     void changed( int angle, int distance, bool );
00058 
00059 protected:
00060     virtual void mouseReleaseEvent( QMouseEvent* );
00061     virtual void paintEvent( QPaintEvent* );
00062 
00063 private:
00064     ShadowWidget* m_parent;
00065 };
00066 
00067 
00068 class ShadowWidget : public QGroupBox
00069 {
00070     Q_OBJECT
00071 
00072 public:
00073     ShadowWidget( QWidget* parent, const char* name, int angle, int distance, bool translucent );
00074     ~ShadowWidget();
00075 
00076     void setUseShadow( bool use );
00077     bool useShadow();
00078     void setShadowAngle( int angle );
00079     int shadowAngle();
00080     void setShadowDistance( int distance );
00081     int shadowDistance();
00082     void setTranslucent( bool translucent );
00083     bool isTranslucent();
00084 
00085 public slots:
00086     void setShadowValues( int angle, int distance, bool translucent );
00087     void updatePreview( int );
00088     void updatePreview();
00089 
00090 protected:
00091     QCheckBox* m_useShadow;
00092     KIntNumInput* m_angle;
00093     KIntNumInput* m_distance;
00094     QCheckBox* m_translucent;
00095     ShadowPreview* m_preview;
00096 };
00097 
00098 
00099 class VTextOptionsWidget : public KDialogBase
00100 {
00101     Q_OBJECT
00102 
00103 public:
00104     VTextOptionsWidget( VTextTool* tool, QWidget *parent );
00105     ~VTextOptionsWidget();
00106 
00107     void setFont( const QFont& font );
00108     QFont font();
00109     void setText( const QString& text );
00110     QString text();
00111     void setPosition( VText::Position position );
00112     VText::Position position();
00113     void setAlignment( VText::Alignment alignment );
00114     VText::Alignment alignment();
00115     void setOffset( double offset );
00116     double offset();
00117     void setUseShadow( bool state );
00118     bool useShadow();
00119     void setShadow( int angle, int distance, bool translucent );
00120     bool translucentShadow();
00121     int shadowAngle();
00122     int shadowDistance();
00123 
00124 public slots:
00125     void valueChanged( int );
00126     void valueChanged( double );
00127     void accept();
00128     void cancel();
00129     void textChanged( const QString& );
00130     void editBasePath();
00131     void convertToShapes();
00132     void initialize( VObject &text );
00133 
00134 protected:
00135     QTabWidget* m_tabWidget;
00136     KFontCombo* m_fontCombo;
00137     QCheckBox* m_boldCheck;
00138     QCheckBox* m_italicCheck;
00139     KIntNumInput* m_fontSize;
00140     QLineEdit* m_textEditor;
00141     ShadowWidget* m_shadow;
00142     QComboBox* m_textAlignment;
00143     QComboBox* m_textPosition;
00144     QPushButton* m_editBasePath;
00145     QPushButton* m_convertToShapes;
00146     KDoubleNumInput* m_textOffset;
00147     VTextTool* m_tool;
00148 };
00149 
00150 
00151 class VTextTool : public VTool, public VVisitor
00152 {
00153 public:
00154     VTextTool( KarbonView *view );
00155     ~VTextTool();
00156 
00157     virtual void setup (KActionCollection *collection );
00158     virtual QString uiname() { return i18n( "Text Tool" ); }
00159 
00160     virtual QString contextHelp();
00161     virtual bool showDialog() const;
00162 
00163     virtual void activate();
00164     virtual void deactivate();
00165 
00166     virtual void mouseButtonPress();
00167     virtual void mouseButtonRelease();
00168     virtual void mouseDrag();
00169     virtual void mouseDragRelease();
00170     virtual void textChanged();
00171     virtual void accept();
00172     virtual void cancel();
00173     virtual void editBasePath();
00174     virtual void convertToShapes();
00175 
00176     virtual void visitVPath( VPath& composite );
00177     virtual void visitVDocument( VDocument& )
00178     {}
00179 
00180     virtual void visitVGroup( VGroup& )
00181     {}
00182 
00183     virtual void visitVLayer( VLayer& )
00184     {}
00185 
00186     virtual void visitVSubpath( VSubpath& path );
00187     virtual void visitVText( VText& text );
00188 
00189     virtual void draw( VPainter* painter );
00190 
00191 protected:
00192     virtual void mouseDragShiftPressed();
00193     virtual void mouseDragShiftReleased();
00194 
00195 private:
00196     class VTextCmd : public VCommand
00197     {
00198     public:
00199         VTextCmd( VDocument* doc, const QString& name, VText* text );
00200         VTextCmd( VDocument* doc, const QString& name, VText* text,
00201                   const QFont &newFont, const VSubpath& newBasePath, VText::Position newPosition, VText::Alignment newAlignment, double newOffset, const QString& newText,
00202                   bool newUseShadow, int newShadowAngle, int newShadowDistance, bool newTranslucentShadow );
00203         virtual ~VTextCmd();
00204 
00205         virtual void execute();
00206         virtual void unexecute();
00207         virtual bool isExecuted()
00208         {
00209             return m_executed;
00210         }
00211         virtual bool changesSelection() const { return true; }
00212 
00213     private:
00214         class VTextModifPrivate
00215         {
00216         public:
00217             VTextModifPrivate() : oldBasePath( 0L ), newBasePath( 0L )
00218             {}
00219 
00220             QFont oldFont;
00221             QFont newFont;
00222             VSubpath oldBasePath;
00223             VSubpath newBasePath;
00224             VText::Position oldPosition;
00225             VText::Position newPosition;
00226             VText::Alignment oldAlignment;
00227             VText::Alignment newAlignment;
00228             double oldOffset;
00229             double newOffset;
00230             QString oldText;
00231             QString newText;
00232             bool oldUseShadow;
00233             bool newUseShadow;
00234             int oldShadowAngle;
00235             int newShadowAngle;
00236             int oldShadowDistance;
00237             int newShadowDistance;
00238             bool oldTranslucentShadow;
00239             bool newTranslucentShadow;
00240         };
00241 
00242         VText* m_text;
00243         bool m_executed;
00244         VTextModifPrivate* m_textModifications;
00245     };
00246 
00247     class VTextToCompositeCmd : public VCommand
00248     {
00249     public:
00250         VTextToCompositeCmd( VDocument* doc, const QString& name, VText* text );
00251         virtual ~VTextToCompositeCmd();
00252 
00253         virtual void execute();
00254         virtual void unexecute();
00255         virtual bool isExecuted()
00256         {
00257             return m_executed;
00258         }
00259 
00260     private:
00261         VText* m_text;
00262         VGroup* m_group;
00263         bool m_executed;
00264     };
00265 
00266     void drawPathCreation();
00267     void drawEditedText();
00268     
00274     bool createText( VSubpath &path );
00275 
00276     VTextOptionsWidget* m_optionsWidget;
00277     KoPoint m_last;
00278     VText* m_text;
00279     VText* m_editedText;
00280     bool m_creating;
00281     // are we dragging in 45 degree steps?
00282     bool m_stepwise;
00283     QCursor* m_cursor;
00284 };
00285 
00286 #endif
00287 
KDE Home | KDE Accessibility Home | Description of Access Keys