• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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(KPixmapRegionSelectorDialog * parent)
00036         : pixmapSelectorWidget( 0 ), q(parent)
00037     {
00038     }
00039 
00040     KPixmapRegionSelectorWidget *pixmapSelectorWidget;
00041     KPixmapRegionSelectorDialog *q;
00042 
00043     void init() {
00044         //When the image is rotated we need to enforce the maximum width&height into the
00045         //KPixmapRegionSelectorWidget; in order to avoid the dialog to get out of the screen
00046         q->connect(pixmapSelectorWidget, SIGNAL(pixmapRotated()), q, SLOT(_k_adjustPixmapSize()));
00047     }
00048 
00049     void _k_adjustPixmapSize() {
00050         if (pixmapSelectorWidget) {
00051             //Set maximum size for picture
00052             QDesktopWidget desktopWidget;
00053             QRect screen = desktopWidget.availableGeometry();
00054             pixmapSelectorWidget->setMaximumWidgetSize(
00055                 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
00056         }
00057     }
00058 };
00059 
00060 KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog( QWidget *parent )
00061   : KDialog( parent ),
00062     d( new Private(this) )
00063 {
00064   setCaption( i18n("Select Region of Image") );
00065   setButtons( Help|Ok|Cancel );
00066 
00067   KVBox *vbox=new KVBox(this);
00068   new QLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox);
00069   d->pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox);
00070 
00071   vbox->setSpacing( -1 );
00072 
00073   setMainWidget(vbox);
00074 
00075   d->init();
00076 }
00077 
00078 KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog()
00079 {
00080   delete d;
00081 }
00082 
00083 KPixmapRegionSelectorWidget *KPixmapRegionSelectorDialog::pixmapRegionSelectorWidget() const
00084 {
00085   return d->pixmapSelectorWidget;
00086 }
00087 
00088 void KPixmapRegionSelectorDialog::adjustRegionSelectorWidgetSizeToFitScreen()
00089 {
00090   d->_k_adjustPixmapSize();
00091 }
00092 
00093 QRect KPixmapRegionSelectorDialog::getSelectedRegion(const QPixmap &pixmap, QWidget *parent )
00094 {
00095   KPixmapRegionSelectorDialog dialog(parent);
00096 
00097   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00098   dialog.adjustRegionSelectorWidgetSizeToFitScreen();
00099 
00100   int result = dialog.exec();
00101 
00102   QRect rect;
00103 
00104   if ( result == QDialog::Accepted )
00105     rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion();
00106 
00107   return rect;
00108 }
00109 
00110 QRect KPixmapRegionSelectorDialog::getSelectedRegion(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent )
00111 {
00112   KPixmapRegionSelectorDialog dialog(parent);
00113 
00114   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00115   dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
00116   dialog.adjustRegionSelectorWidgetSizeToFitScreen();
00117 
00118   int result = dialog.exec();
00119 
00120   QRect rect;
00121 
00122   if ( result == QDialog::Accepted )
00123     rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion();
00124 
00125   return rect;
00126 }
00127 
00128 QImage KPixmapRegionSelectorDialog::getSelectedImage(const QPixmap &pixmap, QWidget *parent )
00129 {
00130   KPixmapRegionSelectorDialog dialog(parent);
00131 
00132   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00133   dialog.adjustRegionSelectorWidgetSizeToFitScreen();
00134 
00135   int result = dialog.exec();
00136 
00137   QImage image;
00138 
00139   if ( result == QDialog::Accepted )
00140     image = dialog.pixmapRegionSelectorWidget()->selectedImage();
00141 
00142   return image;
00143 }
00144 
00145 QImage KPixmapRegionSelectorDialog::getSelectedImage(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent )
00146 {
00147   KPixmapRegionSelectorDialog dialog(parent);
00148 
00149   dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
00150   dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
00151   dialog.adjustRegionSelectorWidgetSizeToFitScreen();
00152 
00153   int result = dialog.exec();
00154 
00155   QImage image;
00156 
00157   if ( result == QDialog::Accepted )
00158     image = dialog.pixmapRegionSelectorWidget()->selectedImage();
00159 
00160   return image;
00161 }
00162 
00163 #include "kpixmapregionselectordialog.moc"

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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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