1 /************************************************************************
3 * Copyright 2012 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #include "prim_QPalette.hpp"
23 #include "primitives.h"
24 #include "../Common.h"
27 #include <PyrKernel.h>
33 namespace QtCollider
{
35 int QPalette_Finalize( struct VMGlobals
*g
, struct PyrObject
*obj
)
37 delete QPALETTE_FROM_OBJECT(obj
);
41 void QPalette_Init( struct VMGlobals
*g
, struct PyrObject
*obj
, const QPalette
& palette
)
43 assert( obj
->classptr
== SC_CLASS(QPalette
) );
44 assert( IsNil(obj
->slots
) && IsNil(obj
->slots
+1) );
46 QPalette
*p
= new QPalette(palette
);
47 SetPtr( obj
->slots
, p
);
48 InstallFinalizer( g
, obj
, 1, QPalette_Finalize
);
51 QC_LANG_PRIMITIVE( QPalette_New
, 0, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
53 QPalette_Init( g
, slotRawObject(r
) );
57 QC_LANG_PRIMITIVE( QPalette_Auto
, 2, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
59 QColor
button( Slot::toColor(a
) );
60 QColor
window( Slot::toColor(a
+1) );
61 QPalette_Init( g
, slotRawObject(r
), QPalette(button
, window
) );
65 QC_LANG_PRIMITIVE( QPalette_System
, 0, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
67 QPalette_Init( g
, slotRawObject(r
), QtCollider::systemPalette() );
71 QC_LANG_PRIMITIVE( QPalette_Color
, 2, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
73 QPalette
*p
= QPALETTE_FROM_OBJECT(slotRawObject(r
));
75 if(NotInt(a
)) return errWrongType
;
76 QPalette::ColorRole role
= (QPalette::ColorRole
)(slotRawInt(a
));
79 QPalette::ColorGroup group
= (QPalette::ColorGroup
)(slotRawInt(a
+1));
80 Slot::setColor( r
, p
->color( group
, role
) );
83 Slot::setColor( r
, p
->color( role
) );
89 QC_LANG_PRIMITIVE( QPalette_SetColor
, 3, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
91 QPalette
*p
= QPALETTE_FROM_OBJECT(slotRawObject(r
));
93 QColor
color( Slot::toColor(a
) );
95 if(NotInt(a
+1)) return errWrongType
;
96 QPalette::ColorRole role
= (QPalette::ColorRole
)(slotRawInt(a
+1));
99 QPalette::ColorGroup group
= (QPalette::ColorGroup
)(slotRawInt(a
+2));
100 p
->setColor( group
, role
, color
);
103 p
->setColor( role
, color
);
109 QC_LANG_PRIMITIVE( QPalette_HasColor
, 2, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
111 QPalette
*p
= QPALETTE_FROM_OBJECT(slotRawObject(r
));
113 if(NotInt(a
)) return errWrongType
;
114 QPalette::ColorRole role
= (QPalette::ColorRole
)(slotRawInt(a
));
116 QPalette::ColorGroup group
;
117 group
= IsInt(a
+1) ? (QPalette::ColorGroup
)(slotRawInt(a
+1)) : QPalette::Normal
;
119 SetBool( r
, p
->isBrushSet( group
, role
) );
124 void defineQPalettePrimitives()
126 LangPrimitiveDefiner definer
;
127 definer
.define
<QPalette_New
>();
128 definer
.define
<QPalette_Auto
>();
129 definer
.define
<QPalette_System
>();
130 definer
.define
<QPalette_Color
>();
131 definer
.define
<QPalette_SetColor
>();
132 definer
.define
<QPalette_HasColor
>();
135 } // namespace QtCollider