summaryrefslogtreecommitdiffstats
path: root/lib/koproperty/editors/sizepolicyedit.cpp
blob: 0c616665bf23b7ef8f16e00ac422bb4eb86fe712 (plain)
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 <tqlabel.h>
#include <tqlayout.h>
#include <tqpainter.h>
#include <tqsizepolicy.h>
#include <tqmap.h>
#include <tqtooltip.h>

#include <klocale.h>

using namespace KoProperty;

TQMap<TQString, TQVariant> *SizePolicyEdit::m_spValues = 0;

SizePolicyEdit::SizePolicyEdit(Property *property, TQWidget *tqparent, const char *name)
 : Widget(property, tqparent, name)
{
	setHasBorders(false);
//	TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
	m_edit = new TQLabel(this);
	m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN);
	m_edit->setBackgroundMode(TQt::PaletteBase);
//	m_edit->tqsetSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
	m_edit->setMinimumHeight(5);
	setEditor(m_edit);
//	l->addWidget(m_edit);
	setFocusWidget(m_edit);


	if(!m_spValues) {
		m_spValues = new TQMap<TQString, TQVariant>();
		(*m_spValues)[i18n("Size Policy", "Fixed")] = TQSizePolicy::Fixed;
		(*m_spValues)[i18n("Size Policy", "Minimum")] = TQSizePolicy::Minimum;
		(*m_spValues)[i18n("Size Policy", "Maximum")] = TQSizePolicy::Maximum;
		(*m_spValues)[i18n("Size Policy", "Preferred")] = TQSizePolicy::Preferred;
		(*m_spValues)[i18n("Size Policy", "Expanding")] = TQSizePolicy::Expanding;
		(*m_spValues)[i18n("Size Policy", "Minimum Expanding")] = TQSizePolicy::MinimumExpanding;
		(*m_spValues)[i18n("Size Policy", "Ignored")] = TQSizePolicy::Ignored;
	}
}

SizePolicyEdit::~SizePolicyEdit()
{
	delete m_spValues;
	m_spValues = 0;
}

TQVariant
SizePolicyEdit::value() const
{
	return m_value;
}

void
SizePolicyEdit::setValue(const TQVariant &value, bool emitChange)
{
	m_value = value;
	m_edit->setText(TQString("%1/%2/%3/%4").tqarg(findDescription(value.toSizePolicy().horData())).
		tqarg(findDescription(value.toSizePolicy().verData())).
		tqarg(value.toSizePolicy().horStretch()).tqarg(value.toSizePolicy().verStretch()));
	TQToolTip::add(this, m_edit->text());

	if (emitChange)
		emit valueChanged(this);
}

void
SizePolicyEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
{
//	p->eraseRect(r);
//	p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine,
	TQRect rect(r);
	rect.setBottom(r.bottom()+1);
	Widget::drawViewer(p, cg, rect, 
		TQString("%1/%2/%3/%4").tqarg(findDescription(value.toSizePolicy().horData())).
		tqarg(findDescription(value.toSizePolicy().verData())).
		tqarg(value.toSizePolicy().horStretch()).tqarg(value.toSizePolicy().verStretch()));
}

TQString
SizePolicyEdit::findDescription(const TQVariant &value) const
{
	if(!m_spValues)
		return TQString();

	TQMap<TQString, TQVariant>::ConstIterator endIt = m_spValues->constEnd();
	for (TQMap<TQString, TQVariant>::ConstIterator it = m_spValues->constBegin(); it != endIt; ++ it) {
		if (it.data() == value)
			return it.key();
	}
	return TQString();;
}

void
SizePolicyEdit::setReadOnlyInternal(bool readOnly)
{
	Q_UNUSED(readOnly);
}

#include "sizepolicyedit.moc"