File: xmltagslistwidget.cpp

package info (click to toggle)
texmaker 4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 42,664 kB
  • ctags: 7,065
  • sloc: cpp: 59,080; ansic: 4,120; xml: 1,660; sh: 59; makefile: 23
file content (113 lines) | stat: -rw-r--r-- 3,787 bytes parent folder | download | duplicates (3)
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
/***************************************************************************
 *   copyright       : (C) 2003-2009 by Pascal Brachet                     *
 *   http://www.xm1math.net/texmaker/                                      *
 *   inspired by the ktikz (GPL) program from Glad Deschrijver             *
 *                                                                         *
 *   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 option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "xmltagslistwidget.h"

#include <QListWidget>
#include <QFont>
#include <QColor>
#include <QDomDocument>
#include <QFile>
#include <QApplication>
#include <QFontDatabase>
#include <QDebug>

XmlTagsListWidget::XmlTagsListWidget(QWidget *parent, QString file):QListWidget(parent)
{
QFile tagsFile(file);
if (tagsFile.open(QFile::ReadOnly))
    {
    QDomDocument domDocument;
    if (domDocument.setContent(&tagsFile))
	{
	QDomElement root = domDocument.documentElement();
	if (root.tagName() == "texmakertags")
	    {
	    xmlSections=getTags(root);
	    for (int i = 0; i < xmlSections.children.size(); ++i)
		{
		addListWidgetItems(xmlSections.children.at(i));
		}
	    }
	}
    }
}

xmlTagList XmlTagsListWidget::getTags(const QDomElement &element)
{
xmlTag item;
xmlTagList tagList;
QList<xmlTag> tags;
tagList.title = element.attribute("title");
QDomElement child = element.firstChildElement("item");
QString txt, code, type;
while (!child.isNull())
    {
    code = child.attribute("tag");
    code.replace("\\\\", "\\");
    code.replace("&lt;", "<");
    code.replace("&gt;", ">");
    item.tag=code;
    txt = child.attribute("txt");
    if (txt!="")
      {
      txt.replace("\\\\", "\\");
      txt.replace("&lt;", "<");
      txt.replace("&gt;", ">");
      }
    else txt=code;
    item.txt=txt;
    item.dx=child.attribute("dx");
    item.dy=child.attribute("dy");
    item.type=child.attribute("type").toInt();
    tags << item;
    child = child.nextSiblingElement("item");
    }
tagList.tags=tags;
QDomElement section = element.firstChildElement("section");
while (!section.isNull())
    {
    tagList.children << getTags(section);
    section = section.nextSiblingElement("section");
    }
return tagList;
}

void XmlTagsListWidget::addListWidgetItems(const xmlTagList &tagList)
{
QFont deft=QFont("DejaVu Sans Condensed",qApp->font().pointSize());
QFont titleFont = deft;//qApp->font();
titleFont.setBold(true);
QFont optionFont=deft;//qApp->font();
optionFont.setItalic(true);
QFont commandFont=deft;//qApp->font();
//QColor titleBg(QApplication::style()->standardPalette().color(QPalette::Normal, QPalette::Highlight));
//QColor titleFg(QApplication::style()->standardPalette().color(QPalette::Normal, QPalette::HighlightedText));
QColor titleBg("#447BCD");
QColor titleFg("#ffffff");
QListWidgetItem *item = new QListWidgetItem(this);
QString itemText = tagList.title;
item->setText(itemText);
item->setBackgroundColor(titleBg);
item->setTextColor(titleFg);
item->setFont(titleFont);
for (int i = 0; i < tagList.tags.size(); ++i)
    {
    QListWidgetItem *item = new QListWidgetItem(this);
    QString itemText = tagList.tags.at(i).txt;
    item->setText(itemText);
    QString role=tagList.tags.at(i).tag+"#"+tagList.tags.at(i).dx+"#"+tagList.tags.at(i).dy;
    item->setData(Qt::UserRole,role);
    if (tagList.tags.at(i).type==0) item->setFont(commandFont); 
    else item->setFont(optionFont);
    }
}