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-2006 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 
00114         virtual void setPaletteBackgroundColor( const QColor & color );
00115 
00117         bool dropDownButtonVisible() const;
00118 
00120         int lineWidth() const { return KexiFrame::lineWidth(); }
00121 
00125         FocusPolicy focusPolicy() const;
00126 
00128         FocusPolicy focusPolicyInternal() const;
00129 
00132         virtual void setFocusPolicy( FocusPolicy policy );
00133 
00134     public slots:
00135         void setPixmapId(uint id);
00136 
00137         void setStoredPixmapId(uint id);
00138 
00140         virtual void setDataSource( const QString &ds );
00141 
00142         inline void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
00143 
00144         virtual void setReadOnly(bool set);
00145 
00148 //todo      void setPixmapData(const QByteArray& pixmapData) { m_value.setData(pixmapData); }
00149 
00152 //todo      void setOriginalFileName(const QString& name) { m_value.setOriginalFileName(name); }
00153 
00154         void setScaledContents(bool set);
00155 
00156         void setAlignment(int alignment);
00157 
00158         void setKeepAspectRatio(bool set);
00159 
00160 //      void updateActionsAvailability();
00161 
00163 //      void slotToggled( bool on );
00164 
00166         void setDropDownButtonVisible( bool set );
00167 
00169         void insertFromFile();
00170 
00171     signals:
00174 //      virtual void pixmapChanged();
00175 //      virtual void valueChanged(const QByteArray& data);
00176 
00177         void idChanged(long id);
00178 
00179     protected slots:
00180         void slotUpdateActionsAvailabilityRequested(bool& valueIsNull, bool& valueIsReadOnly);
00181 
00182         void handleInsertFromFileAction(const KURL& url);
00183         void handleAboutToSaveAsAction(QString& origFilename, QString& fileExtension, bool& dataIsEmpty);
00184         void handleSaveAsAction(const QString& fileName);
00185         void handleCutAction();
00186         void handleCopyAction();
00187         void handlePasteAction();
00188         virtual void clear();
00189         void handleShowPropertiesAction();
00190 
00191     protected:
00193         QByteArray data() const;
00194     
00195         virtual void contextMenuEvent ( QContextMenuEvent * e );
00196 //      virtual void mousePressEvent( QMouseEvent *e );
00197         virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
00198         virtual void paintEvent( QPaintEvent* );
00199         virtual void resizeEvent( QResizeEvent* e );
00200         virtual bool eventFilter( QObject * watched, QEvent * e );
00201 
00203         virtual void setValueInternal( const QVariant& add, bool removeOld ) {
00204             setValueInternal( add, removeOld, true /*loadPixmap*/ );
00205         }
00206 
00208         void setValueInternal( const QVariant& add, bool removeOld, bool loadPixmap );
00209 
00211         void updateActionStrings();
00212         void updatePixmap();
00213 
00215         void setData(const KexiBLOBBuffer::Handle& handle);
00216 
00217         bool popupMenuAvailable();
00218 
00222         virtual bool keyPressed(QKeyEvent *ke);
00223 
00226         int realLineWidth() const;
00227 
00229         virtual bool subwidgetStretchRequired(KexiDBAutoField* autoField) const;
00230 
00231 //      virtual void drawContents ( QPainter *p );
00232 
00233 //      virtual void fontChange( const QFont& font );
00234 //      virtual void styleChange( QStyle& style );
00235 //      virtual void enabledChange( bool enabled );
00236 
00237 //      virtual void paletteChange( const QPalette& pal );
00238 //      virtual void frameChanged();
00239 //      virtual void showEvent( QShowEvent* e );
00240 
00241 //      void updatePixmapLater();
00242 //      class ImageLabel;
00243 //      ImageLabel *m_pixmapLabel;
00244         QPixmap m_pixmap;
00245         QByteArray m_value; 
00246         QString m_valueMimeType; 
00247 //      PixmapData m_value;
00248         KexiBLOBBuffer::Handle m_data;
00249 //      QString m_originalFileName;
00250         KexiDropDownButton *m_chooser;
00251         KexiImageContextMenu *m_popupMenu;
00252 //moved     KActionCollection m_actionCollection;
00253 //moved     KAction *m_insertFromFileAction, *m_saveAsAction, *m_cutAction, *m_copyAction, *m_pasteAction,
00254 //          *m_deleteAction, *m_propertiesAction;
00255 //      QTimer m_clickTimer;
00256         int m_alignment;
00257         FocusPolicy m_focusPolicyInternal; 
00258         bool m_designMode : 1;
00259         bool m_readOnly : 1;
00260         bool m_scaledContents : 1;
00261         bool m_keepAspectRatio : 1;
00262         bool m_insideSetData : 1;
00263         bool m_setFocusOnButtonAfterClosingPopup : 1;
00264         bool m_lineWidthChanged : 1;
00265         bool m_paletteBackgroundColorChanged : 1;
00266         bool m_paintEventEnabled : 1; 
00267         bool m_dropDownButtonVisible : 1;
00268 };
00269 
00270 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys