1
/* This file is part of the KDE project
2
Copyright (C) 2002 Lucijan Busch <lucijan@gmx.at>
3
Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4
Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this program; see the file COPYING. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
31
#include <kiconloader.h>
35
#include "kexipropertyeditoritem.h"
36
#include "kexipropertyeditor.h"
39
// Helper class for QSizePolicy Editor
47
static QStringList list();
48
static QString valueToKey(int key);
49
static QSizePolicy::SizeType keyToValue(const QString &key);
53
spHelper::valueToKey(int key)
57
case QSizePolicy::Fixed: return QString("Fixed");
58
case QSizePolicy::Minimum: return QString("Minimum");
59
case QSizePolicy::Maximum: return QString("Maximum");
60
case QSizePolicy::Preferred: return QString("Preferred");
61
case QSizePolicy::MinimumExpanding: return QString("MinimumExpanding");
62
case QSizePolicy::Expanding: return QString("Expanding");
63
case QSizePolicy::Ignored: return QString("Ignored");
64
default: return QString();
72
list << "Fixed" << "Minimum" << "Maximum" << "Preferred" << "Expanding"
73
<< "MinimumExpanding" << "Ignored";
78
spHelper::keyToValue(const QString &key)
80
if(key == "Fixed") return QSizePolicy::Fixed;
81
if(key == "Minimum") return QSizePolicy::Minimum;
82
if(key == "Maximum") return QSizePolicy::Maximum;
83
if(key == "Preferred") return QSizePolicy::Preferred;
84
if(key == "MinimumExpanding") return QSizePolicy::MinimumExpanding;
85
if(key == "Expanding") return QSizePolicy::Expanding;
86
if(key == "Ignored") return QSizePolicy::Ignored;
88
return QSizePolicy::Expanding;
92
// ======== KexiPropertyEditorItem ============================
94
KexiPropertyEditorItem::KexiPropertyEditorItem(KexiPropertyEditorItem *par, KexiProperty *property,
95
KexiPropertyEditorItem *after)
96
: KListViewItem(par, after, property->desc().isEmpty() ? property->name() : property->desc()
97
, property->valueText())
99
m_order = parent()->childCount();
100
// m_value = property->value();
101
// m_oldvalue = m_value;
106
KexiProperty::List *children = m_property->children();
108
m_children = new Dict();
109
KexiProperty::ListIterator it(*children);
110
KexiPropertyEditorItem *item = 0;
111
for (;it.current();++it) {
112
item = new KexiPropertyEditorItem(this, it.current(), item);
113
m_children->insert( it.current()->name(), item );
120
// m_childprop->setAutoDelete(true);
123
//3 rows per item is enough?
124
setMultiLinesEnabled( true );
125
setHeight(static_cast<KexiPropertyEditor*>(listView())->baseRowHeight()*3);
128
KexiPropertyEditorItem::KexiPropertyEditorItem(KListView *par, const QString &text)
129
: KListViewItem(par, text, "")
131
m_order = listView()->childCount();
133
m_property= new KexiProperty();
134
// m_oldvalue=m_value;
137
setSelectable(false);
140
//3 rows per item is enough?
141
setMultiLinesEnabled( true );
142
setHeight(static_cast<KexiPropertyEditor*>(par)->baseRowHeight()*3);
145
/*KexiPropertyEditorItem* KexiPropertyEditorItem::createChildItem(const QString& name)
147
KexiProperty *childProp = m_property->child(name);
150
return new KexiPropertyEditorItem(this, childProp);
154
KexiPropertyEditorItem::setValue(QVariant value)
156
setText(1, format(value));
162
KexiPropertyEditorItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align)
164
int margin = listView()->itemMargin();
168
switch(m_property->type())
170
case QVariant::Pixmap:
172
p->fillRect(0,0,width,height(),QBrush(backgroundColor()));
173
p->drawPixmap(margin, margin, m_property->value().toPixmap());
176
case QVariant::Color:
178
p->fillRect(0,0,width,height(), QBrush(backgroundColor()));
179
QColor ncolor = m_property->value().toColor();
181
p->drawRect(margin, margin, width - 2*margin, height() - 2*margin);
182
QColorGroup nGroup(cg);
187
p->fillRect(0,0,width,height(), QBrush(backgroundColor()));
188
if(m_property->value().toBool())
190
p->drawPixmap(margin, height()/2 -8, SmallIcon("button_ok"));
191
p->drawText(QRect(margin+20,0,width,height()-1), Qt::AlignVCenter, i18n("Yes"));
195
p->drawPixmap(margin, height()/2 -8, SmallIcon("button_no"));
196
p->drawText(QRect(margin+20,0,width,height()-1), Qt::AlignVCenter, i18n("No"));
205
KListViewItem::paintCell(p, cg, column, width, align);
217
p->fillRect(0,0,width, height(), QBrush(cg.highlight()));
218
p->setPen(cg.highlightedText());
221
p->fillRect(0,0,width, height(), QBrush(backgroundColor()));
223
QFont f = listView()->font();
226
if (m_property->changed())
229
p->drawText(QRect(margin,0,width, height()-1), Qt::AlignVCenter, text(0));
232
p->setPen( QColor(200,200,200) ); //like in table view
233
p->drawLine(width-1, 0, width-1, height()-1);
236
p->setPen( QColor(200,200,200) ); //like in t.v.
237
p->drawLine(-50, height()-1, width, height()-1 );
241
KexiPropertyEditorItem::paintBranches(QPainter *p, const QColorGroup &cg, int w, int y, int h)
243
p->eraseRect(0,0,w,h);
244
KListViewItem *item = (KListViewItem*)firstChild();
245
// const bool invertAlternate = parent() && parent()->parent() && ((childCount() % 2) == 0);
253
/*if (invertAlternate) {
254
if (item->isAlternate())
255
p->fillRect(0,0,w, item->height(),
256
QBrush(listView()->viewport()->colorGroup().base()));
258
p->fillRect(0,0,w, item->height(),
259
QBrush(static_cast<KListView*>(listView())->alternateBackground()));
262
p->fillRect(0,0,w, item->height(), QBrush(item->backgroundColor()));
263
p->fillRect(-50,0,50, item->height(), QBrush(item->backgroundColor()));
265
p->setPen( QColor(200,200,200) ); //like in t.v.
266
p->drawLine(-50, item->height()-1, w, item->height()-1 );
269
if(item->isSelected())
271
p->fillRect(0,0,w, item->height(), QBrush(cg.highlight()));
272
p->fillRect(-50,0,50, item->height(), QBrush(cg.highlight()));
275
if(item->firstChild())
277
// p->drawRect(2, item->height()/2 -4, 9, 9);
278
const int marg = (item->height()-KexiPropertyEditorItem_BranchBoxSize)/2;
280
p->setPen( QColor(200,200,200) );
282
KexiPropertyEditorItem_BranchBoxSize, KexiPropertyEditorItem_BranchBoxSize);
283
p->fillRect(2+1, marg+1,
284
KexiPropertyEditorItem_BranchBoxSize-2, KexiPropertyEditorItem_BranchBoxSize-2, white);
286
// p->drawLine(4, item->height()/2, 8, item->height()/2);
287
p->drawLine(2+2, marg+KexiPropertyEditorItem_BranchBoxSize/2,
288
KexiPropertyEditorItem_BranchBoxSize-1, marg+KexiPropertyEditorItem_BranchBoxSize/2);
290
p->drawLine(2+KexiPropertyEditorItem_BranchBoxSize/2, marg+2,
291
2+KexiPropertyEditorItem_BranchBoxSize/2, marg+KexiPropertyEditorItem_BranchBoxSize-3);
292
// p->drawLine(6, item->height()/2 - 2, 6, item->height()/2 +2);
295
if (!static_cast<KexiPropertyEditorItem*>(item)->m_property->icon().isEmpty()) {
297
int margin = listView()->itemMargin();
298
QPixmap pix = SmallIcon(static_cast<KexiPropertyEditorItem*>(item)->m_property->icon());
299
p->drawPixmap(1,(item->height()-pix.height())/2,pix);
302
p->translate(0, item->totalHeight());
303
item = (KListViewItem*)item->nextSibling();
309
KexiPropertyEditorItem::setup()
311
KListViewItem::setup();
318
KexiPropertyEditorItem::getComposedValue()
320
switch(m_property->type())
326
v = (*m_children)["width"]->property()->value();
327
s.setWidth(v.toInt());
328
(*m_children)["width"]->property()->setValue(v.toInt());
330
v = (*m_children)["height"]->property()->value();
331
s.setHeight(v.toInt());
332
(*m_children)["height"]->property()->setValue(v.toInt());
337
case QVariant::Point:
341
v = (*m_children)["x"]->value();
343
(*m_children)["x"]->property()->setValue(v.toInt());
345
v = (*m_children)["y"]->value();
347
(*m_children)["y"]->property()->setValue(v.toInt());
356
v = (*m_children)["x"]->value();
358
(*m_children)["x"]->property()->setValue(v.toInt());
360
v = (*m_children)["y"]->value();
362
(*m_children)["y"]->property()->setValue(v.toInt());
364
v = (*m_children)["width"]->value();
365
r.setWidth(v.toInt());
366
(*m_children)["width"]->property()->setValue(v.toInt());
368
v = (*m_children)["height"]->value();
369
r.setHeight(v.toInt());
370
(*m_children)["height"]->property()->setValue(v.toInt());
375
case QVariant::SizePolicy:
379
v = (*m_children)["hSize"]->value();
380
p.setHorData(spHelper::keyToValue(v.toString()));
381
(*m_children)["hSize"]->property()->setValue(v.toString());
383
v = (*m_children)["vSize"]->value();
384
p.setVerData(spHelper::keyToValue(v.toString()));
385
(*m_children)["vSize"]->property()->setValue(v.toString());
387
v = (*m_children)["hStretch"]->value();
388
p.setHorStretch(v.toInt());
389
(*m_children)["hStretch"]->property()->setValue(v.toInt());
391
v = (*m_children)["vStretch"]->value();
392
p.setVerStretch(v.toInt());
393
(*m_children)["vStretch"]->property()->setValue(v.toInt());
408
/* let's move this to KexiProperty?
410
KexiPropertyEditorItem::updateChildValue()
412
if(m_property->type() == QVariant::Rect)
414
QRect r = m_value.toRect();
415
(*m_children)["x"]->property()->setValue(r.x());
416
(*m_children)["x"]->setValue(r.x());
417
(*m_children)["y"]->property()->setValue(r.y());
418
(*m_children)["y"]->setValue(r.y());
419
(*m_children)["width"]->property()->setValue(r.width());
420
(*m_children)["width"]->setValue(r.width());
421
(*m_children)["height"]->property()->setValue(r.height());
422
(*m_children)["height"]->setValue(r.height());
426
KexiPropertyEditorItem::~KexiPropertyEditorItem()
432
/* switch(m_property->type())
434
case QVariant::Point:
437
case QVariant::SizePolicy:
439
// delete m_childprop;
440
// delete m_children;
449
void KexiPropertyEditorItem::updateValue(bool alsoParent)
451
QString specialValueText;
452
if (m_property->hasOptions() && m_property->isNumericType()) {
453
//replace min value with minValueText if defined
454
QVariant minValue( m_property->option("min") );
455
QVariant minValueText( m_property->option("minValueText") );
456
if (!minValue.isNull() && !minValueText.isNull() && minValue.toInt()==m_property->value().toInt()) {
457
specialValueText = minValueText.toString();
460
setText( 1, specialValueText.isEmpty() ? m_property->valueText() : specialValueText );
461
if (alsoParent && parent())
462
static_cast<KexiPropertyEditorItem*>(parent())->updateValue();
466
KexiPropertyEditorItem::updateChildrenValue()
468
//update children value
469
KexiPropertyEditorItem *it = static_cast<KexiPropertyEditorItem*>(firstChild());
471
it->updateValue(false);
472
it = static_cast<KexiPropertyEditorItem*>(it->nextSibling());
476
/*QString KexiPropertyEditorItem::key( int column, bool ascending ) const
479
return QListViewItem::key(column, ascending);
481
return QString().sprintf("%5.5d", m_order);
484
int KexiPropertyEditorItem::compare( QListViewItem *i, int col, bool ascending ) const
487
return -QListViewItem::key( col, ascending ).localeAwareCompare( i->key( col, ascending ) );
489
return m_order - static_cast<KexiPropertyEditorItem*>(i)->m_order;
490
// QString().sprintf("%5.5d", m_order).localeAwareCompare( QString().sprintf("%5.5d", i->m_order) );
493
void KexiPropertyEditorItem::paintFocus ( QPainter * , const QColorGroup & , const QRect & )