summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-09 02:08:42 (UTC)
committer llornkcor <llornkcor>2002-02-09 02:08:42 (UTC)
commiteca8d68c7cbc82b11879f03e0b6b4a5894cbe435 (patch) (unidiff)
tree6d6634ecf2d70e15d82b2474fa2e4f4eec51c555
parentcde778848f13e384e55e66117754578d12a5b1e2 (diff)
downloadopie-eca8d68c7cbc82b11879f03e0b6b4a5894cbe435.zip
opie-eca8d68c7cbc82b11879f03e0b6b4a5894cbe435.tar.gz
opie-eca8d68c7cbc82b11879f03e0b6b4a5894cbe435.tar.bz2
added screenshotapplet
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/screenshotapplet/screenshot.cpp189
-rw-r--r--core/applets/screenshotapplet/screenshot.h76
-rw-r--r--core/applets/screenshotapplet/screenshotapplet.pro13
-rw-r--r--core/applets/screenshotapplet/screenshotappletimpl.cpp64
-rw-r--r--core/applets/screenshotapplet/screenshotappletimpl.h44
5 files changed, 386 insertions, 0 deletions
diff --git a/core/applets/screenshotapplet/screenshot.cpp b/core/applets/screenshotapplet/screenshot.cpp
new file mode 100644
index 0000000..d70b57c
--- a/dev/null
+++ b/core/applets/screenshotapplet/screenshot.cpp
@@ -0,0 +1,189 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com
3** All rights reserved.
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12**
13**********************************************************************/
14
15#include "screenshot.h"
16#include <qapplication.h>
17
18#include <qpe/resource.h>
19#include <qpe/qpeapplication.h>
20#include <qpe/timestring.h>
21#include <qpe/resource.h>
22#include <qpe/config.h>
23#include <qpe/applnk.h>
24#include <qpe/config.h>
25
26
27#include <qfileinfo.h>
28#include <qpoint.h>
29#include <qpushbutton.h>
30#include <qpainter.h>
31#include <qcombobox.h>
32#include <qspinbox.h>
33#include <qslider.h>
34#include <qlayout.h>
35#include <qframe.h>
36#include <qpixmap.h>
37#include <qstring.h>
38#include <qfile.h>
39#include <qtimer.h>
40
41static char * snapshot_xpm[] = {
42"16 16 10 1",
43" c None",
44". c #000000",
45"+ c #00C000",
46"@ c #585858",
47"# c #808080",
48"$ c #00FF00",
49"% c #008000",
50"& c #00FFFF",
51"* c #FF0000",
52"= c #FFC0C0",
53" ",
54" ... ",
55" ..+++..@#. ",
56" .$++++++.#. ",
57" .%$$++++++. ",
58" .&%%$$++@***. ",
59" .$&$++$=**@+. ",
60" .+$$+++@*$%%. ",
61" .+++++%+++%%. ",
62" .%%++++..+%%. ",
63" ..%%+++++%%. ",
64" ..%%+++%%. ",
65" ..%%+%%. ",
66" ..%%.. ",
67" .. ",
68" "};
69
70
71ScreenshotControl::ScreenshotControl( QWidget *parent, const char *name )
72 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
73{
74 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
75// qDebug("screenshot control");
76 QVBoxLayout *vbox = new QVBoxLayout( this );
77// qDebug("new layout");
78 delaySpin = new QSpinBox( 0,60,1, this, "Spinner" );
79// qDebug("new spinbox");
80 delaySpin->setFocusPolicy( QWidget::NoFocus );
81 grabItButton= new QPushButton( this, "GrabButton" );
82// qDebug("new pushbutton");
83 grabItButton ->setFocusPolicy( QWidget::TabFocus );
84 grabItButton->setText("Snaphot");
85 vbox->setMargin( 6 );
86 vbox->setSpacing( 3 );
87 vbox->addWidget( delaySpin);
88 vbox->setMargin( 6 );
89 vbox->setSpacing( 3 );
90 vbox->addWidget( grabItButton);
91
92 setFixedHeight( 100 );
93 setFixedWidth( sizeHint().width() );
94 setFocusPolicy(QWidget::NoFocus);
95
96 grabTimer= new QTimer(this,"grab timer");
97// qDebug("newTimer");
98 connect( grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) );
99
100// Config cfg("Snapshot");
101// cfg.setGroup("General");
102// delaySpin->setValue(cfg.readNumEntry("delay",0));
103 connect( grabItButton, SIGNAL(released()), SLOT(slotGrab()) );
104
105}
106
107void ScreenshotControl::slotGrab()
108{
109// qDebug("SlotGrab");
110 hide();
111 if ( delaySpin->value() ) {
112 grabTimer->start( delaySpin->value() * 1000, true );
113 } else {
114 show();
115 }
116}
117
118
119void ScreenshotControl::grabTimerDone()
120{
121 performGrab();
122}
123
124void ScreenshotControl::savePixmap()
125{
126 DocLnk lnk;
127 QString fileName = "sc_"+TimeString::dateString( QDateTime::currentDateTime(),false,true);
128 fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),"");
129
130 fileName="/home/root/Documents/image/png/"+fileName+".png";
131 lnk.setFile(fileName); //sets File property
132 snapshot.save( fileName,"PNG");
133 qDebug("saving file "+fileName);
134 QFileInfo fi( fileName);
135 lnk.setName( fi.fileName()); //sets file name
136 if(!lnk.writeLink())
137 qDebug("Writing doclink did not work");
138
139 QPEApplication::beep();
140
141}
142
143void ScreenshotControl::performGrab()
144{
145 qDebug("grabbing screen");
146 grabTimer->stop();
147 snapshot = QPixmap::grabWindow( QPEApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height() );
148 show();
149 savePixmap();
150}
151
152void ScreenshotControl::setTime(int newTime)
153{
154 delaySpin->setValue(newTime);
155}
156
157//===========================================================================
158
159ScreenshotApplet::ScreenshotApplet( QWidget *parent, const char *name )
160 : QWidget( parent, name )
161{
162// qDebug("beginning applet");
163 setFixedHeight( 18 );
164 setFixedWidth( 14 );
165 vc = new ScreenshotControl;
166// qDebug("new screenshotapplet");
167}
168
169ScreenshotApplet::~ScreenshotApplet()
170{
171}
172
173void ScreenshotApplet::mousePressEvent( QMouseEvent *)
174{
175// if(!vc)
176 vc = new ScreenshotControl;
177 QPoint curPos = mapToGlobal( rect().topLeft() );
178 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 );
179 vc->show();
180
181}
182
183void ScreenshotApplet::paintEvent( QPaintEvent* )
184{
185 QPainter p(this);
186 qDebug("paint pixmap");
187 p.drawPixmap( 0, 1, ( const char** ) snapshot_xpm );
188
189}
diff --git a/core/applets/screenshotapplet/screenshot.h b/core/applets/screenshotapplet/screenshot.h
new file mode 100644
index 0000000..82800b9
--- a/dev/null
+++ b/core/applets/screenshotapplet/screenshot.h
@@ -0,0 +1,76 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com
3** All rights reserved.
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12**
13**********************************************************************/
14
15#ifndef __SCREENSHOT_APPLET_H__
16#define __SCREENSHOT_APPLET_H__
17
18
19
20#include <qwidget.h>
21#include <qframe.h>
22#include <qpixmap.h>
23#include <qguardedptr.h>
24#include <qtimer.h>
25
26class QComboBox;
27class QCheckBox;
28class QSpinBox;
29class QPushButton;
30//class QImage;
31
32class ScreenshotControl : public QFrame
33{
34 Q_OBJECT
35public:
36 ScreenshotControl( QWidget *parent=0, const char *name=0 );
37 void performGrab();
38
39public:
40 QPushButton *grabItButton;
41 QPixmap snapshot;
42 QTimer* grabTimer;
43 void slotSave();
44 void slotCopy();
45 void setTime(int newTime);
46
47 QSpinBox *delaySpin;
48private:
49private slots:
50 void slotGrab();
51 void savePixmap();
52 void grabTimerDone();
53};
54
55class ScreenshotApplet : public QWidget
56{
57 Q_OBJECT
58public:
59 ScreenshotApplet( QWidget *parent = 0, const char *name=0 );
60 ~ScreenshotApplet();
61 ScreenshotControl *vc;
62public slots:
63private:
64 void mousePressEvent( QMouseEvent * );
65 void paintEvent( QPaintEvent* );
66
67private:
68 QPixmap snapshotPixmap;
69private slots:
70
71
72};
73
74
75#endif // __SCREENSHOT_APPLET_H__
76
diff --git a/core/applets/screenshotapplet/screenshotapplet.pro b/core/applets/screenshotapplet/screenshotapplet.pro
new file mode 100644
index 0000000..095cce2
--- a/dev/null
+++ b/core/applets/screenshotapplet/screenshotapplet.pro
@@ -0,0 +1,13 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3HEADERS = screenshot.h screenshotappletimpl.h
4SOURCES = screenshot.cpp screenshotappletimpl.cpp
5TARGET = screenshotapplet
6DESTDIR = ../../plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += ../$(OPIEDIR)/include
9LIBS += -lqpe
10VERSION = 1.0.0
11MOC_DIR=opieobj
12OBJECTS_DIR=opieobj
13
diff --git a/core/applets/screenshotapplet/screenshotappletimpl.cpp b/core/applets/screenshotapplet/screenshotappletimpl.cpp
new file mode 100644
index 0000000..f1a9827
--- a/dev/null
+++ b/core/applets/screenshotapplet/screenshotappletimpl.cpp
@@ -0,0 +1,64 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "screenshot.h"
21#include "screenshotappletimpl.h"
22
23
24ScreenshotAppletImpl::ScreenshotAppletImpl()
25 : volume(0), ref(0)
26{
27}
28
29ScreenshotAppletImpl::~ScreenshotAppletImpl()
30{
31 delete volume;
32}
33
34QWidget *ScreenshotAppletImpl::applet( QWidget *parent )
35{
36 if ( !volume )
37 volume = new ScreenshotApplet( parent );
38 return volume;
39}
40
41int ScreenshotAppletImpl::position() const
42{
43 return 6;
44}
45
46QRESULT ScreenshotAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
47{
48 *iface = 0;
49 if ( uuid == IID_QUnknown )
50 *iface = this;
51 else if ( uuid == IID_TaskbarApplet )
52 *iface = this;
53
54 if ( *iface )
55 (*iface)->addRef();
56 return QS_OK;
57}
58
59Q_EXPORT_INTERFACE()
60{
61 Q_CREATE_INSTANCE( ScreenshotAppletImpl )
62}
63
64
diff --git a/core/applets/screenshotapplet/screenshotappletimpl.h b/core/applets/screenshotapplet/screenshotappletimpl.h
new file mode 100644
index 0000000..deca7a9
--- a/dev/null
+++ b/core/applets/screenshotapplet/screenshotappletimpl.h
@@ -0,0 +1,44 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SCREENSHOTAPPLETIMPL_H
21#define SCREENSHOTAPPLETIMPL_H
22
23#include <qpe/taskbarappletinterface.h>
24
25class ScreenshotApplet;
26
27class ScreenshotAppletImpl : public TaskbarAppletInterface
28{
29public:
30 ScreenshotAppletImpl();
31 virtual ~ScreenshotAppletImpl();
32
33 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
34 Q_REFCOUNT
35
36 virtual QWidget *applet( QWidget *parent );
37 virtual int position() const;
38
39private:
40 ScreenshotApplet *volume;
41 ulong ref;
42};
43
44#endif