Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/KoToolBox.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 66 | public: | |||
---|---|---|---|---|---|
77 | QList<QToolButton*> buttons; | 77 | QList<QToolButton*> buttons; | ||
78 | QMap<QString, Section*> sections; | 78 | QMap<QString, Section*> sections; | ||
79 | KoToolBoxLayout *layout; | 79 | KoToolBoxLayout *layout; | ||
80 | QButtonGroup *buttonGroup; | 80 | QButtonGroup *buttonGroup; | ||
81 | QHash<QToolButton*, QString> visibilityCodes; | 81 | QHash<QToolButton*, QString> visibilityCodes; | ||
82 | bool floating; | 82 | bool floating; | ||
83 | QMap<QAction*,int> contextIconSizes; | 83 | QMap<QAction*,int> contextIconSizes; | ||
84 | QMenu* contextSize; | 84 | QMenu* contextSize; | ||
85 | Qt::Orientation orientation; | ||||
85 | }; | 86 | }; | ||
86 | 87 | | |||
87 | void KoToolBox::Private::addSection(Section *section, const QString &name) | 88 | void KoToolBox::Private::addSection(Section *section, const QString &name) | ||
88 | { | 89 | { | ||
89 | section->setName(name); | 90 | section->setName(name); | ||
90 | layout->addSection(section); | 91 | layout->addSection(section); | ||
91 | sections.insert(name, section); | 92 | sections.insert(name, section); | ||
92 | } | 93 | } | ||
Show All 19 Lines | 112 | connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)), | |||
112 | this, SLOT(setActiveTool(KoCanvasController*,int))); | 113 | this, SLOT(setActiveTool(KoCanvasController*,int))); | ||
113 | connect(KoToolManager::instance(), SIGNAL(currentLayerChanged(const KoCanvasController*,const KoShapeLayer*)), | 114 | connect(KoToolManager::instance(), SIGNAL(currentLayerChanged(const KoCanvasController*,const KoShapeLayer*)), | ||
114 | this, SLOT(setCurrentLayer(const KoCanvasController*,const KoShapeLayer*))); | 115 | this, SLOT(setCurrentLayer(const KoCanvasController*,const KoShapeLayer*))); | ||
115 | connect(KoToolManager::instance(), SIGNAL(toolCodesSelected(QList<QString>)), this, SLOT(setButtonsVisible(QList<QString>))); | 116 | connect(KoToolManager::instance(), SIGNAL(toolCodesSelected(QList<QString>)), this, SLOT(setButtonsVisible(QList<QString>))); | ||
116 | connect(KoToolManager::instance(), | 117 | connect(KoToolManager::instance(), | ||
117 | SIGNAL(addedTool(KoToolAction*,KoCanvasController*)), | 118 | SIGNAL(addedTool(KoToolAction*,KoCanvasController*)), | ||
118 | this, SLOT(toolAdded(KoToolAction*,KoCanvasController*))); | 119 | this, SLOT(toolAdded(KoToolAction*,KoCanvasController*))); | ||
119 | 120 | | |||
120 | QTimer::singleShot(0, this, SLOT(adjustToFit())); | | |||
121 | } | 121 | } | ||
122 | 122 | | |||
123 | KoToolBox::~KoToolBox() | 123 | KoToolBox::~KoToolBox() | ||
124 | { | 124 | { | ||
125 | delete d; | 125 | delete d; | ||
126 | } | 126 | } | ||
127 | 127 | | |||
128 | void KoToolBox::addButton(KoToolAction *toolAction) | 128 | void KoToolBox::addButton(KoToolAction *toolAction) | ||
129 | { | 129 | { | ||
130 | KoToolBoxButton *button = new KoToolBoxButton(toolAction, this); | 130 | KoToolBoxButton *button = new KoToolBoxButton(toolAction, this); | ||
131 | 131 | | |||
132 | d->buttons << button; | 132 | d->buttons << button; | ||
133 | 133 | | |||
134 | int toolbuttonSize = buttonSize(qApp->desktop()->screenNumber(this)); | 134 | int toolbuttonSize = buttonSize(qApp->desktop()->screenNumber(this)); | ||
135 | KConfigGroup cfg = KSharedConfig::openConfig()->group("KoToolBox"); | 135 | KConfigGroup cfg = KSharedConfig::openConfig()->group("KoToolBox"); | ||
136 | int iconSize = cfg.readEntry("iconSize", toolbuttonSize); | 136 | int iconSize = cfg.readEntry("iconSize", toolbuttonSize); | ||
137 | button->setIconSize(QSize(iconSize, iconSize)); | 137 | button->setIconSize(QSize(iconSize, iconSize)); | ||
138 | foreach (Section *section, d->sections) { | 138 | foreach (Section *section, d->sections) { | ||
anthonyfieroni: Revert. | |||||
139 | section->setButtonSize(QSize(iconSize + BUTTON_MARGIN, iconSize + BUTTON_MARGIN)); | 139 | section->setButtonSize(QSize(iconSize + BUTTON_MARGIN, iconSize + BUTTON_MARGIN)); | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | QString sectionToBeAddedTo; | 142 | QString sectionToBeAddedTo; | ||
143 | const QString section = toolAction->section(); | 143 | const QString section = toolAction->section(); | ||
144 | if (section.contains(qApp->applicationName())) { | 144 | if (section.contains(qApp->applicationName())) { | ||
145 | sectionToBeAddedTo = "main"; | 145 | sectionToBeAddedTo = "main"; | ||
146 | } else if (section.contains("main")) { | 146 | } else if (section.contains("main")) { | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 227 | while(iterator != sections.end()) { | |||
246 | } | 246 | } | ||
247 | 247 | | |||
248 | ++iterator; | 248 | ++iterator; | ||
249 | } | 249 | } | ||
250 | 250 | | |||
251 | painter.end(); | 251 | painter.end(); | ||
252 | } | 252 | } | ||
253 | 253 | | |||
254 | void KoToolBox::resizeEvent(QResizeEvent* event) | | |||
255 | { | | |||
256 | QWidget::resizeEvent(event); | | |||
257 | if (!d->floating) { | | |||
258 | setMinimumSize(layout()->minimumSize()); // This enforces the minimum size on the widget | | |||
259 | } | | |||
260 | } | | |||
261 | | ||||
262 | void KoToolBox::setOrientation(Qt::Orientation orientation) | 254 | void KoToolBox::setOrientation(Qt::Orientation orientation) | ||
263 | { | 255 | { | ||
256 | d->orientation = orientation; | ||||
264 | d->layout->setOrientation(orientation); | 257 | d->layout->setOrientation(orientation); | ||
265 | QTimer::singleShot(0, this, SLOT(update())); | 258 | QTimer::singleShot(0, this, SLOT(update())); | ||
266 | foreach(Section* section, d->sections) { | 259 | foreach(Section* section, d->sections) { | ||
267 | section->setOrientation(orientation); | 260 | section->setOrientation(orientation); | ||
268 | } | 261 | } | ||
269 | } | 262 | } | ||
270 | 263 | | |||
271 | void KoToolBox::setFloating(bool v) | 264 | void KoToolBox::setFloating(bool v) | ||
272 | { | 265 | { | ||
273 | setMinimumSize(QSize(1,1)); | | |||
274 | d->floating = v; | 266 | d->floating = v; | ||
275 | } | 267 | } | ||
276 | 268 | | |||
277 | void KoToolBox::toolAdded(KoToolAction *toolAction, KoCanvasController *canvas) | 269 | void KoToolBox::toolAdded(KoToolAction *toolAction, KoCanvasController *canvas) | ||
278 | { | 270 | { | ||
279 | Q_UNUSED(canvas); | 271 | Q_UNUSED(canvas); | ||
280 | addButton(toolAction); | 272 | addButton(toolAction); | ||
281 | setButtonsVisible(QList<QString>()); | 273 | setButtonsVisible(QList<QString>()); | ||
282 | 274 | | |||
283 | } | 275 | } | ||
284 | 276 | | |||
285 | void KoToolBox::adjustToFit() | | |||
286 | { | | |||
287 | int newWidth = width() - (width() % layout()->minimumSize().width()); | | |||
288 | if (newWidth != width() && newWidth >= layout()->minimumSize().width()) { | | |||
289 | setMaximumWidth(newWidth); | | |||
290 | QTimer::singleShot(0, this, SLOT(resizeUnlock())); | | |||
291 | } | | |||
292 | } | | |||
293 | | ||||
294 | void KoToolBox::resizeUnlock() | | |||
295 | { | | |||
296 | setMaximumWidth(QWIDGETSIZE_MAX); | | |||
297 | } | | |||
298 | | ||||
299 | void KoToolBox::slotContextIconSize() | 277 | void KoToolBox::slotContextIconSize() | ||
300 | { | 278 | { | ||
301 | QAction* action = qobject_cast<QAction*>(sender()); | 279 | QAction* action = qobject_cast<QAction*>(sender()); | ||
302 | if (action && d->contextIconSizes.contains(action)) { | 280 | if (action && d->contextIconSizes.contains(action)) { | ||
303 | const int iconSize = d->contextIconSizes.value(action); | 281 | const int iconSize = d->contextIconSizes.value(action); | ||
304 | 282 | | |||
305 | KConfigGroup cfg = KSharedConfig::openConfig()->group("KoToolBox"); | 283 | KConfigGroup cfg = KSharedConfig::openConfig()->group("KoToolBox"); | ||
306 | cfg.writeEntry("iconSize", iconSize); | 284 | cfg.writeEntry("iconSize", iconSize); | ||
307 | 285 | | |||
308 | foreach(QToolButton *button, d->buttons) { | 286 | foreach(QToolButton *button, d->buttons) { | ||
309 | button->setIconSize(QSize(iconSize, iconSize)); | 287 | button->setIconSize(QSize(iconSize, iconSize)); | ||
310 | } | 288 | } | ||
311 | 289 | | |||
312 | foreach(Section *section, d->sections) { | 290 | foreach(Section *section, d->sections) { | ||
anthonyfieroni: Mostly foreach do what you expect, revert. | |||||
313 | section->setButtonSize(QSize(iconSize + BUTTON_MARGIN, iconSize + BUTTON_MARGIN)); | 291 | section->setButtonSize(QSize(iconSize + BUTTON_MARGIN, iconSize + BUTTON_MARGIN)); | ||
314 | } | 292 | } | ||
315 | 293 | | |||
316 | } | 294 | } | ||
317 | | ||||
318 | adjustToFit(); | | |||
319 | } | 295 | } | ||
320 | 296 | | |||
321 | void KoToolBox::contextMenuEvent(QContextMenuEvent *event) | 297 | void KoToolBox::contextMenuEvent(QContextMenuEvent *event) | ||
322 | { | 298 | { | ||
323 | 299 | | |||
324 | int toolbuttonSize = buttonSize(qApp->desktop()->screenNumber(this)); | 300 | int toolbuttonSize = buttonSize(qApp->desktop()->screenNumber(this)); | ||
325 | 301 | | |||
326 | if (!d->contextSize) { | 302 | if (!d->contextSize) { | ||
Show All 24 Lines | 325 | while (it.hasNext()) { | |||
351 | if (it.value() == toolbuttonSize) { | 327 | if (it.value() == toolbuttonSize) { | ||
352 | it.key()->setChecked(true); | 328 | it.key()->setChecked(true); | ||
353 | break; | 329 | break; | ||
354 | } | 330 | } | ||
355 | } | 331 | } | ||
356 | 332 | | |||
357 | d->contextSize->exec(event->globalPos()); | 333 | d->contextSize->exec(event->globalPos()); | ||
358 | } | 334 | } | ||
335 | KoToolBoxLayout *KoToolBox::toolBoxLayout() const | ||||
336 | { | ||||
337 | return d->layout; | ||||
338 | } | ||||
339 | | ||||
340 | #include "moc_KoToolBoxScrollArea_p.cpp" |
Revert.