kpixmapregionselectordialog.cpp
00001 /* 00002 This file is part of libtdepim. 00003 00004 Copyright (C) 2004 Antonio Larrosa <larrosa@kde.org 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "kpixmapregionselectordialog.h" 00023 #include <kdialogbase.h> 00024 #include <tqdialog.h> 00025 #include <tqdesktopwidget.h> 00026 #include <tdelocale.h> 00027 #include <kdialog.h> 00028 00029 using namespace KPIM; 00030 00031 KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog(TQWidget *parent, 00032 const char *name, bool modal ) : KDialogBase(parent, name, modal, i18n("Select Region of Image"), Help|Ok|Cancel, Ok, true ) 00033 { 00034 TQVBox *vbox=new TQVBox(this); 00035 new TQLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox); 00036 m_pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox); 00037 00038 vbox->setSpacing( KDialog::spacingHint() ); 00039 00040 setMainWidget(vbox); 00041 } 00042 00043 KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog() 00044 { 00045 } 00046 00047 TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent ) 00048 { 00049 KPixmapRegionSelectorDialog dialog(parent); 00050 00051 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); 00052 00053 TQDesktopWidget desktopWidget; 00054 TQRect screen=desktopWidget.availableGeometry(); 00055 dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( 00056 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); 00057 00058 int result = dialog.exec(); 00059 00060 TQRect rect; 00061 00062 if ( result == TQDialog::Accepted ) 00063 rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion(); 00064 00065 return rect; 00066 } 00067 00068 TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent ) 00069 { 00070 KPixmapRegionSelectorDialog dialog(parent); 00071 00072 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); 00073 dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight); 00074 00075 TQDesktopWidget desktopWidget; 00076 TQRect screen=desktopWidget.availableGeometry(); 00077 dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( 00078 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); 00079 00080 int result = dialog.exec(); 00081 00082 TQRect rect; 00083 00084 if ( result == TQDialog::Accepted ) 00085 rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion(); 00086 00087 return rect; 00088 } 00089 00090 TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, TQWidget *parent ) 00091 { 00092 KPixmapRegionSelectorDialog dialog(parent); 00093 00094 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); 00095 00096 TQDesktopWidget desktopWidget; 00097 TQRect screen=desktopWidget.availableGeometry(); 00098 dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( 00099 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); 00100 int result = dialog.exec(); 00101 00102 TQImage image; 00103 00104 if ( result == TQDialog::Accepted ) 00105 image = dialog.pixmapRegionSelectorWidget()->selectedImage(); 00106 00107 return image; 00108 } 00109 00110 TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent ) 00111 { 00112 KPixmapRegionSelectorDialog dialog(parent); 00113 00114 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); 00115 dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight); 00116 00117 TQDesktopWidget desktopWidget; 00118 TQRect screen=desktopWidget.availableGeometry(); 00119 dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( 00120 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); 00121 00122 int result = dialog.exec(); 00123 00124 TQImage image; 00125 00126 if ( result == TQDialog::Accepted ) 00127 image = dialog.pixmapRegionSelectorWidget()->selectedImage(); 00128 00129 return image; 00130 } 00131