summaryrefslogtreecommitdiffstats
path: root/konversation/src/images.cpp
blob: dcf7cc01acbcbf305ff1ae621a4e7c096d5c7ce4 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
  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; either version 2 of the License, or
  (at your option) any later version.
*/

/*
  Copyright (C) 2002 Dario Abatianni <eisfuchs@tigress.com>
  Copyright (C) 2005-2006 Eike Hein <hein@kde.org>
*/

#include "images.h"
#include "common.h"
#include "konversationapplication.h"

#include <tqbitmap.h>
#include <tqpainter.h>
#include <tqstringlist.h>

#include <kdebug.h>
#include <kiconloader.h>
#include <kstandarddirs.h>


using namespace Konversation;

Images::Images()
{
    initializeLeds();
    initializeNickIcons();
    initializeKimifaceIcons();

    m_closeIcon = TDEGlobal::iconLoader()->loadIcon("window-close",TDEIcon::Small);
    m_disabledCloseIcon = TDEGlobal::iconLoader()->loadIconSet("window-close",TDEIcon::Small).pixmap(TQIconSet::Small, false);
}

Images::~Images()
{
}

TQIconSet Images::getKimproxyAway() const { return tdeimproxyAway; }
TQIconSet Images::getKimproxyOnline() const { return tdeimproxyOnline; }
TQIconSet Images::getKimproxyOffline() const { return tdeimproxyOffline; }

TQPixmap Images::getNickIcon(NickPrivilege privilege,bool isAway) const
{
    return nickIcons[privilege][isAway?1:0];
}

void Images::initializeLeds()
{
    m_serverColor = "steelblue";
    m_systemColor = Preferences::tabNotificationsSystemColor();
    m_msgsColor = Preferences::tabNotificationsMsgsColor();
    m_privateColor = Preferences::tabNotificationsPrivateColor();
    m_eventsColor = Preferences::tabNotificationsEventsColor();
    m_nickColor = Preferences::tabNotificationsNickColor();
    m_highlightsColor = Preferences::tabNotificationsHighlightsColor();

    // m_serverLedOn = getLed(m_serverColor,true);
    m_serverLedOff = getLed(m_serverColor,false);
    m_systemLedOn = getLed(m_systemColor,true);
    m_systemLedOff = getLed(m_systemColor,false);
    m_msgsLedOn = getLed(m_msgsColor,true);
    m_msgsLedOff = getLed(m_msgsColor,false);
    m_privateLedOn = getLed(m_privateColor,true);
    m_privateLedOff = getLed(m_privateColor,false);
    m_eventsLedOn = getLed(m_eventsColor,true);
    m_nickLedOn = getLed(m_nickColor,true);
    m_highlightsLedOn = getLed(m_highlightsColor,true);
}

void Images::initializeKimifaceIcons()
{
    tdeimproxyAway = TDEGlobal::iconLoader()->loadIconSet("tdeimproxyaway",TDEIcon::Small);
    tdeimproxyOnline = TDEGlobal::iconLoader()->loadIconSet("tdeimproxyonline",TDEIcon::Small);
    tdeimproxyOffline = TDEGlobal::iconLoader()->loadIconSet("tdeimproxyoffline",TDEIcon::Small);
}

// NickIcons

void Images::initializeNickIcons()
{

    TQString iconTheme = Preferences::iconTheme();
    TQStringList icons = TDEGlobal::dirs()->findAllResources("data","konversation/themes/"+iconTheme+"/*.png");

    if( icons.count() < 7 ) // Sanity
        icons = TDEGlobal::dirs()->findAllResources("data","konversation/themes/default/*.png");

    icons.sort();
    TQStringList::ConstIterator it = icons.begin();

    /* The list is sorted alphabetically. */

    TQPixmap elementAdmin(*it);
    ++it;
    TQPixmap elementAway(*it);
    ++it;
    TQPixmap elementHalfOp(*it);
    ++it;
    TQPixmap elementNormal(*it);
    ++it;
    TQPixmap elementOp(*it);
    ++it;
    TQPixmap elementOwner(*it);
    ++it;
    TQPixmap elementVoice(*it);

    nickIcons[Normal][0] = elementNormal;
    nickIcons[Normal][1] = overlayPixmaps( nickIcons[Normal][0], elementAway );

    nickIcons[Voice][0] = overlayPixmaps( elementNormal, elementVoice );
    nickIcons[Voice][1] = overlayPixmaps( nickIcons[Voice][0], elementAway );

    nickIcons[HalfOp][0] = overlayPixmaps( elementNormal, elementHalfOp );
    nickIcons[HalfOp][1] = overlayPixmaps( nickIcons[HalfOp][0], elementAway );

    nickIcons[Op][0] = overlayPixmaps( elementNormal, elementOp );
    nickIcons[Op][1] = overlayPixmaps( nickIcons[Op][0], elementAway );

    nickIcons[Owner][0] = overlayPixmaps( elementNormal, elementOwner );
    nickIcons[Owner][1] = overlayPixmaps( nickIcons[Owner][0], elementAway );

    nickIcons[Admin][0] = overlayPixmaps( elementNormal, elementAdmin );
    nickIcons[Admin][1] = overlayPixmaps( nickIcons[Admin][0], elementAway );

    /*
    // why doesn't it work?
    nickIcons[Op][0] = elementNormal;
    bitBlt( &nickIcons[Op][0], 0, 0, &elementOp, 0, 0, -1, -1, TQt::CopyROP );
    nickIcons[Op][1] = nickIcons[Op][0];
    bitBlt( &nickIcons[Op][1], 0, 0, &elementAway, 0, 0, -1, -1, TQt::CopyROP );
    */
}

void Images::updateIcons()
{
    m_closeIcon = TDEGlobal::iconLoader()->loadIcon("window-close",TDEIcon::Small);
    m_disabledCloseIcon = TDEGlobal::iconLoader()->loadIconSet("window-close",TDEIcon::Small).pixmap(TQIconSet::Small, false);
}

TQIconSet Images::getLed(TQColor col,bool state)
{
    TQColor color;
    TQPainter paint;
    TQBrush brush;
    TQPen pen;

    if (state==false)
        color = col.dark(180);
    else
        color = col;

    int scale = 3;
    int width = 12 * scale;

    TQPixmap *tmpMap = 0;

    tmpMap = new TQPixmap(width + 6, width + 6);
    TQWidget tmpWidget;
    tmpMap->fill(tmpWidget.paletteBackgroundColor());
    paint.begin(tmpMap);

    // Set the brush to SolidPattern, this fills the entire area
    // of the ellipse which is drawn first
    brush.setStyle( Qt::SolidPattern );
    brush.setColor( color );
    paint.setBrush( brush );

    // Draw a "flat" LED with the given color
    paint.drawEllipse( scale, scale, width - scale*2, width - scale*2 );

    // Setting the new width of the pen is essential to avoid "pixelized"
    // shadow like it can be observed with the old LED code
    pen.setWidth( 2 * scale );

    // shrink the light on the LED to a size about 2/3 of the complete LED
    int pos = width/5 + 1;
    int light_width = width;
    light_width *= 2;
    light_width /= 3;

    // Calculate the LEDs "light factor"
    int light_quote = (130*2/(light_width?light_width:1))+100;

    // Draw the bright spot on the LED
    while (light_width)
    {
        color = color.light( light_quote ); // make color lighter
        pen.setColor( color );              // set color as pen color
        paint.setPen( pen );                // select the pen for drawing
        paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle)
        light_width--;
        if (!light_width)
            break;
        paint.drawEllipse( pos, pos, light_width, light_width );
        light_width--;
        if (!light_width)
            break;
        paint.drawEllipse( pos, pos, light_width, light_width );
        pos++; light_width--;
    }

    // Draw border
    pen.setWidth( scale + 1 );
    color = TQColor("#7D7D7D");
    pen.setColor( color );             // Set the pen accordingly
    paint.setPen( pen );               // Select pen for drawing
    brush.setStyle( Qt::NoBrush );     // Switch off the brush
    paint.setBrush( brush );           // This avoids filling of the ellipse
    paint.drawEllipse( 2, 2, width, width );
    paint.end();

    tmpMap->setMask(tmpMap->createHeuristicMask(true));

    // painting done
    TQImage i = tmpMap->convertToImage();
    delete tmpMap;

    i.setAlphaBuffer(true);
    width /= 3;
    i = i.smoothScale(width, width);

    TQPixmap dest = i;

    TQIconSet result;
    result.setPixmap(dest,TQIconSet::Automatic);
    return dest;
}

TQIconSet Images::getServerLed(bool state)
{
    if (state)
        return m_serverLedOn;
    else
        return m_serverLedOff;
}

TQIconSet Images::getSystemLed(bool state)
{
    if (Preferences::tabNotificationsSystemColor()!=m_systemColor)
    {
        if (state)
            return getLed(Preferences::tabNotificationsSystemColor(),true);
        else
            return getLed(Preferences::tabNotificationsSystemColor(),false);
    }
    else
    {
        if (state)
            return m_systemLedOn;
        else
            return m_systemLedOff;
    }
}

TQIconSet Images::getMsgsLed(bool state)
{
    if (Preferences::tabNotificationsMsgsColor()!=m_msgsColor)
    {
        if (state)
            return getLed(Preferences::tabNotificationsMsgsColor(),true);
        else
            return getLed(Preferences::tabNotificationsMsgsColor(),false);
    }
    else
    {
        if (state)
            return m_msgsLedOn;
        else
            return m_msgsLedOff;
    }
}

TQIconSet Images::getPrivateLed(bool state)
{
    if (Preferences::tabNotificationsPrivateColor()!=m_privateColor)
    {
        if (state)
            return getLed(Preferences::tabNotificationsPrivateColor(),true);
        else
            return getLed(Preferences::tabNotificationsPrivateColor(),false);
    }
    else
    {
        if (state)
            return m_privateLedOn;
        else
            return m_privateLedOff;
    }
}

TQIconSet Images::getEventsLed()
{
    if (Preferences::tabNotificationsEventsColor()!=m_eventsColor)
        return getLed(Preferences::tabNotificationsEventsColor(),true);
    else
        return m_eventsLedOn;
}

TQIconSet Images::getNickLed()
{
    if (Preferences::tabNotificationsNickColor()!=m_nickColor)
        return getLed(Preferences::tabNotificationsNickColor(),true);
    else
        return m_nickLedOn;
}

TQIconSet Images::getHighlightsLed()
{
    if (Preferences::tabNotificationsHighlightsColor()!=m_highlightsColor)
        return getLed(Preferences::tabNotificationsHighlightsColor(),true);
    else
        return m_highlightsLedOn;
}

#include "images.moc"