Diffstat (limited to 'libopie2/opiecore/oresource.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oresource.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/libopie2/opiecore/oresource.cpp b/libopie2/opiecore/oresource.cpp new file mode 100644 index 0000000..88058d0 --- a/dev/null +++ b/libopie2/opiecore/oresource.cpp | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | Copyright (C) 2005 Dan Williams <drw@handhelds.org> | ||
5 | Copyright (C) 2003 Patrick S. Vogt <tille@handhelds.org> | ||
6 | =. | ||
7 | .=l. | ||
8 | .>+-= | ||
9 | _;:, .> :=|. This program is free software; you can | ||
10 | .> <`_, > . <= redistribute it and/or modify it under | ||
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
12 | .="- .-=="i, .._ License as published by the Free Software | ||
13 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
14 | ._= =} : or (at your option) any later version. | ||
15 | .%`+i> _;_. | ||
16 | .i_,=:_. -<s. This program is distributed in the hope that | ||
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
18 | : .. .:, . . . without even the implied warranty of | ||
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
21 | ..}^=.= = ; Library General Public License for more | ||
22 | ++= -. .` .: details. | ||
23 | : = ...= . :.=- | ||
24 | -. .:....=;==+<; You should have received a copy of the GNU | ||
25 | -_. . . )=. = Library General Public License along with | ||
26 | -- :-=` this library; see the file COPYING.LIB. | ||
27 | If not, write to the Free Software Foundation, | ||
28 | Inc., 59 Temple Place - Suite 330, | ||
29 | Boston, MA 02111-1307, USA. | ||
30 | */ | ||
31 | |||
32 | #include <opie2/oapplication.h> | ||
33 | #include <opie2/odebug.h> | ||
34 | |||
35 | #include <qpe/applnk.h> | ||
36 | |||
37 | #include "oresource.h" | ||
38 | |||
39 | namespace Opie { | ||
40 | namespace Core { | ||
41 | |||
42 | QImage OResource::loadImage( const QString &name, Scale scale ) | ||
43 | { | ||
44 | // Load image | ||
45 | QString filename; | ||
46 | filename.sprintf( "%spics/%s.png", (const char*) oApp->qpeDir(), (const char*) name ); | ||
47 | QImage image( filename ); | ||
48 | if ( image.isNull() ) | ||
49 | odebug << "libopie2 OResource: can't find image " << filename << oendl; | ||
50 | |||
51 | // Scale image (if necessary) | ||
52 | if ( scale == SmallIcon ) | ||
53 | { | ||
54 | // Retrieve size of small icons | ||
55 | if ( smallIconSize == -1 ) | ||
56 | smallIconSize = AppLnk::smallIconSize(); | ||
57 | |||
58 | // Scale image | ||
59 | return image.smoothScale( smallIconSize, smallIconSize ); | ||
60 | } | ||
61 | else if ( scale == BigIcon ) | ||
62 | { | ||
63 | // Retrieve size of big icons | ||
64 | if ( bigIconSize == -1 ) | ||
65 | bigIconSize = AppLnk::bigIconSize(); | ||
66 | |||
67 | // Scale image | ||
68 | return image.smoothScale( bigIconSize, bigIconSize ); | ||
69 | } | ||
70 | else | ||
71 | return image; | ||
72 | } | ||
73 | |||
74 | QPixmap OResource::loadPixmap( const QString &name, Scale scale ) | ||
75 | { | ||
76 | QPixmap pixmap; | ||
77 | pixmap.convertFromImage( loadImage( name, scale ) ); | ||
78 | return pixmap; | ||
79 | } | ||
80 | |||
81 | } // namespace Core | ||
82 | } // namespace Opie | ||
83 | |||
84 | |||
85 | |||