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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/* This file is part of the KDE project
Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
Copyright (C) 2004-2007 Jaroslaw Staniek <js@iidea.pl>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KexiDBImageBox_H
#define KexiDBImageBox_H
#include "kexiformdataiteminterface.h"
#include "kexiframe.h"
#include "kexidbutils.h"
#include <kexiblobbuffer.h>
class KexiDropDownButton;
class KexiImageContextMenu;
//! @short A data-aware, editable image box.
/*! Can also act as a normal static image box.
*/
class KEXIFORMUTILS_EXPORT KexiDBImageBox :
public KexiFrame,
public KexiFormDataItemInterface,
public KexiSubwidgetInterface
{
Q_OBJECT
TQ_PROPERTY( TQString dataSource READ dataSource WRITE setDataSource )
TQ_PROPERTY( TQCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType )
TQ_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
// TQ_PROPERTY( TQPixmap pixmap READ pixmap WRITE setPixmap )
// TQ_PROPERTY( TQByteArray pixmapData READ pixmapData WRITE setPixmapData )
TQ_PROPERTY( uint pixmapId READ pixmapId WRITE setPixmapId DESIGNABLE true STORED false )
TQ_PROPERTY( uint storedPixmapId READ storedPixmapId WRITE setStoredPixmapId DESIGNABLE false STORED true )
TQ_PROPERTY( bool scaledContents READ hasScaledContents WRITE setScaledContents )
TQ_PROPERTY( bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio )
TQ_PROPERTY( int alignment READ alignment WRITE setAlignment )
// TQ_PROPERTY( TQString originalFileName READ originalFileName WRITE setOriginalFileName DESIGNABLE false )
// TQ_OVERRIDE( FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy )
TQ_PROPERTY( bool dropDownButtonVisible READ dropDownButtonVisible WRITE setDropDownButtonVisible )
TQ_OVERRIDE( int lineWidth READ lineWidth WRITE setLineWidth )
TQ_OVERRIDE( FocusPolicy focusPolicy READ focusPolicyInternal WRITE setFocusPolicy )
public:
KexiDBImageBox( bool designMode, TQWidget *parent, const char *name = 0 );
virtual ~KexiDBImageBox();
inline TQString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
inline TQCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
virtual TQVariant value(); // { return m_value.data(); }
// TQByteArray pixmapData() const { return m_value.data(); }
TQPixmap pixmap() const;
uint pixmapId() const;
uint storedPixmapId() const;
//
virtual void setInvalidState( const TQString& displayText );
virtual bool valueIsNull();
virtual bool valueIsEmpty();
virtual TQWidget* widget();
//! always true
virtual bool cursorAtStart();
//! always true
virtual bool cursorAtEnd();
// //! used to catch setIndent(), etc.
// virtual bool setProperty ( const char * name, const TQVariant & value );
virtual bool isReadOnly() const;
bool hasScaledContents() const;
// bool designMode() const { return m_designMode; }
int alignment() const { return m_alignment; }
bool keepAspectRatio() const { return m_keepAspectRatio; }
virtual TQSize sizeHint() const;
KexiImageContextMenu *contextMenu() const;
/*! \return original file name of image loaded from a file.
This can be later reused for displaying the image within a collection (to be implemented)
or on saving the image data back to file. */
//todo TQString originalFileName() const { return m_value.originalFileName(); }
//! Reimplemented to override behaviour of "lineWidth" property.
virtual void setLineWidth( int width );
//! Reimplemented to override behaviour of "paletteBackgroundColor"
//! and "paletteForegroundColor" properties.
virtual void setPalette( const TQPalette &pal );
//! Reimplemented to override behaviour of "paletteBackgroundColor" property.
virtual void setPaletteBackgroundColor( const TQColor & color );
//! \return true id drop down button should be visible (the default).
bool dropDownButtonVisible() const;
//! For overridden property
int lineWidth() const { return KexiFrame::lineWidth(); }
/*! Overriden to change the policy behaviour a bit:
NoFocus is returned regardless the real focus flag
if the data source is empty (see dataSource()). */
TQ_FocusPolicy focusPolicy() const;
//! \return the internal focus policy value, i.e. the one unrelated to data source presence.
TQ_FocusPolicy focusPolicyInternal() const;
/*! Sets the internal focus policy value.
"Internal" means that if there is no data source set, real policy becomes NoFocus. */
virtual void setFocusPolicy( TQ_FocusPolicy policy );
public slots:
void setPixmapId(uint id);
void setStoredPixmapId(uint id);
//! Sets the datasource to \a ds
virtual void setDataSource( const TQString &ds );
inline void setDataSourceMimeType(const TQCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
virtual void setReadOnly(bool set);
//! Sets \a pixmapData data for this widget. If the widget has data source set,
//! the pixmap will be also placed inside of the buffer and saved later.
//todo void setPixmapData(const TQByteArray& pixmapData) { m_value.setData(pixmapData); }
/*! Sets original file name of image loaded from a file.
@see originalFileName() */
//todo void setOriginalFileName(const TQString& name) { m_value.setOriginalFileName(name); }
void setScaledContents(bool set);
void setAlignment(int alignment);
void setKeepAspectRatio(bool set);
// void updateActionsAvailability();
//! @internal
// void slotToggled( bool on );
//! \return sets dropDownButtonVisible property. @see dropDownButtonVisible()
void setDropDownButtonVisible( bool set );
//! Forces execution of "insert from file" action
void insertFromFile();
signals:
//! Used for db-aware mode. Emitted when value has been changed.
//! Actual value can be obtained using value().
// virtual void pixmapChanged();
// virtual void valueChanged(const TQByteArray& data);
void idChanged(long id);
protected slots:
void slotUpdateActionsAvailabilityRequested(bool& valueIsNull, bool& valueIsReadOnly);
void handleInsertFromFileAction(const KURL& url);
void handleAboutToSaveAsAction(TQString& origFilename, TQString& fileExtension, bool& dataIsEmpty);
void handleSaveAsAction(const TQString& fileName);
void handleCutAction();
void handleCopyAction();
void handlePasteAction();
virtual void clear();
void handleShowPropertiesAction();
protected:
//! \return data depending on the current mode (db-aware or static)
TQByteArray data() const;
virtual void contextMenuEvent ( TQContextMenuEvent * e );
// virtual void mousePressEvent( TQMouseEvent *e );
virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
virtual void paintEvent( TQPaintEvent* );
virtual void resizeEvent( TQResizeEvent* e );
virtual bool eventFilter( TQObject * watched, TQEvent * e );
//! Sets value \a value for a widget.
virtual void setValueInternal( const TQVariant& add, bool removeOld ) {
setValueInternal( add, removeOld, true /*loadPixmap*/ );
}
//! @internal, added \a loadPixmap option used by paste().
void setValueInternal( const TQVariant& add, bool removeOld, bool loadPixmap );
//! Updates i18n'd action strings after datasource change
void updateActionStrings();
void updatePixmap();
//! @internal
void setData(const KexiBLOBBuffer::Handle& handle);
bool popupMenuAvailable();
/*! Called by top-level form on key press event.
Used for Key_Escape to if the popup is visible,
so the key press won't be consumed to perform "cancel editing". */
virtual bool keyPressed(TQKeyEvent *ke);
//! \return real line width, i.e. for Boxed sunken or Boxed raised
//! frames returns doubled width value.
int realLineWidth() const;
//! Implemented for KexiSubwidgetInterface
virtual bool subwidgetStretchRequired(KexiDBAutoField* autoField) const;
// virtual void drawContents ( TQPainter *p );
// virtual void fontChange( const TQFont& font );
// virtual void styleChange( TQStyle& style );
// virtual void enabledChange( bool enabled );
// virtual void paletteChange( const TQPalette& pal );
// virtual void frameChanged();
// virtual void showEvent( TQShowEvent* e );
// void updatePixmapLater();
// class ImageLabel;
// ImageLabel *m_pixmapLabel;
TQPixmap m_pixmap;
TQByteArray m_value; //!< for db-aware mode
TQString m_valueMimeType; //!< for db-aware mode
// PixmapData m_value;
KexiBLOBBuffer::Handle m_data;
// TQString m_originalFileName;
KexiDropDownButton *m_chooser;
KexiImageContextMenu *m_popupMenu;
//moved KActionCollection m_actionCollection;
//moved KAction *m_insertFromFileAction, *m_saveAsAction, *m_cutAction, *m_copyAction, *m_pasteAction,
// *m_deleteAction, *m_propertiesAction;
// TQTimer m_clickTimer;
int m_alignment;
TQ_FocusPolicy m_focusPolicyInternal; //!< Used for focusPolicyInternal()
bool m_designMode : 1;
bool m_readOnly : 1;
bool m_scaledContents : 1;
bool m_keepAspectRatio : 1;
bool m_insideSetData : 1;
bool m_setFocusOnButtonAfterClosingPopup : 1;
bool m_lineWidthChanged : 1;
bool m_paletteBackgroundColorChanged : 1;
bool m_paintEventEnabled : 1; //!< used to disable paintEvent()
bool m_dropDownButtonVisible : 1;
bool m_insideSetPalette : 1;
};
#endif
|