• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • indi
streamwg.cpp
Go to the documentation of this file.
1 /* Stream Widget
2  Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
3 
4  This application is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  2004-03-16: A class to handle video streaming.
10  */
11 
12 #include "streamwg.h"
13 #include "indistd.h"
14 #include "Options.h"
15 
16 #include <kmessagebox.h>
17 #include <klocale.h>
18 #include <kdebug.h>
19 #include <kpushbutton.h>
20 #include <kiconloader.h>
21 #include <ktemporaryfile.h>
22 #include <kio/netaccess.h>
23 #include <kfiledialog.h>
24 #include <kcombobox.h>
25 #include <kurl.h>
26 
27 #include <QRgb>
28 #include <qsocketnotifier.h>
29 #include <qimage.h>
30 #include <qpainter.h>
31 #include <qstringlist.h>
32 #include <qdir.h>
33 #include <qlayout.h>
34 #include <QResizeEvent>
35 #include <QPaintEvent>
36 #include <QCloseEvent>
37 #include <QByteArray>
38 #include <QImageWriter>
39 
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <fcntl.h>
43 
44 StreamWG::StreamWG(QWidget * parent) : QWidget(parent)
45 {
46 
47  setupUi(this);
48  streamWidth = streamHeight = -1;
49  processStream = colorFrame = false;
50 
51  streamFrame = new VideoWG(videoFrame);
52 
53  playPix = KIcon( "media-playback-start" );
54  pausePix = KIcon( "media-playback-pause" );
55  capturePix = KIcon( "media-record" );
56 
57  foreach (const QByteArray &format, QImageWriter::supportedImageFormats())
58  imgFormatCombo->addItem(QString(format));
59 
60  playB->setIcon(pausePix);
61  captureB->setIcon(capturePix);
62 
63  connect(playB, SIGNAL(clicked()), this, SLOT(playPressed()));
64  connect(captureB, SIGNAL(clicked()), this, SLOT(captureImage()));
65 }
66 
67 StreamWG::~StreamWG()
68 {
69  // delete streamBuffer;
70 }
71 
72 void StreamWG::closeEvent ( QCloseEvent * e )
73 {
74  processStream = false;
75  e->accept();
76 }
77 
78 void StreamWG::setColorFrame(bool color)
79 {
80  colorFrame = color;
81 }
82 
83 void StreamWG::enableStream(bool enable)
84 {
85  if (enable)
86  {
87  processStream = true;
88  show();
89  }
90  else
91  {
92  processStream = false;
93  playB->setIcon(pausePix);
94  hide();
95  }
96 
97 }
98 
99 void StreamWG::setSize(int wd, int ht)
100 {
101 
102  streamWidth = wd;
103  streamHeight = ht;
104 
105  streamFrame->totalBaseCount = wd * ht;
106 
107  resize(wd + layout()->margin() * 2 , ht + playB->height() + layout()->margin() * 4 + layout()->spacing());
108  streamFrame->resize(wd, ht);
109 }
110 
111 void StreamWG::resizeEvent(QResizeEvent *ev)
112 {
113  streamFrame->resize(ev->size().width() - layout()->margin() * 2, ev->size().height() - playB->height() - layout()->margin() * 4 - layout()->spacing());
114 
115 }
116 
117 void StreamWG::playPressed()
118 {
119 
120  if (processStream)
121  {
122  playB->setIcon(playPix);
123  processStream = false;
124  }
125  else
126  {
127  playB->setIcon(pausePix);
128  processStream = true;
129  }
130 
131 }
132 
133 void StreamWG::newFrame(unsigned char *buffer, int buffSiz, int w, int h)
134 {
135  streamFrame->newFrame(buffer, buffSiz, w, h);
136 }
137 
138 void StreamWG::captureImage()
139 {
140  QString fname;
141  QString fmt;
142  KUrl currentFileURL;
143  QString currentDir = Options::fitsDir();
144  KTemporaryFile tmpfile;
145  tmpfile.open();
146 
147  fmt = imgFormatCombo->currentText();
148 
149  currentFileURL = KFileDialog::getSaveUrl( currentDir, fmt );
150 
151  if (currentFileURL.isEmpty()) return;
152 
153  if ( currentFileURL.isValid() )
154  {
155  currentDir = currentFileURL.directory();
156 
157  if ( currentFileURL.isLocalFile() )
158  fname = currentFileURL.path();
159  else
160  fname = tmpfile.fileName();
161 
162  if (fname.right(fmt.length()).toLower() != fmt.toLower())
163  {
164  fname += '.';
165  fname += fmt.toLower();
166  }
167 
168  streamFrame->kPix.save(fname, fmt.toAscii());
169 
170  //set rwx for owner, rx for group, rx for other
171  chmod( fname.toAscii(), S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH );
172 
173  if ( tmpfile.fileName() == fname )
174  { //need to upload to remote location
175 
176  if ( ! KIO::NetAccess::upload( tmpfile.fileName(), currentFileURL, (QWidget*) 0 ) )
177  {
178  QString message = i18n( "Could not upload image to remote location: %1", currentFileURL.prettyUrl() );
179  KMessageBox::sorry( 0, message, i18n( "Could not upload file" ) );
180  }
181  }
182  }
183  else
184  {
185  QString message = i18n( "Invalid URL: %1", currentFileURL.url() );
186  KMessageBox::sorry( 0, message, i18n( "Invalid URL" ) );
187  }
188 
189 }
190 
191 
192 VideoWG::VideoWG(QWidget * parent) : QFrame(parent)
193 {
194  setAttribute(Qt::WA_OpaquePaintEvent);
195  streamImage = NULL;
196  //grayTable=new QRgb[256];
197  grayTable.resize(256);
198  for (int i=0;i<256;i++)
199  grayTable[i]=qRgb(i,i,i);
200 }
201 
202 VideoWG::~VideoWG()
203 {
204  delete (streamImage);
205  //delete [] (grayTable);
206 }
207 
208 void VideoWG::newFrame(unsigned char *buffer, int buffSiz, int w, int h)
209 {
210 
211  // TODO: This is highly inefficient. Need to be replaced with a direct blit.
212  if (buffSiz > totalBaseCount)
213  streamImage = new QImage(buffer, w, h, QImage::Format_RGB32);
214  else
215  {
216  streamImage = new QImage(buffer, w, h, QImage::Format_Indexed8);
217  streamImage->setColorTable(grayTable);
218  }
219 
220  update();
221 }
222 
223 void VideoWG::paintEvent(QPaintEvent * /*ev*/)
224 {
225 
226  if (streamImage)
227  {
228  if (streamImage->isNull()) return;
229  kPix = QPixmap::fromImage(streamImage->scaled(width(), height(), Qt::KeepAspectRatio));
230  delete (streamImage);
231  streamImage = NULL;
232  }
233 
234  QPainter p(this);
235  p.drawPixmap(0, 0, kPix);
236  p.end();
237 
238 }
239 
240 #include "streamwg.moc"
StreamWG::setColorFrame
void setColorFrame(bool color)
Definition: streamwg.cpp:78
VideoWG::paintEvent
void paintEvent(QPaintEvent *ev)
Definition: streamwg.cpp:223
StreamWG::VideoWG
friend class VideoWG
Definition: streamwg.h:41
StreamWG::closeEvent
void closeEvent(QCloseEvent *e)
Definition: streamwg.cpp:72
streamwg.h
StreamWG::newFrame
void newFrame(unsigned char *buffer, int buffSiz, int w, int h)
Definition: streamwg.cpp:133
QWidget
StreamWG::StreamWG
StreamWG(QWidget *parent=0)
Definition: streamwg.cpp:44
VideoWG::VideoWG
VideoWG(QWidget *parent=0)
Definition: streamwg.cpp:192
Options::fitsDir
static QString fitsDir()
Get FITS Default directory.
Definition: Options.h:695
VideoWG::newFrame
void newFrame(unsigned char *buffer, int buffSiz, int w, int h)
Definition: streamwg.cpp:208
StreamWG::playPressed
void playPressed()
Definition: streamwg.cpp:117
VideoWG::~VideoWG
~VideoWG()
Definition: streamwg.cpp:202
StreamWG::~StreamWG
~StreamWG()
Definition: streamwg.cpp:67
Options.h
StreamWG::enableStream
void enableStream(bool enable)
Definition: streamwg.cpp:83
indistd.h
StreamWG::captureImage
void captureImage()
Definition: streamwg.cpp:138
StreamWG::setSize
void setSize(int wd, int ht)
Definition: streamwg.cpp:99
StreamWG::resizeEvent
void resizeEvent(QResizeEvent *ev)
Definition: streamwg.cpp:111
QFrame
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal