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