?? helloworld.cpp~
字號:
/* * Hello World demo program for EZX * Copyright (C) 2005 Sam Revitch <samr7@cs.washington.edu> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * Further, this software is distributed without any warranty that it is * free of the rightful claim of any third person regarding infringement * or the like. Any license provided herein, whether implied or * otherwise, applies only to this software file. Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *///#define QT_NO_TEXTCODEC#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_ZOptionsMenu.h>#include <E2_EZX_ZComboBox.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <qfile.h>#include <qtextcodec.h>#include <qlayout.h>#include <qdir.h>#include <pthread.h>
QTextCodec* gbk_codec = QTextCodec::codecForName("UTF-8");
QString ChineseAndEnglish(const char*ChineseString)
{
return gbk_codec->toUnicode(ChineseString);
} int *param = NULL;char* inifile = NULL;void* snap(){ if( param == NULL ) { exit(0); } int interval = param[0]; int times = param[1]; int isCard = param[2]; QDir dir; if( isCard ) { dir.setPath("/mmc/mmca1/snapshot/"); if( !dir.exists()) { dir.mkdir("/mmc/mmca1/snapshot/"); } } else { dir.setPath("/ezxlocal/download/mystuff/snapshot/"); if( !dir.exists()) { dir.mkdir("/ezxlocal/download/mystuff/snapshot/"); } } int index = 0; for( int i = 0 ; i < times ; i++ ) { sleep(interval); char name[256]; do { index++; sprintf(name , "%s/snap_%d.png" , dir.path().ascii() , index ); } while( QFile::exists( name ) ); sprintf(name , "fbgrab %s/snap_%d.png" , dir.path().ascii() , index ); system( name ); system( "/usr/SYSqtapp/phone/alertprocess -playvol 4 -playfile /usr/SYSqtapp/ilove3d/shutter.wav" ); } char result[256]; if( isCard ) { sprintf(result , "showQ 屏幕截圖完成 \"本次一共截取%d張\n請到 內存卡/snapshot 下查看結果\" 2" , times); } else { sprintf(result , "showQ 屏幕截圖完成 \"本次一共截取%d張\n請到 我的文件/snapshot 下查看結果\" 2" , times); } system(result); delete[] param; exit(0);}
class MyDialog : public ZKbMainWidget{
Q_OBJECT ZComboBox* intervalBox; ZComboBox* timesBox; ZComboBox* savePathBox; public: MyDialog( ):ZKbMainWidget((ZHeader::HEADER_TYPE)3,NULL , "ZMainWidget" , 0) { param = new int[3]; param[0] = 5; param[1] = 1; param[2] = 0; QFile file(inifile); if( file.open(IO_ReadWrite) ) { file.readBlock( (char*)param , sizeof(int) *3 ); file.close(); } setMainWidgetTitle(ChineseAndEnglish("屏幕截圖")); ZSoftKey* softKey = new ZSoftKey(NULL , this , this); QRect rect; ZOptionsMenu* menu = new ZOptionsMenu(rect, softKey, NULL , 0 ,(ZSkinService::WidgetClsID)2 ); menu->insertItem(ChineseAndEnglish("截圖") , NULL , NULL , true , 0 , 0 ); menu->insertItem(ChineseAndEnglish("退出") , NULL , NULL , true , 1 , 1 ); softKey->setOptMenu(ZSoftKey::LEFT, menu); softKey->setText(ZSoftKey::LEFT, ChineseAndEnglish("選項"), (ZSoftKey::TEXT_PRIORITY)0); softKey->setText(ZSoftKey::RIGHT, ChineseAndEnglish("關于"), (ZSoftKey::TEXT_PRIORITY)0);
softKey->setClickedSlot(ZSoftKey::RIGHT, this, SLOT(about()));
menu->connectItem(0, this, SLOT(set()));
menu->connectItem(1, qApp, SLOT(quit())); intervalBox = new ZComboBox(this,"interval",true); timesBox = new ZComboBox(this,"times",true); savePathBox = new ZComboBox(this,"savePath",true); char tmp[10]; int i; for( i = 5 ; i < 16 ; i++ ) { sprintf(tmp , "%d秒" , i ); intervalBox->insertItem(ChineseAndEnglish(tmp), i - 5 ); } intervalBox->setCurrentItem( param[0] - 5 ); rect = intervalBox->getContentRect(); rect.setWidth( 140 ); intervalBox->setGeometry(rect); for( i = 1 ; i < 16 ; i++ ) { sprintf(tmp , "%d張" , i ); timesBox->insertItem(ChineseAndEnglish(tmp), i - 1); } timesBox->setCurrentItem( param[1] - 1 ); rect = timesBox->getContentRect(); rect.setWidth( 140 ); timesBox->setGeometry(rect); savePathBox->insertItem(ChineseAndEnglish("我的文件"), 0 ); savePathBox->insertItem(ChineseAndEnglish("內存卡"), 1 ); savePathBox->setCurrentItem( param[2] ); rect = savePathBox->getContentRect(); rect.setWidth( 140 ); savePathBox->setGeometry(rect); ZLabel* infolabel_1 = new ZLabel(ChineseAndEnglish("請在下面設置屏幕抓取參數") , this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); ZLabel* infolabel_2 = new ZLabel(ChineseAndEnglish("間隔:") , this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); ZLabel* infolabel_3 = new ZLabel(ChineseAndEnglish("數量:") , this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); ZLabel* infolabel_4 = new ZLabel(ChineseAndEnglish("路徑:") , this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); infolabel_1->setPreferredWidth(240); infolabel_1->setAutoResize(true ); infolabel_2->setPreferredWidth(80); infolabel_2->setAutoResize(true ); infolabel_3->setPreferredWidth(80); infolabel_3->setAutoResize(true ); infolabel_4->setPreferredWidth(80); infolabel_4->setAutoResize(true ); QVBoxLayout* layout = getVBoxLayout(); ZScrollPanel *zsv = new ZScrollPanel(this , NULL , 0 , (ZSkinService::WidgetClsID)4); int height = heightForWidth(240); zsv->addChild(infolabel_1 , 10 , height); height += infolabel_1->heightForWidth(240); zsv->addChild(infolabel_2 , 10 , height); zsv->addChild(intervalBox, 90 , height); height += (intervalBox->getContentRect()).height() + intervalBox->getBtnHSpacing() * 4 ; zsv->addChild(infolabel_3, 10 , height); zsv->addChild(timesBox, 90 , height); height += (timesBox->getContentRect()).height() + intervalBox->getBtnHSpacing() * 4 ; zsv->addChild(infolabel_4, 10 , height); zsv->addChild(savePathBox, 90 , height ); layout->addWidget(zsv); setSoftKey(softKey); dlg = NULL; } ~MyDialog( ) { if( dlg != NULL ) { delete dlg; } } ZMessageDlg *dlg;public slots: void set() { hide(); param[0] = intervalBox->currentItem() + 5; param[1] = timesBox->currentItem() + 1; param[2] = savePathBox->currentItem(); QFile file(inifile); if( file.open(IO_ReadWrite) ) { file.writeBlock( (char*)param , sizeof(int) *3 ); file.close(); } if( fork() ) { snap(); } else { setsid(); qApp->quit(); } } void about() { if( dlg == NULL ) { QString a = ChineseAndEnglish("關于"); QString b = ChineseAndEnglish("屏幕截圖 ver1.0\nbase on yan0's fbgrab\nby Lasly\nEmail: flylasly@gmail.com"); dlg = new ZMessageDlg(a , b , (ZMessageDlg::MessageDlgType)2 , 0 , this , "about" , true , 0); } dlg->show(); }};int main( int argc, char **argv ){ inifile = new char[256];/* strcpy( inifile , argv[0] ); char* p = strrchr( inifile , '/' ); if( p != NULL ) { *p = 0; } strcat(inifile , "/snapdat");*/ strcpy( inifile , "/ezxlocal/.snapdat"); ZApplication* a = new ZApplication( argc, argv ); MyDialog* w = new MyDialog(); a->setMainWidget( w ); w->show(); int ret = a->exec(); delete w; delete a; delete[] inifile; return ret;}#include "helloworld.moc"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -