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