00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexiarrowtip.h"
00021
00022 #include <qpixmap.h>
00023 #include <qbitmap.h>
00024 #include <qpainter.h>
00025 #include <qimage.h>
00026 #include <qtooltip.h>
00027 #include <qfont.h>
00028 #include <qfontmetrics.h>
00029 #include <qtimer.h>
00030
00031 #include <kexiutils/utils.h>
00032
00033 KexiArrowTip::KexiArrowTip(const QString& text, QWidget* parent)
00034 : KexiToolTip(text, parent)
00035 , m_opacity(0.0)
00036 {
00037 QPalette pal( palette() );
00038 QColorGroup cg(pal.active());
00039 cg.setColor(QColorGroup::Foreground, Qt::red);
00040 pal.setActive(cg);
00041 setPalette(pal);
00042
00043 QFontMetrics fm(font());
00044 QSize sz(fm.boundingRect(m_value.toString()).size());
00045 sz += QSize(14, 10);
00046 m_arrowHeight = sz.height()/2;
00047 sz += QSize(0, m_arrowHeight);
00048 resize(sz);
00049
00050 setAutoMask( false );
00051
00052
00053 QPixmap maskPm(size());
00054 maskPm.fill( black );
00055 QPainter maskPainter(&maskPm);
00056 drawFrame(maskPainter);
00057 QImage maskImg( maskPm.convertToImage() );
00058 QBitmap bm;
00059 bm = maskImg.createHeuristicMask();
00060 setMask( bm );
00061 }
00062
00063 KexiArrowTip::~KexiArrowTip()
00064 {
00065 }
00066
00067 void KexiArrowTip::show()
00068 {
00069 if (isVisible())
00070 return;
00071
00072 m_opacity = 0.0;
00073 setWindowOpacity(0.0);
00074 KexiToolTip::show();
00075 increaseOpacity();
00076 }
00077
00078 void KexiArrowTip::hide()
00079 {
00080 if (!isVisible())
00081 return;
00082
00083 decreaseOpacity();
00084 }
00085
00086 void KexiArrowTip::increaseOpacity()
00087 {
00088 m_opacity += 0.10;
00089 setWindowOpacity(m_opacity);
00090 if (m_opacity < 1.0)
00091 QTimer::singleShot(25, this, SLOT(increaseOpacity()));
00092 }
00093
00094 void KexiArrowTip::decreaseOpacity()
00095 {
00096 if (m_opacity<=0.0) {
00097 KexiToolTip::close();
00098 m_opacity = 0.0;
00099 return;
00100 }
00101 m_opacity -= 0.10;
00102 setWindowOpacity(m_opacity);
00103 QTimer::singleShot(25, this, SLOT(decreaseOpacity()));
00104 }
00105
00106 bool KexiArrowTip::close ( bool alsoDelete )
00107 {
00108 if (!isVisible()) {
00109 return KexiToolTip::close(alsoDelete);
00110 }
00111 if (m_opacity>0.0)
00112 decreaseOpacity();
00113 else
00114 return KexiToolTip::close(alsoDelete);
00115 return m_opacity<=0.0;
00116 }
00117
00118 void KexiArrowTip::drawContents(QPainter& p)
00119 {
00120 p.setPen( QPen(palette().active().foreground(), 1) );
00121 p.drawText(QRect(0,m_arrowHeight,width(),height()-m_arrowHeight),
00122 Qt::AlignCenter, m_value.toString());
00123 }
00124
00125 void KexiArrowTip::drawFrame(QPainter& p)
00126 {
00127 QPen pen(palette().active().foreground(), 1, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
00128 p.setPen( pen );
00129
00130
00131
00132
00133
00134
00135
00136 const int arrowOffset = 5;
00137 QPointArray pa(8);
00138 pa.setPoint(0, 0, m_arrowHeight-1);
00139 pa.setPoint(1, 0, height()-1);
00140 pa.setPoint(2, width()-1, height()-1);
00141 pa.setPoint(3, width()-1, m_arrowHeight-1);
00142 pa.setPoint(4, arrowOffset+m_arrowHeight+m_arrowHeight-2, m_arrowHeight-1);
00143 pa.setPoint(5, arrowOffset+m_arrowHeight-1, 0);
00144 pa.setPoint(6, arrowOffset, m_arrowHeight-1);
00145 pa.setPoint(7, 0, m_arrowHeight-1);
00146 p.drawPolyline(pa);
00147
00148 pa.resize(12);
00149 pa.setPoint(0, 1, m_arrowHeight);
00150 pa.setPoint(1, 1, height()-2);
00151 pa.setPoint(2, width()-2, height()-2);
00152 pa.setPoint(3, width()-2, m_arrowHeight);
00153 pa.setPoint(4, arrowOffset+m_arrowHeight+m_arrowHeight-2, m_arrowHeight);
00154 pa.setPoint(5, arrowOffset+m_arrowHeight-1, 1);
00155 pa.setPoint(6, arrowOffset, m_arrowHeight);
00156 pa.setPoint(7, 0, m_arrowHeight);
00157 pa.setPoint(8, arrowOffset+1, m_arrowHeight);
00158 pa.setPoint(9, arrowOffset+m_arrowHeight-1, 2);
00159 pa.setPoint(10, arrowOffset+m_arrowHeight+m_arrowHeight-3, m_arrowHeight);
00160 pa.setPoint(11, width()-2, m_arrowHeight);
00161 p.drawPolyline(pa);
00162 }
00163
00164 #include "kexiarrowtip.moc"