File indexing completed on 2024-05-12 16:37:14
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org> 0003 * Copyright (C) 2008-2010 Thomas Zander <zander@kde.org> 0004 * Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA 0020 */ 0021 0022 #include "KWStatusBar.h" 0023 #include "KWView.h" 0024 #include "KWDocument.h" 0025 #include "frames/KWTextFrameSet.h" 0026 0027 #include <KoCanvasBase.h> 0028 #include <KoToolManager.h> 0029 #include <KoCanvasControllerWidget.h> 0030 #include <KoZoomController.h> 0031 #include <KoTextDocument.h> 0032 #include <KoTextEditor.h> 0033 #include <KoTextDocumentLayout.h> 0034 #include <KoTextLayoutRootArea.h> 0035 0036 #include <QStackedWidget> 0037 #include <QLabel> 0038 #include <QStatusBar> 0039 #include <QLineEdit> 0040 #include <QIntValidator> 0041 #include <QToolButton> 0042 #include <QTimer> 0043 #include <QAction> 0044 0045 #include <ksqueezedtextlabel.h> 0046 #include <klocalizedstring.h> 0047 0048 const KLocalizedString i18nModified = ki18n("Modified"); 0049 const KLocalizedString i18nSaved = ki18n("Saved"); 0050 const KLocalizedString i18nPage = ki18n("Page %1 of %2"); 0051 const KLocalizedString i18nPageRange = ki18n("Page %1-%2 of %3"); 0052 const KLocalizedString i18nLine = ki18n("Line %1"); 0053 0054 #define KWSTATUSBAR "KWStatusBarPointer" 0055 0056 class KWStatusBarBaseItem : public QStackedWidget 0057 { 0058 public: 0059 QLabel *m_label; 0060 QWidget *m_widget; 0061 KWStatusBarBaseItem(QWidget *parent = 0) : QStackedWidget(parent), m_widget(0) 0062 { 0063 #ifdef Q_WS_MAC 0064 setAttribute(Qt::WA_MacMiniSize, true); 0065 #endif 0066 m_label = new QLabel(this); 0067 addWidget(m_label); 0068 } 0069 protected: 0070 void enterEvent(QEvent*) override 0071 { 0072 setCurrentIndex(1); 0073 } 0074 void leaveEvent(QEvent*) override 0075 { 0076 if (m_widget) { 0077 if (m_widget->hasFocus()) { 0078 m_widget->installEventFilter(this); 0079 } else { 0080 setCurrentIndex(0); 0081 m_widget->removeEventFilter(this); 0082 } 0083 } 0084 } 0085 bool eventFilter(QObject *watched, QEvent *event) override 0086 { 0087 if (watched == m_widget && event->type() == QEvent::FocusOut && !m_widget->hasFocus()) { 0088 setCurrentIndex(0); 0089 m_widget->removeEventFilter(this); 0090 } 0091 return false; 0092 } 0093 }; 0094 0095 class KWStatusBarEditItem : public KWStatusBarBaseItem 0096 { 0097 public: 0098 QLineEdit *m_edit; 0099 KWStatusBarEditItem(QWidget *parent = 0) : KWStatusBarBaseItem(parent) 0100 { 0101 m_edit = new QLineEdit(this); 0102 m_edit->setValidator(new QIntValidator(m_edit)); 0103 m_edit->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 0104 m_widget = m_edit; 0105 addWidget(m_widget); 0106 } 0107 }; 0108 0109 class KWStatusBarButtonItem : public KWStatusBarBaseItem 0110 { 0111 public: 0112 QToolButton *m_button; 0113 KWStatusBarButtonItem(QWidget *parent = 0) : KWStatusBarBaseItem(parent) 0114 { 0115 m_button = new QToolButton(this); 0116 m_widget = m_button; 0117 addWidget(m_widget); 0118 } 0119 }; 0120 0121 KWStatusBar::KWStatusBar(QStatusBar *statusBar, KWView *view) 0122 : QObject(statusBar), 0123 m_statusbar(statusBar), 0124 m_controller(0), 0125 m_currentPageNumber(0) 0126 { 0127 KWDocument *document = view->kwdocument(); 0128 m_statusbar->setContextMenuPolicy(Qt::ActionsContextMenu); 0129 0130 m_pageLabel = new KWStatusBarEditItem(); 0131 m_pageLabel->setFixedWidth(QFontMetrics(m_pageLabel->m_label->font()).width(i18nPageRange.subs("9999").subs("9999").subs("9999").toString())); 0132 m_statusbar->addWidget(m_pageLabel); 0133 m_pageLabel->setVisible(document->config().statusBarShowPage()); 0134 connect(m_pageLabel->m_edit, SIGNAL(returnPressed()), this, SLOT(gotoPage())); 0135 connect(document, SIGNAL(pageSetupChanged()), this, SLOT(updatePageCount())); 0136 0137 QAction *action = new QAction(i18n("Page Number"), this); 0138 action->setObjectName("pages_current_total"); 0139 action->setCheckable(true); 0140 action->setChecked(document->config().statusBarShowPage()); 0141 m_statusbar->addAction(action); 0142 connect(action, SIGNAL(toggled(bool)), this, SLOT(showPage(bool))); 0143 0144 m_lineLabel = new KWStatusBarEditItem(); 0145 m_lineLabel->setFixedWidth(QFontMetrics(m_lineLabel->m_label->font()).width(i18nLine.subs("999999").toString())); 0146 m_statusbar->addWidget(m_lineLabel); 0147 connect(m_lineLabel->m_edit, SIGNAL(returnPressed()), this, SLOT(gotoLine())); 0148 m_lineLabel->setVisible(document->config().statusBarShowLineNumber()); 0149 0150 action = new QAction(i18n("Line Number"), this); 0151 action->setObjectName("textcursor_position"); 0152 action->setCheckable(true); 0153 action->setChecked(document->config().statusBarShowLineNumber()); 0154 m_statusbar->addAction(action); 0155 connect(action, SIGNAL(toggled(bool)), this, SLOT(showLineColumn(bool))); 0156 0157 m_pageStyleLabel = new KWStatusBarButtonItem(); 0158 QFontMetrics psfm(m_pageStyleLabel->m_label->font()); 0159 m_pageStyleLabel->setFixedWidth(psfm.width(I18N_NOOP("Standard")) * 2.5); 0160 m_pageStyleLabel->m_button->setMinimumHeight(psfm.height()); 0161 m_pageStyleLabel->m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 0162 m_statusbar->addWidget(m_pageStyleLabel); 0163 connect(m_pageStyleLabel->m_button, SIGNAL(clicked()), this, SLOT(showPageStyle())); 0164 connect(document, SIGNAL(pageSetupChanged()), this, SLOT(updatePageStyle())); 0165 m_pageStyleLabel->setVisible(document->config().statusBarShowPageStyle()); 0166 0167 action = new QAction(i18n("Page Style"), this); 0168 action->setObjectName("pagestyle_current_name"); 0169 action->setCheckable(true); 0170 action->setChecked(document->config().statusBarShowPageStyle()); 0171 m_statusbar->addAction(action); 0172 connect(action, SIGNAL(toggled(bool)), this, SLOT(showPageStyle(bool))); 0173 0174 m_pageSizeLabel = new QLabel(); 0175 m_pageSizeLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 0176 m_pageSizeLabel->setMinimumWidth(QFontMetrics(m_pageSizeLabel->font()).width("99999x99999")); 0177 m_statusbar->addWidget(m_pageSizeLabel); 0178 m_pageSizeLabel->setVisible(document->config().statusBarShowPageSize()); 0179 connect(document, SIGNAL(pageSetupChanged()), this, SLOT(updatePageSize())); 0180 0181 action = new QAction(i18n("Page Size"), this); 0182 action->setObjectName("pagestyle_current_size"); 0183 action->setCheckable(true); 0184 action->setChecked(document->config().statusBarShowPageSize()); 0185 m_statusbar->addAction(action); 0186 connect(action, SIGNAL(toggled(bool)), this, SLOT(showPageSize(bool))); 0187 0188 m_modifiedLabel = new QLabel(m_statusbar); 0189 m_modifiedLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 0190 QFontMetrics modfm(m_modifiedLabel->font()); 0191 m_modifiedLabel->setMinimumWidth(qMax(modfm.width(i18nModified.toString()), modfm.width(i18nSaved.toString()))); 0192 m_statusbar->addWidget(m_modifiedLabel); 0193 m_modifiedLabel->setVisible(document->config().statusBarShowModified()); 0194 connect(document, SIGNAL(modified(bool)), this, SLOT(setModified(bool))); 0195 0196 action = new QAction(i18n("Saved/Modified"), this); 0197 action->setObjectName("doc_save_state"); 0198 action->setCheckable(true); 0199 action->setChecked(document->config().statusBarShowModified()); 0200 m_statusbar->addAction(action); 0201 connect(action, SIGNAL(toggled(bool)), this, SLOT(showModified(bool))); 0202 0203 m_mousePosLabel = new QLabel(m_statusbar); 0204 m_mousePosLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 0205 m_mousePosLabel->setMinimumWidth(QFontMetrics(m_mousePosLabel->font()).width("99999:99999")); 0206 m_statusbar->addWidget(m_mousePosLabel); 0207 m_mousePosLabel->setVisible(document->config().statusBarShowMouse()); 0208 0209 action = new QAction(i18n("Mouse Cursor X:Y"), this); 0210 action->setObjectName("mousecursor_position"); 0211 action->setCheckable(true); 0212 action->setChecked(document->config().statusBarShowMouse()); 0213 m_statusbar->addAction(action); 0214 connect(action, SIGNAL(toggled(bool)), this, SLOT(showMouse(bool))); 0215 0216 m_statusLabel = new KSqueezedTextLabel(m_statusbar); 0217 m_statusLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 0218 m_statusbar->addWidget(m_statusLabel, 1); 0219 connect(m_statusbar, SIGNAL(messageChanged(QString)), this, SLOT(setText(QString))); 0220 connect(KoToolManager::instance(), SIGNAL(changedStatusText(QString)), 0221 this, SLOT(setText(QString))); 0222 0223 m_zoomAction = new QAction(i18n("Zoom Controller"), this); 0224 m_zoomAction->setObjectName("zoom_controller"); 0225 m_zoomAction->setCheckable(true); 0226 m_zoomAction->setChecked(document->config().statusBarShowZoom()); 0227 m_statusbar->addAction(m_zoomAction); 0228 0229 updateCurrentTool(0); 0230 setCurrentView(view); 0231 connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)), 0232 this, SLOT(updateCurrentTool(KoCanvasController*))); 0233 } 0234 0235 KWStatusBar::~KWStatusBar() 0236 { 0237 // delete these as they are children of the statusBar but we want to delete them when the view disappears 0238 delete m_modifiedLabel; 0239 delete m_pageLabel; 0240 delete m_mousePosLabel; 0241 delete m_statusLabel; 0242 foreach (QWidget *widget, m_zoomWidgets) 0243 widget->deleteLater(); 0244 0245 m_statusbar->setProperty(KWSTATUSBAR, QVariant()); 0246 } 0247 0248 void KWStatusBar::setText(const QString &text) 0249 { 0250 m_statusLabel->setText(text); 0251 } 0252 0253 void KWStatusBar::setModified(bool modified) 0254 { 0255 m_modifiedLabel->setText(modified ? i18nModified.toString() : i18nSaved.toString()); 0256 } 0257 0258 void KWStatusBar::updatePageCount() 0259 { 0260 if (m_currentView) { 0261 if (m_currentView->minPageNumber() == m_currentView->maxPageNumber()) { 0262 m_pageLabel->m_label->setText(i18nPage.subs(m_currentView->minPageNumber()).subs(m_currentView->kwdocument()->pageCount()).toString()); 0263 } else { 0264 m_pageLabel->m_label->setText(i18nPageRange.subs(m_currentView->minPageNumber()).subs(m_currentView->maxPageNumber()).subs(m_currentView->kwdocument()->pageCount()).toString()); 0265 } 0266 m_pageLabel->m_edit->setText(QString::number(m_currentView->currentPage().pageNumber())); 0267 if (m_modifiedLabel->text().isEmpty()) 0268 setModified(m_currentView->kwdocument()->isModified()); 0269 } else { 0270 m_pageLabel->m_label->setText(i18nPage.toString()); 0271 m_pageLabel->m_edit->setText(QString()); 0272 m_modifiedLabel->setText(QString()); 0273 } 0274 } 0275 0276 void KWStatusBar::gotoPage(int pagenumber) 0277 { 0278 if (!m_currentView) 0279 return; 0280 if (pagenumber < 0) 0281 pagenumber = m_pageLabel->m_edit->text().toInt(); 0282 KWPage page = m_currentView->kwdocument()->pageManager()->page(pagenumber); 0283 if (!page.isValid()) 0284 return; 0285 m_currentView->canvasBase()->ensureVisible(page.rect()); 0286 } 0287 0288 void KWStatusBar::updatePageStyle() 0289 { 0290 KWPage page = m_currentView ? m_currentView->currentPage() : KWPage(); 0291 QString name = (page.isValid() && page.pageStyle().isValid() 0292 ? page.pageStyle().displayName() 0293 : QString()); 0294 m_pageStyleLabel->m_label->setText(name); 0295 m_pageStyleLabel->m_button->setText(name); 0296 } 0297 0298 void KWStatusBar::showPageStyle() 0299 { 0300 if (m_currentView) 0301 m_currentView->formatPage(); 0302 } 0303 0304 void KWStatusBar::updatePageSize() 0305 { 0306 KWPage page = m_currentView ? m_currentView->currentPage() : KWPage(); 0307 QString text; 0308 if (page.isValid() && page.pageStyle().isValid()) { 0309 KoPageLayout l = page.pageStyle().pageLayout(); 0310 QLocale locale; 0311 text = QString::fromLatin1("%1x%2").arg(locale.toString(l.width, 'f', 0), locale.toString(l.height, 'f', 0)); 0312 } 0313 m_pageSizeLabel->setText(text); 0314 } 0315 0316 void KWStatusBar::updateCursorPosition() 0317 { 0318 int line = 1; 0319 KWTextFrameSet *fs = m_currentView ? m_currentView->kwdocument()->mainFrameSet() : 0; 0320 KoTextEditor *editor = fs ? KoTextDocument(fs->document()).textEditor() : 0; 0321 if (editor) { 0322 line = editor->block().firstLineNumber(); 0323 int posInDoc = editor->position() - editor->block().position(); 0324 line += editor->block().layout()->lineForTextPosition(posInDoc).lineNumber() + 1; 0325 } 0326 m_lineLabel->m_label->setText(i18nLine.subs(line).toString()); 0327 m_lineLabel->m_edit->setText(QString::number(line)); 0328 } 0329 0330 void KWStatusBar::gotoLine() 0331 { 0332 if (!m_currentView) 0333 return; 0334 int linenumber = m_lineLabel->m_edit->text().toInt(); 0335 KWTextFrameSet *fs = m_currentView->kwdocument()->mainFrameSet(); 0336 QTextBlock block = fs ? fs->document()->findBlockByLineNumber(linenumber) : QTextBlock(); 0337 if (!block.isValid()) 0338 return; 0339 KoTextDocumentLayout *lay = dynamic_cast<KoTextDocumentLayout*>(fs->document()->documentLayout()); 0340 Q_ASSERT(lay); 0341 KoTextLayoutRootArea *area = lay->rootAreaForPosition(block.position()); 0342 if (!area) 0343 return; 0344 gotoPage(area->page()->pageNumber()); 0345 //m_currentView->canvasBase()->ensureVisible(block.layout()->boundingRect()); 0346 } 0347 0348 void KWStatusBar::updateMousePosition(const QPoint &pos) 0349 { 0350 if (m_mousePosLabel->isVisible()) 0351 m_mousePosLabel->setText(QString("%1:%2").arg(pos.x()).arg(pos.y())); 0352 } 0353 0354 void KWStatusBar::canvasResourceChanged(int key, const QVariant &value) 0355 { 0356 Q_UNUSED(value); 0357 if (key == KoCanvasResourceManager::CurrentPage) { 0358 updateCursorPosition(); 0359 updatePageStyle(); 0360 updatePageSize(); 0361 } 0362 } 0363 0364 void KWStatusBar::updateCurrentTool(KoCanvasController *canvasController) 0365 { 0366 KoCanvasControllerWidget *widget = dynamic_cast<KoCanvasControllerWidget*>(canvasController); 0367 if (!widget) { 0368 return; 0369 } 0370 QWidget *root = m_statusbar->window(); 0371 if (root && !root->isAncestorOf(widget)) 0372 return; // ignore tool changes in other mainWindows 0373 0374 if (m_controller) { 0375 disconnect(m_controller, SIGNAL(canvasMousePositionChanged(QPoint)), 0376 this, SLOT(updateMousePosition(QPoint))); 0377 } 0378 m_controller = canvasController->proxyObject; 0379 if (canvasController) { 0380 // find KWView parent of the canvas controller widget 0381 KWView *view = 0; 0382 QWidget *parent = widget->parentWidget(); 0383 while (view == 0 && parent != 0) { 0384 view = dynamic_cast<KWView*>(parent); 0385 if (!view) { 0386 parent = parent->parentWidget(); 0387 } 0388 } 0389 if (view) { 0390 setCurrentView(view); 0391 } 0392 connect(m_controller, SIGNAL(canvasMousePositionChanged(QPoint)), this, 0393 SLOT(updateMousePosition(QPoint))); 0394 } else { 0395 m_mousePosLabel->setText(QString()); 0396 } 0397 } 0398 0399 void KWStatusBar::setCurrentView(KWView *view) 0400 { 0401 if (view == 0) { 0402 m_currentView = 0; 0403 return; 0404 } else if (view == m_currentView) { 0405 return; 0406 } else if (view->canvasBase() == 0 ) { 0407 return; 0408 } 0409 0410 if (m_currentView) { 0411 KoCanvasBase *const canvas = m_currentView->canvasBase(); 0412 Q_ASSERT(canvas); 0413 KoCanvasResourceManager *resourceManager = canvas->resourceManager(); 0414 Q_ASSERT(resourceManager); 0415 disconnect(resourceManager, SIGNAL(canvasResourceChanged(int,QVariant)), 0416 this, SLOT(canvasResourceChanged(int,QVariant))); 0417 QWidget *zoomWidget = m_zoomWidgets.value(m_currentView); 0418 if (zoomWidget) { 0419 m_statusbar->removeWidget(zoomWidget); 0420 disconnect(m_zoomAction, SIGNAL(toggled(bool)), this, SLOT(showZoom(bool))); 0421 } 0422 0423 KWTextFrameSet *fs = m_currentView->kwdocument()->mainFrameSet(); 0424 if (fs) { 0425 KoTextDocument doc(fs->document()); 0426 KoTextEditor *editor = doc.textEditor(); 0427 if (editor) { 0428 disconnect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); 0429 } 0430 } 0431 disconnect(m_currentView, SIGNAL(shownPagesChanged()), this, SLOT(updatePageCount())); 0432 } 0433 0434 m_currentView = view; 0435 0436 updatePageCount(); 0437 updateCursorPosition(); 0438 updatePageStyle(); 0439 updatePageSize(); 0440 0441 if (m_currentView == 0) 0442 return; 0443 0444 QWidget *zoomWidget = m_zoomWidgets.value(m_currentView); 0445 if (zoomWidget) { 0446 m_statusbar->addWidget(zoomWidget); 0447 connect(m_zoomAction, SIGNAL(toggled(bool)), this, SLOT(showZoom(bool))); 0448 zoomWidget->setVisible(m_currentView->kwdocument()->config().statusBarShowZoom()); 0449 } else { 0450 createZoomWidget(); 0451 } 0452 0453 KoCanvasResourceManager *resourceManager = view->canvasBase()->resourceManager(); 0454 Q_ASSERT(resourceManager); 0455 connect(resourceManager, SIGNAL(canvasResourceChanged(int,QVariant)), this, SLOT(canvasResourceChanged(int,QVariant)), Qt::QueuedConnection); 0456 0457 KWTextFrameSet *fs = m_currentView->kwdocument()->mainFrameSet(); 0458 if (fs) { 0459 KoTextDocument doc(fs->document()); 0460 KoTextEditor *editor = doc.textEditor(); 0461 if (editor) { 0462 connect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()), Qt::QueuedConnection); 0463 } 0464 } 0465 connect(m_currentView, SIGNAL(shownPagesChanged()), this, SLOT(updatePageCount())); 0466 } 0467 0468 void KWStatusBar::createZoomWidget() 0469 { 0470 if (m_currentView) { 0471 KoZoomController *zoomController = m_currentView->zoomController(); 0472 if (zoomController && !m_zoomWidgets.contains(m_currentView)) { 0473 QWidget *zoomWidget = zoomController->zoomAction()->createWidget(m_statusbar); 0474 m_zoomWidgets.insert(m_currentView, zoomWidget); 0475 m_statusbar->addWidget(zoomWidget); 0476 connect(m_zoomAction, SIGNAL(toggled(bool)), this, SLOT(showZoom(bool))); 0477 zoomWidget->setVisible(m_currentView->kwdocument()->config().statusBarShowZoom()); 0478 } 0479 } 0480 } 0481 0482 void KWStatusBar::showPage(bool visible) 0483 { 0484 Q_ASSERT(m_currentView); 0485 m_currentView->kwdocument()->config().setStatusBarShowPage(visible); 0486 m_pageLabel->setVisible(visible); 0487 } 0488 0489 void KWStatusBar::showPageStyle(bool visible) 0490 { 0491 Q_ASSERT(m_currentView); 0492 m_currentView->kwdocument()->config().setStatusBarShowPageStyle(visible); 0493 m_pageStyleLabel->setVisible(visible); 0494 } 0495 0496 void KWStatusBar::showPageSize(bool visible) 0497 { 0498 Q_ASSERT(m_currentView); 0499 m_currentView->kwdocument()->config().setStatusBarShowPageSize(visible); 0500 m_pageSizeLabel->setVisible(visible); 0501 } 0502 0503 void KWStatusBar::showLineColumn(bool visible) 0504 { 0505 Q_ASSERT(m_currentView); 0506 m_currentView->kwdocument()->config().setStatusBarShowLineNumber(visible); 0507 m_lineLabel->setVisible(visible); 0508 } 0509 0510 void KWStatusBar::showModified(bool visible) 0511 { 0512 Q_ASSERT(m_currentView); 0513 m_currentView->kwdocument()->config().setStatusBarShowModified(visible); 0514 m_modifiedLabel->setVisible(visible); 0515 } 0516 0517 void KWStatusBar::showMouse(bool visible) 0518 { 0519 Q_ASSERT(m_currentView); 0520 m_currentView->kwdocument()->config().setStatusBarShowMouse(visible); 0521 m_mousePosLabel->setVisible(visible); 0522 } 0523 0524 void KWStatusBar::showZoom(bool visible) 0525 { 0526 Q_ASSERT(m_currentView); 0527 QWidget *zoomWidget = m_zoomWidgets.value(m_currentView); 0528 m_currentView->kwdocument()->config().setStatusBarShowZoom(visible); 0529 zoomWidget->setVisible(visible); 0530 } 0531 0532 void KWStatusBar::removeView(QObject *object) 0533 { 0534 KWView *view = static_cast<KWView*>(object); 0535 QWidget *widget = m_zoomWidgets.value(view); 0536 if (widget) { 0537 widget->deleteLater(); 0538 m_zoomWidgets.remove(view); 0539 } 0540 if (view == m_currentView) 0541 m_currentView = 0; 0542 } 0543 0544 //static 0545 void KWStatusBar::addViewControls(QStatusBar *statusBar, KWView *view) 0546 { 0547 /** 0548 * Life time of a KWStatusBar is tricky... 0549 * One main window has one QStatusBar. But it can be re-used by different 0550 * documents and thus by many different KWView instances. 0551 * So; open a document in a window creates a KWView. That creates a KWStatusBar 0552 * split the view creates a new KWView in the same mainwindow, this reuses 0553 * the already existing KWStatusBar 0554 * Create a new view (new MainWindow) also creates a new KWStatusBar 0555 * Close all your views (deletes all KWViews) but not your Mainwindow will 0556 * NOT destroy all KWStatusBar instance. Note that QStatusBar is not 0557 * destructed in that case either. 0558 */ 0559 0560 QVariant variant = statusBar->property(KWSTATUSBAR); 0561 if (variant.isValid()) { // already exists! 0562 KWStatusBar *decorator = static_cast<KWStatusBar*>(variant.value<void*>()); 0563 if (decorator) 0564 decorator->connect(view, SIGNAL(destroyed(QObject*)), SLOT(removeView(QObject*))); 0565 return; 0566 } 0567 KWStatusBar *decorator = new KWStatusBar(statusBar, view); 0568 decorator->connect(view, SIGNAL(destroyed(QObject*)), SLOT(removeView(QObject*))); 0569 variant.setValue<void*>(decorator); 0570 statusBar->setProperty(KWSTATUSBAR, variant); 0571 }