class library: PriorityQueue - implement removeValue, hide array
[supercollider.git] / QtCollider / primitives / prim_misc.cpp
blob3ff1158bda4c1b989cf5263b910618da796f019a
1 /************************************************************************
3 * Copyright 2010 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 "../Common.h"
25 #include "../Slot.h"
26 #include "../QcApplication.h"
27 #include "../QObjectProxy.h"
28 #include "../style/ProxyStyle.hpp"
29 #include "QtCollider.h"
31 #include <PyrKernel.h>
33 #include <QFontMetrics>
34 #include <QDesktopWidget>
35 #include <QFontDatabase>
36 #include <QStyleFactory>
37 #include <QWebSettings>
39 using namespace QtCollider;
41 QC_LANG_PRIMITIVE( QtGUI_SetDebugLevel, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g )
43 QtCollider::setDebugLevel( Slot::toInt(a) );
44 return errNone;
47 QC_LANG_PRIMITIVE( QtGUI_DebugLevel, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
49 SetInt( r, QtCollider::debugLevel() );
50 return errNone;
53 QC_LANG_PRIMITIVE( QWindow_ScreenBounds, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
55 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
57 QRect screenGeometry = QApplication::desktop()->screenGeometry();
58 Slot::setRect( r, screenGeometry );
59 return errNone;
62 QC_LANG_PRIMITIVE( QWindow_AvailableGeometry, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
64 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
66 QRect rect = QApplication::desktop()->availableGeometry();
67 Slot::setRect( r, rect );
68 return errNone;
71 QC_LANG_PRIMITIVE( Qt_StringBounds, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
73 QString str = Slot::toString( a );
75 QFont f = Slot::toFont( a+1 );
77 QFontMetrics fm( f );
78 QRect bounds = fm.boundingRect( str );
80 // we keep the font height even on empty string;
81 if( str.isEmpty() ) bounds.setHeight( fm.height() );
83 Slot::setRect( r, bounds );
84 return errNone;
87 QC_LANG_PRIMITIVE( Qt_AvailableFonts, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
89 QFontDatabase database;
90 VariantList l;
91 Q_FOREACH( QString family, database.families() ) {
92 l.data << QVariant(family);
94 Slot::setVariantList( r, l );
95 return errNone;
98 QC_LANG_PRIMITIVE( Qt_GlobalPalette, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
100 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
102 QPalette p( QApplication::palette() );
103 Slot::setPalette( r, p );
104 return errNone;
107 QC_LANG_PRIMITIVE( Qt_SetGlobalPalette, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g )
109 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
111 QPalette p = Slot::toPalette( a );
112 QApplication::setPalette( p );
114 return errNone;
117 QC_LANG_PRIMITIVE( Qt_FocusWidget, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
119 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
121 QWidget *w = QApplication::focusWidget();
123 if( w ) {
124 QObjectProxy *proxy = QObjectProxy::fromObject(w);
125 if( proxy && proxy->scObject() ) {
126 SetObject( r, proxy->scObject() );
127 return errNone;
131 SetNil(r);
132 return errNone;
135 QC_LANG_PRIMITIVE( Qt_SetStyle, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g )
137 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
139 QString str = Slot::toString( a );
140 if( str.isEmpty() ) return errFailed;
142 QStyle *style = QStyleFactory::create( str );
143 if( !style ) return errFailed;
145 QApplication::setStyle( new QtCollider::ProxyStyle( style ) );
146 return errNone;
149 QC_LANG_PRIMITIVE( Qt_AvailableStyles, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
151 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
153 VariantList list;
154 Q_FOREACH( QString key, QStyleFactory::keys() ) {
155 list.data << QVariant(key);
158 Slot::setVariantList( r, list );
159 return errNone;
162 QC_LANG_PRIMITIVE( QWebView_ClearMemoryCaches, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
164 if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
166 QWebSettings::clearMemoryCaches();
168 return errNone;