1
//=============================================================================
3
// File : kvi_texticonwin.cpp
4
// Creation date : Fri May 17 2002 02:35:20 by Szymon Stefanek
6
// This file is part of the KVirc irc client distribution
7
// Copyright (C) 2002-2008 Szymon Stefanek (pragma at kvirc dot net)
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#include "kvi_texticonwin.h"
26
#include "kvi_texticonmanager.h"
28
#include "kvi_options.h"
29
#include "kvi_input.h"
30
#include "kvi_topicw.h"
31
#include "kvi_mirccntrl.h"
32
#include "kvi_iconmanager.h"
38
#include <QHeaderView>
42
KviTextIconWindow::KviTextIconWindow()
43
: QWidget(0, Qt::Popup)
48
setFixedSize(KVI_TEXTICON_WIN_WIDTH,KVI_TEXTICON_WIN_HEIGHT);
49
m_pTable = new QTableWidget(this);
50
m_pTable->setFixedSize(KVI_TEXTICON_WIN_WIDTH,KVI_TEXTICON_WIN_HEIGHT);
51
m_pTable->setSelectionMode(QAbstractItemView::SingleSelection);
52
m_pTable->horizontalHeader()->hide();
53
m_pTable->verticalHeader()->hide();
54
m_pTable->setShowGrid(false);
55
m_pTable->setColumnCount(KVI_TEXTICON_COLUMNS);
56
m_pTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57
int iColWidth=((width()-24)/KVI_TEXTICON_COLUMNS);
58
for(int i=0; i<KVI_TEXTICON_COLUMNS;i++)
59
m_pTable->setColumnWidth(i,iColWidth);
63
//connect(g_pTextIconManager,SIGNAL(changed()),this,SLOT(fill()));
64
connect(m_pTable,SIGNAL(cellClicked( int, int )),this,SLOT(cellSelected(int, int)));
67
KviTextIconWindow::~KviTextIconWindow()
69
m_pTable->deleteLater();
72
void KviTextIconWindow::fill()
74
m_pTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
77
KviPointerHashTable<QString,KviTextIcon> * pDict = g_pTextIconManager->textIconDict();
78
KviPointerHashTableIterator<QString,KviTextIcon> it(*pDict);
80
int iCol = KVI_TEXTICON_COLUMNS;
82
while(KviTextIcon * pIcon = it.current())
84
QPixmap * pPix = pIcon->pixmap();
87
newItem = new QLabel();
88
newItem->setToolTip(it.currentKey());
89
newItem->setPixmap(*pPix);
90
newItem->setAlignment(Qt::AlignCenter);
91
if(iCol == KVI_TEXTICON_COLUMNS)
94
m_pTable->insertRow(m_pTable->rowCount());
96
m_pTable->setCellWidget(m_pTable->rowCount()-1,iCol,newItem);
102
m_pTable->sortItems(0,Qt::AscendingOrder);
103
m_pTable->setCurrentItem(0);
106
void KviTextIconWindow::popup(QWidget * pOwner, bool bAltMode)
108
m_bAltMode = bAltMode;
111
disconnect(m_pOwner,SIGNAL(destroyed()),this,SLOT(ownerDead()));
114
connect(m_pOwner,SIGNAL(destroyed()),this,SLOT(ownerDead()));
119
void KviTextIconWindow::keyPressEvent(QKeyEvent * e)
126
cellSelected(m_pTable->currentRow(), m_pTable->currentColumn());
134
QWidget::keyPressEvent(e);
139
void KviTextIconWindow::ownerDead()
145
void KviTextIconWindow::doHide()
150
m_pOwner->setFocus();
153
void KviTextIconWindow::cellSelected(int row, int column)
155
if(m_pTable->cellWidget(row, column))
157
// debug("%i %i %i %s",m_pOwner->inherits("KviInputEditor"),m_pOwner->inherits("KviInput"),m_pOwner->inherits("QLineEdit"),m_pOwner->className());
158
QString szItem(m_pTable->cellWidget(row, column)->toolTip());
162
szItem.prepend(KVI_TEXT_ICON);
164
if(m_pOwner->inherits("KviInputEditor"))
165
((KviInputEditor *)m_pOwner)->insertText(szItem);
166
else if(m_pOwner->inherits("KviInput"))
167
((KviInput *)m_pOwner)->insertText(szItem);
168
else if(m_pOwner->inherits("QLineEdit"))
170
QString szTmp = ((QLineEdit *)m_pOwner)->text();
171
szTmp.insert(((QLineEdit *)m_pOwner)->cursorPosition(),szItem);
172
((QLineEdit *)m_pOwner)->setText(szTmp);
173
((QLineEdit *)m_pOwner)->setCursorPosition(((QLineEdit *)m_pOwner)->cursorPosition() + szItem.length());
181
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
182
#include "kvi_texticonwin.moc"
183
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES