Changeset View
Changeset View
Standalone View
Standalone View
src/kedittoolbar.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
48 | #include "kactioncollection.h" | 48 | #include "kactioncollection.h" | ||
49 | #include "kxmlguifactory.h" | 49 | #include "kxmlguifactory.h" | ||
50 | #include "ktoolbar.h" | 50 | #include "ktoolbar.h" | ||
51 | 51 | | |||
52 | #include "ktoolbarhelper_p.h" | 52 | #include "ktoolbarhelper_p.h" | ||
53 | #include "../kxmlgui_version.h" | 53 | #include "../kxmlgui_version.h" | ||
54 | 54 | | |||
55 | static const char separatorstring[] = I18N_NOOP("--- separator ---"); | 55 | static const char separatorstring[] = I18N_NOOP("--- separator ---"); | ||
56 | static const char spacerstring[] = I18N_NOOP("--- expanding spacer ---"); | ||||
56 | 57 | | |||
57 | #define SEPARATORSTRING i18n(separatorstring) | 58 | #define SEPARATORSTRING i18n(separatorstring) | ||
59 | #define SPACERSTRING i18n(spacerstring) | ||||
58 | 60 | | |||
59 | //static const char *const s_XmlTypeToString[] = { "Shell", "Part", "Local", "Merged" }; | 61 | //static const char *const s_XmlTypeToString[] = { "Shell", "Part", "Local", "Merged" }; | ||
60 | 62 | | |||
61 | typedef QList<QDomElement> ToolBarList; | 63 | typedef QList<QDomElement> ToolBarList; | ||
62 | 64 | | |||
63 | namespace KDEPrivate | 65 | namespace KDEPrivate | ||
64 | { | 66 | { | ||
65 | 67 | | |||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | |||||
181 | { | 183 | { | ||
182 | public: | 184 | public: | ||
183 | ToolBarItem(QListWidget *parent, const QString &tag = QString(), const QString &name = QString(), const QString &statusText = QString()) | 185 | ToolBarItem(QListWidget *parent, const QString &tag = QString(), const QString &name = QString(), const QString &statusText = QString()) | ||
184 | : QListWidgetItem(parent), | 186 | : QListWidgetItem(parent), | ||
185 | m_internalTag(tag), | 187 | m_internalTag(tag), | ||
186 | m_internalName(name), | 188 | m_internalName(name), | ||
187 | m_statusText(statusText), | 189 | m_statusText(statusText), | ||
188 | m_isSeparator(false), | 190 | m_isSeparator(false), | ||
191 | m_isSpacer(false), | ||||
189 | m_isTextAlongsideIconHidden(false) | 192 | m_isTextAlongsideIconHidden(false) | ||
190 | { | 193 | { | ||
191 | // Drop between items, not onto items | 194 | // Drop between items, not onto items | ||
192 | setFlags((flags() | Qt::ItemIsDragEnabled) & ~Qt::ItemIsDropEnabled); | 195 | setFlags((flags() | Qt::ItemIsDragEnabled) & ~Qt::ItemIsDropEnabled); | ||
193 | } | 196 | } | ||
194 | 197 | | |||
195 | void setInternalTag(const QString &tag) | 198 | void setInternalTag(const QString &tag) | ||
196 | { | 199 | { | ||
197 | m_internalTag = tag; | 200 | m_internalTag = tag; | ||
198 | } | 201 | } | ||
199 | void setInternalName(const QString &name) | 202 | void setInternalName(const QString &name) | ||
200 | { | 203 | { | ||
201 | m_internalName = name; | 204 | m_internalName = name; | ||
202 | } | 205 | } | ||
203 | void setStatusText(const QString &text) | 206 | void setStatusText(const QString &text) | ||
204 | { | 207 | { | ||
205 | m_statusText = text; | 208 | m_statusText = text; | ||
206 | } | 209 | } | ||
207 | void setSeparator(bool sep) | 210 | void setSeparator(bool sep) | ||
208 | { | 211 | { | ||
209 | m_isSeparator = sep; | 212 | m_isSeparator = sep; | ||
210 | } | 213 | } | ||
214 | void setSpacer(bool spacer) | ||||
215 | { | ||||
216 | m_isSpacer = spacer; | ||||
217 | } | ||||
211 | void setTextAlongsideIconHidden(bool hidden) | 218 | void setTextAlongsideIconHidden(bool hidden) | ||
212 | { | 219 | { | ||
213 | m_isTextAlongsideIconHidden = hidden; | 220 | m_isTextAlongsideIconHidden = hidden; | ||
214 | } | 221 | } | ||
215 | QString internalTag() const | 222 | QString internalTag() const | ||
216 | { | 223 | { | ||
217 | return m_internalTag; | 224 | return m_internalTag; | ||
218 | } | 225 | } | ||
219 | QString internalName() const | 226 | QString internalName() const | ||
220 | { | 227 | { | ||
221 | return m_internalName; | 228 | return m_internalName; | ||
222 | } | 229 | } | ||
223 | QString statusText() const | 230 | QString statusText() const | ||
224 | { | 231 | { | ||
225 | return m_statusText; | 232 | return m_statusText; | ||
226 | } | 233 | } | ||
227 | bool isSeparator() const | 234 | bool isSeparator() const | ||
228 | { | 235 | { | ||
229 | return m_isSeparator; | 236 | return m_isSeparator; | ||
230 | } | 237 | } | ||
238 | bool isSpacer() const | ||||
239 | { | ||||
240 | return m_isSpacer; | ||||
241 | } | ||||
231 | bool isTextAlongsideIconHidden() const | 242 | bool isTextAlongsideIconHidden() const | ||
232 | { | 243 | { | ||
233 | return m_isTextAlongsideIconHidden; | 244 | return m_isTextAlongsideIconHidden; | ||
234 | } | 245 | } | ||
235 | 246 | | |||
236 | int index() const | 247 | int index() const | ||
237 | { | 248 | { | ||
238 | return listWidget()->row(const_cast<ToolBarItem *>(this)); | 249 | return listWidget()->row(const_cast<ToolBarItem *>(this)); | ||
239 | } | 250 | } | ||
240 | 251 | | |||
241 | private: | 252 | private: | ||
242 | QString m_internalTag; | 253 | QString m_internalTag; | ||
243 | QString m_internalName; | 254 | QString m_internalName; | ||
244 | QString m_statusText; | 255 | QString m_statusText; | ||
245 | bool m_isSeparator; | 256 | bool m_isSeparator; | ||
257 | bool m_isSpacer; | ||||
246 | bool m_isTextAlongsideIconHidden; | 258 | bool m_isTextAlongsideIconHidden; | ||
247 | }; | 259 | }; | ||
248 | 260 | | |||
249 | static QDataStream &operator<< (QDataStream &s, const ToolBarItem &item) | 261 | static QDataStream &operator<< (QDataStream &s, const ToolBarItem &item) | ||
250 | { | 262 | { | ||
251 | s << item.internalTag(); | 263 | s << item.internalTag(); | ||
252 | s << item.internalName(); | 264 | s << item.internalName(); | ||
253 | s << item.statusText(); | 265 | s << item.statusText(); | ||
254 | s << item.isSeparator(); | 266 | s << item.isSeparator(); | ||
267 | s << item.isSpacer(); | ||||
255 | s << item.isTextAlongsideIconHidden(); | 268 | s << item.isTextAlongsideIconHidden(); | ||
256 | return s; | 269 | return s; | ||
257 | } | 270 | } | ||
258 | static QDataStream &operator>> (QDataStream &s, ToolBarItem &item) | 271 | static QDataStream &operator>> (QDataStream &s, ToolBarItem &item) | ||
259 | { | 272 | { | ||
260 | QString internalTag; | 273 | QString internalTag; | ||
261 | s >> internalTag; | 274 | s >> internalTag; | ||
262 | item.setInternalTag(internalTag); | 275 | item.setInternalTag(internalTag); | ||
263 | QString internalName; | 276 | QString internalName; | ||
264 | s >> internalName; | 277 | s >> internalName; | ||
265 | item.setInternalName(internalName); | 278 | item.setInternalName(internalName); | ||
266 | QString statusText; | 279 | QString statusText; | ||
267 | s >> statusText; | 280 | s >> statusText; | ||
268 | item.setStatusText(statusText); | 281 | item.setStatusText(statusText); | ||
269 | bool sep; | 282 | bool sep; | ||
270 | s >> sep; | 283 | s >> sep; | ||
271 | item.setSeparator(sep); | 284 | item.setSeparator(sep); | ||
285 | bool spacer; | ||||
286 | s >> spacer; | ||||
287 | item.setSpacer(spacer); | ||||
272 | bool hidden; | 288 | bool hidden; | ||
273 | s >> hidden; | 289 | s >> hidden; | ||
274 | item.setTextAlongsideIconHidden(hidden); | 290 | item.setTextAlongsideIconHidden(hidden); | ||
275 | return s; | 291 | return s; | ||
276 | } | 292 | } | ||
277 | 293 | | |||
278 | //// | 294 | //// | ||
279 | 295 | | |||
▲ Show 20 Lines • Show All 888 Lines • ▼ Show 20 Line(s) | 1148 | { | |||
1168 | // we want to the specified item selected and its actions loaded | 1184 | // we want to the specified item selected and its actions loaded | ||
1169 | m_toolbarCombo->setCurrentIndex(defaultToolBarId); | 1185 | m_toolbarCombo->setCurrentIndex(defaultToolBarId); | ||
1170 | slotToolBarSelected(m_toolbarCombo->currentIndex()); | 1186 | slotToolBarSelected(m_toolbarCombo->currentIndex()); | ||
1171 | } | 1187 | } | ||
1172 | 1188 | | |||
1173 | void KEditToolBarWidgetPrivate::loadActions(const QDomElement &elem) | 1189 | void KEditToolBarWidgetPrivate::loadActions(const QDomElement &elem) | ||
1174 | { | 1190 | { | ||
1175 | const QLatin1String tagSeparator("Separator"); | 1191 | const QLatin1String tagSeparator("Separator"); | ||
1192 | const QLatin1String tagSpacer("Spacer"); | ||||
1176 | const QLatin1String tagMerge("Merge"); | 1193 | const QLatin1String tagMerge("Merge"); | ||
1177 | const QLatin1String tagActionList("ActionList"); | 1194 | const QLatin1String tagActionList("ActionList"); | ||
1178 | const QLatin1String tagAction("Action"); | 1195 | const QLatin1String tagAction("Action"); | ||
1179 | const QLatin1String attrName("name"); | 1196 | const QLatin1String attrName("name"); | ||
1180 | 1197 | | |||
1181 | int sep_num = 0; | 1198 | int sep_num = 0; | ||
1182 | QString sep_name(QStringLiteral("separator_%1")); | 1199 | QString sep_name(QStringLiteral("separator_%1")); | ||
1200 | int spacer_num = 0; | ||||
1201 | QString spacer_name(QStringLiteral("spacer_%1")); | ||||
1183 | 1202 | | |||
1184 | // clear our lists | 1203 | // clear our lists | ||
1185 | m_inactiveList->clear(); | 1204 | m_inactiveList->clear(); | ||
1186 | m_activeList->clear(); | 1205 | m_activeList->clear(); | ||
1187 | m_insertAction->setEnabled(false); | 1206 | m_insertAction->setEnabled(false); | ||
1188 | m_removeAction->setEnabled(false); | 1207 | m_removeAction->setEnabled(false); | ||
1189 | m_upAction->setEnabled(false); | 1208 | m_upAction->setEnabled(false); | ||
1190 | m_downAction->setEnabled(false); | 1209 | m_downAction->setEnabled(false); | ||
Show All 16 Lines | 1222 | for (; !n.isNull(); n = n.nextSibling()) { | |||
1207 | } | 1226 | } | ||
1208 | if (it.tagName() == tagSeparator) { | 1227 | if (it.tagName() == tagSeparator) { | ||
1209 | ToolBarItem *act = new ToolBarItem(m_activeList, tagSeparator, sep_name.arg(sep_num++), QString()); | 1228 | ToolBarItem *act = new ToolBarItem(m_activeList, tagSeparator, sep_name.arg(sep_num++), QString()); | ||
1210 | act->setSeparator(true); | 1229 | act->setSeparator(true); | ||
1211 | act->setText(SEPARATORSTRING); | 1230 | act->setText(SEPARATORSTRING); | ||
1212 | it.setAttribute(attrName, act->internalName()); | 1231 | it.setAttribute(attrName, act->internalName()); | ||
1213 | continue; | 1232 | continue; | ||
1214 | } | 1233 | } | ||
1234 | if (it.tagName() == tagSpacer) { | ||||
1235 | ToolBarItem *act = new ToolBarItem(m_activeList, tagSpacer, spacer_name.arg(spacer_num++), QString()); | ||||
1236 | act->setSpacer(true); | ||||
1237 | act->setText(SPACERSTRING); | ||||
1238 | it.setAttribute(attrName, act->internalName()); | ||||
1239 | continue; | ||||
1240 | } | ||||
1215 | 1241 | | |||
1216 | if (it.tagName() == tagMerge) { | 1242 | if (it.tagName() == tagMerge) { | ||
1217 | // Merge can be named or not - use the name if there is one | 1243 | // Merge can be named or not - use the name if there is one | ||
1218 | QString name = it.attribute(attrName); | 1244 | QString name = it.attribute(attrName); | ||
1219 | ToolBarItem *act = new ToolBarItem(m_activeList, tagMerge, name, i18n("This element will be replaced with all the elements of an embedded component.")); | 1245 | ToolBarItem *act = new ToolBarItem(m_activeList, tagMerge, name, i18n("This element will be replaced with all the elements of an embedded component.")); | ||
1220 | if (name.isEmpty()) { | 1246 | if (name.isEmpty()) { | ||
1221 | act->setText(i18n("<Merge>")); | 1247 | act->setText(i18n("<Merge>")); | ||
1222 | } else { | 1248 | } else { | ||
Show All 35 Lines | 1279 | foreach (QAction *action, actionCollection->actions()) { | |||
1258 | 1284 | | |||
1259 | ToolBarItem *act = new ToolBarItem(m_inactiveList, tagAction, action->objectName(), action->toolTip()); | 1285 | ToolBarItem *act = new ToolBarItem(m_inactiveList, tagAction, action->objectName(), action->toolTip()); | ||
1260 | act->setText(nameFilter.subs(KLocalizedString::removeAcceleratorMarker(action->text())).toString()); | 1286 | act->setText(nameFilter.subs(KLocalizedString::removeAcceleratorMarker(action->text())).toString()); | ||
1261 | act->setIcon(!action->icon().isNull() ? action->icon() : m_emptyIcon); | 1287 | act->setIcon(!action->icon().isNull() ? action->icon() : m_emptyIcon); | ||
1262 | } | 1288 | } | ||
1263 | 1289 | | |||
1264 | m_inactiveList->sortItems(Qt::AscendingOrder); | 1290 | m_inactiveList->sortItems(Qt::AscendingOrder); | ||
1265 | 1291 | | |||
1266 | // finally, add default separators to the inactive list | 1292 | // finally, add default separators and spacers to the inactive list | ||
1267 | ToolBarItem *act = new ToolBarItem(nullptr, tagSeparator, sep_name.arg(sep_num++), QString()); | 1293 | ToolBarItem *sep = new ToolBarItem(nullptr, tagSeparator, sep_name.arg(sep_num++), QString()); | ||
1268 | act->setSeparator(true); | 1294 | sep->setSeparator(true); | ||
1269 | act->setText(SEPARATORSTRING); | 1295 | sep->setText(SEPARATORSTRING); | ||
1270 | m_inactiveList->insertItem(0, act); | 1296 | m_inactiveList->insertItem(0, sep); | ||
1297 | | ||||
1298 | ToolBarItem *spacer = new ToolBarItem(nullptr, tagSpacer, spacer_name.arg(spacer_num++), QString()); | ||||
1299 | spacer->setSpacer(true); | ||||
1300 | spacer->setText(SPACERSTRING); | ||||
1301 | m_inactiveList->insertItem(1, spacer); | ||||
1271 | } | 1302 | } | ||
1272 | 1303 | | |||
1273 | KActionCollection *KEditToolBarWidget::actionCollection() const | 1304 | KActionCollection *KEditToolBarWidget::actionCollection() const | ||
1274 | { | 1305 | { | ||
1275 | return d->m_collection; | 1306 | return d->m_collection; | ||
1276 | } | 1307 | } | ||
1277 | 1308 | | |||
1278 | void KEditToolBarWidgetPrivate::slotToolBarSelected(int index) | 1309 | void KEditToolBarWidgetPrivate::slotToolBarSelected(int index) | ||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | |||||
1395 | 1426 | | |||
1396 | void KEditToolBarWidgetPrivate::insertActive(ToolBarItem *item, ToolBarItem *before, bool prepend) | 1427 | void KEditToolBarWidgetPrivate::insertActive(ToolBarItem *item, ToolBarItem *before, bool prepend) | ||
1397 | { | 1428 | { | ||
1398 | if (!item) { | 1429 | if (!item) { | ||
1399 | return; | 1430 | return; | ||
1400 | } | 1431 | } | ||
1401 | 1432 | | |||
1402 | QDomElement new_item; | 1433 | QDomElement new_item; | ||
1403 | // let's handle the separator specially | 1434 | // let's handle the separator and spacer specially | ||
1404 | if (item->isSeparator()) { | 1435 | if (item->isSeparator()) { | ||
1405 | new_item = m_widget->domDocument().createElement(QStringLiteral("Separator")); | 1436 | new_item = m_widget->domDocument().createElement(QStringLiteral("Separator")); | ||
1437 | } else if (item->isSpacer()) { | ||||
1438 | new_item = m_widget->domDocument().createElement(QStringLiteral("Spacer")); | ||||
1406 | } else { | 1439 | } else { | ||
1407 | new_item = m_widget->domDocument().createElement(QStringLiteral("Action")); | 1440 | new_item = m_widget->domDocument().createElement(QStringLiteral("Action")); | ||
1408 | } | 1441 | } | ||
1409 | 1442 | | |||
1410 | new_item.setAttribute(QStringLiteral("name"), item->internalName()); | 1443 | new_item.setAttribute(QStringLiteral("name"), item->internalName()); | ||
1411 | 1444 | | |||
1412 | Q_ASSERT(!m_currentToolBarElem.isNull()); | 1445 | Q_ASSERT(!m_currentToolBarElem.isNull()); | ||
1413 | 1446 | | |||
▲ Show 20 Lines • Show All 296 Lines • Show Last 20 Lines |