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-2005 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 <qwidget.h>
00026 #include <kactioncollection.h>
00027 #include <kexiblobbuffer.h>
00028 #include <qtimer.h>
00029 
00031 
00033 class KEXIFORMUTILS_EXPORT KexiDBImageBox : public QWidget, public KexiFormDataItemInterface
00034 {
00035     Q_OBJECT
00036     Q_PROPERTY( QString dataSource READ dataSource WRITE setDataSource )
00037     Q_PROPERTY( QCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType )
00038     Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
00039 //  Q_PROPERTY( QPixmap pixmap READ pixmap WRITE setPixmap )
00040 //  Q_PROPERTY( QByteArray pixmapData READ pixmapData WRITE setPixmapData )
00041     Q_PROPERTY( uint pixmapId READ pixmapId WRITE setPixmapId DESIGNABLE true STORED false )
00042     Q_PROPERTY( uint storedPixmapId READ storedPixmapId WRITE setStoredPixmapId DESIGNABLE false STORED true )
00043     Q_PROPERTY( bool scaledContents READ hasScaledContents WRITE setScaledContents )
00044     Q_PROPERTY( bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio )
00045     Q_PROPERTY( Alignment alignment READ alignment WRITE setAlignment )
00046 //  Q_PROPERTY( QString originalFileName READ originalFileName WRITE setOriginalFileName DESIGNABLE false )
00047 
00048     public:
00049         KexiDBImageBox( bool designMode, QWidget *parent, const char *name = 0 );
00050         virtual ~KexiDBImageBox();
00051 
00052         inline QString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
00053         inline QCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
00054 
00055         virtual QVariant value(); // { return m_value.data(); }
00056 
00057 //      QByteArray pixmapData() const { return m_value.data(); }
00058 
00059         QPixmap pixmap() const;
00060 
00061         uint pixmapId() const;
00062 
00063         uint storedPixmapId() const;
00064 // 
00065         virtual void setInvalidState( const QString& displayText );
00066 
00067         virtual bool valueIsNull();
00068 
00069         virtual bool valueIsEmpty();
00070 
00071         virtual QWidget* widget();
00072 
00074         virtual bool cursorAtStart();
00075 
00077         virtual bool cursorAtEnd();
00078 
00079 //      virtual void clear();
00080 
00081 //      //! used to catch setIndent(), etc.
00082 //      virtual bool setProperty ( const char * name, const QVariant & value );
00083 
00084         virtual bool isReadOnly() const;
00085 
00086         bool hasScaledContents() const;
00087 
00088 //      bool designMode() const { return m_designMode; }
00089 
00090         int alignment() const { return m_alignment; }
00091 
00092         bool keepAspectRatio() const { return m_keepAspectRatio; }
00093 
00094         virtual QSize sizeHint() const;
00095 
00096         KActionCollection* actionCollection() { return &m_actionCollection; }
00097 
00101 //todo      QString originalFileName() const { return m_value.originalFileName(); }
00102 
00103     public slots:
00104         void setPixmapId(uint id);
00105 
00106         void setStoredPixmapId(uint id);
00107 
00109         virtual void setDataSource( const QString &ds );
00110 
00111         inline void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
00112 
00113         virtual void setReadOnly(bool set);
00114 
00117 //todo      void setPixmapData(const QByteArray& pixmapData) { m_value.setData(pixmapData); }
00118 
00121 //todo      void setOriginalFileName(const QString& name) { m_value.setOriginalFileName(name); }
00122 
00123         void setScaledContents(bool set);
00124 
00125         void insertFromFile();
00126 
00127         void setAlignment(int alignment);
00128 
00129         void setKeepAspectRatio(bool set);
00130 
00131         void updateActionsAvailability();
00132 
00133         void saveAs();
00134 
00135         void cut();
00136 
00137         void copy();
00138 
00139         void paste();
00140 
00141         virtual void clear();
00142 
00143         void showProperties();
00144 
00145     signals:
00147         virtual void valueChanged(const QByteArray& data);
00148         void idChanged(long id);
00149 
00150     protected slots:
00151         void slotAboutToHidePopupMenu();
00152         void slotChooserPressed();
00153 
00154     protected:
00156         QByteArray data() const;
00157     
00158         virtual void contextMenuEvent ( QContextMenuEvent * e );
00159 //      virtual void mousePressEvent( QMouseEvent *e );
00160         //      virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
00161         virtual void paintEvent( QPaintEvent* );
00162 //      virtual void resizeEvent( QResizeEvent* e );
00163 
00165         virtual void setValueInternal( const QVariant& add, bool /*removeOld*/ );
00166 
00168         void updateActionStrings();
00169         void updatePixmap();
00170 
00172         void setData(const KexiBLOBBuffer::Handle& handle);
00173 
00174         bool popupMenuAvailable();
00175 
00176 //      virtual void drawContents ( QPainter *p );
00177 
00178 //      virtual void fontChange( const QFont& font );
00179 //      virtual void styleChange( QStyle& style );
00180 //      virtual void enabledChange( bool enabled );
00181 
00182 //      virtual void paletteChange( const QPalette& pal );
00183 //      virtual void frameChanged();
00184 //      virtual void showEvent( QShowEvent* e );
00185 
00186 //      void updatePixmapLater();
00187 //      class ImageLabel;
00188 //      ImageLabel *m_pixmapLabel;
00189         QPixmap m_pixmap;
00190         QByteArray m_value; 
00191 //      PixmapData m_value;
00192         KexiBLOBBuffer::Handle m_data;
00193 //      QString m_originalFileName;
00194         class Button;
00195         Button *m_chooser;
00196         KPopupMenu *m_popup;
00197         KActionCollection m_actionCollection;
00198         KAction *m_insertFromFileAction, *m_saveAsAction, *m_cutAction, *m_copyAction, *m_pasteAction,
00199             *m_deleteAction, *m_propertiesAction;
00200         QTimer m_clickTimer;
00201         int m_titleID;
00202         int m_alignment;
00203         bool m_designMode : 1;
00204         bool m_readOnly : 1;
00205         bool m_scaledContents : 1;
00206         bool m_keepAspectRatio : 1;
00207         bool m_insideSetData : 1;
00208 //      friend class ImageLabel;
00209 };
00210 
00211 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys