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
|
//=============================================================================
//
// File : KviTextIconWindow.cpp
// Creation date : Fri May 17 2002 02:35:20 by Szymon Stefanek
//
// This file is part of the KVIrc irc client distribution
// Copyright (C) 2002-2010 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.
//
//=============================================================================
#include "KviTextIconWindow.h"
#include "KviTextIconManager.h"
#include "KviApplication.h"
#include "KviOptions.h"
#include "KviInput.h"
#include "KviTopicWidget.h"
#include "KviMircCntrl.h"
#include "KviIconManager.h"
#include <QPainter>
#include <QLineEdit>
#include <QEvent>
#include <QKeyEvent>
#include <QHeaderView>
#include <QPalette>
#include <QScrollBar>
KviTextIconWindow::KviTextIconWindow()
: QWidget(0, Qt::Popup)
{
m_pOwner = 0;
m_bAltMode = false;
setFixedSize(KVI_TEXTICON_WIN_WIDTH,KVI_TEXTICON_WIN_HEIGHT);
m_pTable = new QTableWidget(this);
m_pTable->setFixedSize(KVI_TEXTICON_WIN_WIDTH,KVI_TEXTICON_WIN_HEIGHT);
m_pTable->setSelectionMode(QAbstractItemView::SingleSelection);
m_pTable->horizontalHeader()->hide();
m_pTable->verticalHeader()->hide();
m_pTable->setShowGrid(false);
m_pTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
fill();
connect(g_pTextIconManager,SIGNAL(changed()),this,SLOT(fill()));
connect(m_pTable,SIGNAL(cellClicked( int, int )),this,SLOT(cellSelected(int, int)));
}
KviTextIconWindow::~KviTextIconWindow()
{
m_pTable->deleteLater();
}
void KviTextIconWindow::fill()
{
m_pTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_pTable->clear();
m_pTable->setRowCount(0);
m_pTable->setColumnCount(KVI_TEXTICON_COLUMNS);
int iColWidth=((width()-24)/KVI_TEXTICON_COLUMNS);
for(int i=0; i<KVI_TEXTICON_COLUMNS;i++)
m_pTable->setColumnWidth(i,iColWidth);
KviPointerHashTable<QString,KviTextIcon> * pDict = g_pTextIconManager->textIconDict();
KviPointerHashTableIterator<QString,KviTextIcon> it(*pDict);
int iCol = KVI_TEXTICON_COLUMNS;
QLabel* newItem;
while(KviTextIcon * pIcon = it.current())
{
QPixmap * pPix = pIcon->pixmap();
if(pPix)
{
newItem = new QLabel();
newItem->setToolTip(it.currentKey());
newItem->setPixmap(*pPix);
newItem->setAlignment(Qt::AlignCenter);
if(iCol == KVI_TEXTICON_COLUMNS)
{
iCol=0;
m_pTable->insertRow(m_pTable->rowCount());
}
m_pTable->setCellWidget(m_pTable->rowCount()-1,iCol,newItem);
iCol++;
}
++it;
}
m_pTable->sortItems(0,Qt::AscendingOrder);
m_pTable->setCurrentItem(0);
}
void KviTextIconWindow::popup(QWidget * pOwner, bool bAltMode)
{
m_bAltMode = bAltMode;
if(m_pOwner)
disconnect(m_pOwner,SIGNAL(destroyed()),this,SLOT(ownerDead()));
m_pOwner = pOwner;
connect(m_pOwner,SIGNAL(destroyed()),this,SLOT(ownerDead()));
show();
}
void KviTextIconWindow::keyPressEvent(QKeyEvent * e)
{
switch(e->key())
{
case Qt::Key_Space:
case Qt::Key_Return:
{
cellSelected(m_pTable->currentRow(), m_pTable->currentColumn());
}
break;
case Qt::Key_Tab:
//avoid the text edit field to move to the icon cells using tab
break;
break;
case Qt::Key_Escape:
doHide();
break;
break;
default:
QWidget::keyPressEvent(e);
break;
}
}
void KviTextIconWindow::ownerDead()
{
m_pOwner = 0;
doHide();
}
void KviTextIconWindow::doHide()
{
hide();
if(m_pOwner)
m_pOwner->setFocus();
}
void KviTextIconWindow::cellSelected(int row, int column)
{
if(m_pTable->cellWidget(row, column))
{
// qDebug("%i %i %i %s",m_pOwner->inherits("KviInputEditor"),m_pOwner->inherits("KviInput"),m_pOwner->inherits("QLineEdit"),m_pOwner->className());
QString szItem(m_pTable->cellWidget(row, column)->toolTip());
szItem.append(' ');
if(m_bAltMode)
szItem.prepend(KviMircCntrl::Icon);
if(m_pOwner->inherits("KviInputEditor"))
((KviInputEditor *)m_pOwner)->insertText(szItem);
else if(m_pOwner->inherits("KviInput"))
((KviInput *)m_pOwner)->insertText(szItem);
else if(m_pOwner->inherits("QLineEdit"))
{
QString szTmp = ((QLineEdit *)m_pOwner)->text();
szTmp.insert(((QLineEdit *)m_pOwner)->cursorPosition(),szItem);
((QLineEdit *)m_pOwner)->setText(szTmp);
((QLineEdit *)m_pOwner)->setCursorPosition(((QLineEdit *)m_pOwner)->cursorPosition() + szItem.length());
}
doHide();
}
}
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
#include "KviTextIconWindow.moc"
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES
|