lib

sizepolicyedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "sizepolicyedit.h"
22#include "editoritem.h"
23
24#include <tqlabel.h>
25#include <tqlayout.h>
26#include <tqpainter.h>
27#include <tqsizepolicy.h>
28#include <tqmap.h>
29#include <tqtooltip.h>
30
31#include <tdelocale.h>
32
33using namespace KoProperty;
34
35TQStringVariantMap *SizePolicyEdit::m_spValues = 0;
36
37SizePolicyEdit::SizePolicyEdit(Property *property, TQWidget *parent, const char *name)
38 : Widget(property, parent, name)
39{
40 setHasBorders(false);
41// TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
42 m_edit = new TQLabel(this);
43 m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN);
44 m_edit->setBackgroundMode(TQt::PaletteBase);
45// m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
46 m_edit->setMinimumHeight(5);
47 setEditor(m_edit);
48// l->addWidget(m_edit);
49 setFocusWidget(m_edit);
50
51
52 if(!m_spValues) {
53 m_spValues = new TQStringVariantMap();
54 (*m_spValues)[i18n("Size Policy", "Fixed")] = TQSizePolicy::Fixed;
55 (*m_spValues)[i18n("Size Policy", "Minimum")] = TQSizePolicy::Minimum;
56 (*m_spValues)[i18n("Size Policy", "Maximum")] = TQSizePolicy::Maximum;
57 (*m_spValues)[i18n("Size Policy", "Preferred")] = TQSizePolicy::Preferred;
58 (*m_spValues)[i18n("Size Policy", "Expanding")] = TQSizePolicy::Expanding;
59 (*m_spValues)[i18n("Size Policy", "Minimum Expanding")] = TQSizePolicy::MinimumExpanding;
60 (*m_spValues)[i18n("Size Policy", "Ignored")] = TQSizePolicy::Ignored;
61 }
62}
63
64SizePolicyEdit::~SizePolicyEdit()
65{
66 delete m_spValues;
67 m_spValues = 0;
68}
69
70TQVariant
72{
73 return m_value;
74}
75
76void
77SizePolicyEdit::setValue(const TQVariant &value, bool emitChange)
78{
79 m_value = value;
80 m_edit->setText(TQString("%1/%2/%3/%4").arg(findDescription(value.toSizePolicy().horData())).
81 arg(findDescription(value.toSizePolicy().verData())).
82 arg(value.toSizePolicy().horStretch()).arg(value.toSizePolicy().verStretch()));
83 TQToolTip::add(this, m_edit->text());
84
85 if (emitChange)
86 emit valueChanged(this);
87}
88
89void
90SizePolicyEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
91{
92// p->eraseRect(r);
93// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine,
94 TQRect rect(r);
95 rect.setBottom(r.bottom()+1);
96 Widget::drawViewer(p, cg, rect,
97 TQString("%1/%2/%3/%4").arg(findDescription(value.toSizePolicy().horData())).
98 arg(findDescription(value.toSizePolicy().verData())).
99 arg(value.toSizePolicy().horStretch()).arg(value.toSizePolicy().verStretch()));
100}
101
102TQString
103SizePolicyEdit::findDescription(const TQVariant &value) const
104{
105 if(!m_spValues)
106 return TQString();
107
108 TQStringVariantMap::ConstIterator endIt = m_spValues->constEnd();
109 for (TQStringVariantMap::ConstIterator it = m_spValues->constBegin(); it != endIt; ++ it) {
110 if (it.data() == value)
111 return it.key();
112 }
113 return TQString();;
114}
115
116void
117SizePolicyEdit::setReadOnlyInternal(bool readOnly)
118{
119 Q_UNUSED(readOnly);
120}
121
122#include "sizepolicyedit.moc"
The base class representing a single property.
Definition property.h:177
The base class for all item editors used in Editor.
Definition widget.h:37
virtual void drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
Definition widget.cpp:88
virtual TQVariant value() const =0
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.