• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kpixmapregionselectordialog.cpp

Go to the documentation of this file.
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 
00022 #include <QtGui/QDialog>
00023 #include <QtGui/QDesktopWidget>
00024 #include <QImage>
00025 #include <QtGui/QLabel>
00026 
00027 #include <klocale.h>
00028 #include <kdialog.h>
00029 #include <kpixmapregionselectorwidget.h>
00030 #include <kvbox.h>
00031 
00032 class KPixmapRegionSelectorDialog::Private
00033 {
00034 public:
00035     Private()
00036         : pixmapSelectorWidget( 0 )
00037     {
00038     }
00039 
00040     KPixmapRegionSelectorWidget *pixmapSelectorWidget;
00041 };
00042 
00043 KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog( QWidget *parent )
00044   : KDialog( parent ),
00045     d( new Private )
00046 {
00047   setCaption( i18n("Select Region of Image") );
00048   setButtons( Help|Ok|Cancel );
00049   showButtonSeparator( true );
00050 
00051   KVBox *vbox=new KVBox(this);
00052   new QLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox);
00053   d->pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox);
00054 
00055   vbox->setSpacing( KDialog::spacingHint() );
00056 
00057   setMainWidget(vbox);
00058 }
00059 
00060 KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog()
00061 {
00062   delete d;
00063 }
00064 
00065 KPixmapRegionSelectorWidget *KPixmapRegionSelectorDialog::pixmapRegionSelectorWidget() const
00066 {
00067     return d->pixmapSelectorWidget;
00068 }
00069 
00070 QRect KPixmapRegionSelectorDialog::getSelectedRegion(const QPixmap &pixmap, QWidget *parent )
00071 {
00072   KPixmapRegionSelectorDialog dialog(parent);
00073 
00074   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00075 
00076   QDesktopWidget desktopWidget;
00077   QRect screen=desktopWidget.availableGeometry();
00078   dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize(
00079         (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
00080 
00081   int result = dialog.exec();
00082 
00083   QRect rect;
00084 
00085   if ( result == QDialog::Accepted )
00086     rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion();
00087 
00088   return rect;
00089 }
00090 
00091 QRect KPixmapRegionSelectorDialog::getSelectedRegion(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent )
00092 {
00093   KPixmapRegionSelectorDialog dialog(parent);
00094 
00095   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00096   dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
00097 
00098   QDesktopWidget desktopWidget;
00099   QRect screen=desktopWidget.availableGeometry();
00100   dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize(
00101         (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
00102 
00103   int result = dialog.exec();
00104 
00105   QRect rect;
00106 
00107   if ( result == QDialog::Accepted )
00108     rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion();
00109 
00110   return rect;
00111 }
00112 
00113 QImage KPixmapRegionSelectorDialog::getSelectedImage(const QPixmap &pixmap, QWidget *parent )
00114 {
00115   KPixmapRegionSelectorDialog dialog(parent);
00116 
00117   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00118 
00119   QDesktopWidget desktopWidget;
00120   QRect screen=desktopWidget.availableGeometry();
00121   dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize(
00122         (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
00123   int result = dialog.exec();
00124 
00125   QImage image;
00126 
00127   if ( result == QDialog::Accepted )
00128     image = dialog.pixmapRegionSelectorWidget()->selectedImage();
00129 
00130   return image;
00131 }
00132 
00133 QImage KPixmapRegionSelectorDialog::getSelectedImage(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent )
00134 {
00135   KPixmapRegionSelectorDialog dialog(parent);
00136 
00137   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00138   dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
00139 
00140   QDesktopWidget desktopWidget;
00141   QRect screen=desktopWidget.availableGeometry();
00142   dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize(
00143         (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
00144 
00145   int result = dialog.exec();
00146 
00147   QImage image;
00148 
00149   if ( result == QDialog::Accepted )
00150     image = dialog.pixmapRegionSelectorWidget()->selectedImage();
00151 
00152   return image;
00153 }
00154 

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal