krita/ui

kis_selection_options.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
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 
00019 #include "kis_selection_options.h"
00020 
00021 #include <QWidget>
00022 #include <QRadioButton>
00023 #include <QComboBox>
00024 #include <QVBoxLayout>
00025 #include <QLayout>
00026 
00027 #include "kis_types.h"
00028 #include "kis_layer.h"
00029 #include "kis_image.h"
00030 #include "kis_selection.h"
00031 #include "kis_paint_device.h"
00032 #include "canvas/kis_canvas2.h"
00033 #include "kis_view2.h"
00034 
00035 KisSelectionOptions::KisSelectionOptions(KisCanvas2 * canvas)
00036         : m_canvas(canvas)
00037 {
00038     m_page = new WdgSelectionOptions(this);
00039     Q_CHECK_PTR(m_page);
00040 
00041     QVBoxLayout * l = new QVBoxLayout(this);
00042     l->addWidget(m_page);
00043     l->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Preferred, QSizePolicy::Expanding));
00044     l->setContentsMargins(0,0,0,0);
00045 
00046     m_mode = new QButtonGroup(this);
00047     m_mode->addButton(m_page->pixel, PIXEL_SELECTION);
00048     m_mode->addButton(m_page->shape, SHAPE_PROTECTION);
00049 
00050     m_action = new QButtonGroup(this);
00051     m_action->addButton(m_page->add, SELECTION_ADD);
00052     m_action->addButton(m_page->subtract, SELECTION_SUBTRACT);
00053     m_action->addButton(m_page->replace, SELECTION_REPLACE);
00054     m_action->addButton(m_page->intersect, SELECTION_INTERSECT);
00055 
00056     m_page->pixel->setIcon(KIcon("select_pixel"));
00057     m_page->shape->setIcon(KIcon("select_shape"));
00058 
00059     m_page->add->setIcon(KIcon("selection_add"));
00060     m_page->subtract->setIcon(KIcon("selection_subtract"));
00061     m_page->replace->setIcon(KIcon("selection_replace"));
00062     m_page->intersect->setIcon(KIcon("selection_intersect"));
00063 
00064     connect(m_mode, SIGNAL(buttonClicked(int)), this, SIGNAL(modeChanged(int)));
00065     connect(m_action, SIGNAL(buttonClicked(int)), this, SIGNAL(actionChanged(int)));
00066 
00067     //hide action buttons and antialiasing, if shape selection is active (actions currently don't work on shape selection)
00068     connect(m_page->shape, SIGNAL(clicked()), m_page->lblAction, SLOT(hide()));
00069     connect(m_page->shape, SIGNAL(clicked()), m_page->add,       SLOT(hide()));
00070     connect(m_page->shape, SIGNAL(clicked()), m_page->subtract,  SLOT(hide()));
00071     connect(m_page->shape, SIGNAL(clicked()), m_page->replace,   SLOT(hide()));
00072     connect(m_page->shape, SIGNAL(clicked()), m_page->intersect, SLOT(hide()));
00073     connect(m_page->shape, SIGNAL(clicked()), m_page->chkAntiAliasing, SLOT(hide()));
00074 
00075     connect(m_page->pixel, SIGNAL(clicked()), m_page->lblAction, SLOT(show()));
00076     connect(m_page->pixel, SIGNAL(clicked()), m_page->add,       SLOT(show()));
00077     connect(m_page->pixel, SIGNAL(clicked()), m_page->subtract,  SLOT(show()));
00078     connect(m_page->pixel, SIGNAL(clicked()), m_page->replace,   SLOT(show()));
00079     connect(m_page->pixel, SIGNAL(clicked()), m_page->intersect, SLOT(show()));
00080     connect(m_page->pixel, SIGNAL(clicked()), m_page->chkAntiAliasing, SLOT(show()));
00081 }
00082 
00083 KisSelectionOptions::~KisSelectionOptions()
00084 {
00085 }
00086 
00087 int KisSelectionOptions::action()
00088 {
00089     return m_action->checkedId();
00090 }
00091 
00092 void KisSelectionOptions::setAction(int action) {
00093     QAbstractButton* button = m_action->button(action);
00094     Q_ASSERT(button);
00095     if(button) button->setChecked(true);
00096 }
00097 
00098 bool KisSelectionOptions::antiAliasSelection()
00099 {
00100     return m_page->chkAntiAliasing->isChecked();
00101 }
00102 
00103 void KisSelectionOptions::disableAntiAliasSelectionOption()
00104 {
00105     m_page->chkAntiAliasing->hide();
00106     disconnect(m_page->pixel, SIGNAL(clicked()), m_page->chkAntiAliasing, SLOT(show()));
00107 }
00108 
00109 void KisSelectionOptions::disableSelectionModeOption()
00110 {
00111     m_page->lblMode->hide();
00112     m_page->pixel->hide();
00113     m_page->shape->hide();
00114 }
00115 
00116 #include "kis_selection_options.moc"