2 * Copyright (C) 1997-2002 Richard J. Moore <rich@kde.org>
3 * Copyright (C) 2000 Matthias Ettrich <ettrich@troll.no>
4 * Copyright (C) 2002 Aaron J. Seigo <aseigo@kde.org>
5 * Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
6 * Copyright (C) 2004 Bernd Brandstetter <bbrand@freenet.de>
7 * Copyright (C) 2006 Urs Wolfer <uwolfer @ kde.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
32 #include <QStyleOption>
34 #include <QMouseEvent>
37 #include <kglobalsettings.h>
41 #include "ksnapshotobject.h"
42 #include "snapshottimer.h"
44 class KSnapshotWidget
;
47 class KSnapshotServiceAction
: public QAction
51 KSnapshotServiceAction(KService::Ptr s
, QObject
* parent
)
52 : QAction(parent
), service(s
) {}
53 KSnapshotServiceAction(KService::Ptr s
,
56 : QAction(text
, parent
), service(s
) {}
57 KSnapshotServiceAction(KService::Ptr s
,
61 : QAction(icon
, text
, parent
), service(s
) {}
63 KService::Ptr service
;
66 class KSnapshotPreview
: public QLabel
71 KSnapshotPreview(QWidget
*parent
)
74 setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
75 setCursor(Qt::OpenHandCursor
);
77 virtual ~KSnapshotPreview() {}
79 void setPreview(QPixmap pixmap
)
81 // if this looks convoluted, that's because it is. drawing a PE_SizeGrip
82 // does unexpected things when painting directly onto the pixmap
83 QPixmap
handle(15, 15);
87 o
.rect
= QRect(0, 0, 15, 15);
91 style()->drawControl(QStyle::CE_SizeGrip
, &o
, &p
);
98 style()->drawControl(QStyle::CE_SizeGrip
, &o
, &p
);
102 o
.rect
= QRect(pixmap
.width() - 16, pixmap
.height() - 16, 15, 15);
104 p
.drawPixmap(o
.rect
, handle
);
107 // hooray for making things like setPixmap not virtual! *sigh*
115 void mousePressEvent(QMouseEvent
* e
)
117 if ( e
->button() == Qt::LeftButton
)
121 void mouseMoveEvent(QMouseEvent
* e
)
123 if (mClickPt
!= QPoint(0, 0) &&
124 (e
->pos() - mClickPt
).manhattanLength() > KGlobalSettings::dndEventDelay())
126 mClickPt
= QPoint(0, 0);
131 void mouseReleaseEvent(QMouseEvent
* /*e*/)
133 mClickPt
= QPoint(0, 0);
139 class KSnapshot
: public KDialog
, public KSnapshotObject
144 explicit KSnapshot(QWidget
*parent
= 0, KSnapshotObject::CaptureMode mode
= FullScreen
);
148 QString
url() const { return filename
.url(); }
155 void slotOpen(const QString
& application
);
156 void slotMovePointer( int x
, int y
);
157 void setTime( int newTime
);
158 void setURL( const QString
&newURL
);
159 void setGrabMode( int m
);
163 void reject() { close(); }
164 virtual void closeEvent( QCloseEvent
* e
);
165 void resizeEvent(QResizeEvent
*);
166 bool eventFilter( QObject
*, QEvent
* );
167 virtual void refreshCaption();
170 void slotOpen(QAction
*);
171 void slotPopulateOpenMenu();
172 void grabTimerDone();
173 void slotDragSnapshot();
174 void updateCaption();
175 void updatePreview();
176 void slotRegionGrabbed( const QPixmap
& );
177 void slotWindowGrabbed( const QPixmap
& );
178 void slotModeChanged( int mode
);
179 void setPreview( const QPixmap
&pm
);
180 void setDelay( int i
);
181 void setIncludeDecorations( bool b
);
182 void setMode( int mode
);
184 bool includeDecorations() const;
187 int previewWidth() const;
188 int previewHeight() const;
191 int grabMode() const;
197 SnapshotTimer grabTimer
;
200 KSnapshotWidget
*mainWidget
;
204 #endif // KSNAPSHOT_H