KDE Anwendungs Tutorials: Der KDE Anwendungs-Tutorial Leitfaden für die Integrierte Entwicklungsumgebung KDevelop
Zurück | Anhang A. KScribble-1.0 Beispiel Quellcode | Vor

# A.5. kscribbledoc.h

       1 /***************************************************************************
       2                           kscribbledoc.h  -  description
       3                              -------------------
       4     begin                : Mon Jan 31 11:05:05 CET 2000
       5     copyright            : (C) 2000 by Ralf Nolden
       6     email                : Ralf.Nolden@post.rwth-aachen.de
       7  ***************************************************************************/
       8
       9 /***************************************************************************
      10  *                                                                         *
      11  *   This program is free software; you can redistribute it and/or modify  *
      12  *   it under the terms of the GNU General Public License as published by  *
      13  *   the Free Software Foundation; either version 2 of the License, or     *
      14  *   (at your option) any later version.                                   *
      15  *                                                                         *
      16  ***************************************************************************/
      17
      18 #ifndef KSCRIBBLEDOC_H
      19 #define KSCRIBBLEDOC_H
      20
      21 #ifdef HAVE_CONFIG_H
      22 #include <config.h>
      23 #endif
      24
      25 // include files for QT
      26 #include <qobject.h>
      27 #include <qstring.h>
      28 #include <qlist.h>
      29
      30 #include <qsize.h>
      31 #include <qpen.h>
      32 #include <qpoint.h>
      33 //#include <qpixmap.h>
      34 #include <qpointarray.h>
      35
      36 #include <kpixmap.h>
      37
      38
      39 // forward declaration of the KScribble classes
      40 class KScribbleView;
      41
      42 /**  KScribbleDoc provides a document object for a document-view model.
      43   *
      44   * The KScribbleDoc class provides a document object that can be used in conjunction with the classes
      45   * KScribbleApp and KScribbleView to create a document-view model for MDI (Multiple Document Interface)
      46   * KDE 2 applications based on KApplication and KTMainWindow as main classes and QWorkspace as MDI manager widget.
      47   * Thereby, the document object is created by the KScribbleApp instance (and kept in a document list) and contains
      48   * the document structure with the according methods for manipulating the document
      49   * data by KScribbleView objects. Also, KScribbleDoc contains the methods for serialization of the document data
      50   * from and to files.
      51   * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
      52   * @version KDevelop version 1.1 code generation
      53   */
      54 class KScribbleDoc : public QObject
      55 {
      56   Q_OBJECT
      57
      58   friend KScribbleView;
      59
      60   public:
      61     /** Constructor for the fileclass of the application */
      62     KScribbleDoc();
      63     /** Destructor for the fileclass of the application */
      64     ~KScribbleDoc();
      65
      66     /** adds a view to the document which represents the document contents. Usually this is your main view. */
      67     void addView(KScribbleView *view);
      68     /** removes a view from the list of currently connected views */
      69     void removeView(KScribbleView *view);
      70     /** gets called if a view is removed or added */
      71     void changedViewList();
      72     /** returns the first view instance */
      73     KScribbleView* firstView(){ return pViewList->first(); };
      74     /** returns true, if the requested view is the last view of the document */
      75     bool isLastView();
      76     /** This method gets called when the user is about to close a frame window. It checks, if more than one view
      77      * is connected to the document (then the frame can be closed), if pFrame is the last view and the document is
      78      * modified, the user gets asked if he wants to save the document.
      79      */
      80     bool canCloseFrame(KScribbleView* pFrame);
      81     /** sets the modified flag for the document after a modifying action on the view connected to the document.*/
      82     void setModified(bool _m=true){ modified=_m; };
      83     /** returns if the document is modified or not. Use this to determine if your document needs
      84      * saving by the user on closing.
      85      */
      86     bool isModified(){ return modified; };
      87     /** deletes the document's contents */
      88     void deleteContents();
      89     /** initializes the document generally */
      90     bool newDocument();
      91     /** closes the acutal document */
      92     void closeDocument();
      93     /** loads the document by filename and format and emits the updateViews() signal */
      94     bool openDocument(const QString &&;filename, const char *format=0);
      95     /** saves the document under filename and format.*/
      96     bool saveDocument(const QString &&;filename, const char *format=0);
      97     /** sets the path to the file connected with the document */
      98     void setPathName(const QString &&;name);
      99     /** returns the pathname of the current document file*/
     100     const QString&&; pathName() const;
     101
     102     /** sets the filename of the document */
     103     void setTitle(const QString &&;title);
     104     /** returns the title of the document */
     105     const QString&&; title() const;
     106     /** get the current Pen */
     107     const QPen currentPen(){ return pen;};
     108     /** returns the pen width */
     109     const int penWidth() { return pen.width(); }
     110     /** returns the pen color */
     111     const QColor penColor(){ return pen.color(); }
     112     /** sets the pen width */
     113     void setPenWidth( int w ){ pen.setWidth( w ); }
     114     /** sets the pen color */
     115     void setPenColor( const QColor &&;c ){ pen.setColor( c ); }
     116     /** sets the pen style by a second toolbar */
     117     void setPenStyle( PenStyle s){ pen.setStyle(s);}
     118     /** clears the document contents */
     119     void editClearAll();
     120
     121     /** get the document size */
     122     const QSize docSize(){ return size;};
     123     /** sets the pixmap contents. Used by KScribbleApp
     124     to create a new document by drop events */
     125     void setPixmap(KPixmap pix) { buffer=pix;};
     126     void resizeDocument(QSize m_size) { size=m_size; };
     127   public slots:
     128     /** calls repaint() on all views connected to the document object and is called by the view by
     129      * which the document has been changed.
     130      * As this view normally repaints itself, it is excluded from the paintEvent.
     131      */
     132     void updateAllViews(KScribbleView *sender);
     133
     134   protected:
     135
     136     QPen pen;
     137     QPointArray polyline;
     138     KPixmap buffer;
     139
     140   private:
     141     /** the modified flag of the current document */
     142     bool modified;
     143     QString m_title;
     144     QString m_filename;
     145     /** the list of the views currently connected to the document */
     146     QList<KScribbleView> *pViewList;
     147     QSize size;
     148 };
     149
     150 #endif // KSCRIBBLEDOC_H

Zurück | Anfang | Vor
kscribble.cpp | Hoch | kscribbledoc.cpp