Code highlighting produced by Actipro CodeHighlighter (freeware) 1
#include "vs2008smart.h"
#include "stdafx.h"
Vs2008Smart::Vs2008Smart(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
//this->setAttribute(Qt::WA_TranslucentBackground);//透明效果
//窗口居中
QDesktopWidget * deskTop = QApplication::desktop();
int screenIndex = deskTop->screenNumber ( this ); //得到this widget主要出于哪个屏幕中,返回屏幕index
QRect rect = deskTop->screenGeometry(screenIndex); //得到该屏幕大小
int x = (rect.width() - width())/2;
int y = (rect.height() - height())/2;
this->move(x,y);
//以可读写方式打开串口
/*
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
//QTreeView *tree = new QTreeView(splitter);
ui.treeView->setModel(model);
*/
//添加listView Items
//ui.listWidget->insertItem(itemSize++,tr("通讯设置"));
//ui.listWidget->insertItem(itemSize++,QObject::tr("摄像头位置调整"));
//ui.listWidget->insertItem(itemSize++,tr("标定视频范围"));
itemSize=0;
//TODO:添加页面
//comPage=new com_Config();
camPage=new cam_Config();
demarcatePage=new demarcate_Config();
matrixPage=new matrix_Config();
/*
* 移除所有widgets
*/
while(ui.stackedWidget->count()!=0)
ui.stackedWidget->removeWidget(ui.stackedWidget->widget(0));
//addPageItem(tr("通讯设置"),comPage);
addPageItem(tr("摄像机位置调整"),camPage);
addPageItem(tr("摄像机有效信息位置"),demarcatePage);
addPageItem(tr("摄像机内参数标定"),matrixPage);
ui.listWidget->setEnabled(false);
setPageItemIndex(0);
//ui.stackedWidget->addWidget(directPage);
//ui.btn_prepage->setEnabled(false);
setBtnEnable();
connect(ui.btn_prepage,SIGNAL(clicked()),this,SLOT(setPrePage()));//连接下一页
connect(ui.btn_nextpage,SIGNAL(clicked()),this,SLOT(setNextPage()));
connect(ui.listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(setStackedWidget(int)));//连接左边listWidget
//connect(ui.stackedWidget,SIGNAL(currentChanged(int)),ui.listWidget,SLOT(setListWidget(int)));
connect(this,SIGNAL(updateListWidget(int)),this,SLOT(setListWidget(int)));
//connect(ui.btn_close,SIGNAL(clicked()),qApp,SLOT(quit()));
MoveMouseTimer=new QTimer(this);
connect(MoveMouseTimer,SIGNAL(timeout()),this,SLOT(moveMouse()));
connect(ui.btn_openV,SIGNAL(clicked()),this,SLOT(ControlmoveMouse()));
x=0;y=0;
/*
* 增加托盘的相关初始化代码
*/
iTrayIcon=new QSystemTrayIcon();
iTrayIcon->setIcon( QIcon("IconTray.png"));
iTrayIcon->show();
iTrayIcon->setToolTip(QString(tr("One world, One dream!")));
iTrayIcon->showMessage("Message","Hi, I am here.");
connect( iTrayIcon, SIGNAL(messageClicked ()), this, SLOT(hiMessage()));
addMenu();
//end of the trayicon
}
void Vs2008Smart::moveMouse()
{
SystemInteraction::MoveMouseToXY(x,y);
x+=100;
//y++;
if(x>60000)
{
MoveMouseTimer->stop();
x=0;
}
}
/*
* 移动鼠标至x,y坐标处
*/
void Vs2008Smart::ControlmoveMouse()
{
if(MoveMouseTimer->isActive())
{
MoveMouseTimer->stop();
}
else
{
MoveMouseTimer->start(50);//0.5s中断一次
}
}
Vs2008Smart::~Vs2008Smart()
{
//delete comPage;
delete camPage;
delete demarcatePage;
delete matrixPage;
qDebug( "Vs2008Smart is destruct!\n");
}
/*
* 设置上一页下一页的使能状态
*/
void Vs2008Smart::setBtnEnable()
{
ui.Page_Oper->setText(QString("第")+QString::number(ui.stackedWidget->currentIndex()+1)+QString("步/共")+QString::number(ui.stackedWidget->count())+QString("步"));
if(ui.stackedWidget->count()==0)
return;
if(ui.stackedWidget->currentIndex()==0)
ui.btn_prepage->setEnabled(false);
else
ui.btn_prepage->setEnabled(true);
if(ui.stackedWidget->currentIndex()==ui.stackedWidget->count()-1)
{
ui.btn_nextpage->setText("完成");
//ui.btn_nextpage->setEnabled(false);
}
else
{
ui.btn_nextpage->setEnabled(true);
ui.btn_nextpage->setText(tr("下一页"));
}
}
void Vs2008Smart::setPrePage()
{
ui.stackedWidget->setCurrentIndex(ui.stackedWidget->currentIndex()-1);//这里直接用slot,不会再次发送singal,或许这样理解比较好
setBtnEnable();
emit updateListWidget(ui.stackedWidget->currentIndex());
}
void Vs2008Smart::setNextPage()
{
ui.stackedWidget->setCurrentIndex(ui.stackedWidget->currentIndex()+1);
setBtnEnable();
emit updateListWidget(ui.stackedWidget->currentIndex());
}
void Vs2008Smart::setListWidget(int curpage)
{
ui.listWidget->setCurrentRow(curpage);
//setVision(curpage);//设置vision
}
void Vs2008Smart::setStackedWidget(int page)
{
ui.stackedWidget->setCurrentIndex(page);
//setVision(page);//设置vision
setBtnEnable();
}
//////////////////////////////////////////////////////////////////////////
/*
* 添加一个页面,包括item和widget页面
*/
void Vs2008Smart::addPageItem(QString itemName,QWidget* pageWidget)
{
//
ui.listWidget->insertItem(itemSize++,itemName);
ui.stackedWidget->addWidget(pageWidget);
}
void Vs2008Smart::setPageItemIndex(int Index)
{
ui.listWidget->setCurrentRow(Index);
ui.stackedWidget->setCurrentIndex(Index);
}
/*
* 设置每个页面是否是当前显示页面的函数
*/
/*
void Vs2008Smart::setVision(int Index)
{
switch(Index)
{
case 0:
camPage->isVision=true;
demarcatePage->isVision=false;
matrixPage->isVision=false;
break;
case 1:
camPage->isVision=false;
demarcatePage->isVision=true;
matrixPage->isVision=false;
break;
case 2:
camPage->isVision=false;
demarcatePage->isVision=false;
matrixPage->isVision=true;
break;
}
}
*/
/*
* 点击托盘消息slot
*/
void Vs2008Smart::hiMessage()
{
iTrayIcon->setIcon( QIcon("IconTray.png"));
}
/*
* 推出函数
*/
void Vs2008Smart::exitProgram()
{
exit(-1);
}
/*
* 添加菜单项
*/
void Vs2008Smart::addMenu()
{
diaplayAction = new QAction(tr("&配置参数"), this);
connect(diaplayAction, SIGNAL(triggered()), this, SLOT(displayVary()));
normalModeAction = new QAction(tr("&普通模式"), this);
//connect(normalModeAction, SIGNAL(triggered()), this, SLOT(show()));
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), this, SLOT(exitProgram()));
iTraymenu=new QMenu();
iTraymenu->addAction(diaplayAction);
iTraymenu->addAction(normalModeAction);
iTraymenu->addAction(restoreAction);
iTraymenu->addSeparator();
iTraymenu->addAction(quitAction);
iTrayIcon->setContextMenu(iTraymenu);
}
/*
* 切换显示还是隐藏
*/
void Vs2008Smart::displayVary()
{
//
if(this->isHidden())
{
this->setVisible(TRUE);
}
else
{
this->setVisible(FALSE);
}
}
如果是点击另外一个非自身开发的程序(不管是不是用qt)的话,这个就和qt本身没关系了,和操作系统有关。
比如编个程序自动点击qq的登录按钮,在win下一般如下:
1、找到这个按钮窗口的ID然后获取HWND
2、使用winapi函数给他鼠标点击的发消息 sendmessage
或者直接控制鼠标光标移动到那个位置然后点击鼠标(类似按键精灵)
阅读(2902) | 评论(0) | 转发(0) |