~ubuntu-branches/ubuntu/hoary/kvirc/hoary

« back to all changes in this revision

Viewing changes to src/kvirc/kvi_colorwin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Robin Verduijn
  • Date: 2004-12-14 15:32:19 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041214153219-fdink3gyp2s20b6g
Tags: 2:2.1.3.1-2
* Change Recommends on xmms to a Suggests.
* Rebuild against KDE 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
//   File : kvi_colorwin.cpp (/usr/build/NEW_kvirc/kvirc/kvirc/kvi_colorwin.cpp)
3
 
//   Last major modification : Wed Jan 6 1999 04:30:20 by Szymon Stefanek
4
 
//
5
 
//   This file is part of the KVirc irc client distribution
6
 
//   Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
7
 
//
8
 
//   This program is FREE software. You can redistribute it and/or
9
 
//   modify it under the terms of the GNU General Public License
10
 
//   as published by the Free Software Foundation; either version 2
11
 
//   of the License, or (at your opinion) any later version.
12
 
//
13
 
//   This program is distributed in the HOPE that it will be USEFUL,
14
 
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 
//   See the GNU General Public License for more details.
17
 
//
18
 
//   You should have received a copy of the GNU General Public License
19
 
//   along with this program. If not, write to the Free Software Foundation,
20
 
//   Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
 
//
22
 
 
23
 
#include "kvi_colorwin.h"
24
 
#include "kvi_app.h"
25
 
#include "kvi_options.h"
26
 
 
27
 
#include "kvi_xutils.h"
28
 
 
29
 
#include <qnamespace.h>
30
 
 
31
 
#ifdef COMPILE_USE_AA_FONTS
32
 
        extern XftFont        * g_pXftFont;
33
 
        extern XftDraw        * g_pXftDraw;
34
 
        extern int qt_use_xft (void); // qpainter_x11.cpp
35
 
        extern void *qt_ft_font (const QFont *f); // qfont_x11.cpp
36
 
        extern XftDraw * qt_lookup_ft_draw (Drawable draw, bool paintEventClipOn, QRegion *crgn);
37
 
#endif
38
 
 
39
 
KviColorWindow::KviColorWindow()
40
 
:QWidget(0,"KviColorWindow",Qt::WType_Popup)
41
 
{
42
 
        setFocusPolicy(QWidget::NoFocus);
43
 
        setBackgroundMode(NoBackground);
44
 
        setFixedSize(146,38);
45
 
        m_pOwner = 0;
46
 
        QFont fnt("fixed",10);
47
 
        setFont(fnt);
48
 
}
49
 
 
50
 
KviColorWindow::~KviColorWindow()
51
 
{
52
 
        killTimers();
53
 
//      if(m_pOwner)m_pOwner->setFocus();
54
 
}
55
 
 
56
 
void KviColorWindow::popup(QWidget *owner)
57
 
{
58
 
        m_pOwner = owner;
59
 
        show();
60
 
}
61
 
 
62
 
void KviColorWindow::paintEvent(QPaintEvent *)
63
 
{
64
 
        static int clrIdx[16]={ 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,1 };
65
 
        Display *dpy          = x11Display();
66
 
        GC gc_aux             = XCreateGC(dpy,handle(),0,0);
67
 
        XSetLineAttributes(dpy,gc_aux,1,LineSolid,CapButt,JoinMiter);
68
 
#ifdef COMPILE_USE_AA_FONTS
69
 
        if(qt_use_xft())
70
 
        {
71
 
                g_pXftFont = (XftFont *)qt_ft_font(&(font()));
72
 
                g_pXftDraw = qt_lookup_ft_draw (handle(),false,0);
73
 
                if(!g_pXftDraw)
74
 
                {
75
 
                        XSetFont(dpy,gc_aux,font().handle());
76
 
                        g_pXftFont = 0;
77
 
                }
78
 
                
79
 
        } else {
80
 
#endif
81
 
                XSetFont(dpy,gc_aux,font().handle());
82
 
#ifdef COMPILE_USE_AA_FONTS
83
 
                g_pXftFont = 0;
84
 
                g_pXftDraw = 0;
85
 
        }
86
 
#endif
87
 
        kvi_xDraw3dRect(dpy,gc_aux,handle(),colorGroup(),0,0,width()-1,height()-1,false);
88
 
        int curX=1;
89
 
        for(int i=0;i<8;i++){
90
 
                kvi_xDraw3dRect(dpy,gc_aux,handle(),colorGroup(),curX,1,curX+17,18,true);
91
 
                XSetForeground(dpy,gc_aux,g_pOptions->m_pMircColor[i]->pixel());
92
 
                XFillRectangle(dpy,handle(),gc_aux,curX+1,2,16,16);
93
 
                XSetForeground(dpy,gc_aux,g_pOptions->m_pMircColor[clrIdx[i]]->pixel());
94
 
                char c='0'+i;
95
 
#ifdef COMPILE_USE_AA_FONTS
96
 
                if(g_pXftFont){
97
 
                        XftColor color;
98
 
                        QColor * clr = g_pOptions->m_pMircColor[clrIdx[i]];
99
 
                        color.color.red = clr->red() | clr->red() << 8;
100
 
                        color.color.green = clr->green() | clr->green() << 8;
101
 
                        color.color.blue = clr->blue() | clr->blue() << 8;
102
 
                        color.color.alpha = 0xffff;
103
 
                        color.pixel = clr->pixel();
104
 
                        XftDrawString8(g_pXftDraw,&color,g_pXftFont,curX+5,14,(unsigned char *)&c,1);
105
 
                } else
106
 
#endif
107
 
                        XDrawString(dpy,handle(),gc_aux,curX+5,14,&c,1);
108
 
                curX+=18;
109
 
        }
110
 
        curX=1;
111
 
        for(int i=8;i<16;i++){
112
 
                kvi_xDraw3dRect(dpy,gc_aux,handle(),colorGroup(),curX,19,curX+17,36,true);
113
 
                XSetForeground(dpy,gc_aux,g_pOptions->m_pMircColor[i]->pixel());
114
 
                XFillRectangle(dpy,handle(),gc_aux,curX+1,20,16,16);
115
 
                XSetForeground(dpy,gc_aux,g_pOptions->m_pMircColor[clrIdx[i]]->pixel());
116
 
                char c[2];
117
 
                if(i<10){
118
 
                        c[0]='0'+i;
119
 
#ifdef COMPILE_USE_AA_FONTS
120
 
                        if(g_pXftFont){
121
 
                                XftColor color;
122
 
                                QColor * clr = g_pOptions->m_pMircColor[clrIdx[i]];
123
 
                                color.color.red = clr->red() | clr->red() << 8;
124
 
                                color.color.green = clr->green() | clr->green() << 8;
125
 
                                color.color.blue = clr->blue() | clr->blue() << 8;
126
 
                                color.color.alpha = 0xffff;
127
 
                                color.pixel = clr->pixel();
128
 
                                XftDrawString8(g_pXftDraw,&color,g_pXftFont,curX+5,33,
129
 
                                        (unsigned char *)c,1);
130
 
                        } else
131
 
#endif
132
 
                                XDrawString(dpy,handle(),gc_aux,curX+5,33,c,1);
133
 
                } else {
134
 
                        c[0]='1';
135
 
                        c[1]='0'+(i-10);
136
 
#ifdef COMPILE_USE_AA_FONTS
137
 
                        if(g_pXftFont){
138
 
                                XftColor color;
139
 
                                QColor * clr = g_pOptions->m_pMircColor[clrIdx[i]];
140
 
                                color.color.red = clr->red() | clr->red() << 8;
141
 
                                color.color.green = clr->green() | clr->green() << 8;
142
 
                                color.color.blue = clr->blue() | clr->blue() << 8;
143
 
                                color.color.alpha = 0xffff;
144
 
                                color.pixel = clr->pixel();
145
 
                                XftDrawString8(g_pXftDraw,&color,g_pXftFont,curX+2,33,
146
 
                                        (unsigned char *)c,2);
147
 
                        } else
148
 
#endif
149
 
                                XDrawString(dpy,handle(),gc_aux,curX+2,33,c,2);
150
 
                }
151
 
                curX+=18;
152
 
        }
153
 
        XFreeGC(dpy,gc_aux);
154
 
}
155
 
 
156
 
void KviColorWindow::keyPressEvent(QKeyEvent *e)
157
 
{
158
 
        killTimers();
159
 
        hide();
160
 
        if(m_pOwner)g_pApp->sendEvent(m_pOwner,e);
161
 
}
162
 
 
163
 
void KviColorWindow::mousePressEvent(QMouseEvent *)
164
 
{
165
 
        killTimers();
166
 
        hide();
167
 
}
168
 
 
169
 
void KviColorWindow::show()
170
 
{
171
 
        startTimer(10000); //10 sec ...seems enough
172
 
        QWidget::show();
173
 
}
174
 
 
175
 
void KviColorWindow::timerEvent(QTimerEvent *)
176
 
{
177
 
        killTimers();
178
 
        hide();
179
 
}
180
 
 
181
 
#include "m_kvi_colorwin.moc"