summaryrefslogtreecommitdiffstats
path: root/noatun/modules/winskin/waInfo.cpp
blob: 05aa6381c31a78fff3d7166dfa6776a68f5d7d68 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
  Scrolling song title for winamp Skin
  Copyright (C) 1999  Martin Vogt
  Copyright (C) 2001  Ryan Cumming

  This program 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.

  For more information look at the file COPYRIGHT in this package

 */


#include <tqpainter.h>
#include <tqpixmap.h>

#include <stdlib.h>

#include <kconfig.h>
#include <kglobal.h>

#include "waInfo.h"
#include "waSkinModel.h"

WaInfo::WaInfo() : WaWidget(_WA_MAPPING_INFO)
{
    connect(WaSkinModel::instance(), TQT_SIGNAL(skinChanged()),
	    this, TQT_SLOT(pixmapChange()));

    completePixmap = new TQPixmap();

    TQSize size = sizeHint();
    completePixmap->resize(size.width(), size.height());

    xGrabbedPos = -1;

    timer = new TQTimer(this);
    connect(timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeEvent()));
}

WaInfo::~WaInfo()
{
    delete completePixmap;
}


void WaInfo::timeEvent()
{
    if ((xGrabbedPos == -1) && (xScrollDirection)) {
        xScrollPos += xScrollDirection;

        if (abs(xScrollPos) > completePixmap->width()) {
            xScrollPos = 0;
        }

        if (isVisible())
            tqrepaint(false);
    }
}


void WaInfo::scrollerSetup()
{
    xScrollPos = 0;
    xScrollDirection = 0;
    timer->stop();
    TQSize size = sizeHint();
    if (completePixmap->width() > size.width()) {
		xScrollDirection = 1;
		
		KConfig *config=KGlobal::config();
		config->setGroup("Winskin");
		int s = config->readNumEntry("ScrollDelay", 15);
		if (s!=0)
			timer->start(50-s);
    }
}

void WaInfo::paintEvent(TQPaintEvent *)
{
    TQSize size = sizeHint();

    if (completePixmap->width() <= size.width()) {
	bitBlt(this, 0, 0, completePixmap);
	return;
    }

    // pixmap widther than window:
    int xDrawWidth;
    int xRestWidth;

    xDrawWidth = completePixmap->width() - xScrollPos;
    if (xDrawWidth > size.width()) {
	xDrawWidth = size.width();
    }


    bitBlt(this, 0, 0, completePixmap, xScrollPos, 0, xDrawWidth);

    if (xDrawWidth < size.width()) {
	xRestWidth = size.width() - xDrawWidth;
	bitBlt(this, xDrawWidth, 0, completePixmap, 0, 0, xRestWidth);
    }
}


void WaInfo::setText(TQString song)
{
    if (_text != song) {
        _text = song;
        pixmapChange();
    }
}

TQString WaInfo::text() const
{
    return _text;
}


void WaInfo::pixmapChange()
{
    int i;
    const char *infoString = _text.latin1();

    int x = 0;
    int n=infoString ? strlen(infoString) : 0;

    TQSize size = sizeHint();

    completePixmap->resize(TQMAX(n * _WA_TEXT_WIDTH, size.width()), _WA_TEXT_HEIGHT);

    for (i = 0; i < n; i++) {
	WaSkinModel::instance()->getText(infoString[i], TQT_TQPAINTDEVICE(completePixmap), x, 0);
	x += _WA_TEXT_WIDTH;
    }

    // if the size is now smaller than the with of this widget, we
    // fill the pixmap with spaces
    if (x < size.width()) {
	while (x < size.width()) {
	    WaSkinModel::instance()->getText(' ', TQT_TQPAINTDEVICE(completePixmap), x, 0);
	    x += _WA_TEXT_WIDTH;
	}
    }

    scrollerSetup();
    update();
}

void WaInfo::mousePressEvent (TQMouseEvent *e) {
    if (e->button() == Qt::LeftButton)
        xGrabbedPos = (e->x() + xScrollPos) % completePixmap->width();
}

void WaInfo::mouseMoveEvent (TQMouseEvent * e) {
    xScrollPos = -e->x() + xGrabbedPos;

    if (xScrollPos < 0)
        xScrollPos = completePixmap->width() - (-xScrollPos % completePixmap->width());
    else
        xScrollPos %= completePixmap->width(); 

    update();
}

void WaInfo::mouseReleaseEvent (TQMouseEvent *) {
    xGrabbedPos = -1;
}


#include "waInfo.moc"