root/trunk/qt4-gui/src/dockicons/defaultdockicon.cpp

Revision 6058, 4.0 kB (checked in by eugene, 10 months ago)

Major docking fix.

Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 2007 Licq developers
5 *
6 * Licq is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Licq is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Licq; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#include "defaultdockicon.h"
22
23#include "config.h"
24
25#include <QBitmap>
26#include <QPainter>
27
28#include <licq_user.h>
29
30#include "config/general.h"
31#include "dockiconwidget.h"
32
33#include "xpm/dock/away.xpm"
34#include "xpm/dock/back48.xpm"
35#include "xpm/dock/back64.xpm"
36#include "xpm/dock/digits.h"
37#include "xpm/dock/dnd.xpm"
38#include "xpm/dock/ffc.xpm"
39#include "xpm/dock/invisible.xpm"
40#include "xpm/dock/mask48.xpm"
41#include "xpm/dock/mask64.xpm"
42#include "xpm/dock/na.xpm"
43#include "xpm/dock/occupied.xpm"
44#include "xpm/dock/offline.xpm"
45#include "xpm/dock/online.xpm"
46
47using namespace LicqQtGui;
48
49DefaultDockIcon::DefaultDockIcon(QMenu* menu)
50  : DockIcon()
51{
52  myIcon = new DockIconWidget(menu);
53  relayDockIconSignals();
54  updateConfig();
55}
56
57void DefaultDockIcon::updateConfig()
58{
59  myFortyEight = Config::General::instance()->defaultIconFortyEight();
60
61  QPixmap* pic = new QPixmap(myFortyEight ? back48_xpm : back64_xpm);
62  QBitmap bmp = QBitmap(myFortyEight ? mask48_xpm : mask64_xpm);
63  pic->setMask(bmp);
64  myIcon->setFace(pic);
65  delete pic;
66
67  updateStatusIcon();
68  updateIconMessages(myNewMsg, mySysMsg);
69}
70
71void DefaultDockIcon::updateStatusIcon()
72{
73  DockIcon::updateStatusIcon();
74
75  if (!myFortyEight && myNewMsg == 0 && mySysMsg == 0)
76    drawIcon64(myStatusIcon);
77
78  QPixmap m;
79  if (myInvisible)
80    m = QPixmap(invisible_xpm);
81  else
82    switch (myStatus)
83    {
84      case ICQ_STATUS_ONLINE: m = QPixmap(online_xpm); break;
85      case ICQ_STATUS_AWAY: m = QPixmap(away_xpm); break;
86      case ICQ_STATUS_NA: m = QPixmap(na_xpm); break;
87      case ICQ_STATUS_OCCUPIED: m = QPixmap(occupied_xpm); break;
88      case ICQ_STATUS_DND: m = QPixmap(dnd_xpm); break;
89      case ICQ_STATUS_FREEFORCHAT: m = QPixmap(ffc_xpm); break;
90      case ICQ_STATUS_OFFLINE: m = QPixmap(offline_xpm); break;
91    }
92
93  QPixmap* face = myIcon->face();
94  QPainter painter(face);
95  painter.drawPixmap(0, myFortyEight ? 27 : 44, m);
96  painter.end();
97
98  myIcon->setFace(face);
99  delete face;
100}
101
102void DefaultDockIcon::updateIconMessages(int newMsg, int sysMsg)
103{
104  DockIcon::updateIconMessages(newMsg, sysMsg);
105
106  int low, high;
107
108#define SPLIT(num) \
109  (num) = qMin(num, 99); \
110  low = (num) % 10; \
111  high = (num) / 10;
112
113  QPixmap* face = myIcon->face();
114  QPainter p(face);
115
116  SPLIT(newMsg);
117  p.drawPixmap(44, myFortyEight ? 8 : 26, digits[high]);
118  p.drawPixmap(50, myFortyEight ? 8 : 26, digits[low]);
119
120  SPLIT(sysMsg);
121  p.drawPixmap(44, myFortyEight ? 20 : 38, digits[high]);
122  p.drawPixmap(50, myFortyEight ? 20 : 38, digits[low]);
123
124  p.end();
125
126  myIcon->setFace(face);
127  delete face;
128}
129
130void DefaultDockIcon::updateEventIcon()
131{
132  DockIcon::updateEventIcon();
133
134  if (myFortyEight)
135    return;
136
137  drawIcon64((mySysMsg > 0 || myNewMsg > 0) ? myEventIcon : myStatusIcon);
138}
139
140void DefaultDockIcon::drawIcon64(QPixmap* icon)
141{
142  if (icon == NULL || icon->isNull())
143    return;
144
145  QPixmap* face = myIcon->face();
146  QPainter p(face);
147
148  // Clear the icon area
149  p.fillRect(31, 6, 27, 16, Qt::black);
150
151  // Calculate drawing coordinates
152  int w = qMin(icon->width(), 27);
153  int h = qMin(icon->height(), 16);
154  int x = 45 - (w / 2);
155  int y = 14 - (h / 2);
156
157  p.drawPixmap(x, y, *icon, 0, 0, w, h);
158  p.end();
159
160  myIcon->setFace(face);
161  delete face;
162}
Note: See TracBrowser for help on using the browser.