SVN_SILENT made messages (.desktop file)
[kdegraphics.git] / ksnapshot / ksnapshot.h
blob8d75ff0d60d2c8fa4d58758ec88d56794ca749c5
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>
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.
25 #ifndef KSNAPSHOT_H
26 #define KSNAPSHOT_H
28 #include <QAction>
29 #include <QBitmap>
30 #include <QLabel>
31 #include <QPainter>
32 #include <QStyleOption>
33 #include <QTimer>
34 #include <QMouseEvent>
35 #include <QPixmap>
37 #include <kglobalsettings.h>
38 #include <kdialog.h>
39 #include <kservice.h>
40 #include <kurl.h>
41 #include "ksnapshotobject.h"
42 #include "snapshottimer.h"
44 class KSnapshotWidget;
45 class QMenu;
47 class KSnapshotServiceAction : public QAction
49 Q_OBJECT
50 public:
51 KSnapshotServiceAction(KService::Ptr s, QObject * parent)
52 : QAction(parent), service(s) {}
53 KSnapshotServiceAction(KService::Ptr s,
54 const QString & text,
55 QObject * parent)
56 : QAction(text, parent), service(s) {}
57 KSnapshotServiceAction(KService::Ptr s,
58 const QIcon & icon,
59 const QString & text,
60 QObject * parent)
61 : QAction(icon, text, parent), service(s) {}
63 KService::Ptr service;
66 class KSnapshotPreview : public QLabel
68 Q_OBJECT
70 public:
71 KSnapshotPreview(QWidget *parent)
72 : QLabel(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);
84 QBitmap mask(15, 15);
85 mask.clear();
86 QStyleOption o;
87 o.rect = QRect(0, 0, 15, 15);
90 QPainter p(&mask);
91 style()->drawControl(QStyle::CE_SizeGrip, &o, &p);
92 p.end();
93 handle.setMask(mask);
97 QPainter p(&handle);
98 style()->drawControl(QStyle::CE_SizeGrip, &o, &p);
99 p.end();
102 o.rect = QRect(pixmap.width() - 16, pixmap.height() - 16, 15, 15);
103 QPainter p(&pixmap);
104 p.drawPixmap(o.rect, handle);
105 p.end();
107 // hooray for making things like setPixmap not virtual! *sigh*
108 setPixmap(pixmap);
111 signals:
112 void startDrag();
114 protected:
115 void mousePressEvent(QMouseEvent * e)
117 if ( e->button() == Qt::LeftButton )
118 mClickPt = e->pos();
121 void mouseMoveEvent(QMouseEvent * e)
123 if (mClickPt != QPoint(0, 0) &&
124 (e->pos() - mClickPt).manhattanLength() > KGlobalSettings::dndEventDelay())
126 mClickPt = QPoint(0, 0);
127 emit startDrag();
131 void mouseReleaseEvent(QMouseEvent * /*e*/)
133 mClickPt = QPoint(0, 0);
136 QPoint mClickPt;
139 class KSnapshot : public KDialog, public KSnapshotObject
141 Q_OBJECT
143 public:
144 explicit KSnapshot(QWidget *parent= 0, KSnapshotObject::CaptureMode mode = FullScreen);
145 ~KSnapshot();
148 QString url() const { return filename.url(); }
150 public slots:
151 void slotGrab();
152 void slotSave();
153 void slotSaveAs();
154 void slotCopy();
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 );
160 void exit();
162 protected:
163 void reject() { close(); }
164 virtual void closeEvent( QCloseEvent * e );
165 void resizeEvent(QResizeEvent*);
166 bool eventFilter( QObject*, QEvent* );
167 virtual void refreshCaption();
169 private slots:
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 );
183 int delay() const;
184 bool includeDecorations() const;
185 int mode() const;
186 QPixmap preview();
187 int previewWidth() const;
188 int previewHeight() const;
190 public:
191 int grabMode() const;
192 int timeout() const;
194 private:
195 void performGrab();
196 void grabRegion();
197 SnapshotTimer grabTimer;
198 QTimer updateTimer;
199 QMenu* openMenu;
200 KSnapshotWidget *mainWidget;
201 bool modified;
204 #endif // KSNAPSHOT_H