summaryrefslogtreecommitdiffstats
path: root/src/kvirc/ui/kvi_colorwin.cpp
blob: 8b27750e9c3b4b66003f65c5baa4ea99dffc3966 (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
//=============================================================================
//
//   File : kvi_colorwin.cpp
//   Creation date : Wed Jan 6 1999 04:30:20 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 1999-2007 Szymon Stefanek (pragma at kvirc dot net)
//
//   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 opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#define __KVIRC__

#include "kvi_colorwin.h"
#include "kvi_app.h"
#include "kvi_options.h"


#include <tqnamespace.h>
#include <tqpainter.h>
#include <tqstring.h>
#include <tqevent.h>


KviColorWindow::KviColorWindow()
:TQWidget(0,"toplevel_color_window",TQt::WType_Popup)
{
#ifdef COMPILE_USE_QT4
	setFocusPolicy(TQ_NoFocus);
#else
	setFocusPolicy(TQ_NoFocus);
#endif
	setBackgroundMode(TQt::NoBackground);
	setFixedSize(146,38);
	m_pOwner = 0;
	TQFont fnt = TQFont();
	fnt.setStyleHint(TQFont::TypeWriter);
	fnt.setPointSize(10);
	//TQFont fnt("fixed",10);
	setFont(fnt);
	m_iTimerId = -1;
}

KviColorWindow::~KviColorWindow()
{
	if(m_iTimerId != -1)
		killTimer(m_iTimerId);
//	if(m_pOwner)m_pOwner->setFocus();
}

void KviColorWindow::popup(TQWidget *owner)
{
	m_pOwner = owner;
	show();
}


void KviColorWindow::paintEvent(TQPaintEvent *)
{
	static int clrIdx[16]={ 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,1 };
	TQPainter p(this);

	for(int i=0;i<16;i++)
	{
		p.fillRect((i % 8) * 18,(i / 8) * 18,18,18,KVI_OPTION_MIRCCOLOR(i));
		p.setPen(KVI_OPTION_MIRCCOLOR(clrIdx[i]));
		KviStr szI(KviStr::Format,"%d",i);
		p.drawText((i % 8) * 18,(i / 8) * 18,18,18,TQt::AlignVCenter | TQt::AlignHCenter,szI.ptr());
	}
}

void KviColorWindow::keyPressEvent(TQKeyEvent *e)
{
	if(m_iTimerId != -1)
		killTimer(m_iTimerId);
	hide();
	if(m_pOwner)g_pApp->sendEvent(m_pOwner,e);
}

void KviColorWindow::mousePressEvent(TQMouseEvent *e)
{
	TQString str;
	int key=e->x()/18;
	if (e->x()<36 && e->y()>18) key +=8;
	if (e->x()>36 && e->y()>18) key -=2;
	int ascii=key+48;
	str.setNum(key);
	if (e->x()>36 && e->y()>18) 
		if(m_pOwner) g_pApp->sendEvent(m_pOwner,new TQKeyEvent(TQEvent::KeyPress,TQt::Key_1,49,Qt::NoButton,"1"));
	if(m_pOwner) g_pApp->sendEvent(m_pOwner,new TQKeyEvent(TQEvent::KeyPress,key,ascii,Qt::NoButton,str));
	if(m_iTimerId != -1)
		killTimer(m_iTimerId);
	hide();
}
void KviColorWindow::show()
{
	m_iTimerId = startTimer(10000); //10 sec ...seems enough
	TQWidget::show();
}

void KviColorWindow::timerEvent(TQTimerEvent *)
{
	if(m_iTimerId != -1)
		killTimer(m_iTimerId);
	hide();
}


#include "kvi_colorwin.moc"