Commit 2ad5f905 authored by Stefano Bonicatti's avatar Stefano Bonicatti

Fix a crash due to incorrect zoom widget handling

Small refactor for the KisStatusBar so that now it owns its
StatusBarItems and provides methods to manage them.
parent 81fba7a3
......@@ -1172,6 +1172,7 @@ void KisMainWindow::setActiveView(KisView* view)
updateCaption();
actionCollection()->action("edit_undo")->setText(activeView()->undoAction()->text());
actionCollection()->action("edit_redo")->setText(activeView()->redoAction()->text());
d->viewManager->setCurrentView(view);
}
void KisMainWindow::dragEnterEvent(QDragEnterEvent *event)
......@@ -1915,7 +1916,6 @@ void KisMainWindow::setActiveSubWindow(QWidget *window)
KisView *view = qobject_cast<KisView *>(subwin->widget());
//dbgKrita << "\t" << view << activeView();
if (view && view != activeView()) {
d->viewManager->setCurrentView(view);
setActiveView(view);
}
d->activeSubWindow = subwin;
......
......@@ -118,9 +118,6 @@ public:
KisUndoStackAction *undo = 0;
KisUndoStackAction *redo = 0;
class StatusBarItem;
QList<StatusBarItem> statusBarItems; // Our statusbar items
bool inOperation; //in the middle of an operation (no screen refreshing)?
QPointer<KisDocument> document; // our KisDocument
......@@ -551,34 +548,6 @@ void KisView::setDocumentDeleted()
d->documentDeleted = true;
}
void KisView::addStatusBarItem(QWidget * widget, int stretch, bool permanent)
{
Private::StatusBarItem item(widget, stretch, permanent);
QStatusBar * sb = statusBar();
if (sb) {
item.ensureItemShown(sb);
}
d->statusBarItems.append(item);
}
void KisView::removeStatusBarItem(QWidget *widget)
{
QStatusBar *sb = statusBar();
int itemCount = d->statusBarItems.count();
for (int i = itemCount-1; i >= 0; --i) {
Private::StatusBarItem &sbItem = d->statusBarItems[i];
if (sbItem.widget() == widget) {
if (sb) {
sbItem.ensureItemHidden(sb);
}
d->statusBarItems.removeOne(sbItem);
break;
}
}
}
KoPageLayout KisView::pageLayout() const
{
return document()->pageLayout();
......
......@@ -127,64 +127,6 @@
#include "kis_signal_auto_connection.h"
#include "kis_icon_utils.h"
class StatusBarItem
{
public:
StatusBarItem() // for QValueList
: m_widget(0),
m_connected(false),
m_hidden(false) {}
StatusBarItem(QWidget * widget, int stretch, bool permanent)
: m_widget(widget),
m_stretch(stretch),
m_permanent(permanent),
m_connected(false),
m_hidden(false) {}
bool operator==(const StatusBarItem& rhs) {
return m_widget == rhs.m_widget;
}
bool operator!=(const StatusBarItem& rhs) {
return m_widget != rhs.m_widget;
}
QWidget * widget() const {
return m_widget;
}
void ensureItemShown(QStatusBar * sb) {
Q_ASSERT(m_widget);
if (!m_connected) {
if (m_permanent)
sb->addPermanentWidget(m_widget, m_stretch);
else
sb->addWidget(m_widget, m_stretch);
if(!m_hidden)
m_widget->show();
m_connected = true;
}
}
void ensureItemHidden(QStatusBar * sb) {
if (m_connected && m_widget) {
m_hidden = m_widget->isHidden();
sb->removeWidget(m_widget);
m_widget->hide();
m_connected = false;
}
}
private:
QPointer<QWidget> m_widget;
int m_stretch;
bool m_permanent;
bool m_connected;
bool m_hidden;
};
class BlockingUserInputEventFilter : public QObject
{
bool eventFilter(QObject *watched, QEvent *event)
......@@ -278,7 +220,6 @@ public:
QPointer<KisView> currentImageView;
KisCanvasResourceProvider canvasResourceProvider;
KoCanvasResourceManager canvasResourceManager;
QVector<StatusBarItem> statusBarItems;
KisSignalCompressor guiUpdateCompressor;
KActionCollection *actionCollection;
KisMirrorManager mirrorManager;
......@@ -358,11 +299,19 @@ KActionCollection *KisViewManager::actionCollection() const
void KisViewManager::slotViewAdded(KisView *view)
{
d->inputManager.addTrackedCanvas(view->canvasBase());
if (viewCount() == 0) {
d->statusBar.showAllStatusBarItems();
}
}
void KisViewManager::slotViewRemoved(KisView *view)
{
d->inputManager.removeTrackedCanvas(view->canvasBase());
if (viewCount() == 0) {
d->statusBar.hideAllStatusBarItems();
}
}
void KisViewManager::setCurrentView(KisView *view)
......@@ -516,31 +465,14 @@ KisStatusBar * KisViewManager::statusBar() const
return &d->statusBar;
}
void KisViewManager::addStatusBarItem(QWidget * widget, int stretch, bool permanent)
void KisViewManager::addStatusBarItem(QWidget *widget, int stretch, bool permanent)
{
if (!mainWindow()) return;
StatusBarItem item(widget, stretch, permanent);
QStatusBar * sb = mainWindow()->statusBar();
if (sb) {
item.ensureItemShown(sb);
}
d->statusBarItems.append(item);
d->statusBar.addStatusBarItem(widget, stretch, permanent);
}
void KisViewManager::removeStatusBarItem(QWidget * widget)
void KisViewManager::removeStatusBarItem(QWidget *widget)
{
QStatusBar *sb = mainWindow()->statusBar();
int i = 0;
Q_FOREACH(const StatusBarItem& sbItem, d->statusBarItems) {
if (sbItem.widget() == widget) {
break;
}
i++;
}
d->statusBarItems[i].ensureItemHidden(sb);
d->statusBarItems.remove(i);
d->statusBar.removeStatusBarItem(widget);
}
KisPaintopBox* KisViewManager::paintOpBox() const
......
......@@ -56,9 +56,10 @@ enum {
POINTER_POSITION_ID
};
KisStatusBar::KisStatusBar(KisViewManager * view)
: m_view(view)
, m_imageView(0)
KisStatusBar::KisStatusBar(KisViewManager *view)
: m_view(view),
m_imageView(0),
m_statusBar(0)
{
}
......@@ -70,32 +71,39 @@ void KisStatusBar::setup()
m_selectionStatus->setEnabled(false);
updateSelectionIcon();
m_statusBar = m_view->mainWindow()->statusBar();
connect(m_selectionStatus, SIGNAL(clicked()), m_view->selectionManager(), SLOT(slotToggleSelectionDecoration()));
connect(m_view->selectionManager(), SIGNAL(displaySelectionChanged()), SLOT(updateSelectionToolTip()));
connect(m_view->mainWindow(), SIGNAL(themeChanged()), this, SLOT(updateSelectionIcon()));
m_view->addStatusBarItem(m_selectionStatus);
addStatusBarItem(m_selectionStatus);
m_selectionStatus->setVisible(false);
m_statusBarStatusLabel = new KSqueezedTextLabel();
m_statusBarStatusLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_statusBarStatusLabel->setContentsMargins(5, 5, 5, 5);
connect(KoToolManager::instance(), SIGNAL(changedStatusText(const QString &)),
m_statusBarStatusLabel, SLOT(setText(const QString &)));
m_view->addStatusBarItem(m_statusBarStatusLabel, 2);
addStatusBarItem(m_statusBarStatusLabel, 2);
m_statusBarStatusLabel->setVisible(false);
m_statusBarProfileLabel = new KSqueezedTextLabel();
m_statusBarProfileLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_statusBarProfileLabel->setContentsMargins(5, 5, 5, 5);
m_view->addStatusBarItem(m_statusBarProfileLabel, 3);
addStatusBarItem(m_statusBarProfileLabel, 3);
m_statusBarProfileLabel->setVisible(false);
m_progress = new KisProgressWidget();
m_view->addStatusBarItem(m_progress);
addStatusBarItem(m_progress);
m_progress->setVisible(false);
m_memoryReportBox = new QPushButton();
m_memoryReportBox->setFlat(true);
m_memoryReportBox->setContentsMargins(5, 5, 5, 5);
m_memoryReportBox->setMinimumWidth(120);
m_view->addStatusBarItem(m_memoryReportBox);
addStatusBarItem(m_memoryReportBox);
m_memoryReportBox->setVisible(false);
connect(m_memoryReportBox, SIGNAL(clicked()), SLOT(showMemoryInfoToolTip()));
......@@ -103,7 +111,7 @@ void KisStatusBar::setup()
m_pointerPositionLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_pointerPositionLabel->setMinimumWidth(100);
m_pointerPositionLabel->setContentsMargins(5,5, 5, 5);
m_view->addStatusBarItem(m_pointerPositionLabel);
addStatusBarItem(m_pointerPositionLabel);
m_pointerPositionLabel->setVisible(false);
connect(KisMemoryStatisticsServer::instance(),
......@@ -122,7 +130,8 @@ void KisStatusBar::setView(QPointer<KisView> imageView)
}
if (m_imageView) {
m_imageView->disconnect(this);
m_view->removeStatusBarItem(m_imageView->zoomManager()->zoomActionWidget());
removeStatusBarItem(m_imageView->zoomManager()->zoomActionWidget());
m_imageView = 0;
}
if (imageView) {
......@@ -135,12 +144,58 @@ void KisStatusBar::setView(QPointer<KisView> imageView)
connect(m_imageView, SIGNAL(sigSizeChanged(const QPointF&, const QPointF&)),
this, SLOT(imageSizeChanged()));
updateStatusBarProfileLabel();
m_view->addStatusBarItem(m_imageView->zoomManager()->zoomActionWidget());
addStatusBarItem(m_imageView->zoomManager()->zoomActionWidget());
}
imageSizeChanged();
}
void KisStatusBar::addStatusBarItem(QWidget *widget, int stretch, bool permanent)
{
StatusBarItem sbItem(widget);
if (permanent) {
m_statusBar->addPermanentWidget(widget, stretch);
}
else {
m_statusBar->addWidget(widget, stretch);
}
sbItem.show();
m_statusBarItems.append(sbItem);
}
void KisStatusBar::removeStatusBarItem(QWidget *widget)
{
int i = 0;
Q_FOREACH(const StatusBarItem& sbItem, m_statusBarItems) {
if (sbItem.widget() == widget) {
break;
}
i++;
}
if (i < m_statusBarItems.count()) {
m_statusBar->removeWidget(m_statusBarItems[i].widget());
m_statusBarItems.remove(i);
}
}
void KisStatusBar::hideAllStatusBarItems()
{
Q_FOREACH(const StatusBarItem& sbItem, m_statusBarItems) {
sbItem.hide();
}
}
void KisStatusBar::showAllStatusBarItems()
{
Q_FOREACH(const StatusBarItem& sbItem, m_statusBarItems) {
sbItem.show();
}
}
void KisStatusBar::documentMousePositionChanged(const QPointF &pos)
{
if (!m_imageView) return;
......
......@@ -22,6 +22,7 @@
#include <QObject>
#include <QPointer>
#include <QIcon>
#include <QStatusBar>
#include <kis_types.h>
#include "KisView.h"
......@@ -37,15 +38,52 @@ class KisProgressWidget;
class KRITAUI_EXPORT KisStatusBar : public QObject
{
class StatusBarItem
{
public:
StatusBarItem() // for QValueList
: m_widget(0) {}
StatusBarItem(QWidget * widget)
: m_widget(widget) {}
bool operator==(const StatusBarItem& rhs) {
return m_widget == rhs.m_widget;
}
bool operator!=(const StatusBarItem& rhs) {
return m_widget != rhs.m_widget;
}
QWidget * widget() const {
return m_widget;
}
void show() const {
m_widget->show();
}
void hide() const {
m_widget->hide();
}
private:
QPointer<QWidget> m_widget;
};
Q_OBJECT
public:
KisStatusBar(KisViewManager * view);
KisStatusBar(KisViewManager *view);
~KisStatusBar();
void setup();
void setView(QPointer<KisView> imageView);
void addStatusBarItem(QWidget *widget, int stretch = 0, bool permanent = false);
void removeStatusBarItem(QWidget *widget);
void hideAllStatusBarItems();
void showAllStatusBarItems();
KisProgressWidget *progress();
......@@ -70,6 +108,7 @@ private:
QPointer<KisViewManager> m_view;
QPointer<KisView> m_imageView;
QPointer<QStatusBar> m_statusBar;
KisProgressWidget * m_progress;
QToolButton *m_selectionStatus;
......@@ -83,6 +122,8 @@ private:
QString m_shortMemoryTag;
QString m_longMemoryTag;
QIcon m_memoryStatusIcon;
QVector<StatusBarItem> m_statusBarItems;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment