diff options
-rw-r--r-- | client/Makefile.am | 6 | ||||
-rw-r--r-- | client/mainwindow.cc | 32 | ||||
-rw-r--r-- | client/mainwindow.h | 22 | ||||
-rw-r--r-- | client/svgloader.cc | 135 | ||||
-rw-r--r-- | client/svgloader.h | 42 | ||||
-rw-r--r-- | configure.in | 16 |
6 files changed, 226 insertions, 27 deletions
diff --git a/client/Makefile.am b/client/Makefile.am index 73019c4..b7d3a74 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -1,5 +1,5 @@ AM_CXXFLAGS := -I../lib -L../lib \ - $(CXXFLAGS) $(EXTRA_CXXFLAGS) -I../include $(QT_CXXFLAGS) $(SDL_CFLAGS) \ + $(CXXFLAGS) $(EXTRA_CXXFLAGS) -I../include $(QT_CXXFLAGS) $(CAIRO_CXXFLAGS) \ -DQT_THREAD_SUPPORT \ -DPIXMAPS=\"$(datadir)/pixmaps\" \ -DETC=\"$(prefix)/etc/miav\" @@ -23,6 +23,7 @@ miav_client_SOURCES = $(shell ../tools/MocList cc ) \ messagebox.cc \ player.cc \ splashscreen.cc \ + svgloader.cc \ videowidget.cc \ yuv_draw.cc \ xvaccelrenderer.cc @@ -44,13 +45,14 @@ EXTRA_DIST = \ messagebox.h \ player.h \ splashscreen.h \ + svgloader.h \ videowidget.h \ yuv_draw.h \ xvaccelrenderer.h miav_client_LDADD := $(shell ../tools/MocList o ) \ ../lib/libmiav.la \ - $(SDL_LIBS) \ + $(CAIRO_LDFLAGS) \ $(QT_LDADD) \ -lXv diff --git a/client/mainwindow.cc b/client/mainwindow.cc index d2c9248..982388b 100644 --- a/client/mainwindow.cc +++ b/client/mainwindow.cc @@ -41,8 +41,9 @@ #include <QSvgRenderer> #include <QPainter> +#include "svgloader.h" -#define SVG false +#define CAIRO_SVG QPixmap MainWindow::loadIcon(char* fname) { @@ -52,31 +53,40 @@ QPixmap MainWindow::loadIcon(char* fname) int w = (int)((double)x11Info().appDpiX() / 1.5); int h = (int)((double)x11Info().appDpiY() / 1.5); - if(SVG) { +#ifdef CAIRO_SVG + QPixmap pixmap; + SVGLoader cairo; + QString filename = fname; + filename.append(".svg"); + w = h; + pixmap = QPixmap::fromImage(cairo.load(filename, 0, 0, 0.1, 0.1)); + return pixmap; +#else/*CAIRO_SVG*/ +#ifdef QT_SVG QPixmap pixmap(w, h); painter.begin(&pixmap); QString filename = fname; - svgrenderer.load(filename); + svgrenderer.load(filename . ".svg"); svgrenderer.render(&painter); painter.end(); return pixmap; - } else { - QPixmap pixmap(fname); +#else/*QT_SVG*/ + // Load as png + QPixmap pixmap(fname".png"); Qt::AspectRatioMode aspect = pixmap.width()<pixmap.height()? Qt::KeepAspectRatio:Qt::KeepAspectRatioByExpanding; pixmap = pixmap.scaled(w,h, aspect, Qt::SmoothTransformation); return pixmap; - } +#endif/*QT_SVG*/ +#endif/*CAIRO_SVG*/ } QPushButton *MainWindow::createButton(char* icon) { - int w = (int)((double)x11Info().appDpiX() / 1.5); - int h = (int)((double)x11Info().appDpiY() / 1.5); - + QPixmap p = loadIcon(icon); QPushButton *btn = new QPushButton(); - btn->setIconSize(QSize(w,h)); - btn->setIcon(loadIcon(icon)); + btn->setIconSize(QSize(p.width(), p.height())); + btn->setIcon(p); return btn; } diff --git a/client/mainwindow.h b/client/mainwindow.h index 723b747..762b7f3 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -38,21 +38,21 @@ /** * Images */ -#define PIXMAP_MUTE PIXMAPS"/mute.png" -#define PIXMAP_UNMUTE PIXMAPS"/unmute.png" +#define PIXMAP_MUTE PIXMAPS"/mute" +#define PIXMAP_UNMUTE PIXMAPS"/unmute" -#define PIXMAP_RECORD PIXMAPS"/record.png" -#define PIXMAP_STOP PIXMAPS"/stop.png" +#define PIXMAP_RECORD PIXMAPS"/record" +#define PIXMAP_STOP PIXMAPS"/stop" -#define PIXMAP_FREEZE PIXMAPS"/freeze.png" -#define PIXMAP_UNFREEZE PIXMAPS"/unfreeze.png" +#define PIXMAP_FREEZE PIXMAPS"/freeze" +#define PIXMAP_UNFREEZE PIXMAPS"/unfreeze" -#define PIXMAP_CPR PIXMAPS"/cpr.png" -#define PIXMAP_CLEAR PIXMAPS"/clear.png" +#define PIXMAP_CPR PIXMAPS"/cpr" +#define PIXMAP_CLEAR PIXMAPS"/clear" -#define PIXMAP_SNAPSHOT PIXMAPS"/snapshot.png" -#define PIXMAP_DUMMY PIXMAPS"/dummy.png" -#define PIXMAP_LOGO_SMALL PIXMAPS"/miav-logo.png" +#define PIXMAP_SNAPSHOT PIXMAPS"/snapshot" +#define PIXMAP_DUMMY PIXMAPS"/dummy" +#define PIXMAP_LOGO_SMALL PIXMAPS"/miav-logo" class MainWindow : public QWidget { diff --git a/client/svgloader.cc b/client/svgloader.cc new file mode 100644 index 0000000..642fda3 --- /dev/null +++ b/client/svgloader.cc @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * svgloader.cc + * + * Mon May 1 11:03:39 CEST 2006 + * Copyright 2006 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MIaV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "svgloader.h" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> + +#include <cairo.h> +#include <svg.h> +#include <svg-cairo.h> + +SVGLoader::SVGLoader() +{ +} + +SVGLoader::~SVGLoader() +{ +} + +/* load: This is what you're probably interested in! + * ----------------------------------------------------- + * If width and height are greater than 0, the image will + * be scaled to that size. wscale and hscale would be ignored. + * + * If width and height are less than 1, wscale and hscale will + * resize the width and the height to the specified scales. + * + * If width and height are less than 1, and wscale and hscale + * are either 0 or 1, then the image will be loaded at it's + * natural size. + * + * See main() for examples. + */ +QImage SVGLoader::load(QString file, unsigned int width, unsigned int height, float wscale, float hscale) { + svg_cairo_t *scr; + int bpp; + int btpp; + unsigned int rwidth; + unsigned int rheight; + + // Create the SVG cairo stuff. + svg_cairo_create(&scr); + svg_cairo_parse(scr, file.toStdString().c_str()); + + if (wscale <= 0) wscale=1; + if (hscale <= 0) hscale=1; + + // Now get the width and height of the SVG content, so we can calculate + // and adjust our image dimensions + svg_cairo_get_size (scr, &rwidth, &rheight); + + // Calculate final width and height of our surface based on the parameters passed + if (width > 0) { + if (rwidth>width) { + wscale=(float)width/(float)rwidth; + printf ("rwidth/width = %f\n", wscale); + } else { + wscale=(float)rwidth/(float)width; + printf ("width/wwidth = %f\n", wscale); + } + } else { + width=(int)(rwidth*wscale); + printf ("width = %i\n", width); + } + if (height > 0) { + if (rheight>height) { + hscale=(float)height/(float)rheight; + printf ("height/rheight = %f\n", hscale); + } else { + hscale=(float)rheight/(float)height; + printf ("rheight/height = %f\n", hscale); + } + } else { + height=(int)(rheight*hscale); + printf ("height = %i\n", height); + } + + // We will create a CAIRO_FORMAT_ARGB32 surface. We don't need to match + // the screen SDL format, but we are interested in the alpha bit + bpp=32; // bits per pixel + btpp=4; // bytes per pixel + + // scanline width + int stride=width * btpp; + + // Allocate an image + unsigned char *image=(unsigned char*)calloc(stride*height, 1); + + // Create the cairo surface with the adjusted width and height + cairo_surface_t *cairo_surface; + cairo_surface = cairo_image_surface_create_for_data(image, CAIRO_FORMAT_ARGB32, + width, height, stride); + + cairo_t *cr = cairo_create(cairo_surface); + cairo_scale(cr, wscale, hscale); + + // Render SVG to our surface + svg_cairo_render(scr, cr); + + // Cleanup cairo + cairo_surface_destroy(cairo_surface); + cairo_destroy(cr); + + // Destroy the svg_cairo structure + svg_cairo_destroy(scr); + + // Create the QImage using the render buffer. + QImage qimage(image, width, height, QImage::Format_ARGB32); + return qimage; +} diff --git a/client/svgloader.h b/client/svgloader.h new file mode 100644 index 0000000..f052a91 --- /dev/null +++ b/client/svgloader.h @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * svgloader.h + * + * Mon May 1 11:03:39 CEST 2006 + * Copyright 2006 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MIaV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __MIAV_SVGLOADER_H__ +#define __MIAV_SVGLOADER_H__ + +#include <QImage> +#include <QString> + +class SVGLoader { +public: + SVGLoader(); + ~SVGLoader(); + + QImage load(QString file, unsigned int width, unsigned int height, float wscale = 1.0, float hscale = 1.0); +}; + + +#endif/*__MIAV_SVGLOADER_H__*/ diff --git a/configure.in b/configure.in index b31bf49..40b5f75 100644 --- a/configure.in +++ b/configure.in @@ -35,8 +35,8 @@ if test x$with_client != xno && test -z "$CLIENT"; then gw_CHECK_QT # CXXFLAGS="$CXXFLAGS $QT_CXXLAGS" # LDFLAGS="$LDFLAGS $QT_LDADD" - AC_SUBST(QT_CXXFLAGS) - AC_SUBST(QT_LDADD) + AC_SUBST(QT_CXXFLAGS) + AC_SUBST(QT_LDADD) dnl ====================== dnl Check for the Xv extension @@ -50,7 +50,17 @@ if test x$with_client != xno && test -z "$CLIENT"; then AC_CHECK_HEADER(libraw1394/raw1394.h, , AC_MSG_ERROR([*** libraw1394 headers not found!])) AC_CHECK_LIB(raw1394, raw1394_get_userdata, , AC_MSG_ERROR([*** libraw1394 not found!])) - AC_OUTPUT(client/Makefile) + dnl ====================== + dnl Check for the cairo library + dnl ====================== + AC_CHECK_HEADER(cairo/cairo-features.h, , AC_MSG_ERROR([*** cairo headers not found!])) + CAIRO_CXXFLAGS="`pkg-config --cflags cairo` -I/usr/local/include" + AC_SUBST(CAIRO_CXXFLAGS) + AC_CHECK_LIB(svg-cairo, svg_cairo_create, , AC_MSG_ERROR([*** libcairo not found!])) + CAIRO_LDFLAGS="`pkg-config --libs cairo` -lsvg -lsvg-cairo" + AC_SUBST(CAIRO_LDFLAGS) + + AC_OUTPUT(client/Makefile) dnl Make code aware of the gui AC_DEFINE([USE_CLIENT], [], [Is defined if the project is configured to compile with client]) |