~ubuntu-branches/ubuntu/utopic/kile/utopic-proposed

« back to all changes in this revision

Viewing changes to src/widgets/symbolview.cpp

  • Committer: Package Import Robot
  • Author(s): Prasad Murthy
  • Date: 2013-01-24 19:03:35 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20130124190335-29sj32fdx0d2kcmw
Tags: 1:2.1.3-0ubuntu1
* New upstream release
* Drop kubuntu_02_disable_embedded_kbibtex.diff as kbibtex is now usable with kde4
* Add kbibtex to suggests
* Change the Vcs links to the Ubuntu bzr branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
    begin                : Fri Aug 1 2003
3
3
    copyright            : (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)
4
4
                               2006 - 2009 by Thomas Braun
 
5
                               2012 by Michel Ludwig (michel.ludwig@kdemail.net)
5
6
 ****************************************************************************************/
6
7
 
7
8
/***************************************************************************
37
38
#include <QPainter>
38
39
#include <QRegExp>
39
40
#include <QStringList>
 
41
#include <QTextDocument>
40
42
 
 
43
#include <KColorScheme>
41
44
#include <KConfig>
42
45
#include <KLocale>
43
46
#include <KStandardDirs>
44
47
 
45
48
#include "kileconfig.h"
46
49
#include "kiledebug.h"
 
50
#include "kileinfo.h"
47
51
#include "../symbolviewclasses.h"
48
52
 
49
53
#define MFUS_GROUP "MostFrequentlyUsedSymbols"
52
56
 
53
57
namespace KileWidget {
54
58
 
55
 
SymbolView::SymbolView(QWidget *parent, int type, const char *name)
56
 
                : QListWidget(parent)
 
59
SymbolView::SymbolView(KileInfo *kileInfo, QWidget *parent, int type, const char *name)
 
60
                : QListWidget(parent), m_ki(kileInfo)
57
61
{
58
62
        setObjectName(name);
59
63
        setViewMode(IconMode);
86
90
 
87
91
void SymbolView::extract(const QString& key, int& refCnt)
88
92
{
89
 
   if (!key.isEmpty()) {
90
 
        refCnt = key.section('%', 0, 0).toInt();
91
 
   }
 
93
        if (!key.isEmpty()) {
 
94
                refCnt = key.section('%', 0, 0).toInt();
 
95
        }
92
96
}
93
97
 
94
 
void SymbolView::extractPackageString(const QString&string, QList<Package> &packages){
95
 
 
96
 
  QRegExp rePkgs("(?:\\[(.*)\\])?\\{(.*)\\}");
97
 
  QStringList args,pkgs;
98
 
  Package pkg;
99
 
 
100
 
  if(string.isEmpty()){
101
 
      return;
102
 
   }
103
 
 
104
 
   packages.clear();
105
 
 
106
 
   if ( rePkgs.exactMatch(string) ){
107
 
      args = rePkgs.cap(1).split(',');
108
 
      pkgs = rePkgs.cap(2).split(',');
109
 
   }
110
 
   else{
111
 
      return;
112
 
   }
113
 
 
114
 
   for(int i = 0 ; i <  pkgs.count() && i < args.count() ; i++){
115
 
      pkg.name = pkgs.at(i);
116
 
      pkg.arguments = args.at(i);
117
 
      packages.append(pkg);
118
 
   }
 
98
void SymbolView::extractPackageString(const QString&string, QList<Package> &packages)
 
99
{
 
100
        QRegExp rePkgs("(?:\\[(.*)\\])?\\{(.*)\\}");
 
101
        QStringList args,pkgs;
 
102
        Package pkg;
 
103
 
 
104
        if(string.isEmpty()) {
 
105
                return;
 
106
        }
 
107
 
 
108
        packages.clear();
 
109
 
 
110
        if(rePkgs.exactMatch(string)) {
 
111
                args = rePkgs.cap(1).split(',');
 
112
                pkgs = rePkgs.cap(2).split(',');
 
113
        }
 
114
        else {
 
115
                return;
 
116
        }
 
117
 
 
118
        for(int i = 0 ; i < pkgs.count() && i < args.count() ; i++) {
 
119
                const QString packageName = pkgs.at(i);
 
120
                if(packageName.isEmpty()) {
 
121
                        continue;
 
122
                }
 
123
                pkg.name = packageName;
 
124
                pkg.arguments = args.at(i);
 
125
                packages.append(pkg);
 
126
        }
119
127
 
120
128
}
121
129
 
124
132
        if (key.isEmpty()) {
125
133
                return;
126
134
        }
127
 
 
128
135
        QStringList contents = key.split('%');
129
136
        QString packages;
130
137
 
132
139
        cmd.latexCommand = contents.at(1);
133
140
        cmd.unicodeCommand = contents.at(2);
134
141
 
135
 
        extractPackageString(contents.at(3),cmd.unicodePackages);
136
 
        extractPackageString(contents.at(4),cmd.packages);
 
142
        extractPackageString(contents.at(3), cmd.unicodePackages);
 
143
        extractPackageString(contents.at(4), cmd.packages);
137
144
        cmd.comment = contents.at(5);
138
145
        cmd.path = contents.at(6);
139
146
}
193
200
 
194
201
QString SymbolView::getToolTip(const QString &key)
195
202
{
196
 
        QString label;
197
 
        QStringList pkgs, args;
198
203
        Command cmd;
199
 
        Package pkg;
200
 
 
201
204
        extract(key, cmd);
202
205
 
203
 
         label = "<b>" + i18n("Command: ") + cmd.latexCommand + "</b><br>";
204
 
         if(!cmd.unicodeCommand.isEmpty()) {
205
 
            label += i18n("Unicode command: ") + cmd.unicodeCommand + "<br>";
206
 
         }
 
206
        QString label = "<p style='white-space:pre'>";
 
207
        label += "<b>" + i18n("Command: %1", Qt::escape(cmd.latexCommand)) + "</b>";
 
208
        if(!cmd.unicodeCommand.isEmpty()) {
 
209
                label += i18n("<br/>Unicode: %1", Qt::escape(cmd.unicodeCommand));
 
210
        }
207
211
 
208
212
        if(cmd.packages.count() > 0) {
209
 
                if(cmd.packages.count() == 1) {
210
 
                        label += i18n("Package: ");
 
213
                QString packageString;
 
214
 
 
215
                if(cmd.packages.count() == 1) {
 
216
                        Package pkg = cmd.packages.at(0);
 
217
                        if(!pkg.arguments.isEmpty()) {
 
218
                                packageString += '[' + pkg.arguments + ']' + pkg.name;
 
219
                        }
 
220
                        else {
 
221
                                packageString += pkg.name;
 
222
                        }
211
223
                }
212
224
                else {
213
 
                        label += i18n("Packages: ");
214
 
                }
215
 
 
216
 
                for (int i = 0; i < cmd.packages.count() ; i++) {
217
 
                     pkg = cmd.packages.at(i);
218
 
                     if(!pkg.arguments.isEmpty()) {
219
 
                        label += '[' + pkg.arguments + ']' + pkg.name;
220
 
                     }
221
 
                     else {
222
 
                        label += pkg.name;
223
 
                     }
224
 
                     if( i != ( cmd.packages.count() - 1 ) ){
225
 
                        label += "<br>";
226
 
                     }
227
 
                }
 
225
                        packageString = "<ul>";
 
226
                        for (int i = 0; i < cmd.packages.count() ; ++i) {
 
227
                                Package pkg = cmd.packages.at(i);
 
228
                                if(!pkg.arguments.isEmpty()) {
 
229
                                        packageString += "<li>[" + pkg.arguments + ']' + pkg.name + "</li>";
 
230
                                }
 
231
                                else {
 
232
                                        packageString += "<li>" + pkg.name + "</li>";
 
233
                                }
 
234
                        }
 
235
                        packageString += "</ul>";
 
236
                }
 
237
                label += "<br/>" + i18np("Required Package: %2", "Required Packages: %2", cmd.packages.count(), packageString);
228
238
        }
229
239
 
230
240
        if(!cmd.comment.isEmpty()) {
231
 
           label += "<i>" + i18n("Comment: ") + cmd.comment + "</i>";
 
241
                label += "<br/><i>" + i18n("Comment: %1", Qt::escape(cmd.comment))  + "</i>";
232
242
        }
233
243
 
 
244
        label += "</p>";
234
245
        return label;
235
246
}
236
247
 
247
258
                math = event->modifiers() & Qt::ShiftModifier;
248
259
 
249
260
                extract(item->data(Qt::UserRole).toString(), cmd);
250
 
                if(KileConfig::symbolViewUTF8()){
251
 
                  code_symbol = cmd.unicodeCommand;
252
 
                  packages = cmd.unicodePackages;
 
261
                if(KileConfig::symbolViewUTF8()) {
 
262
                        code_symbol = cmd.unicodeCommand;
 
263
                        if(code_symbol.isEmpty()) {
 
264
                                code_symbol = cmd.latexCommand;
 
265
                        }
 
266
                        packages = cmd.unicodePackages;
253
267
                }
254
 
                else{
255
 
                   code_symbol = cmd.latexCommand;
256
 
                   packages = cmd.packages;
 
268
                else {
 
269
                        code_symbol = cmd.latexCommand;
 
270
                        packages = cmd.packages;
257
271
                }
258
272
 
259
273
                if(math != bracket) {
262
276
                        }
263
277
                        else if(bracket) {
264
278
                                        code_symbol = '{' + code_symbol + '}';
265
 
                                }
 
279
                        }
266
280
                }
267
281
                emit(insertText(code_symbol, packages));
268
282
                emit(addToList(item));
 
283
                m_ki->focusEditor();
269
284
        }
270
285
 
271
286
        KILE_DEBUG() << "math is " << math << ", bracket is " << bracket << " and item->data(Qt::UserRole).toString() is " << (item ? item->data(Qt::UserRole).toString() : "");
272
287
}
273
288
 
274
 
QString convertLatin1StringtoUTF8(const QString &string ){
275
 
 
276
 
   if(string.isEmpty()){
277
 
      return QString();
278
 
   }
279
 
 
280
 
   QVector<uint> stringAsIntVector;
281
 
   QStringList stringList = string.split(',', QString::SkipEmptyParts);
282
 
 
283
 
   QStringList::const_iterator it;
284
 
   QString str;
285
 
   bool ok;
286
 
   int stringAsInt;
287
 
   for(it = stringList.constBegin(); it != stringList.constEnd(); it++) {
288
 
         str = *it;
289
 
         str.remove("U+");
290
 
         stringAsInt = str.toInt(&ok);
291
 
         if(!ok) {
292
 
            return QString();
293
 
         }
294
 
         stringAsIntVector.append(stringAsInt);
295
 
   }
296
 
   return QString::fromUcs4(stringAsIntVector.data(),stringAsIntVector.count());
297
 
 
 
289
QString convertLatin1StringtoUTF8(const QString &string)
 
290
{
 
291
        if(string.isEmpty()){
 
292
                return QString();
 
293
        }
 
294
 
 
295
        QVector<uint> stringAsIntVector;
 
296
        QStringList stringList = string.split(',', QString::SkipEmptyParts);
 
297
 
 
298
        QStringList::const_iterator it;
 
299
        QString str;
 
300
        bool ok;
 
301
        int stringAsInt;
 
302
        for(it = stringList.constBegin(); it != stringList.constEnd(); it++) {
 
303
                str = *it;
 
304
                str.remove("U+");
 
305
                stringAsInt = str.toInt(&ok);
 
306
                if(!ok) {
 
307
                        return QString();
 
308
                }
 
309
                stringAsIntVector.append(stringAsInt);
 
310
        }
 
311
 
 
312
        return QString::fromUcs4(stringAsIntVector.data(),stringAsIntVector.count());
298
313
}
299
314
 
300
315
void SymbolView::fillWidget(const QString& prefix)