chalk

kis_brush_chooser.cpp
1/*
2 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include <tqlabel.h>
19#include <tqlayout.h>
20#include <tqcheckbox.h>
21#include <tdelocale.h>
22#include <koIconChooser.h>
23
24#include "kis_double_widget.h"
25#include "kis_brush_chooser.h"
26#include "kis_global.h"
27#include "kis_icon_item.h"
28#include "kis_brush.h"
29
30KisBrushChooser::KisBrushChooser(TQWidget *parent, const char *name)
31 : super(parent, name)
32{
33 m_lbSpacing = new TQLabel(i18n("Spacing:"), this);
34 m_slSpacing = new KisDoubleWidget(0.0, 10, this, "double_widget");
35 m_slSpacing->setTickmarks(TQSlider::Below);
36 m_slSpacing->setTickInterval(1);
37 TQObject::connect(m_slSpacing, TQ_SIGNAL(valueChanged(double)), this, TQ_SLOT(slotSetItemSpacing(double)));
38
39 m_chkColorMask = new TQCheckBox(i18n("Use color as mask"), this);
40 TQObject::connect(m_chkColorMask, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotSetItemUseColorAsMask(bool)));
41
42 m_lbName = new TQLabel(this);
43
44 TQVBoxLayout *mainLayout = new TQVBoxLayout(this, 2, -1, "main layout");
45
46 mainLayout->addWidget(m_lbName);
47 mainLayout->addWidget(chooserWidget(), 10);
48
49 TQGridLayout *spacingLayout = new TQGridLayout( 2, 2);
50
51 mainLayout->addLayout(spacingLayout, 1);
52
53 spacingLayout->addWidget(m_lbSpacing, 0, 0);
54 spacingLayout->addWidget(m_slSpacing, 0, 1);
55
56 spacingLayout->addMultiCellWidget(m_chkColorMask, 1, 1, 0, 1);
57}
58
59KisBrushChooser::~KisBrushChooser()
60{
61}
62
63void KisBrushChooser::slotSetItemSpacing(double spacingValue)
64{
65 KisIconItem *item = static_cast<KisIconItem *>(currentItem());
66
67 if (item) {
68 KisBrush *brush = static_cast<KisBrush *>(item->resource());
69 brush->setSpacing(spacingValue);
70 }
71}
72
73void KisBrushChooser::slotSetItemUseColorAsMask(bool useColorAsMask)
74{
75 KisIconItem *item = static_cast<KisIconItem *>(currentItem());
76
77 if (item) {
78 KisBrush *brush = static_cast<KisBrush *>(item->resource());
79 brush->setUseColorAsMask(useColorAsMask);
80 item->updatePixmaps();
81 emit selected(currentItem());
82 }
83}
84
85void KisBrushChooser::update(KoIconItem *item)
86{
87 KisIconItem *kisItem = static_cast<KisIconItem *>(item);
88
89 if (kisItem) {
90 KisBrush *brush = static_cast<KisBrush *>(kisItem->resource());
91
92 TQString text = TQString("%1 (%2 x %3)").arg(brush->name()).arg(brush->width()).arg(brush->height());
93
94 m_lbName->setText(text);
95 m_slSpacing->setValue(brush->spacing());
96 m_chkColorMask->setChecked(brush->useColorAsMask());
97 m_chkColorMask->setEnabled(brush->hasColor());
98 }
99}
100
101#include "kis_brush_chooser.moc"
102