1/*
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>
8 *
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.
13 *
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.
18 *
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.
23 */
24
25#ifndef KSNAPSHOT_H
26#define KSNAPSHOT_H
27
28#include <QAction>
29#include <QTimer>
30#include <QPixmap>
31
32#include <kglobalsettings.h>
33#include <kdialog.h>
34#include <kservice.h>
35#include <kurl.h>
36#include "ksnapshotobject.h"
37#include "snapshottimer.h"
38
39#include <config-ksnapshot.h>
40
41class KSnapshotWidget;
42class QMenu;
43
44#ifdef KIPI_FOUND
45#include "ksnapshotimagecollectionshared.h"
46#include <libkipi/pluginloader.h>
47#endif
48
49class KSnapshotServiceAction : public QAction
50{
51 Q_OBJECT
52 public:
53 KSnapshotServiceAction(KService::Ptr s, QObject * parent)
54 : QAction(parent), service(s) {}
55 KSnapshotServiceAction(KService::Ptr s,
56 const QString & text,
57 QObject * parent)
58 : QAction(text, parent), service(s) {}
59 KSnapshotServiceAction(KService::Ptr s,
60 const QIcon & icon,
61 const QString & text,
62 QObject * parent)
63 : QAction(icon, text, parent), service(s) {}
64
65 KService::Ptr service;
66};
67
68class KSnapshot : public KDialog, public KSnapshotObject
69{
70 Q_OBJECT
71
72public:
73 explicit KSnapshot(QWidget *parent= 0, KSnapshotObject::CaptureMode mode = FullScreen);
74 ~KSnapshot();
75
76
77 QString url() const { return filename.url(); }
78
79public slots:
80 void slotGrab();
81 void slotSave();
82 void slotSaveAs();
83 void slotCopy();
84 void slotOpen(const QString& application);
85 void slotMovePointer( int x, int y );
86 void setTime( int newTime );
87 void setURL( const QString &newURL );
88 void setGrabMode( int m );
89 void exit();
90
91protected:
92 void reject() { close(); }
93 virtual void closeEvent( QCloseEvent * e );
94 void resizeEvent(QResizeEvent*);
95 bool eventFilter( QObject*, QEvent* );
96 virtual void refreshCaption();
97
98private slots:
99 void slotOpen(QAction*);
100 void slotPopulateOpenMenu();
101 void grabTimerDone();
102 void slotDragSnapshot();
103 void updateCaption();
104 void updatePreview();
105 void slotRegionGrabbed( const QPixmap & );
106 void slotRegionUpdated( const QRect & );
107 void slotFreeRegionUpdated( const QPolygon & );
108 void slotWindowGrabbed( const QPixmap & );
109 void slotModeChanged( int mode );
110 void setPreview( const QPixmap &pm );
111 void setDelay( int i );
112 void setIncludeDecorations( bool b );
113 void setIncludePointer( bool b );
114 bool includePointer() const;
115 void setMode( int mode );
116 int delay() const;
117 bool includeDecorations() const;
118 int mode() const;
119 QPixmap preview();
120 int previewWidth() const;
121 int previewHeight() const;
122 void startUndelayedGrab();
123 void slotScreenshotReceived(qulonglong handle);
124
125public:
126 int grabMode() const;
127 int timeout() const;
128
129private:
130 KUrl urlToOpen(bool *isTempfile = 0);
131 void performGrab();
132 void grabPointerImage(int offsetx, int offsety);
133 void grabRegion();
134 void grabFreeRegion();
135
136 SnapshotTimer grabTimer;
137 QTimer updateTimer;
138 QMenu* openMenu;
139 KSnapshotWidget *mainWidget;
140 bool modified;
141 QPoint savedPosition;
142 bool haveXFixes;
143 bool includeAlpha;
144 QPolygon lastFreeRegion;
145 QRect lastRegion;
146
147#ifdef KIPI_FOUND
148 KIPI::PluginLoader* mPluginLoader;
149 friend KUrl::List KSnapshotImageCollectionShared::images();
150#endif
151};
152
153#endif // KSNAPSHOT_H
154