umbrello API Documentation

codeeditor.h

00001 
00002 /***************************************************************************
00003                           codeeditor.h  -  description
00004                              -------------------
00005     begin                : Fri Aug 1 2003
00006     copyright            : (C) 2003 by Brian Thomas
00007     email                : brian.thomas@gsfc.nasa.gov
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #ifndef CODEEDITOR_H
00020 #define CODEEDITOR_H
00021 
00022 #include <qpopupmenu.h>
00023 #include <qstring.h>
00024 #include <qlabel.h>
00025 #include <qtextedit.h>
00026 #include "../codeviewerstate.h"
00027 #include "../textblocklist.h"
00028 
00029 class UMLObject;
00030 
00031 class CodeViewerDialog;
00032 class CodeComment;
00033 class CodeDocument;
00034 class CodeClassFieldDeclarationBlock;
00035 class CodeMethodBlock;
00036 class CodeBlockWithComments;
00037 class HierarchicalCodeBlock;
00038 
00039 class TextBlockInfo;
00040 class TextBlock;
00041 class ParaInfo;
00042 
00043 class CodeEditor : public QTextEdit
00044 {
00045     Q_OBJECT
00046 public:
00047 
00048     explicit CodeEditor ( const QString & text, const QString & context = QString(), CodeViewerDialog * parent = 0, const char * name = 0 , CodeDocument * doc = 0);
00049     explicit CodeEditor ( CodeViewerDialog * parent, const char* name = 0, CodeDocument * doc = 0);
00050     ~CodeEditor ();
00051 
00052     // return code viewer state
00053     Settings::CodeViewerState getState( );
00054 
00055 protected:
00056 
00057     bool close ( bool alsoDelete );
00058 
00059     // various methods for appending various types of text blocks in the editor.
00060     void appendText (TextBlock * tblock);
00061     void appendText (HierarchicalCodeBlock * hblock);
00062     void appendText (CodeClassFieldDeclarationBlock * db );
00063     void appendText (TextBlockList * items);
00064     void appendText (CodeMethodBlock * mb);
00065     void appendText (CodeComment * comment, TextBlock * parent, UMLObject * umlObj = 0, const QString & compName="");
00066     void appendText (CodeBlockWithComments * cb );
00067 
00068     // Rebuild our view of the document. Happens whenever we change
00069     // some field/aspect of an underlying UML object used to create
00070     // the view.
00071     // If connections are right, then the UMLObject will send out the modified()
00072     // signal which will trigger a call to re-generate the appropriate code within
00073     // the code document. Our burden is to appropriately prepare the tool: we clear
00074     // out ALL the textblocks in the QTextEdit widget and then re-show them
00075     // after the dialog disappears
00076     void rebuildView( int startCursorPos );
00077 
00078     // override the QT event so we can do appropriate things
00079     void contentsMouseMoveEvent ( QMouseEvent * e );
00080 
00081     // implemented so we may capture certain key presses, namely backspace
00082     // and 'return' events.
00083     void keyPressEvent ( QKeyEvent * e );
00084 
00085     // (re) load the parent code document into the editor
00086     void loadFromDocument();
00087 
00088     // specialized popup menu for our tool
00089     QPopupMenu * createPopupMenu ( const QPoint & pos );
00090 
00091 private:
00092 
00093     QString parentDocName;
00094     CodeDocument * m_parentDoc;
00095     CodeViewerDialog * m_parentDlg;
00096 
00097     int m_lastPara;
00098     int m_lastPos;
00099 
00100     bool m_newLinePressed;
00101     bool m_backspacePressed;
00102     bool m_isHighlighted;
00103     bool m_showHiddenBlocks;
00104 
00105     TextBlock * m_textBlockToPaste;
00106     TextBlock * m_selectedTextBlock;
00107     TextBlock * m_lastTextBlockToBeEdited;
00108 
00109     QMap<TextBlock*, TextBlockInfo*> *m_tbInfoMap;
00110     TextBlockList m_textBlockList;
00111 
00112     // main insert routine. Will append if startline is not supplied.
00113     void insert (const QString & text, TextBlock * parent, bool isEditable = false,
00114                  const QColor & fgcolor = QColor("black"), const QColor & bgcolor = QColor("white"),
00115                  UMLObject * umlobj = 0, const QString & displayName = "", int startLine = -1);
00116 
00117     void editTextBlock(TextBlock * tBlock, int para);
00118     void clearText();
00119     QLabel * getComponentLabel();
00120     bool paraIsNotSingleLine (int para);
00121     void expandSelectedParagraph( int where );
00122     void contractSelectedParagraph( int where );
00123     void updateTextBlockFromText (TextBlock * block);
00124 
00125     void initText ( CodeDocument * doc );
00126     void init ( CodeViewerDialog * parentDlg, CodeDocument * parentDoc );
00127 
00128     void changeTextBlockHighlighting(TextBlock * tb, bool selected);
00129     bool isParaEditable (int para);
00130     bool textBlockIsClickable(UMLObject * obj);
00131 
00132     // return whether or not the passed string is empty or
00133     // contains nothing but whitespace
00134     static bool StringIsBlank( const QString &str );
00135 
00136 public slots:
00137 
00138     void insertParagraph ( const QString & text, int para );
00139     void removeParagraph ( int para );
00140     void changeHighlighting(int signal);
00141     void changeShowHidden (int signal);
00142     void slotRedrawText();
00143 
00144 protected slots:
00145 
00146     void clicked(int para, int pos );
00147     void doubleClicked(int para, int pos );
00148     void cursorPositionChanged(int para, int pos );
00149     void slotCopyTextBlock ( );
00150     void slotCutTextBlock ( );
00151     void slotPasteTextBlock ( );
00152     void slotChangeSelectedBlockView();
00153     void slotChangeSelectedBlockCommentView();
00154     void slotInsertCodeBlockAfterSelected();
00155     void slotInsertCodeBlockBeforeSelected();
00156 
00157 signals:
00158 
00159     /*
00160         void sigNewLinePressed ();
00161         void sigBackspacePressed ();
00162     */
00163 
00164 };
00165 
00166 class ParaInfo {
00167 public:
00168     int start; // this is a relative offset from the beginning of the tblock
00169     int size;
00170     QColor fgcolor;
00171     QColor bgcolor;
00172     bool isEditable;
00173 
00174     ParaInfo () { isEditable = false; }
00175 };
00176 
00177 class TextBlockInfo {
00178 public:
00179     QPtrList<ParaInfo> m_paraList;
00180     UMLObject * m_parent;
00181     QString displayName;
00182     bool isClickable;
00183     bool isCodeAccessorMethod;
00184 
00185     TextBlockInfo () { m_parent = 0; isClickable = false; isCodeAccessorMethod = false; }
00186     void setParent(UMLObject *p = 0) { m_parent = p; }
00187     UMLObject * getParent() { return m_parent; }
00188 
00189 };
00190 
00191 #endif // CODEEDITOR_H
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003