krita

kis_brush_chooser.cc

00001 /*
00002  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #include <qlabel.h>
00019 #include <qlayout.h>
00020 #include <qcheckbox.h>
00021 #include <klocale.h>
00022 #include <koIconChooser.h>
00023 
00024 #include "kis_double_widget.h"
00025 #include "kis_brush_chooser.h"
00026 #include "kis_global.h"
00027 #include "kis_icon_item.h"
00028 #include "kis_brush.h"
00029 
00030 KisBrushChooser::KisBrushChooser(QWidget *parent, const char *name)
00031     : super(parent, name)
00032 {
00033     m_lbSpacing = new QLabel(i18n("Spacing: "), this);
00034     m_slSpacing = new KisDoubleWidget(0.0, 10, this, "double_widget");
00035     m_slSpacing->setTickmarks(QSlider::Below);
00036     m_slSpacing->setTickInterval(1);
00037     QObject::connect(m_slSpacing, SIGNAL(valueChanged(double)), this, SLOT(slotSetItemSpacing(double)));
00038 
00039     m_chkColorMask = new QCheckBox(i18n("Use color as mask"), this);
00040     QObject::connect(m_chkColorMask, SIGNAL(toggled(bool)), this, SLOT(slotSetItemUseColorAsMask(bool)));
00041 
00042     m_lbName = new QLabel(this);
00043 
00044     QVBoxLayout *mainLayout = new QVBoxLayout(this, 2, -1, "main layout");
00045 
00046     mainLayout->addWidget(m_lbName);
00047     mainLayout->addWidget(chooserWidget(), 10);
00048 
00049     QGridLayout *spacingLayout = new QGridLayout( 2, 2);
00050 
00051     mainLayout->addLayout(spacingLayout, 1);
00052 
00053     spacingLayout->addWidget(m_lbSpacing, 0, 0);
00054     spacingLayout->addWidget(m_slSpacing, 0, 1);
00055 
00056     spacingLayout->addMultiCellWidget(m_chkColorMask, 1, 1, 0, 1);
00057 }
00058 
00059 KisBrushChooser::~KisBrushChooser()
00060 {
00061 }
00062 
00063 void KisBrushChooser::slotSetItemSpacing(double spacingValue)
00064 {
00065     KisIconItem *item = static_cast<KisIconItem *>(currentItem());
00066 
00067     if (item) {
00068         KisBrush *brush = static_cast<KisBrush *>(item->resource());
00069         brush->setSpacing(spacingValue);
00070     }
00071 }
00072 
00073 void KisBrushChooser::slotSetItemUseColorAsMask(bool useColorAsMask)
00074 {
00075     KisIconItem *item = static_cast<KisIconItem *>(currentItem());
00076 
00077     if (item) {
00078         KisBrush *brush = static_cast<KisBrush *>(item->resource());
00079         brush->setUseColorAsMask(useColorAsMask);
00080         item->updatePixmaps();
00081         emit selected(currentItem());
00082     }
00083 }
00084 
00085 void KisBrushChooser::update(KoIconItem *item)
00086 {
00087     KisIconItem *kisItem = static_cast<KisIconItem *>(item);
00088 
00089     if (kisItem) {
00090         KisBrush *brush = static_cast<KisBrush *>(kisItem->resource());
00091 
00092         QString text = QString("%1 (%2 x %3)").arg(brush->name()).arg(brush->width()).arg(brush->height());
00093 
00094         m_lbName->setText(text);
00095         m_slSpacing->setValue(brush->spacing());
00096         m_chkColorMask->setChecked(brush->useColorAsMask());
00097         m_chkColorMask->setEnabled(brush->hasColor());
00098     }
00099 }
00100 
00101 #include "kis_brush_chooser.moc"
00102 
KDE Home | KDE Accessibility Home | Description of Access Keys