kexi

kexiarrowtip.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexiarrowtip.h"
21
22#include <tqpixmap.h>
23#include <tqbitmap.h>
24#include <tqpainter.h>
25#include <tqimage.h>
26#include <tqtooltip.h>
27#include <tqfont.h>
28#include <tqfontmetrics.h>
29#include <tqtimer.h>
30
31#include <kexiutils/utils.h>
32
33KexiArrowTip::KexiArrowTip(const TQString& text, TQWidget* parent)
34 : KexiToolTip(text, parent)
35 , m_opacity(0.0)
36{
37 TQPalette pal( palette() );
38 TQColorGroup cg(pal.active());
39 cg.setColor(TQColorGroup::Foreground, TQt::red);
40 pal.setActive(cg);
41 setPalette(pal);
42
43 TQFontMetrics fm(font());
44 TQSize sz(fm.boundingRect(m_value.toString()).size());
45 sz += TQSize(14, 10); //+margins
46 m_arrowHeight = sz.height()/2;
47 sz += TQSize(0, m_arrowHeight); //+arrow height
48 resize(sz);
49
50 setAutoMask( false );
51
52 //generate mask
53 TQPixmap maskPm(size());
54 maskPm.fill( black );
55 TQPainter maskPainter(&maskPm);
56 drawFrame(maskPainter);
57 TQImage maskImg( maskPm.convertToImage() );
58 TQBitmap bm;
59 bm = maskImg.createHeuristicMask();
60 setMask( bm );
61}
62
63KexiArrowTip::~KexiArrowTip()
64{
65}
66
67void KexiArrowTip::show()
68{
69 if (isVisible())
70 return;
71
72 m_opacity = 0.0;
73 setWindowOpacity(0.0);
74 KexiToolTip::show();
75 increaseOpacity();
76}
77
78void KexiArrowTip::hide()
79{
80 if (!isVisible())
81 return;
82
83 decreaseOpacity();
84}
85
86void KexiArrowTip::increaseOpacity()
87{
88 m_opacity += 0.10;
89 setWindowOpacity(m_opacity);
90 if (m_opacity < 1.0)
91 TQTimer::singleShot(25, this, TQ_SLOT(increaseOpacity()));
92}
93
94void KexiArrowTip::decreaseOpacity()
95{
96 if (m_opacity<=0.0) {
97 KexiToolTip::close();
98 m_opacity = 0.0;
99 return;
100 }
101 m_opacity -= 0.10;
102 setWindowOpacity(m_opacity);
103 TQTimer::singleShot(25, this, TQ_SLOT(decreaseOpacity()));
104}
105
106bool KexiArrowTip::close ( bool alsoDelete )
107{
108 if (!isVisible()) {
109 return KexiToolTip::close(alsoDelete);
110 }
111 if (m_opacity>0.0)
112 decreaseOpacity();
113 else
114 return KexiToolTip::close(alsoDelete);
115 return m_opacity<=0.0;
116}
117
118void KexiArrowTip::drawContents(TQPainter& p)
119{
120 p.setPen( TQPen(palette().active().foreground(), 1) );
121 p.drawText(TQRect(0,m_arrowHeight,width(),height()-m_arrowHeight),
122 TQt::AlignCenter, m_value.toString());
123}
124
125void KexiArrowTip::drawFrame(TQPainter& p)
126{
127 TQPen pen(palette().active().foreground(), 1, TQt::SolidLine, TQt::SquareCap, TQt::MiterJoin);
128 p.setPen( pen );
129 /*
130 /\
131 +- -----+
132 | text |
133 +--------+
134 */
135 //1st line
136 const int arrowOffset = 5; //5 pixels to right
137 TQPointArray pa(8);
138 pa.setPoint(0, 0, m_arrowHeight-1);
139 pa.setPoint(1, 0, height()-1);
140 pa.setPoint(2, width()-1, height()-1);
141 pa.setPoint(3, width()-1, m_arrowHeight-1);
142 pa.setPoint(4, arrowOffset+m_arrowHeight+m_arrowHeight-2, m_arrowHeight-1);
143 pa.setPoint(5, arrowOffset+m_arrowHeight-1, 0);
144 pa.setPoint(6, arrowOffset, m_arrowHeight-1);
145 pa.setPoint(7, 0, m_arrowHeight-1);
146 p.drawPolyline(pa);
147 //-2nd, internal line
148 pa.resize(12);
149 pa.setPoint(0, 1, m_arrowHeight);
150 pa.setPoint(1, 1, height()-2);
151 pa.setPoint(2, width()-2, height()-2);
152 pa.setPoint(3, width()-2, m_arrowHeight);
153 pa.setPoint(4, arrowOffset+m_arrowHeight+m_arrowHeight-2, m_arrowHeight);
154 pa.setPoint(5, arrowOffset+m_arrowHeight-1, 1);
155 pa.setPoint(6, arrowOffset, m_arrowHeight);
156 pa.setPoint(7, 0, m_arrowHeight);
157 pa.setPoint(8, arrowOffset+1, m_arrowHeight);
158 pa.setPoint(9, arrowOffset+m_arrowHeight-1, 2);
159 pa.setPoint(10, arrowOffset+m_arrowHeight+m_arrowHeight-3, m_arrowHeight);
160 pa.setPoint(11, width()-2, m_arrowHeight);
161 p.drawPolyline(pa);
162}
163
164#include "kexiarrowtip.moc"
A tooltip that can display rich content.
Definition kexitooltip.h:28