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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • 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"
KPixmapRegionSelectorDialog
A dialog that uses a KPixmapRegionSelectorWidget to allow the user to select a region of an image...
Definition: kpixmapregionselectordialog.h:44
kdialog.h
KPixmapRegionSelectorDialog::adjustRegionSelectorWidgetSizeToFitScreen
void adjustRegionSelectorWidgetSizeToFitScreen()
Definition: kpixmapregionselectordialog.cpp:88
i18n
QString i18n(const char *text)
KVBox
A container widget which arranges its children vertically.
Definition: kvbox.h:36
KPixmapRegionSelectorDialog::getSelectedImage
static QImage getSelectedImage(const QPixmap &pixmap, QWidget *parent=0L)
Creates a modal dialog, lets the user to select a region of the pixmap and returns when the dialog is...
Definition: kpixmapregionselectordialog.cpp:128
kpixmapregionselectordialog.h
KDialog::Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
Definition: kdialog.h:144
QWidget
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:128
klocale.h
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
KPixmapRegionSelectorWidget::unzoomedSelectedRegion
QRect unzoomedSelectedRegion() const
Returns the selected region ( in unzoomed, original pixmap coordinates )
Definition: kpixmapregionselectorwidget.cpp:464
KPixmapRegionSelectorDialog::getSelectedRegion
static QRect getSelectedRegion(const QPixmap &pixmap, QWidget *parent=0L)
Creates a modal dialog, lets the user to select a region of the pixmap and returns when the dialog is...
Definition: kpixmapregionselectordialog.cpp:93
KPixmapRegionSelectorWidget::setPixmap
void setPixmap(const QPixmap &pixmap)
Sets the pixmap which will be shown for the user to select a region from.
Definition: kpixmapregionselectorwidget.cpp:113
kpixmapregionselectorwidget.h
KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog
~KPixmapRegionSelectorDialog()
The destructor of the dialog.
Definition: kpixmapregionselectordialog.cpp:78
KPixmapRegionSelectorWidget
KPixmapRegionSelectorWidget is a widget that shows a picture and provides the user with a friendly wa...
Definition: kpixmapregionselectorwidget.h:44
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
kvbox.h
KDialog::Help
Show Help button. (this button will run the help set with setHelp)
Definition: kdialog.h:139
KDialog::Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted) ...
Definition: kdialog.h:141
QRect
QLabel
KHBox::setSpacing
void setSpacing(int space)
Sets the spacing between the child widgets to space.
Definition: khbox.cpp:98
KPixmapRegionSelectorWidget::selectedImage
QImage selectedImage() const
Definition: kpixmapregionselectorwidget.cpp:472
KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog
KPixmapRegionSelectorDialog(QWidget *parent=0)
The constructor of an empty KPixmapRegionSelectorDialog, you have to call later the setPixmap method ...
Definition: kpixmapregionselectordialog.cpp:60
KPixmapRegionSelectorWidget::setSelectionAspectRatio
void setSelectionAspectRatio(int width, int height)
Sets the aspect ration that the selected subimage should have.
Definition: kpixmapregionselectorwidget.cpp:478
KPixmapRegionSelectorDialog::pixmapRegionSelectorWidget
KPixmapRegionSelectorWidget * pixmapRegionSelectorWidget() const
Definition: kpixmapregionselectordialog.cpp:83
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:15 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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