00001 #include <qapplication.h>
00002 #include <qstring.h>
00003 #include <qpixmap.h>
00004 #include <qimage.h>
00005 #include <qpainter.h>
00006 #include <iostream>
00007 using namespace std;
00008
00009 #include "treecheckitem.h"
00010 #include "playlist.h"
00011
00012 #include <mythtv/mythcontext.h>
00013
00014 #include "res/album_pix.xpm"
00015 #include "res/artist_pix.xpm"
00016 #include "res/catalog_pix.xpm"
00017 #include "res/track_pix.xpm"
00018 #include "res/cd_pix.xpm"
00019 #include "res/track_up_down_pix.xpm"
00020 #include "res/favorites_pix.xpm"
00021 #include "res/playlist_pix.xpm"
00022 #include "res/streams_pix.xpm"
00023 #include "res/uncategorized_pix.xpm"
00024
00025 static bool pixmapsSet = false;
00026 static QPixmap *pixartist = NULL;
00027 static QPixmap *pixalbum = NULL;
00028 static QPixmap *pixtrack = NULL;
00029 static QPixmap *pixcatalog = NULL;
00030 static QPixmap *pixcd = NULL;
00031 static QPixmap *pixtrack_up_down = NULL;
00032 static QPixmap *pixfavorites = NULL;
00033 static QPixmap *pixplaylist = NULL;
00034 static QPixmap *pixstreams = NULL;
00035 static QPixmap *pixuncat = NULL;
00036
00037 static QPixmap *scalePixmap(const char **xpmdata, float wmult, float hmult)
00038 {
00039 QImage tmpimage(xpmdata);
00040 QImage tmp2 = tmpimage.smoothScale((int)(tmpimage.width() * wmult),
00041 (int)(tmpimage.height() * hmult));
00042 QPixmap *ret = new QPixmap();
00043 ret->convertFromImage(tmp2);
00044
00045 return ret;
00046 }
00047
00048 static void setupPixmaps(void)
00049 {
00050 int screenheight = 0, screenwidth = 0;
00051 float wmult = 0, hmult = 0;
00052
00053 gContext->GetScreenSettings(screenwidth, wmult, screenheight, hmult);
00054
00055 if (screenheight != 600 || screenwidth != 800)
00056 {
00057 pixartist = scalePixmap((const char **)artist_pix, wmult, hmult);
00058 pixalbum = scalePixmap((const char **)album_pix, wmult, hmult);
00059 pixtrack = scalePixmap((const char **)track_pix, wmult, hmult);
00060 pixcatalog = scalePixmap((const char **)catalog_pix, wmult, hmult);
00061 pixcd = scalePixmap((const char **)cd_pix, wmult, hmult);
00062 pixfavorites = scalePixmap((const char **)favorites_pix, wmult, hmult);
00063 pixplaylist = scalePixmap((const char **)playlist_pix, wmult, hmult);
00064 pixstreams = scalePixmap((const char **)streams_pix, wmult, hmult);
00065 pixuncat = scalePixmap((const char **)uncategorized_pix, wmult, hmult);
00066 pixtrack_up_down = scalePixmap((const char **)track_up_down_pix_xpm,
00067 wmult, hmult);
00068 }
00069 else
00070 {
00071 pixartist = new QPixmap((const char **)artist_pix);
00072 pixalbum = new QPixmap((const char **)album_pix);
00073 pixtrack = new QPixmap((const char **)track_pix);
00074 pixcatalog = new QPixmap((const char **)catalog_pix);
00075 pixcd = new QPixmap((const char **)cd_pix);
00076 pixfavorites = new QPixmap((const char **)favorites_pix);
00077 pixplaylist = new QPixmap((const char **)playlist_pix);
00078 pixstreams = new QPixmap((const char **)streams_pix);
00079 pixuncat = new QPixmap((const char **)uncategorized_pix);
00080 pixtrack_up_down = new QPixmap((const char **)track_up_down_pix_xpm);
00081 }
00082
00083 pixmapsSet = true;
00084 }
00085
00086 static QPixmap *getPixmap(const QString &level)
00087 {
00088 if (level == "artist")
00089 return pixartist;
00090 else if (level == "album")
00091 return pixalbum;
00092 else if (level == "title")
00093 return pixtrack;
00094 else if (level == "genre")
00095 return pixcatalog;
00096 else if (level == "cd")
00097 return pixcd;
00098 else if (level == "playlist")
00099 return pixplaylist;
00100 else if (level == "favorite")
00101 return pixfavorites;
00102 else if (level == "stream")
00103 return pixstreams;
00104 else if (level == "uncategorized")
00105 return pixuncat;
00106
00107 return NULL;
00108 }
00109
00110 TreeCheckItem::TreeCheckItem(UIListGenericTree *parent, const QString &text,
00111 const QString &level, int id)
00112 : UIListGenericTree(parent, text, "TREECHECK", 0)
00113 {
00114 m_checkable = true;
00115 m_level = level;
00116 m_id = id;
00117
00118 pickPixmap();
00119 }
00120
00121 void TreeCheckItem::setCheckable(bool flag)
00122 {
00123 if (flag == false)
00124 setCheck(-1);
00125 m_checkable = flag;
00126 }
00127
00128 void TreeCheckItem::setCheck(int flag)
00129 {
00130 if (m_checkable)
00131 UIListGenericTree::setCheck(flag);
00132 }
00133
00134 void TreeCheckItem::pickPixmap(void)
00135 {
00136 if (!pixmapsSet)
00137 setupPixmaps();
00138
00139 QPixmap *pix = getPixmap(m_level);
00140 if (pix)
00141 m_image = pix;
00142 }
00143
00144 CDCheckItem::CDCheckItem(UIListGenericTree *parent, const QString &text,
00145 const QString &level, int track)
00146 : TreeCheckItem(parent, text, level, track)
00147 {
00148 }
00149
00150 PlaylistItem::PlaylistItem(UIListGenericTree *parent, const QString &title)
00151 : UIListGenericTree(parent, title, "PLAYLISTITEM", -1)
00152 {
00153 text = title;
00154 }
00155
00156 PlaylistTitle::PlaylistTitle(UIListGenericTree *parent, const QString &title)
00157 : PlaylistItem(parent, title)
00158 {
00159 active = false;
00160
00161 if (!pixmapsSet)
00162 setupPixmaps();
00163
00164 QPixmap *pix = getPixmap("playlist");
00165 if (pix)
00166 m_image = pix;
00167 }
00168
00169 void PlaylistTitle::userSelectedMe(void)
00170 {
00171 }
00172
00173 void PlaylistTitle::setOwner(Playlist *owner)
00174 {
00175 ptr_to_owner = owner;
00176 }
00177
00178 PlaylistTrack::PlaylistTrack(UIListGenericTree *parent, const QString &title)
00179 : PlaylistItem(parent, title)
00180 {
00181 held = false;
00182
00183 QString level = "title";
00184 if (title.left(10).lower() == "playlist -")
00185 level = "playlist";
00186
00187 if (!pixmapsSet)
00188 setupPixmaps();
00189
00190 pixmap = getPixmap(level);
00191 if (pixmap)
00192 m_image = pixmap;
00193 }
00194
00195 void PlaylistTrack::userSelectedMe(void)
00196 {
00197 }
00198
00199 void PlaylistTrack::setOwner(Track *owner)
00200 {
00201 ptr_to_owner = owner;
00202 }
00203
00204 int PlaylistTrack::getID()
00205 {
00206 return ptr_to_owner->getValue();
00207 }
00208
00209 void PlaylistTitle::removeTrack(int x)
00210 {
00211 ptr_to_owner->removeTrack(x, false);
00212 }
00213
00214 void PlaylistTrack::beMoving(bool flag)
00215 {
00216 if (flag)
00217 setPixmap(pixtrack_up_down);
00218 else if (pixmap)
00219 setPixmap(pixmap);
00220 else
00221 setPixmap(pixtrack);
00222 }
00223
00224 void PlaylistTrack::moveUpDown(bool flag)
00225 {
00226 if (movePositionUpDown(flag))
00227 ptr_to_owner->moveUpDown(flag);
00228 }
00229
00230 PlaylistPlaylist::PlaylistPlaylist(UIListGenericTree *parent,
00231 const QString &title)
00232 : PlaylistTrack(parent, title)
00233 {
00234 pixmap = getPixmap("playlist");
00235 if (pixmap)
00236 m_image = pixmap;
00237 }
00238
00239 PlaylistCD::PlaylistCD(UIListGenericTree *parent, const QString &title)
00240 : PlaylistTrack(parent, title)
00241 {
00242 pixmap = getPixmap("cd");
00243 if (pixmap)
00244 m_image = pixmap;
00245 }
00246