F:/KPlato/koffice/libs/koproperty/widget.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "widget.h"
00022 #include "property.h"
00023 #include "editoritem.h"
00024 #include "editor.h"
00025 
00026 #include <QPainter>
00027 #include <QVariant>
00028 
00029 #include <k3listview.h>
00030 #include <kdebug.h>
00031 
00032 using namespace KoProperty;
00033 
00034 namespace KoProperty {
00035 class WidgetPrivate
00036 {
00037         public:
00038                 WidgetPrivate()
00039                 : property(0)
00040                 , editor(0)
00041                 , leaveTheSpaceForRevertButton(false)
00042                 , hasBorders(true)
00043                 , readOnly(false)
00044                 , visibleFlag(true)
00045                 {
00046                 }
00047                 ~WidgetPrivate() {}
00048 
00049                 Property *property;
00050                 QWidget *editor;
00051                 bool leaveTheSpaceForRevertButton : 1;
00052                 bool hasBorders : 1;
00053                 bool readOnly : 1;
00054                 bool visibleFlag : 1;
00055 };
00056 }
00057 
00058 Widget::Widget(Property *property, QWidget *parent)
00059  : QWidget(parent)
00060 {
00061         d = new WidgetPrivate();
00062         d->property = property;
00063 }
00064 
00065 Widget::~Widget()
00066 {
00067         delete d;
00068         d = 0;
00069 }
00070 
00071 Property*
00072 Widget::property() const
00073 {
00074         return d ? d->property : 0; //for sanity
00075 }
00076 
00077 void
00078 Widget::setProperty(Property *property)
00079 {
00080         d->property = property;
00081         if(property)
00082                 setValue(property->value(), false);
00083         //if(property->type() == ValueFromList)
00084         //      setValueList(property->valueList());
00085 }
00086 
00087 void
00088 Widget::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value)
00089 {
00090         p->eraseRect(r);
00091         QRect rect(r);
00092         rect.setLeft(rect.left()+KPROPEDITOR_ITEM_MARGIN);
00093 //      if (d->hasBorders)
00094 //              rect.setTop(rect.top()+1); //+1 to have the same vertical position as editor
00095 //      else
00096 //              rect.setHeight(rect.height()-1); //don't place over listviews's border
00097         p->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, value.toString());
00098 }
00099 
00100 void
00101 Widget::undo()
00102 {
00103         if(d->property)
00104                 d->property->resetValue();
00105 }
00106 
00107 bool
00108 Widget::eventFilter(QObject*, QEvent* e)
00109 {
00110         if(e->type() == QEvent::KeyPress)
00111         {
00112                 QKeyEvent* ev = static_cast<QKeyEvent*>(e);
00113                 if(ev->key() == Qt::Key_Escape)
00114                 {
00115                         emit rejectInput(this);
00116                         return true;
00117                 }
00118                 else if((ev->key() == Qt::Key_Return) || (ev->key() == Qt::Key_Enter))
00119                 {
00120                         // should apply when autosync == false
00121                         emit acceptInput(this);
00122                         return true;
00123                 }
00124                 else {
00125                         Editor *list = static_cast<KoProperty::Editor*>(parentWidget()->parentWidget());
00126                         if (!list)
00127                                 return false; //for sanity
00128                         return list->handleKeyPress(ev);
00129                 }
00130 
00131                 /* moved in Editor
00132                 if (item) {
00133                         if(ev->key() == Qt::Key_Up && ev->state() != Qt::ControlButton)
00134                         {
00135                                 if(item->itemAbove())
00136                                         list->setCurrentItem(item->itemAbove());
00137                                 return true;
00138                         }
00139                         else if(ev->key() == Qt::Key_Down && ev->state() != Qt::ControlButton)
00140                         {
00141                                 if(item->itemBelow())
00142                                         list->setCurrentItem(item->itemBelow());
00143                                 return true;
00144                         }
00145                 }*/
00146         }
00147 
00148         return false;
00149 }
00150 
00151 void
00152 Widget::setFocusWidget(QWidget*focusProxy)
00153 {
00154         if (focusProxy) {
00155                 if (focusProxy->focusPolicy() != Qt::NoFocus)
00156                         setFocusProxy(focusProxy);
00157                 focusProxy->installEventFilter(this);
00158         }
00159         else if (this->focusProxy()) {
00160                 this->focusProxy()->removeEventFilter(this);
00161                 setFocusProxy(0);
00162         }
00163 }
00164 
00165 bool
00166 Widget::leavesTheSpaceForRevertButton() const
00167 {
00168         return d->leaveTheSpaceForRevertButton;
00169 }
00170 
00171 void
00172 Widget::setLeavesTheSpaceForRevertButton(bool set)
00173 {
00174         d->leaveTheSpaceForRevertButton = set;
00175 }
00176 
00177 void
00178 Widget::setHasBorders(bool set)
00179 {
00180         d->hasBorders = set;
00181 }
00182 
00183 bool
00184 Widget::hasBorders() const
00185 {
00186         return d->hasBorders;
00187 }
00188 
00189 void
00190 Widget::setEditor(QWidget* editor)
00191 {
00192         d->editor = editor;
00193         if (!d->editor)
00194                 return;
00195         d->editor->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
00196         d->editor->move(0,0);
00197 }
00198 
00199 void
00200 Widget::resizeEvent(QResizeEvent *e)
00201 {
00202         QWidget::resizeEvent(e);
00203         if (d->editor)
00204                 d->editor->resize(size());
00205 }
00206 
00207 bool
00208 Widget::isReadOnly() const
00209 {
00210         return d->readOnly;
00211 }
00212 
00213 void
00214 Widget::setReadOnly(bool readOnly)
00215 {
00216         d->readOnly = readOnly;
00217         setReadOnlyInternal(readOnly);
00218 }
00219 
00220 bool 
00221 Widget::visibleFlag() const
00222 {
00223         return d->visibleFlag;
00224 }
00225 
00226 void
00227 Widget::setVisibleFlag(bool visible)
00228 {
00229         d->visibleFlag = visible;
00230 }
00231 
00232 #include "widget.moc"

Généré le Wed Nov 22 23:41:07 2006 pour KPlato par  doxygen 1.5.1-p1