kexi

kexibooltableedit.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
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 "kexibooltableedit.h"
00021 
00022 #include <kexidb/field.h>
00023 
00024 #include <qpainter.h>
00025 
00026 #include <kglobal.h>
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029 #include <kglobalsettings.h>
00030 
00031 
00032 KexiBoolTableEdit::KexiBoolTableEdit(KexiTableViewColumn &column, QScrollView *parent)
00033  : KexiTableEdit(column, parent, "KexiBoolTableEdit")
00034 {
00035     init();
00036 }
00037 
00038 KexiBoolTableEdit::~KexiBoolTableEdit()
00039 {
00040 }
00041 
00042 void KexiBoolTableEdit::init()
00043 {
00044     kdDebug() << "KexiBoolTableEdit: m_origValue.typeName()==" << m_origValue.typeName() << endl;
00045     kdDebug() << "KexiBoolTableEdit: type== " << field()->typeName() << endl;
00046 
00047     m_hasFocusableWidget = false;
00048 }
00049     
00050 void KexiBoolTableEdit::setValueInternal(const QVariant& /*add*/, bool /*removeOld*/)
00051 {
00052     m_currentValue = m_origValue;
00053     //nothing to do more...
00054 }
00055 
00056 /*bool KexiBoolTableEdit::valueChanged()
00057 {
00058     if (m_lineedit->text()!=m_origText)
00059         return true;
00060     return KexiTableEdit::valueChanged();
00061 }*/
00062 
00063 bool KexiBoolTableEdit::valueIsNull()
00064 {
00065     return m_currentValue.isNull();
00066 }
00067 
00068 bool KexiBoolTableEdit::valueIsEmpty()
00069 {
00070     return m_currentValue.isNull();
00071 }
00072 
00073 QVariant KexiBoolTableEdit::value()
00074 {
00075 //  ok = true;
00076     return m_currentValue;
00077 }
00078 
00079 void KexiBoolTableEdit::clear()
00080 {
00081     m_currentValue = QVariant();
00082 }
00083 
00084 bool KexiBoolTableEdit::cursorAtStart()
00085 {
00086     return true;
00087 }
00088 
00089 bool KexiBoolTableEdit::cursorAtEnd()
00090 {
00091     return true;
00092 }
00093 
00094 /*QSize KexiBoolTableEdit::totalSize()
00095 {
00096     if (!m_lineedit)
00097         return size();
00098     return m_lineedit->size();
00099 }*/
00100 
00101 void KexiBoolTableEdit::setupContents( QPainter *p, bool /*focused*/, QVariant val, 
00102     QString &/*txt*/, int &/*align*/, int &/*x*/, int &y_offset, int &w, int &h  )
00103 {
00104 #ifdef Q_WS_WIN
00105 //  x = 1;
00106     y_offset = -1;
00107 #else
00108 //  x = 1;
00109     y_offset = 0;
00110 #endif
00111     int s = QMAX(h - 5, 12);
00112     s = QMIN( h-3, s );
00113     s = QMIN( w-3, s );//avoid too large box
00114 //      QRect r(w/2 - s/2 + x, h/2 - s/2 - 1, s, s);
00115     QRect r( QMAX( w/2 - s/2, 0 ) , h/2 - s/2 /*- 1*/, s, s);
00116     p->setPen(QPen(colorGroup().text(), 1));
00117     p->drawRect(r);
00118     if (val.asBool()) {
00119         p->drawLine(r.x(), r.y(), r.right(), r.bottom());
00120         p->drawLine(r.x(), r.bottom(), r.right(), r.y());
00121 //          p->drawLine(r.x() + 2, r.y() + 2, r.right() - 1, r.bottom() - 1);
00122 //          p->drawLine(r.x() + 2, r.bottom() - 2, r.right() - 1, r.y() + 1);
00123     }
00124 }
00125 
00126 void KexiBoolTableEdit::clickedOnContents()
00127 {
00128     m_currentValue = QVariant( !m_currentValue.toBool(), 0 );
00129 }
00130 
00131 //======================================================
00132 
00133 KexiBoolEditorFactoryItem::KexiBoolEditorFactoryItem()
00134 {
00135 }
00136 
00137 KexiBoolEditorFactoryItem::~KexiBoolEditorFactoryItem()
00138 {
00139 }
00140 
00141 KexiTableEdit* KexiBoolEditorFactoryItem::createEditor(
00142     KexiTableViewColumn &column, QScrollView* parent)
00143 {
00144     return new KexiBoolTableEdit(column, parent);
00145 }
00146 
00147 #include "kexibooltableedit.moc"
00148 
KDE Home | KDE Accessibility Home | Description of Access Keys