[Kst] kdeextragear-2/kst/kst
Andrew Walker
arwalker at sumusltd.com
Wed Mar 16 23:37:39 CET 2005
CVS commit by arwalker:
Add mime types of PNG, JPG, and EPS when dragging and dropping. For now only the entire window is handled.
M +1 -3 kstviewwindow.cpp 1.45
M +39 -3 plotmimesource.cpp 1.4
M +1 -5 extensions/elog/elog.cpp 1.21
--- kdeextragear-2/kst/kst/extensions/elog/elog.cpp #1.20:1.21
@@ -110,6 +110,5 @@ void KstELOG::submitEntry() {
KstELOGCaptureStruct captureStruct;
QByteArray byteArrayCapture;
- QByteArray byteArrayCaptureRaw;
- QDataStream dataStreamCapture( byteArrayCaptureRaw, IO_ReadWrite );
+ QDataStream dataStreamCapture( byteArrayCapture, IO_ReadWrite );
QCustomEvent eventCapture(KstELOGCaptureEvent);
@@ -121,7 +120,4 @@ void KstELOG::submitEntry() {
QApplication::sendEvent( (QObject*)app(), (QEvent*)&eventCapture );
- if( byteArrayCaptureRaw.size() > 0 ) {
- byteArrayCapture.duplicate( byteArrayCaptureRaw.data() + 4, byteArrayCaptureRaw.size() - 4 );
- }
}
--- kdeextragear-2/kst/kst/kstviewwindow.cpp #1.44:1.45
@@ -155,6 +155,4 @@ void KstViewWindow::immediatePrintToFile
void KstViewWindow::immediatePrintToPng(QDataStream* dataStream, const QSize& size, const QString &format) {
- Q_UNUSED(format)
-
QPixmap pixmap(size);
QSize sizeOld;
@@ -167,5 +165,5 @@ void KstViewWindow::immediatePrintToPng(
view()->resizeForPrint(size);
view()->paint(P_EXPORT, paint);
- (*dataStream) << pixmap;
+ pixmap.save(dataStream->device(), format.latin1());
view()->revertForPrint();
paint.end();
--- kdeextragear-2/kst/kst/plotmimesource.cpp #1.3:1.4
@@ -23,6 +23,20 @@
// application specific includes
#include "kst.h"
+#include "kstviewwindow.h"
#include "plotmimesource.h"
+typedef struct formatTypes {
+ char* mime;
+ char* format;
+};
+
+static formatTypes formats[] = {
+ { "image/png", "PNG" },
+ { "image/jpeg", "JPG" },
+ { "application/postscript", "EPS" },
+};
+
+static int iNumFormats = sizeof(formats) / sizeof(formatTypes);
+
PlotMimeSource::PlotMimeSource(QString window, QStringList plots, QWidget *dragSource) :
KstDrag(mimeType(), dragSource) {
@@ -35,7 +49,19 @@ QByteArray PlotMimeSource::encodedData(c
QDataStream data(bytes, IO_WriteOnly);
- if (provides(mime)) {
+ if (strcmp(mime, format(0)) == 0) {
data << _window;
data << _plots;
+ } else {
+ for (int i=0; i<iNumFormats; i++) {
+ if (strcmp(mime, formats[i].mime) == 0) {
+ KstViewWindow *window = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_window));
+
+ if (window) {
+ window->immediatePrintToPng(&data, window->size(), formats[i].format);
+ }
+
+ break;
+ }
+ }
}
@@ -46,4 +72,6 @@ const char * PlotMimeSource::format(int
if (i == 0) {
return mimeType();
+ } else if (i >= 1 && i <= iNumFormats) {
+ return formats[i-1].mime;
}
@@ -54,6 +82,14 @@ bool PlotMimeSource::provides(const char
bool rc = false;
- if( strcmp(mime, mimeType()) == 0) {
+ if (strcmp(mime, mimeType()) == 0) {
+ rc = true;
+ } else {
+ for (int i=0; i<iNumFormats; i++) {
+ if (strcmp(mime, formats[i].mime) == 0) {
rc = true;
+
+ break;
+ }
+ }
}
More information about the Kst
mailing list