/*
*show pictrue main cpp
*/
#include "frmMain.h"
#include <qaccel.h>
#include <qtextview.h>
#include <qcstring.h>
#include <qmenubar.h>
#include <qfiledialog.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qpopupmenu.h>
#include <qkeycode.h>
#include <qclipboard.h>
#include <qpainter.h>
#include <qapplication.h>//for qApp
//frmM::frmM( QWidget *parent, const char *name, bool modal, WFlags f )
frmM::frmM( QWidget *parent, const char *name, WFlags f )
: frmMain( parent, name, f ),
//conversion_flags( PreferDither ),
//filename( 0 ),
helpmsg( 0 ) //初始化帮助对话框,否则出现断错误
{
conversion_flags=0;
menubar = new QMenuBar(this);
menubar->setSeparator( QMenuBar::InWindowsStyle );
QStrList fmt = QImage::outputFormats();//可保存的图片格式
saveimage = new QPopupMenu();
for (const char* f = fmt.first(); f; f = fmt.next()) {
saveimage->insertItem( f );//插入保存的图片格式
}
connect( saveimage, SIGNAL(activated(int)), this, SLOT(saveImage(int)) );
//文件菜单
file = new QPopupMenu();
menubar->insertItem( tr("文件"), file ,Key_F2);
file->insertItem( tr("新建"), this, SLOT(newWindow()), CTRL+Key_N );
file->insertItem( tr("打开"), this, SLOT(openFile()), CTRL+Key_O );
si = file->insertItem( tr("保存图片"), saveimage );//插入带子项的保存菜单
file->insertSeparator();//插入横杠
file->insertItem( tr("退出"), qApp, SLOT(quit()), Key_Escape );
//帮助菜单
QPopupMenu* help = new QPopupMenu();
menubar->insertItem( tr("帮助"), help );
help->insertItem( tr("关于??"), this, SLOT(giveHelp()), Key_F1 );
PixmapLabel1 = new QLabel( fmShowPic, "PixmapLabel1" );
PixmapLabel1->setGeometry( QRect( 0, 0, 510, 430 ) );
//PixmapLabel1->setPixmap( image0 );
PixmapLabel1->setScaledContents( TRUE );
connect(btnOpenPic,SIGNAL(clicked()),this,SLOT(openFile()));
QAccel *accel = new QAccel( this );
accel->connectItem( accel->insertItem( Key_F1 ),this, SLOT(showKeyf1()) );
accel->connectItem( accel->insertItem( Key_F2 ),this, SLOT(showKeyf2()) );
accel->connectItem( accel->insertItem( Key_F3 ),this, SLOT(showKeyf3()) );
accel->connectItem( accel->insertItem( Key_F4 ),this, SLOT(showKeyf4()) );
}
frmM::~frmM(){
}
void frmM::showKeyf1()
{
txtVShowKey->setText( tr( "显示按键 F1 " ) );
}
void frmM::showKeyf2()
{
txtVShowKey->setText( tr( "显示按键 F2 " ) );
}
void frmM::showKeyf3()
{
txtVShowKey->setText( tr( "显示按键 F3 " ) );
}
void frmM::showKeyf4()
{
txtVShowKey->setText( tr( "显示按键 F4 " ) );
}
void frmM::newWindow()
{
frmM* that = new frmM(0, tr("新画板"), 1);
that->show();
}
void frmM::openFile()
{
QString newfilename = QFileDialog::getOpenFileName();
if ( !newfilename.isEmpty() ) {
showpic( newfilename ) ;
repaint(); // show image in widget
}
}
void frmM::saveImage( int item )
{
const char* fmt = saveimage->text(item);
QString savefilename = QFileDialog::getSaveFileName(QString::null, QString::null,
this, filename);
if ( !savefilename.isEmpty() )
if ( !image.save( savefilename, fmt ) )
QMessageBox::warning( this, "Save failed", "Error saving file" );
}
bool frmM::showpic( const char *fileName )
{
filename = fileName;
bool ok = FALSE;
if ( filename ) {
QApplication::setOverrideCursor( waitCursor ); // this might take time
ok = image.load(filename, 0);
if ( ok )
ok = reconvertImage();
if ( !ok ) {//show failed
pm.resize(0,0); // couldn't load image
update();
}
}
return ok;
}
void frmM::giveHelp()
{
if (!helpmsg) {
QString helptext =
tr("<b>名称:</b><i>图片和按键的测试程序</i>"
"<p><b>作者:</b> <tt>wisjohn</tt>"
"<p><b>版本:</b> <i>Version:1.0.0</i>"
"<p>支持的图片格式:"
"<blockquote>");
helptext += QImage::inputFormatList().join(", ");
helptext += "</blockquote>";
helpmsg = new QMessageBox( tr("关于"), helptext,
QMessageBox::Information, QMessageBox::Ok, 0, 0, 0, 0, FALSE );
}
helpmsg->show();
helpmsg->raise();
}
#if 1
void frmM::paintEvent( QPaintEvent *e )
{
#if 0
if ( pm.size() != QSize( 0, 0 ) ) { // is an image loaded?
QPainter painter(this);
painter.setClipRect(e->rect());
painter.drawPixmap(0, menubar->heightForWidth( width() ), pmScaled);
}
#endif
}
#endif
bool frmM::reconvertImage()
{
bool success = FALSE;
if ( image.isNull() ) return FALSE;
QApplication::setOverrideCursor( waitCursor ); // this might take time
if ( pm.convertFromImage(image, conversion_flags) )
{
pmScaled = QPixmap();
scale();
resize( width(), height() );
success = TRUE; // load successful
} else {
pm.resize(0,0); // couldn't load image
}
QApplication::restoreOverrideCursor(); // restore original cursor
return success; // TRUE if loaded OK
}
void frmM::scale()
{
int h = 430;
if ( image.isNull() ) return;
QApplication::setOverrideCursor( waitCursor ); // this might take time
QWMatrix m; // transformation matrix
m.scale(((double)width())/pm.width(),// define scale factors
((double)h)/pm.height());
pmScaled = pm.xForm( m ); // create scaled pixmap
PixmapLabel1->setPixmap(pmScaled);
QApplication::restoreOverrideCursor(); // restore original cursor
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
canvpic.rar (31个子文件)
canvpic
canvpic
main.cpp 564B
moc_frmMainbase.cpp 2KB
bin
canvpic_x86 123KB
Makefile_x86 2KB
canvpic_x86_727 152KB
rc.local 2KB
tmp
share.rar 107KB
vistabold1.png 16KB
simheii1.png 15KB
ccccccwenquan.png 5KB
simsun windows.png 18KB
simsun.png 17KB
huawenxihei.png 17KB
simfang1.png 18KB
simkai1.png 19KB
show 117KB
hello 59KB
Makefile_arm 2KB
canvpic_arm 40KB
frmMainbase.ui 29KB
frmMain.h 1KB
frmMainbase.cpp 2KB
canvpic.pro 370B
kubical.jpg 66KB
frmMain.cpp 5KB
Makefile 2KB
canvpic 152KB
moc_frmMain.cpp 4KB
frmMainbase.h 866B
pause.bmp 40KB
Makefile_arm 2KB
共 31 条
- 1
资源评论
- monsl2013-11-04初学者可以学习
- Android高级知识分享官2012-07-22我好想在Qt上运行不了哎
- hyx12092011-10-10可以当做 QT/E 的初级使用的例子
- cxm7104418172013-01-11可以运行。。
勺城之客
- 粉丝: 117
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功