1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //    $Id: checkbox.cpp,v 1.2.2.2 2006/10/29 07:54:52 terminator356 Exp $
5 //  (C) Copyright 2004 Werner Schweer (ws@seh.de)
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; version 2 of
10 //  the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 //=========================================================
22 
23 #include "checkbox.h"
24 
25 #include <QMouseEvent>
26 
27 namespace MusEGui {
28 
29 //---------------------------------------------------------
30 //   CheckBox
31 //---------------------------------------------------------
32 
CheckBox(QWidget * parent,int i,const char * name)33 CheckBox::CheckBox(QWidget* parent, int i, const char* name)
34    : QCheckBox(parent)
35       {
36       setObjectName(name);
37       _id = i;
38       connect(this, SIGNAL(toggled(bool)), SLOT(hasToggled(bool)));
39       }
40 
hasToggled(bool val)41 void CheckBox::hasToggled(bool val)
42       {
43       emit toggleChanged(val, _id);
44       }
45 
46 //------------------------------------------------------------
47 //  mousePressEvent
48 //------------------------------------------------------------
49 
mousePressEvent(QMouseEvent * e)50 void CheckBox::mousePressEvent(QMouseEvent *e)
51 {
52   if(e->button() == Qt::RightButton)
53     emit checkboxRightClicked(e->globalPos(), _id);
54   else
55   {
56     if(isChecked())
57       setChecked(false);
58     else
59       setChecked(true);
60     emit checkboxPressed(_id);
61   }
62 }
63 
64 //------------------------------------------------------------
65 //  mouseReleaseEvent
66 //------------------------------------------------------------
67 
mouseReleaseEvent(QMouseEvent * e)68 void CheckBox::mouseReleaseEvent(QMouseEvent *e)
69 {
70   if(e->button() == Qt::RightButton)
71     return;
72 
73   emit checkboxReleased(_id);
74 }
75 
76 } // namespace MusEGui
77