Audio Volume Key Event On Symbian/bg: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: Line 11:
'''MediakeyCaptureItem.h'''
'''MediakeyCaptureItem.h'''


<code><br />#ifndef MediakeyCaptureItem_H<br />#define MediakeyCaptureItem_H
<code>
#ifndef MediakeyCaptureItem_H
#define MediakeyCaptureItem_H


#include <QDeclarativeItem>
#include <QDeclarativeItem>


#ifdef Q_WS_S60<br />#include <remconcoreapitargetobserver.h> // link against RemConCoreApi.lib<br />#include <remconcoreapitarget.h> // and<br />#include <remconinterfaceselector.h> // RemConInterfaceBase.lib
#ifdef Q_WS_S60
#include <remconcoreapitargetobserver.h> // link against RemConCoreApi.lib
#include <remconcoreapitarget.h> // and
#include <remconinterfaceselector.h> // RemConInterfaceBase.lib


class MediakeyCaptureItemPrivate;<br />class MediakeyCaptureItem : public QDeclarativeItem<br />{<br /> Q_OBJECT<br />public:<br /> MediakeyCaptureItem(QDeclarativeItem *parent = 0);<br /> void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
class MediakeyCaptureItemPrivate;
class MediakeyCaptureItem : public QDeclarativeItem
{
Q_OBJECT
public:
MediakeyCaptureItem(QDeclarativeItem *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);


signals:<br /> void volumeDownPressed();<br /> void volumeUpPressed();
signals:
void volumeDownPressed();
void volumeUpPressed();


private:<br /> MediakeyCaptureItemPrivate *d_ptr;<br />private: // Friend class definitions<br /> friend class MediakeyCaptureItemPrivate;<br />};
private:
MediakeyCaptureItemPrivate *d_ptr;
private: // Friend class definitions
friend class MediakeyCaptureItemPrivate;
};


#endif // Q_WS_S60<br />#endif // MediakeyCaptureItem_H<br /></code>
#endif // Q_WS_S60
#endif // MediakeyCaptureItem_H
</code>


'''MediakeyCaptureItem.cpp'''
'''MediakeyCaptureItem.cpp'''


<code><br />#include "MediaKeyCaptureItem.h"<br />#ifdef Q_WS_S60
<code>
#include "MediaKeyCaptureItem.h"
#ifdef Q_WS_S60


// A private class to access Symbian RemCon API<br />class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver<br />{<br />public:<br /> MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent);<br /> ~MediakeyCaptureItemPrivate();<br /> virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId,<br /> TRemConCoreApiButtonAction aButtonAct);<br />private:<br /> CRemConInterfaceSelector''' iInterfaceSelector;<br /> CRemConCoreApiTarget* iCoreTarget;<br /> MediakeyCaptureItem *d_ptr;<br />};
// A private class to access Symbian RemCon API
class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver
{
public:
MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent);
~MediakeyCaptureItemPrivate();
virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId,
TRemConCoreApiButtonAction aButtonAct);
private:
CRemConInterfaceSelector''' iInterfaceSelector;
CRemConCoreApiTarget* iCoreTarget;
MediakeyCaptureItem *d_ptr;
};


// Consructor<br />MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent)<br />{<br /> d_ptr = new MediakeyCaptureItemPrivate(this);<br />}
// Consructor
MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent)
{
d_ptr = new MediakeyCaptureItemPrivate(this);
}


// The paint method<br />void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)<br />{<br /> // This item has no visual<br />}
// The paint method
void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// This item has no visual
}


// Constructor<br />MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent)<br />{<br /> QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL());<br /> QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this));<br /> iInterfaceSelector->OpenTargetL();<br />}
// Constructor
<br />// Destructor<br />MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){<br /> delete iInterfaceSelector;<br /> delete iCoreTarget;<br />}
MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent)
<br />// Callback when media keys are pressed<br />void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,<br /> TRemConCoreApiButtonAction aButtonAct)<br />{<br /> //TRequestStatus status;<br /> switch( aOperationId )<br /> {<br /> case ERemConCoreApiVolumeUp:<br /> emit d_ptr->volumeUpPressed();<br /> break;<br /> case ERemConCoreApiVolumeDown:<br /> emit d_ptr->volumeDownPressed();<br /> break;<br /> default:<br /> break;<br /> }<br />}<br />#endif // Q_WS_S60<br /></code>
{
<br />В C++ кода направете регистрация:
QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL());
<br /><code><br />qmlRegisterType<MediakeyCaptureItem>("Mediakey", 1, 0, "MediakeyCapture");<br /></code>
QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this));
<br />Необходимо е да добавите следните няколко реда във .pro файла на вашия проект:
iInterfaceSelector->OpenTargetL();
<br /><code><br />symbian{<br /> INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed…<br /> LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi<br /> LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase<br />}<br /></code>
}


<br />В QML слушайте за сигнали по следния начин:
// Destructor
<br /><code><br />import Qt 4.7<br />import Mediakey 1.0<br />Item{
MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){
<br />
delete iInterfaceSelector;
<br /> MediakeyCapture{<br /> onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ')<br /> onVolumeUpPressed: console.log('VOLUME UP PRESSED ')<br /> }<br />}<br /></code>
delete iCoreTarget;
<br />h2. Отстраняване на проблеми
}
<br />Ако използвате Qt SDK 1.1 (Windows, Beta and RC) за Symbian^3 е необходимо да копирате всичко от<br /><code><br />C:3Qt472\epoc32\release\armv5\lib\rem'''<br /></code><br />в<br /><code><br />C:1Qt472\epoc32\release\armv5\lib<br /></code>
 
// Callback when media keys are pressed
void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,
TRemConCoreApiButtonAction aButtonAct)
{
//TRequestStatus status;
switch( aOperationId )
{
case ERemConCoreApiVolumeUp:
emit d_ptr->volumeUpPressed();
break;
case ERemConCoreApiVolumeDown:
emit d_ptr->volumeDownPressed();
break;
default:
break;
}
}
#endif // Q_WS_S60
</code>
 
В C++ кода направете регистрация:
 
<code>
qmlRegisterType<MediakeyCaptureItem>("Mediakey", 1, 0, "MediakeyCapture");
</code>
 
Необходимо е да добавите следните няколко реда във .pro файла на вашия проект:
 
<code>
symbian{
INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed…
LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi
LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase
}
</code>
 
 
В QML слушайте за сигнали по следния начин:
 
<code>
import Qt 4.7
import Mediakey 1.0
Item{
 
 
MediakeyCapture{
onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ')
onVolumeUpPressed: console.log('VOLUME UP PRESSED ')
}
}
</code>
 
h2. Отстраняване на проблеми
 
Ако използвате Qt SDK 1.1 (Windows, Beta and RC) за Symbian^3 е необходимо да копирате всичко от
<code>
C:3Qt472\epoc32\release\armv5\lib\rem'''
</code>
в
<code>
C:1Qt472\epoc32\release\armv5\lib
</code>

Revision as of 12:09, 25 February 2015


Български English

Прихващане на събития, свързани с бутон за звук на Symbian устройства

В QML за Symbian устройста събитията за бутона за звук не могат да бъдат прихванати чрез Keys.onVolumeDownPressed, Keys.onVolumeUpPressed, or Keys.onPressed. Подходящо решение на този проблем е създаване на клас, обвиващ "S60 Remote Control API":http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys чрез наследяване на "MRemConCoreApiTargetObserver":http://library.forum.nokia.com/index.jsp?topic=/S60_5th_Edition_Cpp_Developers_Library/GUID-35228542-8C95-4849-A73F-2B4F082F0C44/sdk/doc_source/reference/reference-cpp/Remote_Control_Framework/MRemConCoreApiTargetObserverClass.html. Този примерен код, който показва как това може да бъде направено при създаване на QML/C++ приложение. Аналогично може да бъде създаден и QML plugin.

Създайте нов QML елемент, които да обработва събития, свързани с бутоните за звук. Всъщност чрез S60 Remote Control API могат да бъдат прихващани и други събития свързвани с бутоните за медия. За подробности вижте линка по-горе.

MediakeyCaptureItem.h

#ifndef MediakeyCaptureItem_H
#define MediakeyCaptureItem_H

#include <QDeclarativeItem>

#ifdef Q_WS_S60
#include <remconcoreapitargetobserver.h> // link against RemConCoreApi.lib
#include <remconcoreapitarget.h> // and
#include <remconinterfaceselector.h> // RemConInterfaceBase.lib

class MediakeyCaptureItemPrivate;
class MediakeyCaptureItem : public QDeclarativeItem
{
 Q_OBJECT
public:
 MediakeyCaptureItem(QDeclarativeItem *parent = 0);
 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

signals:
 void volumeDownPressed();
 void volumeUpPressed();

private:
 MediakeyCaptureItemPrivate *d_ptr;
private: // Friend class definitions
 friend class MediakeyCaptureItemPrivate;
};

#endif // Q_WS_S60
#endif // MediakeyCaptureItem_H

MediakeyCaptureItem.cpp

#include "MediaKeyCaptureItem.h"
#ifdef Q_WS_S60

// A private class to access Symbian RemCon API
class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver
{
public:
 MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent);
 ~MediakeyCaptureItemPrivate();
 virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId,
 TRemConCoreApiButtonAction aButtonAct);
private:
 CRemConInterfaceSelector''' iInterfaceSelector;
 CRemConCoreApiTarget* iCoreTarget;
 MediakeyCaptureItem *d_ptr;
};

// Consructor
MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent)
{
 d_ptr = new MediakeyCaptureItemPrivate(this);
}

// The paint method
void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
 // This item has no visual
}

// Constructor
MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent)
{
 QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL());
 QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this));
 iInterfaceSelector->OpenTargetL();
}

// Destructor
MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){
 delete iInterfaceSelector;
 delete iCoreTarget;
}

// Callback when media keys are pressed
void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,
 TRemConCoreApiButtonAction aButtonAct)
{
 //TRequestStatus status;
 switch( aOperationId )
 {
 case ERemConCoreApiVolumeUp:
 emit d_ptr->volumeUpPressed();
 break;
 case ERemConCoreApiVolumeDown:
 emit d_ptr->volumeDownPressed();
 break;
 default:
 break;
 }
}
#endif // Q_WS_S60

В C++ кода направете регистрация:

qmlRegisterType<MediakeyCaptureItem>("Mediakey", 1, 0, "MediakeyCapture");

Необходимо е да добавите следните няколко реда във .pro файла на вашия проект:

symbian{
 INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed…
 LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi
 LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase
}


В QML слушайте за сигнали по следния начин:

import Qt 4.7
import Mediakey 1.0
Item{

 

 MediakeyCapture{
 onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ')
 onVolumeUpPressed: console.log('VOLUME UP PRESSED ')
 }
}

h2. Отстраняване на проблеми

Ако използвате Qt SDK 1.1 (Windows, Beta and RC) за Symbian^3 е необходимо да копирате всичко от

C:3Qt472\epoc32\release\armv5\lib\rem'''

в

C:1Qt472\epoc32\release\armv5\lib