summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/forms/widgets/kexidblabel.h
blob: ec4e626a5e51834be4c157b74a222ddcd0eccac5 (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
/* This file is part of the KDE project
   Copyright (C) 2005 Christian Nitschkowski <segfault_ii@web.de>
   Copyright (C) 2005 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 KEXIDBLABEL_H
#define KEXIDBLABEL_H

#include <qimage.h>
#include <qlabel.h>

#include <kpixmap.h>

#include "../kexiformdataiteminterface.h"
#include "../kexidbtextwidgetinterface.h"
#include <widget/utils/kexidisplayutils.h>

class QPainter;
class QTimer;
class KexiDBInternalLabel;

//! @short An extended, data-aware, read-only text label.
/*! It's text may have a drop-shadow.

 @author Christian Nitschkowski, Jaroslaw Staniek
*/
class KEXIFORMUTILS_EXPORT KexiDBLabel : public QLabel, protected KexiDBTextWidgetInterface, public KexiFormDataItemInterface {
		Q_OBJECT
		Q_PROPERTY( QString dataSource READ dataSource WRITE setDataSource DESIGNABLE true )
		Q_PROPERTY( QCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType DESIGNABLE true )
		Q_PROPERTY( bool shadowEnabled READ shadowEnabled WRITE setShadowEnabled DESIGNABLE true )
		Q_OVERRIDE( QPixmap pixmap DESIGNABLE false )
		Q_OVERRIDE( bool scaledContents DESIGNABLE false )
//		Q_OVERRIDE( QColor paletteForegroundColor READ paletteForegroundColor WRITE setPaletteForegroundColor DESIGNABLE true )
		Q_PROPERTY( QColor frameColor READ frameColor WRITE setFrameColor DESIGNABLE true )

	public:
		KexiDBLabel( QWidget *parent, const char *name = 0, WFlags f = 0 );
		KexiDBLabel( const QString& text, QWidget *parent, const char *name = 0, WFlags f = 0 );
		virtual ~KexiDBLabel();

		inline QString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
		inline QCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }

		virtual QVariant value();

		bool shadowEnabled() const;

		virtual void setInvalidState( const QString& displayText );

		virtual bool valueIsNull();

		virtual bool valueIsEmpty();

		//! always true
		virtual bool isReadOnly() const;

		virtual QWidget* widget();

		//! always false
		virtual bool cursorAtStart();

		//! always false
		virtual bool cursorAtEnd();

		virtual void clear();

		//! used to catch setIndent(), etc.
		virtual bool setProperty ( const char * name, const QVariant & value );

		virtual const QColor& frameColor() const;

//		const QColor & paletteForegroundColor() const;

	public slots:
		//! Sets the datasource to \a ds
		inline void setDataSource( const QString &ds ) { KexiFormDataItemInterface::setDataSource( ds ); }

		inline void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }

		virtual void setText( const QString& text );

		/*! Enable/Disable the shadow effect.
		 KexiDBLabel acts just like a normal QLabel when shadow is disabled. */
		void setShadowEnabled( bool state );

		virtual void setPalette( const QPalette &pal );

		virtual void setFrameColor(const QColor& color);

//		void setPaletteForegroundColor( const QColor& color );

	protected slots:
		//! empty
		virtual void setReadOnly( bool readOnly );
		void updatePixmap();

	protected:
		void init();
		virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
		virtual void paintEvent( QPaintEvent* );
		virtual void resizeEvent( QResizeEvent* e );

		//! Sets value \a value for a widget.
		virtual void setValueInternal( const QVariant& add, bool removeOld );

		virtual void fontChange( const QFont& font );
		virtual void styleChange( QStyle& style );
		virtual void enabledChange( bool enabled );

		virtual void paletteChange( const QPalette& oldPal );
		virtual void frameChanged();
		virtual void showEvent( QShowEvent* e );

		//! Reimplemented to paint using real frame color instead of froeground. 
		//! Also allows to paint more types of frame.
		virtual void drawFrame( QPainter * );

		void updatePixmapLater();

		class Private;
		Private *d;
};

#endif