Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/KoModeBox.cpp
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | 121 | { | |||
---|---|---|---|---|---|
125 | d->iconMode = (IconMode)cfg.readEntry("ModeBoxIconMode", (int)IconAndText); | 125 | d->iconMode = (IconMode)cfg.readEntry("ModeBoxIconMode", (int)IconAndText); | ||
126 | d->verticalTabsSide = (VerticalTabsSide)cfg.readEntry("ModeBoxVerticalTabsSide", (int)TopSide); | 126 | d->verticalTabsSide = (VerticalTabsSide)cfg.readEntry("ModeBoxVerticalTabsSide", (int)TopSide); | ||
127 | d->horizontalTabsSide = (HorizontalTabsSide)cfg.readEntry("ModeBoxHorizontalTabsSide", (int)LeftSide); | 127 | d->horizontalTabsSide = (HorizontalTabsSide)cfg.readEntry("ModeBoxHorizontalTabsSide", (int)LeftSide); | ||
128 | 128 | | |||
129 | d->layout = new QGridLayout(); | 129 | d->layout = new QGridLayout(); | ||
130 | d->stack = new QStackedWidget(); | 130 | d->stack = new QStackedWidget(); | ||
131 | 131 | | |||
132 | d->tabBar = new QTabBar(); | 132 | d->tabBar = new QTabBar(); | ||
133 | d->tabBar->setExpanding(false); | 133 | | ||
134 | if (d->iconMode == IconAndText) { | | |||
135 | if (d->horizontalMode) { | | |||
136 | d->tabBar->setIconSize(QSize(38,32)); | | |||
137 | } else { | | |||
138 | d->tabBar->setIconSize(QSize(32,64)); | | |||
139 | } | | |||
140 | } else { | | |||
141 | d->tabBar->setIconSize(QSize(22,22)); | 134 | d->tabBar->setIconSize(QSize(22,22)); | ||
142 | } | | |||
143 | d->tabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | | |||
144 | if (d->horizontalMode) { | 135 | if (d->horizontalMode) { | ||
136 | d->tabBar->setExpanding(true); | ||||
145 | switchTabsSide(d->verticalTabsSide); | 137 | switchTabsSide(d->verticalTabsSide); | ||
146 | } else { | 138 | } else { | ||
139 | d->tabBar->setExpanding(false); | ||||
140 | if (d->iconMode == IconAndText) { | ||||
141 | d->tabBar->setIconSize(QSize(32,64)); | ||||
142 | } | ||||
147 | switchTabsSide(d->horizontalTabsSide); | 143 | switchTabsSide(d->horizontalTabsSide); | ||
148 | } | 144 | } | ||
145 | | ||||
146 | d->tabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | ||||
149 | d->layout->addWidget(d->stack, 0, 1); | 147 | d->layout->addWidget(d->stack, 0, 1); | ||
150 | 148 | | |||
151 | d->layout->setContentsMargins(0,0,0,0); | 149 | d->layout->setContentsMargins(0,0,0,0); | ||
152 | setLayout(d->layout); | 150 | setLayout(d->layout); | ||
153 | 151 | | |||
154 | foreach(KoToolAction *toolAction, KoToolManager::instance()->toolActionList()) { | 152 | foreach(KoToolAction *toolAction, KoToolManager::instance()->toolActionList()) { | ||
155 | addToolAction(toolAction); | 153 | addToolAction(toolAction); | ||
156 | } | 154 | } | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 201 | case Qt::RightDockWidgetArea: | |||
208 | d->layout->setRowStretch(1, 0); | 206 | d->layout->setRowStretch(1, 0); | ||
209 | break; | 207 | break; | ||
210 | default: | 208 | default: | ||
211 | break; | 209 | break; | ||
212 | } | 210 | } | ||
213 | d->layout->setSizeConstraint(QLayout::SetMinAndMaxSize); | 211 | d->layout->setSizeConstraint(QLayout::SetMinAndMaxSize); | ||
214 | d->layout->invalidate(); | 212 | d->layout->invalidate(); | ||
215 | 213 | | |||
216 | if (d->iconMode == IconAndText) { | | |||
217 | if (d->horizontalMode) { | | |||
218 | d->tabBar->setIconSize(QSize(42,32)); | | |||
219 | } else { | | |||
220 | d->tabBar->setIconSize(QSize(32,64)); | | |||
221 | } | | |||
222 | } else { | | |||
223 | d->tabBar->setIconSize(QSize(22,22)); | 214 | d->tabBar->setIconSize(QSize(22,22)); | ||
224 | } | | |||
225 | | ||||
226 | if (d->horizontalMode) { | 215 | if (d->horizontalMode) { | ||
216 | d->tabBar->setExpanding(true); | ||||
227 | switchTabsSide(d->verticalTabsSide); | 217 | switchTabsSide(d->verticalTabsSide); | ||
228 | } else { | 218 | } else { | ||
219 | d->tabBar->setExpanding(false); | ||||
220 | if (d->iconMode == IconAndText) { | ||||
221 | d->tabBar->setIconSize(QSize(32,64)); | ||||
222 | } | ||||
229 | switchTabsSide(d->horizontalTabsSide); | 223 | switchTabsSide(d->horizontalTabsSide); | ||
230 | } | 224 | } | ||
231 | } | 225 | } | ||
232 | 226 | | |||
233 | void KoModeBox::setActiveTool(KoCanvasController *canvas, int id) | 227 | void KoModeBox::setActiveTool(KoCanvasController *canvas, int id) | ||
234 | { | 228 | { | ||
235 | if (canvas->canvas() == d->canvas) { | 229 | if (canvas->canvas() == d->canvas) { | ||
236 | // Clear the minimumSize instigated by the previous tool | 230 | // Clear the minimumSize instigated by the previous tool | ||
Show All 17 Lines | |||||
254 | } | 248 | } | ||
255 | d->tabBar->blockSignals(false); | 249 | d->tabBar->blockSignals(false); | ||
256 | return; | 250 | return; | ||
257 | } | 251 | } | ||
258 | } | 252 | } | ||
259 | 253 | | |||
260 | QIcon KoModeBox::createTextIcon(KoToolAction *toolAction) const | 254 | QIcon KoModeBox::createTextIcon(KoToolAction *toolAction) const | ||
261 | { | 255 | { | ||
256 | assert(!d->horizontalMode); | ||||
257 | | ||||
262 | QSize iconSize = d->tabBar->iconSize(); | 258 | QSize iconSize = d->tabBar->iconSize(); | ||
263 | QFont smallFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); | 259 | QFont smallFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); | ||
264 | qreal pointSize = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF(); | 260 | qreal pointSize = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF(); | ||
265 | smallFont.setPointSizeF(pointSize); | 261 | smallFont.setPointSizeF(pointSize); | ||
266 | // This must be a QImage, as drawing to a QPixmap outside the | 262 | // This must be a QImage, as drawing to a QPixmap outside the | ||
267 | // UI thread will cause sporadic crashes. | 263 | // UI thread will cause sporadic crashes. | ||
268 | QImage pm(iconSize, QImage::Format_ARGB32_Premultiplied); | 264 | QImage pm(iconSize, QImage::Format_ARGB32_Premultiplied); | ||
269 | pm.fill(Qt::transparent); | 265 | pm.fill(Qt::transparent); | ||
270 | QPainter p(&pm); | 266 | QPainter p(&pm); | ||
271 | if (!d->horizontalMode) { | | |||
272 | if (d->horizontalTabsSide == LeftSide ) { | 267 | if (d->horizontalTabsSide == LeftSide ) { | ||
273 | p.rotate(90); | 268 | p.rotate(90); | ||
274 | p.translate(0,-iconSize.width()); | 269 | p.translate(0,-iconSize.width()); | ||
275 | } else { | 270 | } else { | ||
276 | p.rotate(-90); | 271 | p.rotate(-90); | ||
277 | p.translate(-iconSize.height(),0); | 272 | p.translate(-iconSize.height(),0); | ||
278 | } | 273 | } | ||
279 | } | | |||
280 | 274 | | |||
281 | QIcon::fromTheme(toolAction->iconName()).paint(&p, 0, 0, iconSize.height(), 22); | 275 | QIcon::fromTheme(toolAction->iconName()).paint(&p, 0, 0, iconSize.height(), 22); | ||
282 | 276 | | |||
283 | QTextLayout textLayout(toolAction->iconText(), smallFont, p.device()); | 277 | QTextLayout textLayout(toolAction->iconText(), smallFont, p.device()); | ||
284 | QTextOption option; | 278 | QTextOption option = QTextOption(Qt::AlignTop | Qt::AlignHCenter); | ||
285 | if (d->horizontalMode) { | | |||
286 | option = QTextOption(Qt::AlignVCenter | Qt::AlignHCenter); | | |||
287 | } else { | | |||
288 | option = QTextOption(Qt::AlignTop | Qt::AlignHCenter); | | |||
289 | } | | |||
290 | option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | 279 | option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | ||
291 | textLayout.setTextOption(option); | 280 | textLayout.setTextOption(option); | ||
292 | textLayout.beginLayout(); | 281 | textLayout.beginLayout(); | ||
293 | qreal height = 0; | 282 | qreal height = 0; | ||
294 | while (1) { | 283 | while (1) { | ||
295 | QTextLine line = textLayout.createLine(); | 284 | QTextLine line = textLayout.createLine(); | ||
296 | if (!line.isValid()) | 285 | if (!line.isValid()) | ||
297 | break; | 286 | break; | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 337 | { | |||
360 | widget = new QWidget(); | 349 | widget = new QWidget(); | ||
361 | widget->setLayout(layout); | 350 | widget->setLayout(layout); | ||
362 | layout->setContentsMargins(0,0,0,0); | 351 | layout->setContentsMargins(0,0,0,0); | ||
363 | layout->setSizeConstraint(QLayout::SetMinAndMaxSize); | 352 | layout->setSizeConstraint(QLayout::SetMinAndMaxSize); | ||
364 | d->addedWidgets[toolAction->buttonGroupId()] = widget; | 353 | d->addedWidgets[toolAction->buttonGroupId()] = widget; | ||
365 | 354 | | |||
366 | // Create a rotated icon with text | 355 | // Create a rotated icon with text | ||
367 | if (d->iconMode == IconAndText) { | 356 | if (d->iconMode == IconAndText) { | ||
357 | if (d->horizontalMode) { | ||||
358 | d->tabBar->addTab(QIcon::fromTheme(toolAction->iconName()), toolAction->iconText()); | ||||
359 | } else { | ||||
368 | d->tabBar->addTab(createTextIcon(toolAction), QString()); | 360 | d->tabBar->addTab(createTextIcon(toolAction), QString()); | ||
361 | } | ||||
369 | } else { | 362 | } else { | ||
370 | int index = d->tabBar->addTab(createSimpleIcon(toolAction), QString()); | 363 | int index = d->tabBar->addTab(createSimpleIcon(toolAction), QString()); | ||
371 | d->tabBar->setTabToolTip(index, toolAction->toolTip()); | 364 | d->tabBar->setTabToolTip(index, toolAction->toolTip()); | ||
372 | } | 365 | } | ||
373 | d->tabBar->blockSignals(false); | 366 | d->tabBar->blockSignals(false); | ||
374 | ScrollArea *sa = new ScrollArea(); | 367 | ScrollArea *sa = new ScrollArea(); | ||
375 | if (d->horizontalMode) { | 368 | if (d->horizontalMode) { | ||
376 | sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | 369 | sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |