kexi

kexidbimagebox.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004-2007 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this program; see the file COPYING.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KexiDBImageBox_H
00022 #define KexiDBImageBox_H
00023 
00024 #include "kexiformdataiteminterface.h"
00025 #include "kexiframe.h"
00026 #include "kexidbutils.h"
00027 #include <kexiblobbuffer.h>
00028 #include <widget/utils/kexiimagecontextmenu.h>
00029 
00030 class KexiDropDownButton;
00031 
00033 
00035 class KEXIFORMUTILS_EXPORT KexiDBImageBox : 
00036     public KexiFrame, 
00037     public KexiFormDataItemInterface, 
00038     public KexiSubwidgetInterface
00039 {
00040     Q_OBJECT
00041     Q_PROPERTY( QString dataSource READ dataSource WRITE setDataSource )
00042     Q_PROPERTY( QCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType )
00043     Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
00044 //  Q_PROPERTY( QPixmap pixmap READ pixmap WRITE setPixmap )
00045 //  Q_PROPERTY( QByteArray pixmapData READ pixmapData WRITE setPixmapData )
00046     Q_PROPERTY( uint pixmapId READ pixmapId WRITE setPixmapId DESIGNABLE true STORED false )
00047     Q_PROPERTY( uint storedPixmapId READ storedPixmapId WRITE setStoredPixmapId DESIGNABLE false STORED true )
00048     Q_PROPERTY( bool scaledContents READ hasScaledContents WRITE setScaledContents )
00049     Q_PROPERTY( bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio )
00050     Q_PROPERTY( Alignment alignment READ alignment WRITE setAlignment )
00051 //  Q_PROPERTY( QString originalFileName READ originalFileName WRITE setOriginalFileName DESIGNABLE false )
00052 //  Q_OVERRIDE( FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy )
00053     Q_PROPERTY( bool dropDownButtonVisible READ dropDownButtonVisible WRITE setDropDownButtonVisible )
00054     Q_OVERRIDE( int lineWidth READ lineWidth WRITE setLineWidth )
00055     Q_OVERRIDE( FocusPolicy focusPolicy READ focusPolicyInternal WRITE setFocusPolicy )
00056 
00057     public:
00058         KexiDBImageBox( bool designMode, QWidget *parent, const char *name = 0 );
00059         virtual ~KexiDBImageBox();
00060 
00061         inline QString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
00062         inline QCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
00063 
00064         virtual QVariant value(); // { return m_value.data(); }
00065 
00066 //      QByteArray pixmapData() const { return m_value.data(); }
00067 
00068         QPixmap pixmap() const;
00069 
00070         uint pixmapId() const;
00071 
00072         uint storedPixmapId() const;
00073 // 
00074         virtual void setInvalidState( const QString& displayText );
00075 
00076         virtual bool valueIsNull();
00077 
00078         virtual bool valueIsEmpty();
00079 
00080         virtual QWidget* widget();
00081 
00083         virtual bool cursorAtStart();
00084 
00086         virtual bool cursorAtEnd();
00087 
00088 //      //! used to catch setIndent(), etc.
00089 //      virtual bool setProperty ( const char * name, const QVariant & value );
00090 
00091         virtual bool isReadOnly() const;
00092 
00093         bool hasScaledContents() const;
00094 
00095 //      bool designMode() const { return m_designMode; }
00096 
00097         int alignment() const { return m_alignment; }
00098 
00099         bool keepAspectRatio() const { return m_keepAspectRatio; }
00100 
00101         virtual QSize sizeHint() const;
00102 
00103         KexiImageContextMenu *contextMenu() const;
00104 
00108 //todo      QString originalFileName() const { return m_value.originalFileName(); }
00109 
00111         virtual void setLineWidth( int width );
00112 
00115         virtual void setPalette( const QPalette &pal );
00116 
00118         virtual void setPaletteBackgroundColor( const QColor & color );
00119 
00121         bool dropDownButtonVisible() const;
00122 
00124         int lineWidth() const { return KexiFrame::lineWidth(); }
00125 
00129         FocusPolicy focusPolicy() const;
00130 
00132         FocusPolicy focusPolicyInternal() const;
00133 
00136         virtual void setFocusPolicy( FocusPolicy policy );
00137 
00138     public slots:
00139         void setPixmapId(uint id);
00140 
00141         void setStoredPixmapId(uint id);
00142 
00144         virtual void setDataSource( const QString &ds );
00145 
00146         inline void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
00147 
00148         virtual void setReadOnly(bool set);
00149 
00152 //todo      void setPixmapData(const QByteArray& pixmapData) { m_value.setData(pixmapData); }
00153 
00156 //todo      void setOriginalFileName(const QString& name) { m_value.setOriginalFileName(name); }
00157 
00158         void setScaledContents(bool set);
00159 
00160         void setAlignment(int alignment);
00161 
00162         void setKeepAspectRatio(bool set);
00163 
00164 //      void updateActionsAvailability();
00165 
00167 //      void slotToggled( bool on );
00168 
00170         void setDropDownButtonVisible( bool set );
00171 
00173         void insertFromFile();
00174 
00175     signals:
00178 //      virtual void pixmapChanged();
00179 //      virtual void valueChanged(const QByteArray& data);
00180 
00181         void idChanged(long id);
00182 
00183     protected slots:
00184         void slotUpdateActionsAvailabilityRequested(bool& valueIsNull, bool& valueIsReadOnly);
00185 
00186         void handleInsertFromFileAction(const KURL& url);
00187         void handleAboutToSaveAsAction(QString& origFilename, QString& fileExtension, bool& dataIsEmpty);
00188         void handleSaveAsAction(const QString& fileName);
00189         void handleCutAction();
00190         void handleCopyAction();
00191         void handlePasteAction();
00192         virtual void clear();
00193         void handleShowPropertiesAction();
00194 
00195     protected:
00197         QByteArray data() const;
00198     
00199         virtual void contextMenuEvent ( QContextMenuEvent * e );
00200 //      virtual void mousePressEvent( QMouseEvent *e );
00201         virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
00202         virtual void paintEvent( QPaintEvent* );
00203         virtual void resizeEvent( QResizeEvent* e );
00204         virtual bool eventFilter( QObject * watched, QEvent * e );
00205 
00207         virtual void setValueInternal( const QVariant& add, bool removeOld ) {
00208             setValueInternal( add, removeOld, true /*loadPixmap*/ );
00209         }
00210 
00212         void setValueInternal( const QVariant& add, bool removeOld, bool loadPixmap );
00213 
00215         void updateActionStrings();
00216         void updatePixmap();
00217 
00219         void setData(const KexiBLOBBuffer::Handle& handle);
00220 
00221         bool popupMenuAvailable();
00222 
00226         virtual bool keyPressed(QKeyEvent *ke);
00227 
00230         int realLineWidth() const;
00231 
00233         virtual bool subwidgetStretchRequired(KexiDBAutoField* autoField) const;
00234 
00235 //      virtual void drawContents ( QPainter *p );
00236 
00237 //      virtual void fontChange( const QFont& font );
00238 //      virtual void styleChange( QStyle& style );
00239 //      virtual void enabledChange( bool enabled );
00240 
00241 //      virtual void paletteChange( const QPalette& pal );
00242 //      virtual void frameChanged();
00243 //      virtual void showEvent( QShowEvent* e );
00244 
00245 //      void updatePixmapLater();
00246 //      class ImageLabel;
00247 //      ImageLabel *m_pixmapLabel;
00248         QPixmap m_pixmap;
00249         QByteArray m_value; 
00250         QString m_valueMimeType; 
00251 //      PixmapData m_value;
00252         KexiBLOBBuffer::Handle m_data;
00253 //      QString m_originalFileName;
00254         KexiDropDownButton *m_chooser;
00255         KexiImageContextMenu *m_popupMenu;
00256 //moved     KActionCollection m_actionCollection;
00257 //moved     KAction *m_insertFromFileAction, *m_saveAsAction, *m_cutAction, *m_copyAction, *m_pasteAction,
00258 //          *m_deleteAction, *m_propertiesAction;
00259 //      QTimer m_clickTimer;
00260         int m_alignment;
00261         FocusPolicy m_focusPolicyInternal; 
00262         bool m_designMode : 1;
00263         bool m_readOnly : 1;
00264         bool m_scaledContents : 1;
00265         bool m_keepAspectRatio : 1;
00266         bool m_insideSetData : 1;
00267         bool m_setFocusOnButtonAfterClosingPopup : 1;
00268         bool m_lineWidthChanged : 1;
00269         bool m_paletteBackgroundColorChanged : 1;
00270         bool m_paintEventEnabled : 1; 
00271         bool m_dropDownButtonVisible : 1;
00272         bool m_insideSetPalette : 1;
00273 };
00274 
00275 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys