summaryrefslogtreecommitdiff
path: root/client/icons.cc
blob: 93fc137f3fc35ae54e291fd831fa510bf9bad04c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
 *            icons.cc
 *
 *  Thu May  4 15:47:51 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 "icons.h"

/** 
 * The image files
 */
#define PIXMAP_MUTE       PIXMAPS"/mute"
#define PIXMAP_UNMUTE     PIXMAPS"/unmute"

#define PIXMAP_RECORD     PIXMAPS"/record"
#define PIXMAP_STOP       PIXMAPS"/stop"

#define PIXMAP_FREEZE     PIXMAPS"/freeze"
#define PIXMAP_UNFREEZE   PIXMAPS"/unfreeze"

#define PIXMAP_CPR        PIXMAPS"/cpr"
#define PIXMAP_CLEAR      PIXMAPS"/clear"

#define PIXMAP_SNAPSHOT   PIXMAPS"/snapshot"
#define PIXMAP_DUMMY      PIXMAPS"/dummy"
#define PIXMAP_LOGO_SMALL PIXMAPS"/miav-logo"

//#define QT_SVG
#define CAIRO_SVG

#ifdef QT_SVG
#include <QSvgRenderer>
#include <QPainter>
#endif /*QT_SVG*/

#ifdef CAIRO_SVG
#include "svgloader.h"
#endif /*CAIRO_SVG*/

#include <QApplication>
#include <QDesktopWidget>
#include <QX11Info>

QPixmap *loadIcon(char* fname)
{
  QPixmap *pixmap;

  int dpix = qApp->desktop()->x11Info().appDpiX();
  int dpiy = qApp->desktop()->x11Info().appDpiY();

  //  printf("DpiX: %d DpiY: %d\n", dpix, dpiy);

#ifdef CAIRO_SVG
  SVGLoader svg;
  QString filename = fname;
  filename.append(".svg");
  double dpi = (double)(dpix + dpiy) / 2.0;
  pixmap = new QPixmap(QPixmap::fromImage(svg.load(filename, 0, 0, 14.0 / dpi, 14.0 / dpi)));
#endif/*CAIRO_SVG*/

#ifdef QT_SVG
  QSvgRenderer svgrenderer;
  QPainter painter;

  pixmap = new QPixmap(w, h);
  painter.begin(pixmap);
  QString filename = fname;
  svgrenderer.load(filename . ".svg");
  svgrenderer.render(&painter);
  painter.end();
#endif/*QT_SVG*/

#ifndef QT_SVG
#ifndef CAIRO_SVG
  // Load as png
  QString filename = fname;
  filename.append(".png");
  pixmap = new QPixmap(filename);
  Qt::AspectRatioMode aspect =  pixmap.width()<pixmap.height()?
    Qt::KeepAspectRatio:Qt::KeepAspectRatioByExpanding;
  double dpi = (double)(dpix + dpiy) / 2.0;
  *pixmap = pixmap->scaled((int)(dpi / 1.5),(int)(dpi / 1.5), aspect, Qt::SmoothTransformation);
#endif/*CAIRO_SVG*/
#endif/*QT_SVG*/

  return pixmap;
}


bool Icons::loadIcons()
{
  cpr = loadIcon(PIXMAP_CPR);
  record = loadIcon(PIXMAP_RECORD);
  stop = loadIcon(PIXMAP_STOP);
  snapshot = loadIcon(PIXMAP_SNAPSHOT);
  freeze = loadIcon(PIXMAP_FREEZE);
  unfreeze = loadIcon(PIXMAP_UNFREEZE);
  mute = loadIcon(PIXMAP_MUTE);
  unmute = loadIcon(PIXMAP_UNMUTE);
  clear = loadIcon(PIXMAP_CLEAR);
  return true;
}

bool Icons::unloadIcons()
{
  delete cpr;
  delete record;
  delete stop;
  delete snapshot;
  delete freeze;
  delete unfreeze;
  delete mute;
  delete unmute;
  delete clear;
  return true;
}

// The pixmaps
QPixmap *Icons::cpr;
QPixmap *Icons::record;
QPixmap *Icons::stop;
QPixmap *Icons::snapshot;
QPixmap *Icons::freeze;
QPixmap *Icons::unfreeze;
QPixmap *Icons::mute;
QPixmap *Icons::unmute;
QPixmap *Icons::clear;