kexi

kexitableheader.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002   Lucijan Busch <lucijan@gmx.at>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qpainter.h>
00021 #include <qregion.h>
00022 
00023 #include <kdebug.h>
00024 
00025 #include "kexitableheader.h"
00026 
00027 KexiTableHeader::KexiTableHeader(QWidget *parent, const char *name)
00028  : QHeader(parent, name)
00029 {
00030     m_currentRow = -1;
00031     m_insertRow = -1;
00032 
00033     m_cellHeight = 1;
00034 
00035     m_painter = 0;
00036 }
00037 
00038 void
00039 KexiTableHeader::paintEvent(QPaintEvent *e)
00040 {
00041     QPainter p(this);
00042     p.setPen(colorGroup().buttonText());
00043     int pos = orientation() == Horizontal
00044              ? e->rect().left()
00045              : e->rect().top();
00046     int id = mapToIndex( sectionAt( pos + offset() ) );
00047     if ( id < 0 ) {
00048     if ( pos > 0 )
00049         return;
00050     else
00051         id = 0;
00052     }
00053 
00054     QRegion reg = e->region();
00055     for ( int i = id; i < count(); i++ ) {
00056     QRect r = sRect(i);
00057     reg -= r;
00058     p.save();
00059     
00060     paintSection( &p, i, r );
00061     p.restore();
00062     if ( orientation() == Horizontal && r. right() >= e->rect().right() ||
00063          orientation() == Vertical && r. bottom() >= e->rect().bottom() )
00064         return;
00065     }
00066     if ( !reg.isEmpty() )
00067     erase( reg );
00068 }
00069 
00070 
00071 void
00072 KexiTableHeader::paintSectionLabel(QPainter *p, int index, const QRect & fr)
00073 {
00074     if(index == m_currentRow && index != m_insertRow - 1)
00075     {
00076         int h = fr.height() - 3;
00077         int pos = fr.y() + h;
00078         for(int i=0; i < h/2 - 1; i++)
00079         {
00080             p->drawLine(i + 4, pos - h + 2 + i, i + 4, pos - 2 - i);
00081         }
00082 
00083         QHeader::paintSectionLabel(p, index, fr);
00084     }
00085     else
00086     {
00087         QHeader::paintSectionLabel(p, index, fr);
00088     }
00089 }
00090 
00091 
00092 void
00093 KexiTableHeader::setCurrentRow(int row)
00094 {
00095     if(row != -1)
00096     {
00097         int old = m_currentRow;
00098         m_currentRow = row;
00099         
00100         QRect restore = sRect(old);
00101         paintEvent(new QPaintEvent(restore, false));
00102         
00103         QRect update = sRect(row);
00104         QPaintEvent *ev = new QPaintEvent(update, false);
00105         paintEvent(ev);
00106         
00107         return;
00108     }
00109     m_currentRow = row;
00110     
00111 }
00112 
00113 void
00114 KexiTableHeader::setCellHeight(int height)
00115 {
00116     if(height < 1)
00117     {
00118         m_cellHeight = 1;
00119         return;
00120     }
00121     else
00122     {
00123         m_cellHeight = height;
00124     }
00125         
00126 }
00127 
00128 void
00129 KexiTableHeader::setInsertRow(int row)
00130 {
00131     setLabel(row - 1, "*");
00132     setLabel(m_insertRow - 1, "");
00133     m_insertRow = row;
00134 }
00135 
00136 KexiTableHeader::~KexiTableHeader()
00137 {
00138 }
00139 
00140 #include "kexitableheader.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys