📄 photoeditui.cpp
字号:
switch( status ) { case ImageIO::NORMAL: { // Initialize editor controls brightness_slider->setValue( 0 ); // Zoom to fit image in screen QSize size = image_io->size(); QSize view = image_ui->size(); disconnect( zoom_slider, SIGNAL( valueChanged( int ) ), this, SLOT( setZoom( int ) ) ); if( size.width() > view.width() || size.height() > view.height() ) { double ratio = REDUCTION_RATIO( view.width(), view.height(), size.width(), size.height() ); ratio = LIMIT( ratio, 0.1, 1.0 ); image_processor->setZoom( ratio ); zoom_slider->setValue( (int) ( log( ratio * 100 ) / log( 10 ) * 100 ) ); } else { image_processor->setZoom( 1.0 ); zoom_slider->setValue( 200 ); } connect( zoom_slider, SIGNAL( valueChanged( int ) ), this, SLOT( setZoom( int ) ) ); image_ui->reset(); image_ui->setEnabled( true ); navigator->show(); navigator->setFocus(); ui_state = EDITOR; } break; case ImageIO::LOAD_ERROR: QMessageBox::warning( 0, tr( "Load Error" ), tr( "<qt>Unable to load image.</qt>" ) ); if( only_editor ) close(); else enterSelector(); break; case ImageIO::DEPTH_ERROR: QMessageBox::warning( 0, tr( "Depth Error" ), tr( "<qt>Image depth is not supported.</qt>" ) ); if( only_editor ) close(); else enterSelector(); break; }}void PhotoEditUI::enterZoom(){#ifndef QTOPIA_PHONE exitCurrentEditorState();#endif // Hide navigator navigator->hide(); // Show zoom control zoom_slider->show();#ifdef QTOPIA_PHONE zoom_slider->setFocus();#endif editor_state = ZOOM;}void PhotoEditUI::enterBrightness(){#ifndef QTOPIA_PHONE exitCurrentEditorState();#endif // Hide navigator navigator->hide(); // Show brightness control brightness_slider->show();#ifdef QTOPIA_PHONE brightness_slider->setFocus();#endif editor_state = BRIGHTNESS;}void PhotoEditUI::enterCrop(){#ifndef QTOPIA_PHONE exitCurrentEditorState();#endif // Hide navigator navigator->hide(); // Enable selection in region selector region_selector->reset(); region_selector->setEnabled( true ); region_selector->setFocus(); editor_state = CROP;}void PhotoEditUI::enterFullScreen(){#ifndef QTOPIA_PHONE exitCurrentEditorState();#endif // Show editor view in full screen image_ui->reparent( 0, QPoint( 0, 0 ) ); image_ui->showFullScreen(); navigator->setFocus();#ifdef QTOPIA_PHONE if( !Global::mousePreferred() ) { connect( region_selector, SIGNAL( pressed() ), this, SLOT( exitCurrentEditorState() ) ); }#endif editor_state = FULL_SCREEN;}void PhotoEditUI::setViewSingle(){#ifdef QTOPIA_PHONE // If image selector not in single, change to single and update context menu if( image_selector->viewMode() != ImageSelector::Single ) { image_selector->setViewMode( ImageSelector::Single ); selector_menu->setItemEnabled( EDIT_ID, true ); selector_menu->setItemEnabled( BEAM_ID, true ); selector_menu->setItemEnabled( DELETE_ID, true ); selector_menu->setItemEnabled( PROPERTIES_ID, true ); selector_menu->setItemEnabled( SLIDE_SHOW_ID, false ); ContextBar::setLabel( image_selector, Qt::Key_Select, ContextBar::NoLabel ); }#else image_selector->setViewMode( ImageSelector::Single );#endif}void PhotoEditUI::launchPopupMenu( const DocLnk&, const QPoint& #ifndef QTOPIA_PHONEpos #endif){#ifndef QTOPIA_PHONE selector_menu->popup( pos );#endif}void PhotoEditUI::launchSlideShowDialog(){ // If slide show dialog accepted, start slideshow if( QPEApplication::execDialog( slide_show_dialog, true ) ) { // Set slide show options slide_show_ui->setDisplayName( slide_show_dialog->isDisplayName() ); slide_show->setSlideLength( slide_show_dialog->slideLength() ); slide_show->setLoopThrough( slide_show_dialog->isLoopThrough() ); enterSlideShow(); }}void PhotoEditUI::launchPropertiesDialog(){ DocLnk doc( image_selector->selectedDocument() ); DocPropertiesDialog dialog( &doc ); // Launch properties dialog with current image QPEApplication::execDialog( &dialog );}void PhotoEditUI::exitCurrentUIState(){ switch( ui_state ) { case SELECTOR:#ifdef QTOPIA_PHONE switch( image_selector->viewMode() ) { // If in single view case ImageSelector::Single: // If there are images, change to thumbnail and update context menu // Otherwise, close application if( image_selector->fileCount() ) { image_selector->setViewMode( ImageSelector::Thumbnail ); selector_menu->setItemEnabled( SLIDE_SHOW_ID, true ); selector_menu->setItemEnabled( EDIT_ID, false ); selector_menu->setItemEnabled( BEAM_ID, false ); selector_menu->setItemEnabled( DELETE_ID, false ); selector_menu->setItemEnabled( PROPERTIES_ID, false ); ContextBar::setLabel( image_selector, Qt::Key_Select, ContextBar::View ); } else close_ok = true; break; // If in thumbnail view, close application case ImageSelector::Thumbnail: close_ok = true; break; }#endif break; case SLIDE_SHOW: // Return from slide show slide_show_ui->reparent( widget_stack, QPoint( 0, 0 ) ); ui_state = SELECTOR; break; case EDITOR:#ifdef QTOPIA_PHONE if( !edit_canceled ) {#endif if( service_requested ) sendValueSupplied(); else saveChanges();#ifdef QTOPIA_PHONE } if( only_editor ) { if( service_requested && service_image.isNull() && edit_canceled ) enterSelector(); else close_ok = true; } else enterSelector(); edit_canceled = false;#else enterSelector();#endif break; }}void PhotoEditUI::exitCurrentEditorState(){ switch( editor_state ) { // If in view, no change case VIEW:#ifdef QTOPIA_PHONE editor_state_changed = false;#endif break; // If in full screen, return from full screen case FULL_SCREEN:#ifdef QTOPIA_PHONE if( !Global::mousePreferred() ) { disconnect( region_selector, SIGNAL( pressed() ), this, SLOT( exitCurrentEditorState() ) ); }#endif // Set editor central widget to editor view image_ui->reparent( editor_ui, QPoint( 0, 0 ) ); editor_ui->setCentralWidget( image_ui ); editor_ui->setFocus();#ifdef QTOPIA_PHONE if( !Global::mousePreferred() ) was_fullscreen = true;#endif editor_state = VIEW;#ifdef QTOPIA_PHONE editor_state_changed = true;#endif break; // If in zoom, hide zoom control case ZOOM: zoom_slider->hide(); // Show navigator navigator->show();#ifdef QTOPIA_PHONE navigator->setFocus();#endif editor_state = VIEW;#ifdef QTOPIA_PHONE editor_state_changed = true;#endif break; // If in brightness, hide brightness control case BRIGHTNESS: brightness_slider->hide(); // Show navigator navigator->show();#ifdef QTOPIA_PHONE navigator->setFocus();#endif editor_state = VIEW;#ifdef QTOPIA_PHONE editor_state_changed = true;#endif break; // If in crop, disable region selector and show navigator case CROP: region_selector->setEnabled( false ); region_selector->update(); // Show navigator navigator->show(); navigator->setFocus(); editor_state = VIEW;#ifdef QTOPIA_PHONE editor_state_changed = true;#endif break; };}void PhotoEditUI::setZoom( int x ){ image_processor->setZoom( pow( 10.0, (double)x / 100.0 ) / 100.0 );}void PhotoEditUI::setBrightness( int x ){ image_processor->setBrightness( (double)x / 100.0 );}void PhotoEditUI::editCurrentSelection(){ // Retrieve current selection from image selector and open for editing current_image = image_selector->selectedDocument(); enterEditor();}void PhotoEditUI::cancelEdit(){#ifdef QTOPIA_PHONE edit_canceled = true; close();#endif}void PhotoEditUI::cropImage(){ // Ensure cropping region is valid QRect region( region_selector->region() ); if( region.isValid() ) { // Retrieve region from region selector // Calculate cropped viewport and crop image_processor->crop( image_ui->viewport( region_selector->region() ) ); // Reset viewport image_ui->reset(); }}void PhotoEditUI::beamImage(){ // Send current image over IR link DocLnk image = image_selector->selectedDocument(); Ir().send( image, image.name() );}void PhotoEditUI::deleteImage(){ // Retrieve currently highlighted image from selector DocLnk image = image_selector->selectedDocument(); // Lauch confirmation dialog // If deletion confirmed, delete image if( QMessageBox::information( this, tr( "Delete" ), tr( "<qt>Are you sure " "you want to delete %1?</qt>"," %1 = file name" ).arg(image.name()), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) image.removeFiles();}void PhotoEditUI::linkChanged( const QString& file ){ // If lnk is current image and has been deleted, show selector DocLnk lnk( file ); if( !lnk.fileKnown() && ( ( current_image.linkFileKnown() && current_image.linkFile() == file ) || ( current_image.fileKnown() && current_image.file() == file ) ) ) { if( only_editor ) close(); else enterSelector(); }}void PhotoEditUI::closeEvent( QCloseEvent* e ){#ifdef QTOPIA_PHONE if( Global::mousePreferred() ) { if( ui_state != EDITOR || ( editor_state == VIEW && !editor_state_changed ) || edit_canceled ) { exitCurrentUIState(); if( close_ok ) e->accept(); } } else { if( was_fullscreen ) was_fullscreen = false; else { if( ui_state == EDITOR && editor_state != VIEW ) exitCurrentEditorState(); else { exitCurrentUIState(); if( close_ok ) e->accept(); } } }#else exitCurrentEditorState(); exitCurrentUIState(); // Reverse effects of only editor launch for fast load if( only_editor ) { widget_stack->raiseWidget( selector_ui ); editor_ui->addFileItems(); only_editor = service_requested = false; service_image.reset(); } e->accept();#endif}#ifndef QTOPIA_PHONEvoid PhotoEditUI::interruptCurrentState(){ // If editing, conclude editing if( ui_state == EDITOR ) { if( service_requested ) sendValueSupplied(); else saveChanges(); }}#endifvoid PhotoEditUI::clearEditor(){ navigator->hide();#ifndef QTOPIA_PHONE zoom_slider->hide(); brightness_slider->hide();#endif image_ui->setEnabled( false ); image_ui->repaint();}void PhotoEditUI::saveChanges(){ // If image was changed, prompt user to save changes if( image_processor->isChanged() ) {#ifndef QTOPIA_PHONE if( QMessageBox::information( this, tr( "Save Changes" ), tr( "<qt>Do you want to save your changes?</qt>" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {#endif // If save supported, prompt user to overwrite original // Otherwise, save as new file bool overwrite = false; if( image_io->isSaveSupported() ) { if( QMessageBox::information( this, tr( "Save Changes " ), tr( "<qt>Do you want to overwrite the original?</qt>" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) overwrite = true; } else { const char* format = image_io->format(); QMessageBox::warning( this, tr( "Saving %1" ).arg( format ), tr( "<qt>Saving as %1 is not supported. " "Using the default format instead.</qt>" ) .arg( format ) ); } QImage image = image_processor->image(); // Attempt to save changes bool saving = true; while( saving && !image_io->save( image, overwrite ) ) { QMessageBox mb( tr( "Out Of Space" ), tr( "<qt>Try to cleanup storage space?</qt>" ), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton, this ); if( mb.exec() == QMessageBox::Yes ) { ServiceRequest req( "CleanupWizard", "showCleanupWizard()" ); req.send(); mb.setCaption( tr( "Save Changes" ) ); mb.setText( tr( "Try again?" ) ); mb.exec(); } if( mb.result() == QMessageBox::No ) saving = false; }#ifndef QTOPIA_PHONE }#endif }}void PhotoEditUI::sendValueSupplied(){ QCopEnvelope e( service_channel, "valueSupplied(QString,QImage)" ); e << service_id << image_processor->image( QSize( service_width, service_height ) );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -