libtdepim

kpixmapregionselectordialog.cpp
1/*
2 This file is part of libtdepim.
3
4 Copyright (C) 2004 Antonio Larrosa <larrosa@kde.org
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "kpixmapregionselectordialog.h"
23#include <kdialogbase.h>
24#include <tqdialog.h>
25#include <tqdesktopwidget.h>
26#include <tdelocale.h>
27#include <kdialog.h>
28
29using namespace KPIM;
30
31KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog(TQWidget *parent,
32 const char *name, bool modal ) : KDialogBase(parent, name, modal, i18n("Select Region of Image"), Help|Ok|Cancel, Ok, true )
33{
34 TQVBox *vbox=new TQVBox(this);
35 new TQLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox);
36 m_pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox);
37
38 vbox->setSpacing( KDialog::spacingHint() );
39
40 setMainWidget(vbox);
41}
42
44{
45}
46
47TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent )
48{
49 KPixmapRegionSelectorDialog dialog(parent);
50
51 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
52
53 TQDesktopWidget desktopWidget;
54 TQRect screen=desktopWidget.availableGeometry();
56 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
57
58 int result = dialog.exec();
59
60 TQRect rect;
61
62 if ( result == TQDialog::Accepted )
64
65 return rect;
66}
67
68TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent )
69{
70 KPixmapRegionSelectorDialog dialog(parent);
71
72 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
73 dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
74
75 TQDesktopWidget desktopWidget;
76 TQRect screen=desktopWidget.availableGeometry();
78 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
79
80 int result = dialog.exec();
81
82 TQRect rect;
83
84 if ( result == TQDialog::Accepted )
86
87 return rect;
88}
89
90TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, TQWidget *parent )
91{
92 KPixmapRegionSelectorDialog dialog(parent);
93
94 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
95
96 TQDesktopWidget desktopWidget;
97 TQRect screen=desktopWidget.availableGeometry();
99 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
100 int result = dialog.exec();
101
102 TQImage image;
103
104 if ( result == TQDialog::Accepted )
105 image = dialog.pixmapRegionSelectorWidget()->selectedImage();
106
107 return image;
108}
109
110TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent )
111{
112 KPixmapRegionSelectorDialog dialog(parent);
113
114 dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap);
115 dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight);
116
117 TQDesktopWidget desktopWidget;
118 TQRect screen=desktopWidget.availableGeometry();
120 (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5));
121
122 int result = dialog.exec();
123
124 TQImage image;
125
126 if ( result == TQDialog::Accepted )
127 image = dialog.pixmapRegionSelectorWidget()->selectedImage();
128
129 return image;
130}
131
A dialog that uses a KPixmapRegionSelectorWidget to allow the user to select a region of an image.
KPIM::KPixmapRegionSelectorWidget * pixmapRegionSelectorWidget() const
~KPixmapRegionSelectorDialog()
The destructor of the dialog.
static TQRect getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent=0L)
Creates a modal dialog, lets the user to select a region of the pixmap and returns when the dialog is...
static TQImage getSelectedImage(const TQPixmap &pixmap, TQWidget *parent=0L)
Creates a modal dialog, lets the user to select a region of the pixmap and returns when the dialog is...
KPixmapRegionSelectorWidget is a widget that shows a picture and provides the user with a friendly wa...
TQRect unzoomedSelectedRegion() const
Returns the selected region ( in unzoomed, original pixmap coordinates )
void setSelectionAspectRatio(int width, int height)
Sets the aspect ration that the selected subimage should have.
void setPixmap(const TQPixmap &pixmap)
Sets the pixmap which will be shown for the user to select a region from.
void setMaximumWidgetSize(int width, int height)
Sets the maximum size for the widget.
TDEPIM classes for drag and drop of mails.