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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
//
// File : optw_texticons.cpp
// Creation date : Fri May 24 2002 00:16:13 CEST by Szymon Stefanek
//
// This file is part of the KVirc irc client distribution
// Copyright (C) 2002 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 "optw_texticons.h"
#include "kvi_iconmanager.h"
#include "kvi_texticonmanager.h"
#include "kvi_locale.h"
#include "kvi_filedialog.h"
#include <layout.h>
#include <tqcursor.h>
#include "kvi_tal_hbox.h"
KviTextIconEditor::KviTextIconEditor(TQWidget * par,KviTextIcon * icon,KviTextIconTableItem* item)
: KviTalHBox(par),m_pTableItem(item)
{
m_pIconButton=new TQToolButton(this);
m_pBrowseButton=new TQToolButton(this);
m_pBrowseButton->setSizePolicy(TQSizePolicy(TQSizePolicy::Maximum,TQSizePolicy::Maximum));
m_pBrowseButton->setText("...");
m_pIcon = icon;
m_pPopup = 0;
updateIcon();
connect(m_pIconButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(doPopup()));
connect(m_pBrowseButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(chooseFromFile()));
}
KviTextIconEditor::~KviTextIconEditor()
{
}
void KviTextIconEditor::doPopup()
{
if(!m_pPopup)
{
m_pPopup = new KviTalPopupMenu(this);
KviIconWidget * iw = new KviIconWidget(m_pPopup);
connect(iw,TQT_SIGNAL(selected(int)),this,TQT_SLOT(iconSelected(int)));
m_pPopup->insertItem(iw);
}
m_pPopup->popup(TQCursor::pos());
}
void KviTextIconEditor::iconSelected(int id)
{
m_pIcon->setId(id);
updateIcon();
}
void KviTextIconEditor::chooseFromFile()
{
TQString szFile;
KviFileDialog::askForOpenFileName(szFile,"Choose icon filename",TQString(),"*.png","options");
if(!szFile.isEmpty())
{
if(g_pIconManager->getPixmap(szFile))
{
m_pIcon->setFilename(szFile);
// debug("%s %s %i |%s| %p",__FILE__,__FUNCTION__,__LINE__,m_pIcon->filename().utf8().data(),m_pIcon);
updateIcon();
}
}
}
void KviTextIconEditor::updateIcon()
{
if(m_pIcon)
{
TQPixmap* pix=m_pIcon->pixmap();
if(pix)
m_pIconButton->setPixmap(*pix);
}
}
KviTextIconTableItem::KviTextIconTableItem(KviTalTable * t,KviTextIcon * icon)
: KviTalTableItem(t,KviTalTableItem::WhenCurrent,TQString())
{
if(icon)
m_pIcon=icon;
else
m_pIcon=new KviTextIcon(0);
TQPixmap* pix=m_pIcon->pixmap();
if(pix)
setPixmap(*pix);
}
KviTextIconTableItem::~KviTextIconTableItem()
{
delete m_pIcon;
}
void KviTextIconTableItem::setId(int id)
{
m_pIcon->setId(id);
TQPixmap* pix=m_pIcon->pixmap();
if(pix)
setPixmap(*pix);
}
TQWidget * KviTextIconTableItem::createEditor() const
{
return new KviTextIconEditor(table()->viewport(),m_pIcon,(KviTextIconTableItem*)this);
}
void KviTextIconTableItem::setContentFromEditor(TQWidget * w)
{
if(w->inherits("KviTextIconEditor"))
{
TQPixmap* pix=m_pIcon->pixmap();
if(pix)
setPixmap(*pix);
}
}
KviTextIconsOptionsWidget::KviTextIconsOptionsWidget(TQWidget * parent)
: KviOptionsWidget(parent,"texticons_options_widget")
{
createLayout(2,2);
KviPointerHashTableIterator<TQString,KviTextIcon> it(*(g_pTextIconManager->textIconDict()));
m_pTable = new KviTalTable(g_pTextIconManager->textIconDict()->count(),2,this);
#ifdef COMPILE_INFO_TIPS
mergeTip(m_pTable->viewport(),__tr2qs_ctx("This table contains the text icon associations.<br>" \
"KVirc will use them to display the CTRL+I escape sequences and eventually the " \
"emoticons.","options"));
#endif
int idx = 0;
while(KviTextIcon * i = it.current())
{
m_pTable->setText(idx,0,it.currentKey());
m_pTable->setItem(idx,1,new KviTextIconTableItem(m_pTable,new KviTextIcon(i)));
++idx;
++it;
}
layout()->addMultiCellWidget(m_pTable,0,0,0,1);
m_pAdd = new TQPushButton(__tr2qs_ctx("Add","options"),this);
layout()->addWidget(m_pAdd,1,0);
connect(m_pAdd,TQT_SIGNAL(clicked()),this,TQT_SLOT(addClicked()));
m_pDel = new TQPushButton(__tr2qs_ctx("Delete","options"),this);
layout()->addWidget(m_pDel,1,1);
connect(m_pDel,TQT_SIGNAL(clicked()),this,TQT_SLOT(delClicked()));
m_pDel->setEnabled(false);
connect(m_pTable,TQT_SIGNAL(selectionChanged()),this,TQT_SLOT(selectionChanged()));
}
KviTextIconsOptionsWidget::~KviTextIconsOptionsWidget()
{
}
void KviTextIconsOptionsWidget::selectionChanged()
{
int i = m_pTable->currentRow();
m_pDel->setEnabled(i >= 0 && i < m_pTable->numRows());
}
void KviTextIconsOptionsWidget::addClicked()
{
m_pTable->setNumRows(m_pTable->numRows() + 1);
m_pTable->setText(m_pTable->numRows() - 1,0,__tr2qs_ctx("unnamed","options"));
m_pTable->setItem(m_pTable->numRows() - 1,1,new KviTextIconTableItem(m_pTable,0));
m_pDel->setEnabled(true);
}
void KviTextIconsOptionsWidget::delClicked()
{
int i = m_pTable->currentRow();
if((i > -1) && (i < m_pTable->numRows()))
{
// remove row i
m_pTable->clearCell(i,0);
m_pTable->clearCell(i,1);
m_pTable->clearCell(i,2);
for(;i < (m_pTable->numRows() - 1);i++)
{
m_pTable->swapRows(i,i+1);
}
m_pTable->setNumRows(m_pTable->numRows() - 1);
if(m_pTable->numRows() == 0)m_pDel->setEnabled(false);
}
}
void KviTextIconsOptionsWidget::commit()
{
KviOptionsWidget::commit();
g_pTextIconManager->clear();
int n = m_pTable->numRows();
for(int i=0;i < n;i++)
{
TQString szVal = m_pTable->text(i,0);
if(!szVal.isEmpty())
{
KviTextIconTableItem * it = (KviTextIconTableItem *)m_pTable->item(i,1);
if(it)
{
g_pTextIconManager->insert(szVal,*(it->icon()));
}
}
}
g_pTextIconManager->checkDefaultAssociations();
for(int i=0; i<n; i++)
for (int j=0; j<m_pTable->numCols(); j++)
if (m_pTable->item(i,j))
m_pTable->clearCell(i,j);
}
#include "m_optw_texticons.moc"
|