📄 softlock.cpp
字号:
/*Written by Letterb @scnu_cs2007.08.26Email: letterb@tom.comThanks Lasly's SDK for E2(v0.02)*/#define QT_NO_DRAGANDDROP#define QT_NO_PROPERTIES#include <E2_EZX_ZApplication.h>#include <E2_EZX_ZKbMainWidget.h>#include <E2_EZX_ZMessageDlg.h>#include <E2_EZX_ZLabel.h>#include <E2_EZX_ZScrollPanel.h>#include <E2_EZX_ZSoftKey.h>#include <E2_EZX_ZFormContainer.h>#include <qpainter.h>#include <qlabel.h>#include <stdio.h>#include <stdlib.h>#include <qfile.h>#include <qtextcodec.h>#include <qlayout.h>#include <string.h>#include <time.h>#include <unistd.h>QString ChineseAndEnglish(const char*ChineseString);//change string to utf-8typedef struct tagDate{ int day; int month; int year;}Date,*PDate;class MyZKbMain : public ZKbMainWidget{ Q_OBJECT////////////////// public:// bool leftkey_flag; QString nltemp;//用于显示农历 int pm_infocountor;//电话/短信计数器 int Timer_countor; bool ulock_flag; bool ulock_music; ZScrollPanel *zsv; ZLabel* infolabel ; ZLabel* infolabel2 ; ZSoftKey* softKey; bool open_music_flag;// char *mypath; char mycommand[500]; ZAppInfoArea* InfoArea;//no used////////////////////// public: MyZKbMain(char * currentpath):ZKbMainWidget((ZHeader::HEADER_TYPE)3,NULL , "ZMainWidget" , 0){/////////////初始化/////////// pm_infocountor=0; sprintf(mycommand,"cd %s ; ./killvr.sh",currentpath); Timer_countor=0; ulock_flag=false; open_music_flag=false; ulock_music=false;//////////////////////////////// QVBoxLayout* layout = getVBoxLayout(); setMainWidgetTitle(ChineseAndEnglish("键盘软锁 v2.0")); QString qstemp; char buf[100]; FILE *pp; if( (pp = popen("export TZ=GMT-8 ; date +\"Day: \"%Y/%m/%e%nDate:%A%nTime:%T", "r")) == NULL ) { printf("popen() error!\n"); } while(fgets(buf, sizeof buf, pp))//读文件; { qstemp+=buf; qstemp+='\n'; } pclose(pp);//////////////// Date tdate;// qstemp+=ChineseAndEnglish("农历:"); if( (pp = popen("export TZ=GMT-8 ; date +%Y ; date +%m ; date +%e", "r")) == NULL )//system调用,获取当前时间 fgets(buf, sizeof buf, pp); fgets(buf, sizeof buf, pp); tdate.year=atoi(buf); fgets(buf, sizeof buf, pp); tdate.month=atoi(buf); fgets(buf, sizeof buf, pp); tdate.day=atoi(buf); pclose(pp);// QString nltemp; GetDayOf(tdate,nltemp); qstemp+=nltemp; qstemp.replace( QRegExp("Day"), ChineseAndEnglish("日期" )); qstemp.replace( QRegExp("Date"), ChineseAndEnglish("星期" )); qstemp.replace( QRegExp("Time"), ChineseAndEnglish("时间" )); zsv = new ZScrollPanel(this , NULL , 0, (ZSkinService::WidgetClsID)4); QString info=qstemp; QString info2=ChineseAndEnglish(""); infolabel = new ZLabel(info, this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); infolabel->setPreferredWidth(240); infolabel->setAutoResize(true ); infolabel2 = new ZLabel(info2, this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); infolabel2->setPreferredWidth(240); infolabel2->setAutoResize(true ); int height = heightForWidth(240); height+=32; zsv->addChild(infolabel , 35 , height); height+=40; zsv->addChild(infolabel2, 15 , height); layout->addWidget(zsv);/////////// softKey = new ZSoftKey(NULL , this , this); softKey->setOptMenu(ZSoftKey::LEFT, NULL); softKey->setText(ZSoftKey::LEFT, ChineseAndEnglish(""), (ZSoftKey::TEXT_PRIORITY)0); softKey->setText(ZSoftKey::RIGHT, ChineseAndEnglish("键盘已锁"), (ZSoftKey::TEXT_PRIORITY)0); setSoftKey(softKey); softKey->setClickedSlot(ZSoftKey::RIGHT, this, SLOT(ulock_keyboard())); softKey->setClickedSlot(ZSoftKey::LEFT, this, SLOT(ulock_music_keys())); system(mycommand); startTimer(1000); }public : void GetDayOf(Date &tdate,QString &strLuner);//农历算法的函数public slots: virtual void timerEvent(QTimerEvent* e);//timer virtual void keyPressEvent(QKeyEvent* k); void ulock_keyboard();//解所有键 void ulock_music_keys();//解音乐键};void MyZKbMain::ulock_music_keys(){ if(ulock_music) { ulock_music=false;// leftkey_flag=true; open_music_flag=true; softKey->setText(ZSoftKey::LEFT, ChineseAndEnglish("音乐键已解"), (ZSoftKey::TEXT_PRIORITY)0);// QTimerEvent* e=NULL;// timerEvent(e):: Timer_countor=0; killTimers(); startTimer(1000); } else { infolabel->setText(""); infolabel->setPreferredWidth(220);//设置标签 infolabel->setAutoResize(true ); infolabel2->setText(ChineseAndEnglish("===================\n 请按\"*\"键,再按解锁\n===================")); infolabel2->setPreferredWidth(220);//设置标签 infolabel2->setAutoResize(true ); } }void MyZKbMain::ulock_keyboard(){ if(ulock_flag)//解锁 qApp->quit();//quit() else { infolabel->setText(""); infolabel->setPreferredWidth(220);//设置标签 infolabel->setAutoResize(true ); infolabel2->setText(ChineseAndEnglish("===================\n 请按\"*\"键,再按解锁\n===================")); infolabel2->setPreferredWidth(220);//设置标签 infolabel2->setAutoResize(true ); }}void MyZKbMain::keyPressEvent(QKeyEvent* k)//按键{ bool flag=false; switch (k->key()) { case 42://"*"号键 ulock_flag=true; char buf[500]; FILE *pp1; if( (pp1 = popen("pidof mediaplayer ; pidof fmradio", "r")) == NULL )//检查进程 printf("error"); while(fgets(buf, sizeof buf, pp1)) if(strlen(buf)>1) {flag=true;break;} pclose(pp1); if(flag) { ulock_music=true; softKey->setText(ZSoftKey::LEFT, ChineseAndEnglish("解音乐键"), (ZSoftKey::TEXT_PRIORITY)0); } softKey->setText(ZSoftKey::RIGHT, ChineseAndEnglish("解锁"), (ZSoftKey::TEXT_PRIORITY)0); Timer_countor=0; killTimers(); startTimer(1000); break; case 4100: case 53://“5”键 infolabel2->setText(ChineseAndEnglish("")); infolabel2->setPreferredWidth(220);//设置标签 infolabel2->setAutoResize(true ); infolabel->setText(ChineseAndEnglish("***********************\nWritten by:\n letterb @scnu_cs_05\nEmail:letterb@tom.com\n2007.8(v2.0)\n说明:\n先按*键再按解锁键\n即可返回屏幕\n***********************")); infolabel->setPreferredWidth(220);//设置标签 infolabel->setAutoResize(true ); break; case 35: if(ulock_flag) pm_infocountor=0; else { infolabel->setText(""); infolabel->setPreferredWidth(220);//设置标签 infolabel->setAutoResize(true ); infolabel2->setText(ChineseAndEnglish("===================\n键盘已锁,请按\"*\"键解锁\n===================")); infolabel2->setPreferredWidth(220);//设置标签 infolabel2->setAutoResize(true ); } break; case 4118://音乐键 case 4119: case 4171: case 4172: case 4169: if(open_music_flag==true) { if(k->key()==4171) infolabel2->setText(ChineseAndEnglish("===================\n\t上一首\n===================")); else if(k->key()==4172) infolabel2->setText(ChineseAndEnglish("===================\n\t下一首\n===================")); else if(k->key()==4169) infolabel2->setText(ChineseAndEnglish("===================\n\t播放/暂停\n===================")); else if(k->key()==4118) infolabel2->setText(ChineseAndEnglish("===================\n\t音量+\n===================")); else if(k->key()==4119) infolabel2->setText(ChineseAndEnglish("===================\n\t音量-\n===================")); return QWidget::keyPressEvent(k); } else { infolabel->setText(""); infolabel->setPreferredWidth(220);//设置标签 infolabel->setAutoResize(true ); infolabel2->setText(ChineseAndEnglish("===================\n键盘已锁,请按\"*\"键解锁\n===================")); infolabel2->setPreferredWidth(220);//设置标签 infolabel2->setAutoResize(true ); } break; case 4154: break; case 4152: break; case 52: if(ulock_flag&&pm_infocountor>0) {pm_infocountor--;break;} // else // break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -