📄 mainwindow.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** 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 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** 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.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#define QTOPIA_INTERNAL_FILEOPERATIONS#include "mainwindow.h"#include "videocaptureview.h"#include "camerasettings.h"#include "thumbbutton.h"#include <qtopia/config.h>#include <qtopia/image.h>#include <qtopia/qpeapplication.h>#include <qtopia/locationcombo.h>#include <qtopia/contextmenu.h>#include <qtopia/qcopenvelope_qws.h>#include <qtopia/resource.h>#include <qtopia/services.h>#include <qtopia/categories.h>#include <qtopia/qpetoolbar.h>#include <qtopia/global.h>#include <qaction.h>#include <qlabel.h>#include <qtoolbutton.h>#include <qpushbutton.h>#include <qgroupbox.h>#include <qsignalmapper.h>#include <qdir.h>#include <qimage.h>#include <qslider.h>#include <qtimer.h>#include <qmessagebox.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>static const int thmarg=2;static const bool video_supported = FALSE;CameraMainWindow::CameraMainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f){ setCaption(tr("Camera")); picfile = Global::tempDir() + "image.jpg"; camera = new CameraBase(this); setCentralWidget(camera); connect(qApp,SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&))); connect(qApp,SIGNAL(linkChanged(const QString&)), this, SLOT(linkChanged(const QString&))); Categories cats; cats.load(categoryFileName()); camcat = cats.id("Document View","_Camera"); // No tr if ( !camcat ) { camcat = cats.addCategory("Document View","_Camera"); // No tr cats.save(categoryFileName()); } camera->photo->setFocus(); connect(camera->photo, SIGNAL(clicked()), this, SLOT(takePhoto())); connect(camera->video, SIGNAL(clicked()), this, SLOT(toggleVideo())); refocusTimer = new QTimer(this); connect(refocusTimer, SIGNAL(timeout()), this, SLOT(takePhotoNow())); thumb[0] = camera->thumb1; thumb[1] = camera->thumb2; thumb[2] = camera->thumb3; thumb[3] = camera->thumb4; thumb[4] = camera->thumb5; cur_thumb = -1; QSignalMapper* sm = new QSignalMapper(this); for (int i=0; i<nthumb; i++) { sm->setMapping(thumb[i],i); connect(thumb[i],SIGNAL(clicked()),sm,SLOT(map())); thumb[i]->installEventFilter(this); } connect(sm,SIGNAL(mapped(int)),this,SLOT(thumbClicked(int))); AppLnk picture_viewer = Service::appLnk("PhotoEdit"); AppLnk video_viewer = Service::appLnk("Open/video/mpeg"); a_pview = new QAction( tr("%1...","app name").arg(picture_viewer.name()), Resource::loadPixmap(picture_viewer.icon()), QString::null, 0, this, 0 ); connect( a_pview, SIGNAL( activated() ), this, SLOT( viewPictures() ) ); a_vview = new QAction( tr("%1...","app name").arg(video_viewer.name()), Resource::loadIconSet(video_viewer.icon()), QString::null, 0, this, 0 ); connect( a_vview, SIGNAL( activated() ), this, SLOT( viewVideos() ) ); a_settings = new QAction( tr("Settings..."), Resource::loadIconSet( "settings" ), QString::null, 0, this, 0 ); connect( a_settings, SIGNAL( activated() ), this, SLOT( doSettings() ) ); a_th_edit = new QAction( tr("Edit"), Resource::loadIconSet("edit"), QString::null, 0, this, 0 ); connect( a_th_edit, SIGNAL( activated() ), this, SLOT( editThumb() ) ); a_th_del = new QAction( tr("Delete"), Resource::loadIconSet("trash"), QString::null, 0, this, 0 ); connect( a_th_del, SIGNAL( activated() ), this, SLOT( delThumb() ) ); a_th_add = new QAction( tr("Move to Contact..."), Resource::loadPixmap("addressbook/generic-contact"), QString::null, 0, this, 0 ); connect( a_th_add, SIGNAL( activated() ), this, SLOT( moveToContact() ) ); a_send = new QAction( tr("Send to Contact..."), Resource::loadIconSet( "beam" ), QString::null, 0, this, 0); connect( a_send, SIGNAL( activated() ), this, SLOT( sendFile() ) );#ifndef QTOPIA_PHONE // Create Toolbars QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); setToolBarsMovable( FALSE ); a_pview->addTo( bar ); if ( video_supported ) a_vview->addTo( bar ); a_th_edit->addTo( bar ); a_th_del->addTo( bar ); a_th_add->addTo( bar ); a_send->addTo( bar ); a_settings->addTo( bar );#else ContextMenu *contextMenu = new ContextMenu(this); a_pview->addTo( contextMenu ); if ( video_supported ) a_vview->addTo( contextMenu ); a_th_edit->addTo( contextMenu ); a_th_del->addTo( contextMenu ); a_th_add->addTo( contextMenu ); a_send->addTo( contextMenu ); a_settings->addTo( contextMenu );#endif installEventFilter(camera->photo); installEventFilter(camera->video); camera->photo->installEventFilter(this); camera->video->installEventFilter(this); // Load the allowable sizes from the camera hardware. photo_size = camera->videocaptureview->photoSizes(); video_size = camera->videocaptureview->videoSizes(); settings = new CameraSettings(this,0,TRUE); // load settings from config Config cfg("Camera"); cfg.setGroup("General"); QString l = cfg.readEntry("location"); if ( !l.isEmpty() ) settings->location->setLocation(l); storagepath = settings->location->documentPath(); cfg.setGroup("Photo"); int w; w = cfg.readNumEntry("width",camera->videocaptureview->recommendedPhotoSize().width()); for (psize=0; psize<(int)photo_size.count()-1 && photo_size[psize].width() > w;) psize++; pquality = cfg.readNumEntry("quality",settings->photo_quality->value()); cfg.setGroup("Video"); w = cfg.readNumEntry("width",camera->videocaptureview->recommendedVideoSize().width()); for (vsize=0; vsize<(int)video_size.count()-1 && video_size[vsize].width() > w;) vsize++; vquality = cfg.readNumEntry("quality",settings->video_quality->value()); vframerate = cfg.readNumEntry("framerate",settings->video_framerate->value()); for (int i=0; i<(int)photo_size.count(); i++) { settings->photo_size->insertItem(tr("%1 x %2").arg(photo_size[i].width()).arg(photo_size[i].height())); } for (int i=0; i<(int)video_size.count(); i++) { settings->video_size->insertItem(tr("%1 x %2").arg(video_size[i].width()).arg(video_size[i].height())); } namehint=0; recording = FALSE; preview(); if ( !video_supported ) { // Room for longer text camera->photo->setText(tr("Take Photo")); camera->video->setEnabled(FALSE); camera->video->hide(); }}CameraMainWindow::~CameraMainWindow(){}void CameraMainWindow::resizeEvent(QResizeEvent*){ thumbw = width()/5-4; thumbh = thumbw*3/4; thumb[0]->setFixedHeight(thumbh+thmarg*2); loadThumbs();}bool CameraMainWindow::event(QEvent* e){ if ( e->type() == QEvent::WindowActivate ) { if ( cur_thumb < 0 ) camera->videocaptureview->setLive(); } else if ( e->type() == QEvent::WindowDeactivate ) { camera->videocaptureview->setLive(-1); } return QMainWindow::event(e);}bool CameraMainWindow::eventFilter(QObject* o, QEvent* e){ if ( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e;#if QTOPIA_PHONE if (!ke->isAutoRepeat()) { if (ke->key() == Key_1) { takePhoto(); return TRUE; } else if (ke->key() == Key_2) { toggleVideo(); return TRUE; } }#endif if ( ke->key() == Key_Up ) { camera->photo->setFocus(); return TRUE; } else if ( ke->key() == Key_Down ) { thumb[0]->setFocus(); return TRUE; } else if ( ke->key() == Key_Left ) { if ( o == camera->video ) { camera->photo->setFocus(); return TRUE; } else { if ( o == thumb[0] ) return TRUE; for (int i=1; i<nthumb; ++i) { if ( o == thumb[i] ) { thumb[i-1]->setFocus(); return TRUE; } } } } else if ( ke->key() == Key_Right ) { if ( o == camera->photo ) { camera->video->setFocus(); return TRUE; } else { if ( o == thumb[nthumb-1] ) return TRUE; for (int i=0; i<nthumb-1; ++i) { if ( o == thumb[i] ) { thumb[i+1]->setFocus(); return TRUE; } } } } } else if ( e->type() == QEvent::FocusIn ) { if (o == camera->photo) camera->photo->setText(tr("Take Photo")); updateActions(); } else if (e->type() == QEvent::FocusOut ) { if (o == camera->photo) camera->photo->setText(tr("Activate Camera")); } return QWidget::eventFilter(o,e);}void CameraMainWindow::updateActions(){ bool p=FALSE,v=FALSE; QWidget *foc = focusWidget(); if ( foc == camera->photo ) { p = TRUE; v = FALSE; } else if ( foc == camera->video ) { v = TRUE; p = FALSE; } a_pview->setEnabled(p); a_vview->setEnabled(v); a_settings->setEnabled(p || v); bool th=!p && !v; if ( th ) { int i; for (i=0; i<nthumb; i++) { if ( thumb[i] == foc ) { selectThumb(i); break; } } if ( i==nthumb || !thumb[i]->pixmap() ) th = FALSE; } else { selectThumb(-1); }}void CameraMainWindow::viewPictures(){ ServiceRequest req("PhotoEdit","showCategory(int)"); req << camcat; req.send();}void CameraMainWindow::viewVideos(){ Service::appLnk("Open/video/mpeg").execute();}void CameraMainWindow::doSettings(){ bool v = video_supported;#ifdef QTOPIA_PHONE bool p; p = a_pview->isEnabled(); v = v && a_vview->isEnabled(); if (p) settings->photo->show(); else settings->photo->hide();#endif if (v) settings->video->show(); else settings->video->hide();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -