summaryrefslogtreecommitdiffstats
path: root/kcoloredit/kcoloreditdoc.h
blob: afbb65c088284913df94f7a5f08221b23f700bab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/***************************************************************************
                          kcoloreditdoc.h  -  description
                             -------------------
    begin                : Sat Jul  8 09:57:28 CEST 2000
    copyright            : (C) 2000 by Artur Rataj
    email                : art@zeus.polsl.gliwice.pl
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KCOLOREDITDOC_H
#define KCOLOREDITDOC_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// include files for QT
#include <tqobject.h>
#include <tqstring.h>
#include <tqptrlist.h>

// application specific includes
#include "palette.h"
#include "palettehistory.h"

// forward declaration of the KColorEdit classes
class KColorEditView;

/**	KColorEditDoc provides a document object for a document-view model.
  *
  * The KColorEditDoc class provides a document object that can be used in conjunction with the classes KColorEditApp and KColorEditView
  * to create a document-view model for standard KDE applications based on KApplication and KMainWindow. Thereby, the document object
  * is created by the KColorEditApp instance and contains the document structure with the according methods for manipulation of the document
  * data by KColorEditView objects. Also, KColorEditDoc contains the methods for serialization of the document data from and to files.
  *
  * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
  * @version KDevelop version 0.4 code generation
  */
class KColorEditDoc : public TQObject
{
  Q_OBJECT
  TQ_OBJECT

  public:
    /** Constructor for the fileclass of the application */
    KColorEditDoc(TQWidget *parent, const char *name=0);
    /** Destructor for the fileclass of the application */
    ~KColorEditDoc();

    /** adds a view to the document which represents the document contents. Usually this is your main view. */
    void addView(KColorEditView *view);
    /** removes a view from the list of currently connected views */
    void removeView(KColorEditView *view);
    /** sets the modified flag for the document after a modifying action on the view connected to the document.*/
    void setModified(bool modified);
    /** returns if the document is modified or not. Use this to determine if your document needs saving by the user on closing.*/
    bool isModified() const { return m_modified; };
    /** "save modified" - asks the user for saving if the document is modified */
    bool saveModified();
    /** deletes the document's contents */
    void deleteContents();
    /** initializes the document generally */
    bool newDocument();
    /** closes the actual document */
    void closeDocument();
    /** loads the document */
    bool openDocument(const TQString& filename);
    /** saves the document */
    bool saveDocument(const TQString& filename);
    /** sets the path to the file connected with the document */
    void setAbsFilePath(const TQString &filename);
    /** returns the pathname of the current document file*/
    const TQString& absFilePath() const;
    /** sets the filename of the document */
    void setTitle(const TQString &_t);
    /** returns the title of the document */
    const TQString& title() const;
		/** @return a description of a possible unsuccessfull IO operation */
		const TQString& errorString() const;
		/** returns a pointer to paletteHistory */
		PaletteHistory* paletteHistory();
		/** sets a palette cursor position */
		void setPaletteCursorPos(const int pos);
		/** @return a palette cursor position */
		int paletteCursorPos();
		/** Sets palette selection and enables or disables cut/paste
		 *  depending on whether any colors are selected
		 */
		void setPaletteSelection(const int begin, const int end);
		/** Gets lesser selection position or equal selection position
		 *  if no colors are selected
		 */
		int paletteSelectionBegin() const;
		/** Gets greater selection position or equal selection position
		 *  if no colors are selected
		 */
		int paletteSelectionEnd() const;
		/** Copies a selection into a clipboard */
		void copy();
		/** Cuts a selection into a clipboard */
		void cut();
		/** Pastes a selection from a clipboard */
		void paste();
		/** Inserts a color at index */
		void insert(int index, const Color& color);
		/** Replaces a color at index */
		void replace(int index, const Color& color);

	protected:
		/** Sets an error string if an IO operation was unsuccesfull */
		void setErrorString(const TQString& string);
		/** Copies a palette to clipboard */
		void copyToClipboard(Palette& palette);

  public slots:
    /** Calls redraw() on all views connected to the document object,
     *  except for sender if sender is not null
     */
    void slotRedrawAllViews(KColorEditView* sender, bool newDocument = false);
    /** Sets a view mode */
	void slotChangeViewMode(bool viewColorNames);

  signals:

    void selectionChanged( int, int );
    void clipboardChanged();
    void modified( bool );
    void paletteAvailable( bool );

  public:
    /** the list of the views currently connected to the document */
    TQPtrList<KColorEditView> *m_pViewList;

  private:
    /** the modified flag of the current document */
    bool m_modified;
    TQString m_title;
    TQString m_absFilePath;
    TQString m_errorString;

	protected:
		Palette m_palette;
		PaletteHistory m_paletteHistory;
		int m_paletteCursorPos;
		int m_paletteSelectionBegin;
		int m_paletteSelectionEnd;
};

#endif // KCOLOREDITDOC_H