~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvirc/ui/kvi_texticonwin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : kvi_texticonwin.cpp
4
 
//   Creation date : Fri May 17 2002 02:35:20 by Szymon Stefanek
5
 
//
6
 
//   This file is part of the KVirc irc client distribution
7
 
//   Copyright (C) 2002-2008 Szymon Stefanek (pragma at kvirc dot net)
8
 
//
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.
13
 
//
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.
18
 
//
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.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#include "kvi_texticonwin.h"
26
 
#include "kvi_texticonmanager.h"
27
 
#include "kvi_app.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"
33
 
 
34
 
#include <QPainter>
35
 
#include <QLineEdit>
36
 
#include <QEvent>
37
 
#include <QKeyEvent>
38
 
#include <QHeaderView>
39
 
#include <QPalette>
40
 
#include <QScrollBar>
41
 
 
42
 
KviTextIconWindow::KviTextIconWindow()
43
 
: QWidget(0, Qt::Popup)
44
 
{
45
 
        m_pOwner   = 0;
46
 
        m_bAltMode = false;
47
 
 
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);
60
 
 
61
 
 
62
 
        fill();
63
 
        //connect(g_pTextIconManager,SIGNAL(changed()),this,SLOT(fill()));
64
 
        connect(m_pTable,SIGNAL(cellClicked( int, int )),this,SLOT(cellSelected(int, int)));
65
 
}
66
 
 
67
 
KviTextIconWindow::~KviTextIconWindow()
68
 
{
69
 
        m_pTable->deleteLater();
70
 
}
71
 
 
72
 
void KviTextIconWindow::fill()
73
 
{
74
 
        m_pTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
75
 
        m_pTable->clear();
76
 
 
77
 
        KviPointerHashTable<QString,KviTextIcon> * pDict = g_pTextIconManager->textIconDict();
78
 
        KviPointerHashTableIterator<QString,KviTextIcon> it(*pDict);
79
 
 
80
 
        int iCol = KVI_TEXTICON_COLUMNS;
81
 
        QLabel* newItem;
82
 
        while(KviTextIcon * pIcon = it.current())
83
 
        {
84
 
                QPixmap * pPix = pIcon->pixmap();
85
 
                if(pPix)
86
 
                {
87
 
                        newItem = new QLabel();
88
 
                        newItem->setToolTip(it.currentKey());
89
 
                        newItem->setPixmap(*pPix);
90
 
                        newItem->setAlignment(Qt::AlignCenter);
91
 
                        if(iCol == KVI_TEXTICON_COLUMNS)
92
 
                        {
93
 
                                iCol=0;
94
 
                                m_pTable->insertRow(m_pTable->rowCount());
95
 
                        }
96
 
                        m_pTable->setCellWidget(m_pTable->rowCount()-1,iCol,newItem);
97
 
                        iCol++;
98
 
                }
99
 
                ++it;
100
 
        }
101
 
 
102
 
        m_pTable->sortItems(0,Qt::AscendingOrder);
103
 
        m_pTable->setCurrentItem(0);
104
 
}
105
 
 
106
 
void KviTextIconWindow::popup(QWidget * pOwner, bool bAltMode)
107
 
{
108
 
        m_bAltMode = bAltMode;
109
 
 
110
 
        if(m_pOwner)
111
 
                disconnect(m_pOwner,SIGNAL(destroyed()),this,SLOT(ownerDead()));
112
 
 
113
 
        m_pOwner = pOwner;
114
 
        connect(m_pOwner,SIGNAL(destroyed()),this,SLOT(ownerDead()));
115
 
 
116
 
        show();
117
 
}
118
 
 
119
 
void KviTextIconWindow::keyPressEvent(QKeyEvent * e)
120
 
{
121
 
        switch(e->key())
122
 
        {
123
 
                case Qt::Key_Space:
124
 
                case Qt::Key_Return:
125
 
                {
126
 
                        cellSelected(m_pTable->currentRow(), m_pTable->currentColumn());
127
 
                }
128
 
                break;
129
 
                case Qt::Key_Escape:
130
 
                        doHide();
131
 
                        break;
132
 
                break;
133
 
                default:
134
 
                        QWidget::keyPressEvent(e);
135
 
                        break;
136
 
        }
137
 
}
138
 
 
139
 
void KviTextIconWindow::ownerDead()
140
 
{
141
 
        m_pOwner = 0;
142
 
        doHide();
143
 
}
144
 
 
145
 
void KviTextIconWindow::doHide()
146
 
{
147
 
        hide();
148
 
 
149
 
        if(m_pOwner)
150
 
                m_pOwner->setFocus();
151
 
}
152
 
 
153
 
void KviTextIconWindow::cellSelected(int row, int column)
154
 
{
155
 
        if(m_pTable->cellWidget(row, column))
156
 
        {
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());
159
 
                szItem.append(' ');
160
 
 
161
 
                if(m_bAltMode)
162
 
                        szItem.prepend(KVI_TEXT_ICON);
163
 
 
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"))
169
 
                {
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());
174
 
                }
175
 
                doHide();
176
 
        }
177
 
}
178
 
 
179
 
 
180
 
 
181
 
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
182
 
#include "kvi_texticonwin.moc"
183
 
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES