]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/BulletsModule.cpp
use "real" resources
[lyx.git] / src / frontends / qt4 / BulletsModule.cpp
1 /**
2  * \file BulletsModule.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "BulletsModule.h"
14 #include "qt_helpers.h"
15
16 #include <QPixmap>
17 #include <QPainter>
18
19
20 namespace lyx {
21
22 BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
23 {
24         setupUi(this);
25
26         for (int iter = 0; iter < 4; ++iter)
27                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
28
29         current_font_ = -1;
30         current_char_ = 0;
31
32         // add levels
33         levelLW->addItem("1");
34         levelLW->addItem("2");
35         levelLW->addItem("3");
36         levelLW->addItem("4");
37
38         // insert pixmaps
39         setupPanel(new QListWidget(bulletpaneSW), qt_("Standard[[Bullets]]"), "standard");
40         setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
41         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
42         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
43         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
44         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
45
46         connect(levelLW, SIGNAL(currentRowChanged(int)),
47                 this, SLOT(showLevel(int)));
48         connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
49                 SLOT(setCurrentIndex(int)));
50 }
51
52
53 void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
54         std::string const & fname)
55 {
56         connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
57                 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
58
59         // add panelname to combox
60         bulletpaneCO->addItem(panelname);
61
62         // get pixmap with bullets
63         QPixmap pixmap(":/images/" + toqstr(fname) + ".png");
64
65         int const w = pixmap.width() / 6;
66         int const h = pixmap.height() / 6;
67
68         // apply setting to listwidget
69         lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
70         lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
71         lw->setViewMode(QListView::IconMode);
72         lw->setFlow(QListView::LeftToRight);
73         lw->setMovement(QListView::Static);
74         lw->setUniformItemSizes(true);
75         lw->setGridSize(QSize(w, h));
76         // the widening by 21 is needed to avoid wrapping
77         lw->resize(6 * w + 21, 6 * h);
78         bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6);
79
80         // get individual bullets from pixmap
81         for (int row = 0; row < 6; ++row) {
82                 for (int col = 0; col < 6; ++col) {
83                         QPixmap small(w, h);
84                         small.fill();
85                         QPainter painter(&small);
86                         painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
87                         new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
88                 }
89         }
90
91         // add bulletpanel to stackedwidget
92         bulletpaneSW->addWidget(lw);
93 }
94
95
96 void BulletsModule::showLevel(int level)
97 {
98         // unselect previous item
99         selectItem(current_font_, current_char_, false);
100
101         current_font_ = bullets_[level].getFont();
102
103         if (bullets_[level].getFont() < 0) {
104                 customCB->setCheckState(Qt::Checked);
105                 customLE->setText(toqstr(bullets_[level].getText()));
106         } else {
107                 customCB->setCheckState(Qt::Unchecked);
108                 customLE->clear();
109                 current_char_ = bullets_[level].getCharacter();
110                 selectItem(current_font_, current_char_, true);
111                 bulletpaneCO->setCurrentIndex(current_font_);
112                 bulletpaneSW->setCurrentIndex(current_font_);
113         }
114         bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
115 }
116
117
118 void BulletsModule::init()
119 {
120         levelLW->setCurrentRow(0);
121         showLevel(0);
122 }
123
124
125 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
126 {
127         // unselect previous item
128         selectItem(current_font_, current_char_, false);
129
130         int const level = levelLW->currentRow();
131         bullets_[level].setCharacter(item->type());
132         bullets_[level].setFont(bulletpaneCO->currentIndex());
133         current_font_ = bulletpaneCO->currentIndex();
134         current_char_ = item->type();
135         changed();
136 }
137
138
139 void BulletsModule::on_customCB_clicked(bool custom)
140 {
141         if (!custom) {
142                 if (current_font_ < 0)
143                         current_font_ = bulletpaneCO->currentIndex();
144                 return;
145         }
146
147         // unselect previous item
148         selectItem(current_font_, current_char_, false);
149         current_font_ = -1;
150         changed();
151 }
152
153
154 void BulletsModule::selectItem(int font, int character, bool select)
155 {
156         if (font < 0)
157                 return;
158
159         QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
160         lw->setItemSelected(lw->item(character), select);
161 }
162
163
164 void BulletsModule::on_customLE_textEdited(const QString & text)
165 {
166         if (customCB->checkState() == Qt::Unchecked)
167                 return;
168
169         bullets_[levelLW->currentRow()].setFont(current_font_);
170         bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
171         changed();
172 }
173
174
175 void BulletsModule::on_bulletsizeCO_activated(int size)
176 {
177         // -1 apparently means default...
178         bullets_[levelLW->currentRow()].setSize(size - 1);
179 }
180
181
182 void BulletsModule::setBullet(int level, Bullet const & bullet)
183 {
184         bullets_[level] = bullet;
185 }
186
187
188 Bullet const & BulletsModule::getBullet(int level) const
189 {
190         return bullets_[level];
191 }
192
193 } // namespace lyx
194
195
196 #include "BulletsModule_moc.cpp"