1 /*
2  * GroupBox.cpp - groupbox for LMMS
3  *
4  * Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5  *
6  * This file is part of LMMS - https://lmms.io
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program (see COPYING); if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301 USA.
22  *
23  */
24 
25 #include <QMouseEvent>
26 #include <QPainter>
27 
28 #ifndef __USE_XOPEN
29 #define __USE_XOPEN
30 #endif
31 
32 #include "GroupBox.h"
33 #include "embed.h"
34 #include "gui_templates.h"
35 
36 
37 
GroupBox(const QString & _caption,QWidget * _parent)38 GroupBox::GroupBox( const QString & _caption, QWidget * _parent ) :
39 	QWidget( _parent ),
40 	BoolModelView( NULL, this ),
41 	m_caption( _caption ),
42 	m_titleBarHeight( 11 )
43 {
44 	m_led = new PixmapButton( this, _caption );
45 	m_led->setCheckable( true );
46 	m_led->move( 3, 0 );
47 	m_led->setActiveGraphic( embed::getIconPixmap( "led_green" ) );
48 	m_led->setInactiveGraphic( embed::getIconPixmap( "led_off" ) );
49 
50 	setModel( new BoolModel( false, NULL, _caption, true ) );
51 	setAutoFillBackground( true );
52 	unsetCursor();
53 }
54 
55 
56 
57 
~GroupBox()58 GroupBox::~GroupBox()
59 {
60 	delete m_led;
61 }
62 
63 
64 
65 
modelChanged()66 void GroupBox::modelChanged()
67 {
68 	m_led->setModel( model() );
69 }
70 
71 
72 
73 
mousePressEvent(QMouseEvent * _me)74 void GroupBox::mousePressEvent( QMouseEvent * _me )
75 {
76 	if( _me->y() > 1 && _me->y() < 13 && _me->button() == Qt::LeftButton )
77 	{
78 		model()->setValue( !model()->value() );
79 	}
80 }
81 
82 
83 
84 
paintEvent(QPaintEvent * pe)85 void GroupBox::paintEvent( QPaintEvent * pe )
86 {
87 	QPainter p( this );
88 
89 	// Draw background
90 	p.fillRect( 0, 0, width() - 1, height() - 1, p.background() );
91 
92 	// outer rect
93 	p.setPen( p.background().color().dark( 150 ) );
94 	p.drawRect( 0, 0, width() - 1, height() - 1 );
95 
96 	// draw line below titlebar
97 	p.fillRect( 1, 1, width() - 2, m_titleBarHeight + 1, p.background().color().darker( 150 ) );
98 
99 	// draw text
100 	p.setPen( palette().color( QPalette::Active, QPalette::Text ) );
101 	p.setFont( pointSize<8>( font() ) );
102 	p.drawText( 22, m_titleBarHeight, m_caption );
103 }
104