2
// File : kvi_opaquelabel.cpp
3
// Last major modification : Thu Jan 23 2000 02:15:12 by Szymon Stefanek
5
// This file is part of the KVirc irc client distribution
6
// Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
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.
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.
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.
23
#include "kvi_opaquelabel.h"
24
#include "kvi_xutils.h"
25
#include "kvi_defines.h"
26
#include "kvi_malloc.h"
28
#include <qfontmetrics.h>
31
#define KVI_CHAN_LABEL_BORDER 2
33
#ifdef COMPILE_USE_AA_FONTS
36
extern int qt_use_xft (void); // qpainter_x11.cpp
37
extern void *qt_ft_font (const QFont *f); // qfont_x11.cpp
38
extern XftDraw * qt_lookup_ft_draw (Drawable draw, bool paintEventClipOn, QRegion *crgn);
42
// A non themeable label
45
KviOpaqueLabel::KviOpaqueLabel(QWidget *parent,const char *name)
50
KviOpaqueLabel::KviOpaqueLabel(const QString &text,QWidget *parent,const char *name)
51
:QLabel(text,parent,name)
55
KviOpaqueLabel::~KviOpaqueLabel()
62
void KviOpaqueLabel::setMask(const QBitmap &)
66
void KviOpaqueLabel::setMask(const QRegion &)
70
void KviOpaqueLabel::setAutoMask(bool)
75
// A non themeable (from outside) label
76
// Used for the channel labels
79
KviChanLabel::KviChanLabel(const char * text,QWidget *parent,const char *name)
83
m_szText = text ? text : "";
84
m_iFirstVisibleChar = 0;
85
m_textColor = colorGroup().text();
86
m_backColor = colorGroup().button();
88
setBackgroundMode(NoBackground);
90
m_bLeft = new QToolButton(LeftArrow,this);
91
m_bRight = new QToolButton(RightArrow,this);
93
m_bLeft->setFocusPolicy(QWidget::NoFocus);
94
m_bLeft->setAutoRepeat(true);
96
m_bRight->setFocusPolicy(QWidget::NoFocus);
97
m_bRight->setAutoRepeat(true);
102
connect(m_bLeft,SIGNAL(pressed()),this,SLOT(scrollLeft()));
103
connect(m_bRight,SIGNAL(pressed()),this,SLOT(scrollRight()));
106
KviChanLabel::~KviChanLabel()
108
delete m_bLeft,m_bRight;
111
const char * KviChanLabel::strippedText()
114
char * p = m_szText.ptr();
118
case KVI_TEXT_REVERSE:
120
case KVI_TEXT_UNDERLINE:
125
if((*p)&&(*p >= '0')&&(*p <= '9')){
127
if((*p)&&(*p >= '0')&&(*p <= '9'))
129
if((*p)&&(*p == ',')){
131
if((*p)&&(*p >= '0')&&(*p <= '9'))
133
if((*p)&&(*p >= '0')&&(*p <= '9'))
144
p = (char *)kvi_malloc(text.len()+1);
145
qstrcpy(p, text.ptr());
149
void KviChanLabel::setBackgroundPixmapPointer(QPixmap * pix)
155
void KviChanLabel::setTextColor(QColor &clr)
161
void KviChanLabel::setBackColor(QColor &clr)
167
void KviChanLabel::paintEvent(QPaintEvent *e)
169
QPixmap * pix = new QPixmap(width(),height());
170
QColorGroup g = colorGroup();
171
Display * dpy = qt_xdisplay();
172
GC the_gc = XCreateGC(dpy,pix->handle(),0,0);
176
XSetTile(dpy,the_gc,m_pPixPointer->handle());
177
XSetFillStyle(dpy,the_gc,FillTiled);
179
XSetForeground(dpy,the_gc,m_backColor.pixel());
180
XSetBackground(dpy,the_gc,m_backColor.pixel());
181
XSetFillStyle(dpy,the_gc,FillSolid);
183
XFillRectangle(dpy,pix->handle(),the_gc,0,0,width(),height());
185
kvi_xDraw3dRect(dpy,the_gc,pix->handle(),colorGroup(),0,0,width() - 1,height() - 1,true);
187
KviStr pT(strippedText());
188
if(m_iFirstVisibleChar < 0)m_iFirstVisibleChar = 0;
189
KviStr t(pT.right(pT.len()-m_iFirstVisibleChar));
190
if(fontMetrics().width(pT.ptr()) < width()){
195
bs.setHeight(height());
196
bs.setWidth(height()*5/6); // 5/8 - reciprocal golden mean
198
m_bRight->resize(bs);
199
int buttonWidth = m_bRight->width();
200
int x = width() - buttonWidth;
201
m_bLeft->move(x-buttonWidth,0);
202
m_bLeft->setEnabled((m_iFirstVisibleChar != 0));
204
m_bRight->setEnabled(fontMetrics().width(t.ptr()) >= width()-m_bLeft->width()-m_bRight->width());
211
// const char * t = m_szText.ptr();
212
XSetForeground(dpy,the_gc,m_textColor.pixel());
213
#ifdef COMPILE_USE_AA_FONTS
216
g_pXftFont = (XftFont *)qt_ft_font(&(font()));
217
g_pXftDraw = qt_lookup_ft_draw (pix->handle(),false,0);
220
XSetFont(dpy,the_gc,font().handle());
225
XSetFont(dpy,the_gc,font().handle());
226
#ifdef COMPILE_USE_AA_FONTS
232
QColor * clr = &m_textColor;
233
color.color.red = clr->red() | clr->red() << 8;
234
color.color.green = clr->green() | clr->green() << 8;
235
color.color.blue = clr->blue() | clr->blue() << 8;
236
color.color.alpha = 0xffff;
237
color.pixel = clr->pixel();
238
XftDrawString8(g_pXftDraw,&color,g_pXftFont,KVI_CHAN_LABEL_BORDER,
239
(height() >> 1) + (fontMetrics().height() >> 1) - (fontMetrics().descent() + 1),(unsigned char *)t.ptr(),t.len());
242
XDrawString(dpy,pix->handle(),the_gc,KVI_CHAN_LABEL_BORDER,
243
(height() >> 1) + (fontMetrics().height() >> 1) - (fontMetrics().descent() + 1),t.ptr(),t.len());
246
XCopyArea(dpy,pix->handle(),this->handle(),the_gc,0,0,width(),height(),0,0);
252
void KviChanLabel::setText(const char * text)
254
m_szText = text ? text : "";
255
m_iFirstVisibleChar = 0;
259
void KviChanLabel::scrollLeft()
261
if(m_iFirstVisibleChar)m_iFirstVisibleChar--;
265
void KviChanLabel::scrollRight()
267
KviStr pT(strippedText());
268
KviStr t(pT.right(pT.len()-m_iFirstVisibleChar));
270
if(fontMetrics().width(t.ptr()) >= width()-m_bLeft->width()-m_bRight->width())
271
m_iFirstVisibleChar++;
275
void KviChanLabel::mousePressEvent(QMouseEvent *e)
277
if(e->button() & RightButton)emit rightClicked();
278
else QWidget::mousePressEvent(e);
281
void KviChanLabel::mouseDoubleClickEvent(QMouseEvent *)
286
void KviChanLabel::mouseReleaseEvent(QMouseEvent *)
290
emit doubleClicked();
295
QSize KviChanLabel::sizeHint()
297
QFontMetrics fm = fontMetrics();
298
return QSize(100,fm.height() + (KVI_CHAN_LABEL_BORDER << 1));
301
#include "m_kvi_opaquelabel.moc"