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