00001 #include <qwidget.h>
00002 #include <qcheckbox.h>
00003 #include <qlabel.h>
00004 #include <qsignalmapper.h>
00005 #include <qpushbutton.h>
00006
00007 #include <opie2/oresource.h>
00008
00009 #include "exampleboardimpl.h"
00010
00011 ExampleBoard::ExampleBoard(QWidget* par, WFlags fl )
00012 : QHBox(par, "name", fl )
00013 {
00014 QCheckBox *box1 = new QCheckBox(tr("Alt"),this);
00015 connect(box1,SIGNAL(toggled(bool)),
00016 this,SLOT(slotAlt(bool)));
00017 m_alt = box1;
00018 box1 = new QCheckBox(tr("Shift"),this );
00019 connect(box1,SIGNAL(toggled(bool)),
00020 this,SLOT(slotShift(bool)));
00021 m_shi = box1;
00022 box1 = new QCheckBox(tr("Ctrl","Control Shortcut on keyboard"),this );
00023 connect(box1,SIGNAL(toggled(bool)),
00024 this,SLOT(slotCtrl(bool)));
00025 m_ctrl = box1;
00026
00027 QSignalMapper *map = new QSignalMapper(this);
00028 QPushButton *btn = new QPushButton("a",this);
00029 map->setMapping(btn,0);
00030 connect(btn,SIGNAL(clicked()),map,SLOT(map()));
00031
00032 btn = new QPushButton("b",this);
00033 map->setMapping(btn,1);
00034 connect(btn,SIGNAL(clicked()),map,SLOT(map()));
00035
00036 btn = new QPushButton("c",this);
00037 map->setMapping(btn,2);
00038 connect(btn,SIGNAL(clicked()),map,SLOT(map()));
00039
00040 connect(map,SIGNAL(mapped(int)),
00041 this,SLOT(slotKey(int)));
00042 resetState();
00043 }
00044
00045 ExampleBoard::~ExampleBoard(){
00046 }
00047
00048 void ExampleBoard::resetState(){
00049 m_state = 0;
00050 m_shi->setChecked(false);
00051 m_ctrl->setChecked(false);
00052 m_alt->setChecked(false);
00053 }
00054
00055 void ExampleBoard::slotKey(int _ke){
00056 int ke = _ke + 0x61;
00057 if(m_state & ShiftButton )
00058 ke -= 0x20;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 emit key(ke, _ke +0x41,m_state,true,false);
00069 emit key(ke, _ke + 0x41,m_state,false,false);
00070 }
00071
00072 void ExampleBoard::slotShift(bool b){
00073 if(b)
00074 m_state |= ShiftButton;
00075 else
00076 m_state &= ~ShiftButton;
00077 }
00078
00079 void ExampleBoard::slotAlt(bool b){
00080 if(b)
00081 m_state |= AltButton;
00082 else
00083 m_state &= ~AltButton;
00084 }
00085
00086 void ExampleBoard::slotCtrl(bool b){
00087 if(b)
00088 m_state |= ControlButton;
00089 else
00090 m_state &= ~ControlButton;
00091 }
00092
00093
00094
00095 ExampleboardImpl::ExampleboardImpl()
00096 : m_pickboard(0), m_icn(0)
00097 {
00098 }
00099
00100 ExampleboardImpl::~ExampleboardImpl()
00101 {
00102 delete m_pickboard;
00103 delete m_icn;
00104 }
00105
00106 QWidget *ExampleboardImpl::inputMethod( QWidget *parent, Qt::WFlags f )
00107 {
00108 if ( !m_pickboard )
00109 m_pickboard = new ExampleBoard( parent, f );
00110 return m_pickboard;
00111 }
00112
00113 void ExampleboardImpl::resetState()
00114 {
00115 if ( m_pickboard )
00116 m_pickboard->resetState();
00117 }
00118
00119 QPixmap *ExampleboardImpl::icon()
00120 {
00121 if ( !m_icn )
00122 m_icn = new QPixmap(Opie::Core::OResource::loadPixmap("Tux", Opie::Core::OResource::SmallIcon));
00123 return m_icn;
00124 }
00125
00126 QString ExampleboardImpl::name()
00127 {
00128 return QObject::tr("Example Input");
00129 }
00130
00131 void ExampleboardImpl::onKeyPress( QObject *receiver, const char *slot )
00132 {
00133 if ( m_pickboard )
00134 QObject::connect( m_pickboard, SIGNAL(key(ushort,ushort,ushort,bool,bool)), receiver, slot );
00135 }
00136
00137 #ifndef QT_NO_COMPONENT
00138 QRESULT ExampleboardImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00139 {
00140 *iface = 0;
00141 if ( uuid == IID_QUnknown )
00142 *iface = this;
00143 else if ( uuid == IID_InputMethod )
00144 *iface = this;
00145 else
00146 return QS_FALSE;
00147
00148 if ( *iface )
00149 (*iface)->addRef();
00150 return QS_OK;
00151 }
00152
00153 Q_EXPORT_INTERFACE()
00154 {
00155 Q_CREATE_INSTANCE( ExampleboardImpl )
00156 }
00157 #endif
00158