~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/winskin/waInfo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  standard Button for winamp Skin
 
3
  Copyright (C) 1999  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include <waInfo.h>
 
15
 
 
16
 
 
17
WaInfo::WaInfo(WaSkinModell* waSkinModell,QWidget* parent,char* name):
 
18
QWidget(parent,name){
 
19
  this->waSkinModell=waSkinModell;
 
20
  connect(waSkinModell,SIGNAL(event_WA_SKIN_TEXT()),
 
21
          this,SLOT(pixmapChange()));
 
22
  completePixmap=new QPixmap();
 
23
  buildPixmap=new QPixmap();
 
24
 
 
25
  QSize size=sizeHint();
 
26
  completePixmap->resize(size.width(),size.height());
 
27
  WaSkinDesc* waSkinDesc=waSkinModell->getWaSkinMapDesc(_WA_MAPPING_INFO);
 
28
  setGeometry((*waSkinDesc->getGeometry()));
 
29
 
 
30
 
 
31
  timer=new QTimer(this);
 
32
  connect(timer,SIGNAL(timeout()),this,SLOT(timeEvent()));
 
33
  
 
34
  pixmapChange();
 
35
}
 
36
 
 
37
WaInfo::~WaInfo() {
 
38
  delete completePixmap;
 
39
  delete buildPixmap;
 
40
}
 
41
 
 
42
 
 
43
void WaInfo::timeEvent() {
 
44
  repaint(false);
 
45
}
 
46
 
 
47
 
 
48
void WaInfo::scrollerSetup() {
 
49
  xScrollPos=0;
 
50
  xScrollDirection=0;
 
51
  timer->stop();
 
52
  QSize size=sizeHint();
 
53
  if (completePixmap->width() > size.width()) {
 
54
    xScrollDirection=1;
 
55
    timer->start(50);
 
56
  }
 
57
}
 
58
 
 
59
 
 
60
 
 
61
 
 
62
QSize WaInfo::sizeHint() const {
 
63
  WaSkinDesc* waSkinDesc=waSkinModell->getWaSkinMapDesc(_WA_MAPPING_INFO);
 
64
  return QSize(waSkinDesc->getWidgetWidth(),waSkinDesc->getWidgetHeight());
 
65
}
 
66
 
 
67
 
 
68
void WaInfo::paintEvent ( QPaintEvent * paintEvent ) {
 
69
 
 
70
  QPainter paint;
 
71
  QSize size=sizeHint();
 
72
  if (completePixmap->width() <= size.width()) {
 
73
    paint.begin( this );
 
74
    paint.drawPixmap(0,0,*completePixmap);
 
75
    paint.end();  
 
76
    return;
 
77
  }
 
78
  
 
79
  // pixmap widther than window:
 
80
  int xDrawWidth;
 
81
  int xRestWidth;
 
82
 
 
83
  xDrawWidth=completePixmap->width()-xScrollPos;
 
84
  if (xDrawWidth > size.width()) {
 
85
    xDrawWidth=size.width();
 
86
  }
 
87
  paint.begin( this );
 
88
  paint.drawPixmap(0,0,*completePixmap,xScrollPos,0,xDrawWidth);
 
89
  if (xDrawWidth < size.width()) {
 
90
    xRestWidth=size.width()-xDrawWidth;
 
91
    paint.drawPixmap(xDrawWidth,0,*completePixmap,0,0,xRestWidth);
 
92
  }
 
93
  paint.end();  
 
94
  
 
95
  xScrollPos+=xScrollDirection;
 
96
  if (abs(xScrollPos) >completePixmap->width() ) {
 
97
    xScrollPos=0;
 
98
  }
 
99
}
 
100
 
 
101
 
 
102
void WaInfo::setSong(QString song) {
 
103
  text=song;
 
104
  pixmapChange();
 
105
}
 
106
 
 
107
QString WaInfo::getSong() {
 
108
  return text;
 
109
}
 
110
 
 
111
 
 
112
void WaInfo::pixmapChange() {
 
113
  int i;
 
114
  const char* infoString=getSong().latin1();
 
115
 
 
116
  int x=0;
 
117
  int n=strlen(infoString);
 
118
  QSize size=sizeHint();
 
119
 
 
120
  completePixmap->resize(0,0);
 
121
  
 
122
  for(i=0;i<n;i++) {
 
123
    waSkinModell->getNumber(_WA_SKIN_TEXT,infoString[i],buildPixmap);
 
124
    if (i == 0) {
 
125
      int w=buildPixmap->width();
 
126
      int h=buildPixmap->height();
 
127
      int textWidth=w*n;
 
128
      if (textWidth < size.width()) {
 
129
        textWidth=size.width();
 
130
      }
 
131
      completePixmap->resize(textWidth,h);
 
132
    }
 
133
 
 
134
    bitBlt(completePixmap,x,0,buildPixmap);
 
135
    x=x+buildPixmap->width();
 
136
  }
 
137
  // if the size is now smaller than the with of this widget, we
 
138
  // fill the pixmap with spaces
 
139
  if (x < size.width()) {
 
140
    while (x < size.width()) {
 
141
      waSkinModell->getNumber(_WA_SKIN_TEXT,' ',buildPixmap);
 
142
      bitBlt(completePixmap,x,0,buildPixmap);
 
143
      x=x+buildPixmap->width();
 
144
    }
 
145
  }
 
146
 
 
147
 
 
148
  scrollerSetup();
 
149
  repaint(false);
 
150
}
 
151
     
 
152
 
 
153
 
 
154
 
 
155
#include "waInfo.moc"