1 /************************************************************************
3 * Copyright 2010-2011 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 "primitives.h"
24 #include "../QWidgetProxy.h"
25 #include "../Common.h"
27 #include <PyrKernel.h>
32 #include <QApplication>
36 using namespace QtCollider
;
38 // WARNING these primitives have to always execute asynchronously, or Cocoa language client will
41 QC_LANG_PRIMITIVE( QWidget_SetFocus
, 1, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
)
43 QWidgetProxy
*proxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy( r
) );
45 QApplication::postEvent( proxy
, new SetFocusEvent( IsTrue(a
) ) );
50 QC_LANG_PRIMITIVE( QWidget_BringFront
, 1, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
51 QWidgetProxy
*proxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy( r
) );
53 QApplication::postEvent( proxy
,
54 new QEvent( (QEvent::Type
) QtCollider::Event_Proxy_BringFront
) );
59 QC_LANG_PRIMITIVE( QWidget_Refresh
, 1, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
60 QWidgetProxy
*proxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy( r
) );
62 if( !proxy
->compareThread() ) return QtCollider::wrongThreadError();
69 QC_LANG_PRIMITIVE( QWidget_MapToGlobal
, 1, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
70 QWidgetProxy
*proxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy( r
) );
72 if( !proxy
->compareThread() ) return QtCollider::wrongThreadError();
74 QWidget
*w
= proxy
->widget();
75 if( !w
) return errNone
;
77 QPoint
pt( Slot::toPoint( a
).toPoint() );
78 pt
= w
->mapToGlobal( pt
);
79 Slot::setPoint( r
, pt
);
84 QC_LANG_PRIMITIVE( QWidget_SetLayout
, 1, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
85 if( !isKindOfSlot( a
, class_QLayout
) ) return errWrongType
;
87 QWidgetProxy
*wProxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy(r
) );
89 if( !wProxy
->compareThread() ) return QtCollider::wrongThreadError();
91 QObjectProxy
*lProxy
= Slot::toObjectProxy( a
);
92 wProxy
->setLayout( lProxy
);
97 QC_LANG_PRIMITIVE( QWidget_GetAlwaysOnTop
, 0, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
98 QWidgetProxy
*wProxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy(r
) );
100 if( QThread::currentThread() != wProxy
->thread() ) return errFailed
;
102 SetBool( r
, wProxy
->alwaysOnTop() );
106 QC_LANG_PRIMITIVE( QWidget_SetAlwaysOnTop
, 1, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
107 QWidgetProxy
*wProxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy(r
) );
109 QApplication::postEvent( wProxy
, new SetAlwaysOnTopEvent( IsTrue(a
) ) );
114 namespace QtCollider
{
116 struct MimeData
: public QMimeData
{
117 virtual ~MimeData() {
118 qcDebugMsg(1,"Drag data object destroyed, clearing QView.currentDrag.");
120 QtCollider::lockLang();
122 PyrClass
*classView
= getsym("View")->u
.classobj
;
123 PyrSymbol
*symClearDrag
= getsym("prClearCurrentDrag");
124 if( !classView
|| !symClearDrag
) return;
126 QtCollider::runLang( classView
, symClearDrag
);
128 QtCollider::unlockLang();
134 QC_LANG_PRIMITIVE( QWidget_StartDrag
, 3, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
135 QWidgetProxy
*wProxy
= qobject_cast
<QWidgetProxy
*>( Slot::toObjectProxy(r
) );
136 if( !wProxy
->compareThread() ) return QtCollider::wrongThreadError();
139 QString str
= Slot::toString(a
+2);
141 QMimeData
*mime
= new QtCollider::MimeData
;
143 mime
->setData( "application/supercollider", QByteArray() );
145 if( isKindOfSlot( data
, class_Color
) )
146 mime
->setColorData( QVariant(Slot::toColor(data
)) );
149 mime
->setText( str
);
151 QApplication::postEvent( wProxy
, new StartDragEvent( Slot::toString(a
), mime
) );
156 QC_LANG_PRIMITIVE( QWidget_SetGlobalEventEnabled
, 2, PyrSlot
*r
, PyrSlot
*a
, VMGlobals
*g
) {
157 if( NotInt( a
+0 ) ) return errWrongType
;
158 int event
= Slot::toInt(a
+0);
159 bool enabled
= IsTrue(a
+1);
160 if( !enabled
&& !IsFalse(a
+1) ) return errWrongType
;
162 QWidgetProxy::setGlobalEventEnabled( (QWidgetProxy::GlobalEvent
) event
, enabled
);