• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • dialogs
kpixmapregionselectordialog.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2004 Antonio Larrosa <larrosa@kde.org
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kpixmapregionselectordialog.h"
21 
22 #include <QtGui/QDialog>
23 #include <QtGui/QDesktopWidget>
24 #include <QImage>
25 #include <QtGui/QLabel>
26 
27 #include <klocale.h>
28 #include <kdialog.h>
29 #include <kpixmapregionselectorwidget.h>
30 #include <kvbox.h>
31 
32 class KPixmapRegionSelectorDialog::Private
33 {
34 public:
35  Private(KPixmapRegionSelectorDialog * parent)
36  : pixmapSelectorWidget( 0 ), q(parent)
37  {
38  }
39 
40  KPixmapRegionSelectorWidget *pixmapSelectorWidget;
41  KPixmapRegionSelectorDialog *q;
42 
43  void init() {
44  //When the image is rotated we need to enforce the maximum width&height into the
45  //KPixmapRegionSelectorWidget; in order to avoid the dialog to get out of the screen
46  q->connect(pixmapSelectorWidget, SIGNAL(pixmapRotated()), q, SLOT(_k_adjustPixmapSize()));
47  }
48 
49  void _k_adjustPixmapSize() {
50  if (pixmapSelectorWidget) {
51  //Set maximum size for picture
52  QDesktopWidget desktopWidget;
53  QRect screen = desktopWidget.availableGeometry();
54  pixmapSelectorWidget->setMaximumWidgetSize(
55  (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
56  }
57  }
58 };
59 
60 KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog( QWidget *parent )
61  : KDialog( parent ),
62  d( new Private(this) )
63 {
64  setCaption( i18n("Select Region of Image") );
65  setButtons( Help|Ok|Cancel );
66 
67  KVBox *vbox=new KVBox(this);
68  new QLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox);
69  d->pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox);
70 
71  vbox->setSpacing( -1 );
72 
73  setMainWidget(vbox);
74 
75  d->init();
76 }
77 
78 KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog()
79 {
80  delete d;
81 }
82 
83 KPixmapRegionSelectorWidget *KPixmapRegionSelectorDialog::pixmapRegionSelectorWidget() const
84 {
85  return d->pixmapSelectorWidget;
86 }
87 
88 void KPixmapRegionSelectorDialog::adjustRegionSelectorWidgetSizeToFitScreen()
89 {
90  d->_k_adjustPixmapSize();
91 }
92 
93 QRect KPixmapRegionSelectorDialog::getSelectedRegion(const QPixmap &pixmap, QWidget *parent )
94 {
95  KPixmapRegionSelectorDialog dialog(parent);
96 
97  dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
98  dialog.adjustRegionSelectorWidgetSizeToFitScreen();
99 
100  int result = dialog.exec();
101 
102  QRect rect;
103 
104  if ( result == QDialog::Accepted )
105  rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion();
106 
107  return rect;
108 }
109 
110 QRect KPixmapRegionSelectorDialog::getSelectedRegion(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent )
111 {
112  KPixmapRegionSelectorDialog dialog(parent);
113 
114  dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
115  dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
116  dialog.adjustRegionSelectorWidgetSizeToFitScreen();
117 
118  int result = dialog.exec();
119 
120  QRect rect;
121 
122  if ( result == QDialog::Accepted )
123  rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion();
124 
125  return rect;
126 }
127 
128 QImage KPixmapRegionSelectorDialog::getSelectedImage(const QPixmap &pixmap, QWidget *parent )
129 {
130  KPixmapRegionSelectorDialog dialog(parent);
131 
132  dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
133  dialog.adjustRegionSelectorWidgetSizeToFitScreen();
134 
135  int result = dialog.exec();
136 
137  QImage image;
138 
139  if ( result == QDialog::Accepted )
140  image = dialog.pixmapRegionSelectorWidget()->selectedImage();
141 
142  return image;
143 }
144 
145 QImage KPixmapRegionSelectorDialog::getSelectedImage(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent )
146 {
147  KPixmapRegionSelectorDialog dialog(parent);
148 
149  dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
150  dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
151  dialog.adjustRegionSelectorWidgetSizeToFitScreen();
152 
153  int result = dialog.exec();
154 
155  QImage image;
156 
157  if ( result == QDialog::Accepted )
158  image = dialog.pixmapRegionSelectorWidget()->selectedImage();
159 
160  return image;
161 }
162 
163 #include "kpixmapregionselectordialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Apr 16 2013 19:13:48 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.10.2 API Reference

Skip menu "kdelibs-4.10.2 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal