capture QKeySequence from QKeyEvent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if (event->type() == QEvent::KeyPress){ 
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); 
 
int keyInt = keyEvent->key(); 
Qt::Key key = static_cast<Qt::Key>(keyInt); 
if(key == Qt::Key_unknown){ 
    qDebug() << "Unknown key from a macro probably"; 
    return; 
} 
// the user have clicked just and only the special keys Ctrl, Shift, Alt, Meta. 
if(key == Qt::Key_Control || 
    key == Qt::Key_Shift || 
    key == Qt::Key_Alt || 
    key == Qt::Key_Meta)
{ 
    qDebug() << "Single click of special key: Ctrl, Shift, Alt or Meta"; 
    qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText); 
    return; 
} 
 
// check for a combination of user clicks 
Qt::KeyboardModifiers modifiers = keyEvent->modifiers(); 
QString keyText = keyEvent->text(); 
// if the keyText is empty than it's a special key like F1, F5, ... 
qDebug() << "Pressed Key:" << keyText; 
 
QList<Qt::Key> modifiersList; 
if(modifiers & Qt::ShiftModifier) 
    keyInt += Qt::SHIFT; 
if(modifiers & Qt::ControlModifier) 
    keyInt += Qt::CTRL; 
if(modifiers & Qt::AltModifier) 
    keyInt += Qt::ALT; 
if(modifiers & Qt::MetaModifier) 
    keyInt += Qt::META; 
 
qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText); 
}

Posted in Qt

Static cast : Pass QWidget and grab Custom class out that

/* Pass QWidget and grab MainWindow out that */
 
Pane::Pane(QWidget *parent) : QFrame (parent){
 
 mainWindow = static_cast<MainWindow*>(parent);
 
}

Posted in Qt

HTML 5 Framework for game development

appmobi
limejs
impactjs
tapjs
TheRenderEngine
box2d
scoreoid

Posted in Featured, HTML5, Javascript

Find actual javascript size of array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//find value in associative array 
for (i in tmpArr) { 
    console.log(i+':'+tmpArr[i]+', '); 
// outputs: one:First, two:Second, three:Third
}
 
           
//find the actual size of array i.e. irrelevant to last key of array           
Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
}
//use of above        
var size = Object.size(tmpArr);
for(i=0;i<size;i++){
    console.log(tmpArr[i] + "|" + i)
}

Posted in Javascript

Dynamic base url : CodeIgniter and Zend Framework

1
2
3
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://".$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);  

Posted in CodeIgniter, PHP, Zend Framework

Javascript: checking if a function exists

It’s typeof to the rescue (again)!

To check if a function exists before you try and call it (and get a nasty javasscript error), use typeof to check.

Heres something I prepared earlier:

1
2
3
4
if(typeof window.myFunction == 'function') {
// function exists, so we can now call it
myFunction('foo', 'bar');
}

Posted in Javascript

Calling a JavaScript function using JavaScript variable

Functions are first-class objects, so they can be properties of an object (in which case they are called methods) or even elements of arrays.
If you aren’t choosing the object a function belongs to, it belongs to the global scope. In the browser, that means you’re hanging it on the object named “window,” which is where globals live.
Arrays and objects are intimately related. (Rumor is they might even be the result of incest!) You can often substitute using a dot . rather than square brackets [], or vice versa.

Your problem is a result of considering the dot manner of reference rather than the square bracket manner.

So, why not something like,

window["functionName"]();

That’s assuming your function lives in the global space. If you’ve namespaced, then:

myNameSpace["functionName"]();

Avoid eval, and avoid passing a string in to setTimeout and setInterval. I write a lot of JS, and I NEVER need eval. “Needing” eval comes from not knowing the language deeply enough. You need to learn about scoping, context, and syntax. If you’re ever stuck with an eval, just ask–you’ll learn quickly.

 

function foo() 
{      
    alert('foo'); 
}
 
var a = 'foo'; 
window[a]();

Posted in Javascript, MooTools

Jquery Live alternate/replacement in MooTools

1
2
3
4
5
6
7
8
9
10
11
  
 $('base-id').addEvent('dblclick:relay(childelement)', function(event,clicked) {
 
}
 
//example
 
   $('selected_modules').addEvent('dblclick:relay(option)', function(event,clicked) {
 
   }                  
        

Posted in Javascript, MooTools

Dynamic Height using Fx.Slide element with Mootools

this.step_3 = new Fx.Slide('step_3', {
        onComplete: function(){
 
            this.wrapper.setStyle('height', null);
           //or
           this.wrapper.setStyle('height', 'auto');
 
        }
    });

Posted in Javascript, MooTools

Remove style attribute using MooTools

element.setStyle(‘somestyle’, null);

element.setStyle(‘border’,”Smilie: ;);//empty string

Posted in Javascript, MooTools